Merge bitcoin/bitcoin#33259: rpc, logging: add backgroundvalidation to getblockchaininfo

25f69d970a release note (Pol Espinasa)
af629821cf test: add background validation test for getblockchaininfo (Pol Espinasa)
a3d6f32a39 rpc, log: add backgroundvalidation to getblockchaininfo (Pol Espinasa)
5b2e4c4a88 log: update progress calculations for background validation (Pol Espinasa)

Pull request description:

  `getblockchaininfo` returns `verificationprogress=1` and `initialblockdownload=false` even if there's background validation.
  This PR adds information about background validation to rpc `getblockchaininfo` in a similar way to `validationprogress` does.

  If assume utxo was used the output of a "sync" node performing background validation:
  ```
  $ ./build/bin/bitcoin-cli getblockchaininfo
  ...
    "mediantime": 1756933740,
    "verificationprogress": 1,
    "initialblockdownload": false,
    "backgroundvalidation": {
      "snapshotheight": 880000,
      "blocks": 527589,
      "bestblockhash": "0000000000000000002326308420fa5ccd28a9155217f4d1896ab443d84148fa",
      "mediantime": 1529076654,
      "chainwork": "0000000000000000000000000000000000000000020c92fab9e5e1d8ed2d8dbc",
      "verificationprogress": 0.2815790617966284
    },
    "chainwork": "0000000000000000000000000000000000000000df97866c410b0302954919d2",
    "size_on_disk": 61198817285,

  ...
  ```

  If assume utxo was not used the progress is hidden:
  ```
  $ ./build/bin/bitcoin-cli getblockchaininfo
  ...
    "mediantime": 1756245700,
    "verificationprogress": 1,
    "initialblockdownload": false,
    "chainwork": "00000000000000000000000000000000000000000000000000000656d6bb052b",
    "size_on_disk": 3964972194,
  ...
  ```

  The PR also updates the way we estimate the verification progress returning a 100% on the snapshot block and not on the tip as we will stop doing background validation when reaching it.

ACKs for top commit:
  fjahr:
    ACK 25f69d970a
  danielabrozzoni:
    ACK 25f69d970a
  achow101:
    ACK 25f69d970a
  sedited:
    ACK 25f69d970a

Tree-SHA512: 5e5e08fd39af5f764962b862bc6d8257b0d2175fe920d4b79dc5105578fd4ebe08aee2fe9bfa5c9cad5d7610197a435ebaac0de23e7a5efa740dfea031a8a9d4
This commit is contained in:
Ava Chow
2026-03-24 14:36:09 -07:00
6 changed files with 81 additions and 8 deletions

View File

@@ -542,6 +542,30 @@ class AssumeutxoTest(BitcoinTestFramework):
assert_equal(utxo_info['height'], SNAPSHOT_BASE_HEIGHT)
assert_equal(utxo_info['bestblock'], snapshot_hash)
self.log.info("Check that getblockchaininfo returns information about the background validation process")
expected_keys = [
"snapshotheight",
"blocks",
"bestblockhash",
"mediantime",
"chainwork",
"verificationprogress"
]
res = n1.getblockchaininfo()
assert "backgroundvalidation" in res.keys()
bv_res = res["backgroundvalidation"]
assert_equal(sorted(expected_keys), sorted(bv_res.keys()))
assert_equal(bv_res["snapshotheight"], SNAPSHOT_BASE_HEIGHT)
assert_equal(bv_res["blocks"], START_HEIGHT)
assert_equal(bv_res["bestblockhash"], n1.getblockhash(START_HEIGHT))
block = n1.getblockheader(bv_res["bestblockhash"])
assert_equal(bv_res["mediantime"], block["mediantime"])
assert_equal(bv_res["chainwork"], block["chainwork"])
background_tx_count = n1.getchaintxstats(blockhash=bv_res["bestblockhash"])["txcount"]
snapshot_tx_count = n1.getchaintxstats(blockhash=snapshot_hash)["txcount"]
expected_verification_progress = background_tx_count / snapshot_tx_count
assert_approx(bv_res["verificationprogress"], expected_verification_progress, vspan=0.01)
# find coinbase output at snapshot height on node0 and scan for it on node1,
# where the block is not available, but the snapshot was loaded successfully
coinbase_tx = n0.getblock(snapshot_hash, verbosity=2)['tx'][0]

View File

@@ -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