From a3d6f32a396e6be2041c2877bf7e6b8dd757f9d2 Mon Sep 17 00:00:00 2001 From: Pol Espinasa Date: Wed, 27 Aug 2025 00:56:17 +0200 Subject: [PATCH] rpc, log: add backgroundvalidation to getblockchaininfo --- src/rpc/blockchain.cpp | 28 +++++++++++++++++++++++++--- test/functional/rpc_blockchain.py | 3 +++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5156f65813c..dc6473b9279 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1374,12 +1374,21 @@ RPCHelpMan getblockchaininfo() {RPCResult::Type::NUM, "headers", "the current number of headers we have validated"}, {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"}, {RPCResult::Type::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"}, - {RPCResult::Type::STR_HEX, "target", "The difficulty target"}, + {RPCResult::Type::STR_HEX, "target", "the difficulty target"}, {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, - {RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME}, - {RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME}, + {RPCResult::Type::NUM_TIME, "time", "the block time expressed in " + UNIX_EPOCH_TIME}, + {RPCResult::Type::NUM_TIME, "mediantime", "the median block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"}, {RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"}, + {RPCResult::Type::OBJ, "backgroundvalidation", /*optional=*/true, "state info regarding background validation process", + { + {RPCResult::Type::NUM, "snapshotheight", "the height of the snapshot block. Background validation verifies the chain from genesis up to this height"}, + {RPCResult::Type::NUM, "blocks", "the height of the most-work background fully-validated chain. The genesis block has height 0"}, + {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block validated in the background"}, + {RPCResult::Type::NUM_TIME, "mediantime", "the median block time expressed in " + UNIX_EPOCH_TIME}, + {RPCResult::Type::NUM, "verificationprogress", "estimate of background verification progress [0..1]"}, + {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in background validated chain, in hexadecimal"}, + }}, {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"}, {RPCResult::Type::NUM, "size_on_disk", "the estimated size of the block and undo files on disk"}, {RPCResult::Type::BOOL, "pruned", "if the blocks are subject to pruning"}, @@ -1420,6 +1429,19 @@ RPCHelpMan getblockchaininfo() obj.pushKV("mediantime", tip.GetMedianTimePast()); obj.pushKV("verificationprogress", chainman.GuessVerificationProgress(&tip)); obj.pushKV("initialblockdownload", chainman.IsInitialBlockDownload()); + auto historical_blocks{chainman.GetHistoricalBlockRange()}; + if (historical_blocks) { + UniValue background_validation(UniValue::VOBJ); + const CBlockIndex& btip{*CHECK_NONFATAL(historical_blocks->first)}; + const CBlockIndex& btarget{*CHECK_NONFATAL(historical_blocks->second)}; + background_validation.pushKV("snapshotheight", btarget.nHeight); + background_validation.pushKV("blocks", btip.nHeight); + background_validation.pushKV("bestblockhash", btip.GetBlockHash().GetHex()); + background_validation.pushKV("mediantime", btip.GetMedianTimePast()); + background_validation.pushKV("chainwork", btip.nChainWork.GetHex()); + background_validation.pushKV("verificationprogress", chainman.GetBackgroundVerificationProgress(btip)); + obj.pushKV("backgroundvalidation", std::move(background_validation)); + } obj.pushKV("chainwork", tip.nChainWork.GetHex()); obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage()); obj.pushKV("pruned", chainman.m_blockman.IsPruneMode()); diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index cecd0c03fac..18a67ce5abf 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -170,6 +170,9 @@ class BlockchainTest(BitcoinTestFramework): assert res['pruned'] assert not res['automatic_pruning'] + # check background validation is not present when we are not using assumeutxo + assert "backgroundvalidation" not in res.keys() + self.restart_node(0, ['-stopatheight=207']) res = self.nodes[0].getblockchaininfo() # should have exact keys