Skip to content

Conversation

@polespinasa
Copy link
Member

@polespinasa polespinasa commented Aug 26, 2025

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": true,
  "background": {
    "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 and background validation is set to false:

$ ./build/bin/bitcoin-cli getblockchaininfo
...
  "mediantime": 1756245700,
  "verificationprogress": 1,
  "initialblockdownload": false,
  "backgroundvalidation": 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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 26, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33259.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK rogersala21
Concept ACK yuvicc, luke-jr, danielabrozzoni

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

@yuvicc
Copy link
Contributor

yuvicc commented Aug 27, 2025

Concept ACK

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK. Would be nice to test the active state.

@polespinasa
Copy link
Member Author

Would be nice to test the active state.

@luke-jr what do you mean by active state?

@bitcoin bitcoin deleted a comment from lucifermmmenriquejr Aug 27, 2025
@luke-jr
Copy link
Member

luke-jr commented Aug 27, 2025

When there is a background sync, not just false

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Aug 28, 2025
Github-Pull: bitcoin#33259
Rebased-From: c1f545248ea0966a3aad0d70fc4c317cd9611d3f
@ajtowns
Copy link
Contributor

ajtowns commented Aug 28, 2025

Would it be better to return an object, eg:

{
    "background": {
        "blocks": 100000,
        "bestblockhash": "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506",
        "mediantime": 1293622620,
        "chainwork": "0000000000000000000000000000000000000000000000000644cb7f5234089e"
        "verificationprogress": 0.001,
    }
    ...
}

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch 2 times, most recently from b9d3ccb to 8efdfa9 Compare August 28, 2025 02:31
@polespinasa
Copy link
Member Author

@ajtowns sgtm, done.
Not sure about the order thought... I'm open to suggestions.

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch 3 times, most recently from 17d9926 to fd504bb Compare August 28, 2025 20:57
@polespinasa
Copy link
Member Author

polespinasa commented Aug 28, 2025

2d48902999a7ad1fcf19a8e630c69d6228dbd373 added snapshot height

83a1721817fda4db88ba12e0395ed63ba064c41b modify the way verification progress is calculated for background validation -> context: #33259 (comment)

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch 2 times, most recently from f3ee351 to 2d48902 Compare August 28, 2025 21:15
@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch from 2d48902 to 01860ea Compare August 29, 2025 18:42
Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

I did a very rough first pass and the code looks good to me. As others have said, I would like to see a functional test testing the newly introduced fields when the background validation is in progress

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch from c31014d to a48d92a Compare September 3, 2025 22:06
@polespinasa
Copy link
Member Author

@danielabrozzoni @ajtowns @luke-jr

Tests implemented, not the cleanest way for sure, but I couldn't figure out anything simpler.
Open to suggestions :)

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch from a48d92a to 21fb4c9 Compare September 15, 2025 17:21
@polespinasa
Copy link
Member Author

21fb4c9 correct typos

@polespinasa polespinasa force-pushed the 2025-08-26-getblockchaininfo-backgroundvalidation branch from 21fb4c9 to ea37456 Compare December 21, 2025 13:27
@polespinasa
Copy link
Member Author

Rebased on top of master to solve conflicts with #30214

Copy link

@rogersala21 rogersala21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ea37456

Built from source, tested, and reviewed the code. New RPC fields behave as expected.

Without loading UTXO snapshot: backgroundvalidation=false

Details

bitcoin-cli getblockchaininfo
  ...
  "mediantime": 1231006505,
  "verificationprogress": 7.692763291753853e-10,
  "initialblockdownload": true,
  "backgroundvalidation": false,
  "chainwork": "0000000000000000000000000000000000000000000000000000000100010001",
  "size_on_disk": 293,
  "pruned": false,
  ...

With loadtxoutset: backgroundvalidation=true and background progress shown.

Details

bitcoin-cli getblockchaininfo
  ...
  "mediantime": 1737334898,
  "verificationprogress": 0.8812817484397629,
  "initialblockdownload": true,
  "backgroundvalidation": true,
  "background": {
    "snapshotheight": 880000,
    "blocks": 34031,
    "bestblockhash": "00000000b2d3088131445fb70bda85e90663c36a66d429a2089c05014b8aac2b",
    "mediantime": 1263124911,
    "chainwork": "000000000000000000000000000000000000000000000000000086355a943ee0",
    "verificationprogress": 2.990124328575242e-05
  },
  "chainwork": "0000000000000000000000000000000000000000a879619cfddf806d3bdf607b",
  "size_on_disk": 9569248,
  "pruned": false,
  ...

Left a few nits in comments.

auto historical_blocks{chainman.GetHistoricalBlockRange()};
bool background_sync = historical_blocks.has_value();
obj.pushKV("backgroundvalidation", background_sync);
if(historical_blocks) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after ifif (historical_blocks)

UniValue bValidation(UniValue::VOBJ);
const CBlockIndex& btip{*CHECK_NONFATAL(historical_blocks->first)};
const std::optional<int> bHeight{active_chainstate.SnapshotBase()->nHeight};
if(bHeight) bValidation.pushKV("snapshotheight", *bHeight);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after ifif (bHeight)

const CBlockIndex& btip{*CHECK_NONFATAL(historical_blocks->first)};
const std::optional<int> bHeight{active_chainstate.SnapshotBase()->nHeight};
if(bHeight) bValidation.pushKV("snapshotheight", *bHeight);
bValidation.pushKV("blocks",btip.nHeight);
Copy link

@rogersala21 rogersala21 Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing space after comma → bValidation.pushKV("blocks", btip.nHeight);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants