diff options
author | Carl Dong <contact@carldong.me> | 2022-02-13 19:27:36 -0500 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-05-20 16:33:24 -0400 |
commit | a789f3f2b878e1236f8e043a8bb1ffb1afc1b673 (patch) | |
tree | fe1d822cb8ea6b54d520ad06cb55850e6c5d8ce3 /src/node | |
parent | 102294898d708b7adc0150aba8e500a4aa19bc1c (diff) | |
download | bitcoin-a789f3f2b878e1236f8e043a8bb1ffb1afc1b673.tar.xz |
coinstats: Extract hash_type in-member to in-param
Currently, CCoinsStats is a struct with both in-params and out-params
where the hash_type and index_requested members are the only in-params.
This change removes CCoinsStats' hash_type in-param member and adds it
to the relevant functions instead.
[META] In subsequent commits, all of CCoinsStats' members which serve as
in-params will be moved out so as to make CCoinsStats a pure
out-param struct.
Diffstat (limited to 'src/node')
-rw-r--r-- | src/node/coinstats.cpp | 14 | ||||
-rw-r--r-- | src/node/coinstats.h | 7 |
2 files changed, 8 insertions, 13 deletions
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index eed43a1bc7..8d94e1bd36 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -93,7 +93,7 @@ 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, const CBlockIndex* pindex) +static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type) { std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); assert(pcursor); @@ -106,7 +106,7 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats.hashBlock = pindex->GetBlockHash(); // Use CoinStatsIndex if it is requested and 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.index_requested) { + if ((hash_type == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && stats.index_requested) { stats.index_used = true; return g_coin_stats_index->LookUpStats(pindex, stats); } @@ -144,19 +144,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, const CBlockIndex* pindex) +bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point, const CBlockIndex* pindex) { - switch (stats.m_hash_type) { + switch (hash_type) { case(CoinStatsHashType::HASH_SERIALIZED): { CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex); + return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex, hash_type); } case(CoinStatsHashType::MUHASH): { MuHash3072 muhash; - return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex); + return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex, hash_type); } case(CoinStatsHashType::NONE): { - return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex); + return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex, hash_type); } } // 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 aa771b18b0..ee3f3b0030 100644 --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -28,9 +28,6 @@ enum class CoinStatsHashType { }; struct CCoinsStats { - //! Which hash type to use - const CoinStatsHashType m_hash_type; - int nHeight{0}; uint256 hashBlock{}; uint64_t nTransactions{0}; @@ -69,12 +66,10 @@ struct CCoinsStats { CAmount total_unspendables_scripts{0}; //! Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block CAmount total_unspendables_unclaimed_rewards{0}; - - CCoinsStats(CoinStatsHashType hash_type) : m_hash_type(hash_type) {} }; //! Calculate statistics about the unspent transaction output set -bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr); +bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr); uint64_t GetBogoSize(const CScript& script_pub_key); |