diff --git a/src/node/coinstats.h b/src/node/coinstats.h --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -17,6 +17,7 @@ enum class CoinStatsHashType { HASH_SERIALIZED, + NONE, }; struct CCoinsStats { diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -38,6 +38,17 @@ ss << VARINT(0u); } +static void ApplyStats(CCoinsStats &stats, std::nullptr_t, const uint256 &hash, + const std::map &outputs) { + assert(!outputs.empty()); + stats.nTransactions++; + for (const auto &output : outputs) { + stats.nTransactionOutputs++; + stats.nTotalAmount += output.second.GetTxOut().nValue; + stats.nBogoSize += GetBogoSize(output.second.GetTxOut().scriptPubKey); + } +} + //! Calculate statistics about the unspent transaction output set template static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, @@ -91,6 +102,9 @@ CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); return GetUTXOStats(view, stats, ss, interruption_point); } + case (CoinStatsHashType::NONE): { + return GetUTXOStats(view, stats, nullptr, interruption_point); + } } // no default case, so the compiler can warn about missing cases assert(false); } @@ -99,7 +113,9 @@ static void PrepareHash(CHashWriter &ss, CCoinsStats &stats) { ss << stats.hashBlock; } +static void PrepareHash(std::nullptr_t, CCoinsStats &stats) {} static void FinalizeHash(CHashWriter &ss, CCoinsStats &stats) { stats.hashSerialized = ss.GetHash(); } +static void FinalizeHash(std::nullptr_t, CCoinsStats &stats) {} diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1183,7 +1183,7 @@ { {"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized", "Which UTXO set hash should be calculated. Options: " - "'hash_serialized' (the legacy algorithm)."}, + "'hash_serialized' (the legacy algorithm), 'none'."}, }, RPCResult{RPCResult::Type::OBJ, "", @@ -2897,7 +2897,7 @@ ::ChainstateActive().ForceFlushStateToDisk(); if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, - CoinStatsHashType::HASH_SERIALIZED, + CoinStatsHashType::NONE, node.rpc_interruption_point)) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set"); } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -144,6 +144,8 @@ if (hash_type_input == "hash_serialized") { return CoinStatsHashType::HASH_SERIALIZED; + } else if (hash_type_input == "none") { + return CoinStatsHashType::NONE; } else { throw JSONRPCError( RPC_INVALID_PARAMETER,