Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed

Conversation

jonasschnelli
Copy link
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

@@ -2705,6 +2705,12 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
{
LOCK(cs_main);
CBlockIndex* starting_tip = chainActive.Tip();

if (nStopAtHeight && starting_tip && starting_tip->nHeight >= nStopAtHeight && ShutdownRequested()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

@fanquake fanquake requested a review from sdaftuar July 21, 2018 04:44
@fanquake
Copy link
Member

Note previous discussion about -stopatheight in #13490.

@laanwj
Copy link
Member

laanwj commented Aug 31, 2018

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.

@DrahtBot DrahtBot closed this Sep 7, 2018
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 7, 2018

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.

@DrahtBot DrahtBot reopened this Sep 7, 2018
@Sjors
Copy link
Member

Sjors commented Sep 8, 2018

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.

@Sjors
Copy link
Member

Sjors commented Sep 10, 2018

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

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Nov 28, 2018

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

@Sjors
Copy link
Member

Sjors commented Nov 30, 2018

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

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Nov 30, 2018

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 15, 2019

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.

@Sjors Sjors mentioned this pull request Apr 19, 2019
18 tasks
@DrahtBot
Copy link
Contributor

DrahtBot commented May 7, 2019

Needs rebase

@DrahtBot
Copy link
Contributor

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.

@DrahtBot DrahtBot closed this Sep 30, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-stopatheight is imprecise
7 participants