validation: fix verification progress during IBD. #22804

pull klementtan wants to merge 1 commits into bitcoin:master from klementtan:verification_progress_fix changing 1 files +1 −1
  1. klementtan commented at 10:52 AM on August 26, 2021: contributor

    Description

    Motivation: Currently verificationprogress attribute of getblockchaininfo returns incorrect value(1.92338932716318e-06) during the headers synchronization phase of IBD. This PR fixes this by returning 0 instead of ...e-0x.

    <details> <summary>getblockchaininfo on master</summary>

    $ ./src/bitcoin-cli -signet getblockchaininfo                                                                                                                                                               
    {
      "chain": "signet",
      "blocks": 0,
      "headers": 32410,
      "bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
      "difficulty": 0.001126515290698186,
      "time": 1598918400,
      "mediantime": 1598918400,
      "verificationprogress": 1.921578597095376e-06,
      "initialblockdownload": true,
      "chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
      "size_on_disk": 17095548,
      "pruned": false,
      "softforks": {
        "bip34": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "bip66": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "bip65": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "csv": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "segwit": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "taproot": {
          "type": "bip9",
          "bip9": {
            "status": "active",
            "start_time": -1,
            "timeout": 9223372036854775807,
            "since": 0,
            "min_activation_height": 0
          },
          "height": 0,
          "active": true
        }
      },
      "warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
    }
    

    </details>

    <details> <summary>getblockchaininfo in this PR</summary>

    $ ./src/bitcoin-cli -signet getblockchaininfo                                                                                                                                                               
    {
      "chain": "signet",
      "blocks": 0,
      "headers": 21940,
      "bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
      "difficulty": 0.001126515290698186,
      "time": 1598918400,
      "mediantime": 1598918400,
      "verificationprogress": 0,
      "initialblockdownload": true,
      "chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
      "size_on_disk": 8546460,
      "pruned": false,
      "softforks": {
        "bip34": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "bip66": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "bip65": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "csv": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "segwit": {
          "type": "buried",
          "active": true,
          "height": 1
        },
        "taproot": {
          "type": "bip9",
          "bip9": {
            "status": "active",
            "start_time": -1,
            "timeout": 9223372036854775807,
            "since": 0,
            "min_activation_height": 0
          },
          "height": 0,
          "active": true
        }
      },
      "warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
    }
    

    </details>

    Conext:

    Changes:

    • This PR fixes the issue by returning 0.0 in GuessVerificationProgress option when nHeight == 0

    Reviewing

    Testing:

    You can test this by running bitconid with -reindex option and immediately running getblockchainfo afterward.

    $ ./src/bitcoind --daemon -signet -reindex
    $ ./src/bitcoin-cli -signet getblockchaininfo
    
  2. klementtan force-pushed on Aug 26, 2021
  3. fanquake added the label Validation on Aug 26, 2021
  4. theStack commented at 3:05 PM on August 26, 2021: member

    Concept ACK

  5. validation: fix verification progress during IBD. cdcf672bd8
  6. klementtan force-pushed on Aug 27, 2021
  7. klementtan renamed this:
    validation: GuessVerificationProgress returns 0 when no blocks downloaded
    validation: fix verification progress during IBD.
    on Aug 27, 2021
  8. theStack commented at 2:28 AM on September 5, 2021: member

    Note that the code line you mentioned is currently never executed in the codebase. It resides in ChainstateManager::PopulateAndValidateSnapshot, which is in turn called by ChainstateManager::ActivateSnapshot, which is not called anywhere (besides of fuzzing and unit tests). The value 1 for nChainTx simply results from the coinbase transaction of the genesis block that is embedded in the code (and hence already available before IBD starts). So in that sense one could argue that the calculation is actually not entirely wrong; the verification value is (hopefully) only used for statistical purposes anyways and if the progress value before IBD is zero or almost-zero doesn't matter that much.

    So with that in mind, I'm updating Concept ACK ~0 (neutral) on this, would love to hear others opinion on this.

  9. MarcoFalke commented at 9:35 AM on September 5, 2021: member

    Agree with @theStack

    If too much precision is an issue, it could make sense to round to the closest 1/10000 in the display.

  10. klementtan commented at 9:46 AM on September 5, 2021: contributor

    Thanks @theStack and @MarcoFalke for the review and insights!

    Will be closing this PR as GuessVerificationProgress is working as intended and will create another one that uses @MarcoFalke's suggestion instead.

  11. klementtan closed this on Sep 5, 2021

  12. klementtan deleted the branch on Sep 5, 2021
  13. DrahtBot locked this on Sep 5, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-25 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me