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.

    0        if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) {
    1            LogPrintf("-stopatheight target (%d) reached, shutting down\n", nStopAtHeight);
    2            StartShutdown();
    3        }
    4
    5...
    6
    7        if (ShutdownRequested())
    8            break;
    9    } 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
  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:

    0bitcoind -stopatheight 500000
    1# Wait it reached it
    2bitcoin-cli gettxoutsetinfo
    3# Note the UTXOSet hash
    4bitcoin-cli stop
    5tar xcf "bitcoin-chainstate-snapshot-500000.tar" ~/.bitcoin/chainstate
    6# Upload the  bitcoin-chainstate-snapshot-500000.tar on a public location
    7# Sign the snapshot shasum
    

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

    0# On reference machine 
    1bitcoind -stopatheight 500000
    2# Wait it reached it
    3bitcoin-cli gettxoutsetinfo
    4# Note the UTXOSet hash
    

    Then try to import the UTXO set from the tar

    0# On low powered device
    1tar xvf  bitcoin-chainstate-snapshot-500000.tar -C ~/.bitcoin/chainstate
    2bitcoind -stopatheight 500000
    3bitcoin-cli gettxoutsetinfo
    4# 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

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

    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
  19. DrahtBot commented at 1:02 pm on September 30, 2019: member
  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: 2024-07-03 10:13 UTC

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