From f7f760aaf02fe95487bef642a1c97c2dc1b7a19d Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Mon, 24 Jan 2022 09:12:56 +0200 Subject: [PATCH] Don't count minted coins in block stats Signed-off-by: Anthony Fieroni --- src/rpc/blockchain.cpp | 12 ++++++++++-- test/functional/feature_accounts_validation.py | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e6d506137d..e533e1a23e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1883,8 +1884,15 @@ static UniValue getblockstats(const JSONRPCRequest& request) CAmount tx_total_out = 0; if (loop_outputs) { - for (const CTxOut& out : tx->vout) { - tx_total_out += out.nValue; + auto mintingOutputsStart = ~0u; + if (auto accountToUtxos = GetAccountToUtxosMsg(*tx)) { + mintingOutputsStart = accountToUtxos->mintingOutputsStart; + } + for (size_t i = 0; i < tx->vout.size(); ++i) { + const auto& out = tx->vout[i]; + if (i < mintingOutputsStart) { + tx_total_out += out.nValue; + } utxo_size_inc += GetSerializeSize(out, PROTOCOL_VERSION) + PER_UTXO_OVERHEAD; } } diff --git a/test/functional/feature_accounts_validation.py b/test/functional/feature_accounts_validation.py index 7695738a96..5265d8a50d 100755 --- a/test/functional/feature_accounts_validation.py +++ b/test/functional/feature_accounts_validation.py @@ -46,6 +46,10 @@ def run_test(self): node.generate(1) self.sync_all() + stats = node.getblockstats(blockcount + 1) + assert_equal(stats["total_out"], 18199952120) + assert_equal(stats["totalfee"], 25880) + # Check the blockchain has extended as expected assert_equal(node1.getblockcount(), blockcount + 1)