From df2b8b4bf663c1967793942bbd005ff5ceb1a7df Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 28 Apr 2026 19:30:21 +0200 Subject: [PATCH] rpc: fix incomplete range check in get_coinbase_tx_sum + update test --- src/rpc/core_rpc_server.cpp | 4 ++-- tests/functional_tests/blockchain.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index ed8b536d1..9719a67e8 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -3076,9 +3076,9 @@ namespace cryptonote { RPC_TRACKER(get_coinbase_tx_sum); const uint64_t bc_height = m_core.get_current_blockchain_height(); - if (req.height >= bc_height || req.count > bc_height) + if (req.height >= bc_height || req.count > bc_height - req.height) { - res.status = "height or count is too large"; + res.status = "requested range exceeds blockchain height"; return true; } CHECK_PAYMENT_MIN1(req, res, COST_PER_COINBASE_TX_SUM_BLOCK * req.count, false); diff --git a/tests/functional_tests/blockchain.py b/tests/functional_tests/blockchain.py index c1b610596..250489918 100755 --- a/tests/functional_tests/blockchain.py +++ b/tests/functional_tests/blockchain.py @@ -219,9 +219,12 @@ class BlockchainTest(): assert res.emission_amount < extrapolated and res.emission_amount > extrapolated - 1e12 assert res.fee_amount == 0 sum_blocks_emission = res.emission_amount - res = daemon.get_coinbase_tx_sum(1, sum_blocks) + res = daemon.get_coinbase_tx_sum(1, sum_blocks - 1) assert res.emission_amount == sum_blocks_emission - 17592186044415 assert res.fee_amount == 0 + # height + count must not exceed the blockchain height + res = daemon.get_coinbase_tx_sum(1, sum_blocks) + assert res.status != 'OK' res = daemon.get_output_distribution([0, 1, 17592186044415], 0, 0) assert len(res.distributions) == 3