Ignore new blocks when -stopatheight target has been reached #13713

pull jonasschnelli wants to merge 1 commits into bitcoin:master from jonasschnelli:2018/07/stopatheight changing 1 files +10 −1
  1. jonasschnelli commented at 9:06 AM on July 19, 2018: contributor

    If the -stopatheight target has been reached, a shutdown will be triggered, though, already loaded blocks will still be activated, making it impossible to precisely stop at a certain height.

    This PR will ignore future blocks once the -stopatheight target has been reached.

    Fixes #13477

  2. Ignore new blocks when -stopatheight target has been reached ee02c4234c
  3. fanquake added the label Validation on Jul 19, 2018
  4. in src/validation.cpp:2709 in ee02c4234c
    2704 | @@ -2705,6 +2705,12 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
    2705 |          {
    2706 |              LOCK(cs_main);
    2707 |              CBlockIndex* starting_tip = chainActive.Tip();
    2708 | +
    2709 | +            if (nStopAtHeight && starting_tip && starting_tip->nHeight >= nStopAtHeight && ShutdownRequested()) {
    


    l2a5b1 commented at 3:27 PM on July 19, 2018:

    Can you explain the && ShutdownRequested() in the boolean expression?

    If it is here to catch the StartShutdown() below, the do .. while loop is already terminated before it can reach this if statement.

            if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) {
                LogPrintf("-stopatheight target (%d) reached, shutting down\n", nStopAtHeight);
                StartShutdown();
            }
    
    ...
    
            if (ShutdownRequested())
                break;
        } while (pindexNewTip != pindexMostWork);
    

    jonasschnelli commented at 7:45 PM on July 19, 2018:

    The upper if statement with the ShutdownRequested() does make sure that on future calls of ActivateBestChain() and after StartShutdown() will not process blocks when stopheight is set at a shutdown is triggered.

    The lower if statement is there to trigger the shutdown.


    NicolasDorier commented at 2:04 PM on November 30, 2018:

    What I don't understand is that if ShutdownRequested() is false, then you will end up processing one more block, and this is not what you want. Removing ShutdownRequested() and just call StartShutdown at this place?

  5. fanquake requested review from sdaftuar on Jul 21, 2018
  6. fanquake commented at 4:45 AM on July 21, 2018: member

    Note previous discussion about -stopatheight in #13490.

  7. laanwj commented at 1:10 PM on August 31, 2018: member

    Note previous discussion about -stopatheight in #13490.

    I tend to agree with @sdaftuar's reasoning that it is undesirable to burden the validation code further with this.

    Then again, if we're not going to fix this we should close #13477 (with "wontfix" and this reasoning), otherwise people will wasting time trying to fix it.

  8. DrahtBot closed this on Sep 7, 2018

  9. DrahtBot commented at 9:00 PM on September 7, 2018: member

    <!--5d09a71f8925f3f132321140b44b946d-->The last travis run for this pull request was 50 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

  10. DrahtBot reopened this on Sep 7, 2018

  11. Sjors commented at 3:15 PM on September 8, 2018: member

    This change is already a lot smaller than the previous attempt.

    Being able to produce a deterministic UTXO set for a given height, as well as block files and indexes, could be quite useful. There may be other approaches than -stopatheight, or perhaps we can fix -stopatheight in a less disruptive way, e.g. by rolling back after overshooting.

  12. Sjors commented at 7:25 AM on September 10, 2018: member

    Lightly tested on testnet and it seems to indeed fix the issue.

  13. NicolasDorier commented at 6:19 AM on November 28, 2018: contributor

    @jonasschnelli this is not good. Here is what I wished I could do:

    bitcoind -stopatheight 500000
    # Wait it reached it
    bitcoin-cli gettxoutsetinfo
    # Note the UTXOSet hash
    bitcoin-cli stop
    tar xcf "bitcoin-chainstate-snapshot-500000.tar" ~/.bitcoin/chainstate
    # Upload the  bitcoin-chainstate-snapshot-500000.tar on a public location
    # Sign the snapshot shasum
    

    Then somebody who wants to verify and sign the snapshot as well would repeat

    # On reference machine 
    bitcoind -stopatheight 500000
    # Wait it reached it
    bitcoin-cli gettxoutsetinfo
    # Note the UTXOSet hash
    

    Then try to import the UTXO set from the tar

    # On low powered device
    tar xvf  bitcoin-chainstate-snapshot-500000.tar -C ~/.bitcoin/chainstate
    bitcoind -stopatheight 500000
    bitcoin-cli gettxoutsetinfo
    # Check that the utxoset hash is the same as on the reference machine
    

    Then he can add his signature to the shasum of bitcoin-chainstate-snapshot-500000.tar so people can trust it more.

    If you stop the node once the height is reached, then there is no way to have the hash of the utxoset with gettxoutsetinfo, and no way for somebody else to independently verify a given utxoset inside a tar file.

  14. Sjors commented at 11:01 AM on November 30, 2018: member

    @NicolasDorier I totally agree your workflow is what we should strive for. However this PR only fixes a bug in the existing behaviour. Let's redefine -stopatheight (e.g. by adding a stop_sync_but_dont_exit param) in a followup PR.

  15. NicolasDorier commented at 1:56 PM on November 30, 2018: contributor

    Ah got it, this is already the current situation. I misunderstood thinking it was changing the behavior.

  16. DrahtBot commented at 5:31 PM on March 15, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15948 (refactor: rename chainActive by jamesob)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  17. DrahtBot added the label Needs rebase on May 7, 2019
  18. DrahtBot commented at 4:07 PM on May 7, 2019: member

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  19. DrahtBot commented at 1:02 PM on September 30, 2019: member

    <!--5fd3d806e98f4a0ca80977bb178665a0-->There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.

  20. DrahtBot added the label Up for grabs on Sep 30, 2019
  21. DrahtBot closed this on Sep 30, 2019

  22. laanwj removed the label Needs rebase on Oct 24, 2019
  23. MarcoFalke locked this on Dec 16, 2021

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-24 12:15 UTC

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