diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2020-05-15 16:14:07 +0200 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2021-04-19 20:30:59 +0200 |
commit | 3f166ecc125fce6ccd995687fa16572090a5d099 (patch) | |
tree | 0110f1a8cea9495fbe3be5f0467a4e2bf0083633 /src/node | |
parent | 3c914d58ff323255b32e717d0ce28209ec0abdaa (diff) |
rpc: gettxoutsetinfo can be requested for specific blockheights
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/coinstats.cpp | 28 | ||||
-rw-r--r-- | src/node/coinstats.h | 4 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index dc9d32035d..eacd7e2ab5 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -89,22 +89,24 @@ static void ApplyStats(CCoinsStats& stats, const uint256& hash, const std::map<u //! Calculate statistics about the unspent transaction output set template <typename T> -static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point) +static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point, const CBlockIndex* pindex) { std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); assert(pcursor); - stats.hashBlock = pcursor->GetBestBlock(); - - const CBlockIndex* pindex; - { - LOCK(cs_main); - assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); - pindex = blockman.LookupBlockIndex(stats.hashBlock); - stats.nHeight = Assert(pindex)->nHeight; + + if (!pindex) { + { + LOCK(cs_main); + assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); + pindex = blockman.LookupBlockIndex(view->GetBestBlock()); + } } + stats.nHeight = Assert(pindex)->nHeight; + stats.hashBlock = pindex->GetBlockHash(); // Use CoinStatsIndex if it is available and a hash_type of Muhash or None was requested if ((stats.m_hash_type == CoinStatsHashType::MUHASH || stats.m_hash_type == CoinStatsHashType::NONE) && g_coin_stats_index) { + stats.from_index = true; return g_coin_stats_index->LookUpStats(pindex, stats); } @@ -141,19 +143,19 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& return true; } -bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point) +bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point, const CBlockIndex* pindex) { switch (stats.m_hash_type) { case(CoinStatsHashType::HASH_SERIALIZED): { CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - return GetUTXOStats(view, blockman, stats, ss, interruption_point); + return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex); } case(CoinStatsHashType::MUHASH): { MuHash3072 muhash; - return GetUTXOStats(view, blockman, stats, muhash, interruption_point); + return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex); } case(CoinStatsHashType::NONE): { - return GetUTXOStats(view, blockman, stats, nullptr, interruption_point); + return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex); } } // no default case, so the compiler can warn about missing cases assert(false); diff --git a/src/node/coinstats.h b/src/node/coinstats.h index 826df2fd73..e30b2778c5 100644 --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -39,11 +39,13 @@ struct CCoinsStats //! The number of coins contained. uint64_t coins_count{0}; + bool from_index{false}; + CCoinsStats(CoinStatsHashType hash_type) : m_hash_type(hash_type) {} }; //! Calculate statistics about the unspent transaction output set -bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}); +bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr); uint64_t GetBogoSize(const CScript& script_pub_key); |