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

[Core][Qt] Rewind block index to last checkpoint functionality #2820

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Liquid369
Copy link
Member

This pull request supersedes #2298

This feature is a good addition because in cases of late updates, or a short fork a user can start from the latest hardcoded checkpoints instead of re-syncing from scratch.

Cleaned up a little and added the missing functionality that was remaining.

This PR now:

  • Allows starting with -rewindblockindex param
  • Added GUI section Rewind Blockchain inside "Wallet Repair" tab
  • Functional test
  • New Checkpoint

Potential TODO:

  • More checkpoints?

Some work was done by PeterL73

Comment on lines +3753 to +3755
// First load options
if(!fJustCheck)
return true;

Choose a reason for hiding this comment

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

Could we automatically detect if a rewind is needed?
If there are checkpoints between the tip and the last (known) checkpoint, we are not on the right chain.
Maybe something like this:

// If there are checkpoints between prevCheckPoint and chainActive.Tip
// This is not the right chain and a rewind to prevCheckPoint is needed
bool bNeedRewind = fJustCheck;
if (Checkpoints::fEnabled){
    const MapCheckpoints& checkpoints = *Params().Checkpoints().mapCheckpoints;

    for (const auto& i : reverse_iterate(checkpoints)) {
        if (i.first > checkPointHeight && i.first <= nHeight) {
            bNeedRewind = true;
            break;
        }
    }
}

if(!bNeedRewind)
    return true;

Choose a reason for hiding this comment

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

If there are checkpoints between the tip and the last (known) checkpoint, we are not on the right chain. and this is right,
but if there are not checkpoints between the tip and the last (known) checkpoint it does not necessarily mean we are on the right chain

Copy link
Member Author

Choose a reason for hiding this comment

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

I do not see a possibility in automatically detecting a rewind.

In such we have two cases:
1.
There is a checkpoint known and in the future, but we are behind said checkpoint, we would then simply sync to it.
2.
There is not a checkpoint and between the tip and the last known, to which we should be fine.

IE: Checkpoint block is 2150000, we are at block 2150010, if there was any in-between, that user would already have synced those
Checkpoint is block 2150005 and 2150000, while we are at block 2150010, there's no way we would be at 2150010 with a prevCheckpoint of 2150000 not 2150005 and on the same wallet version.

@Liquid369 Liquid369 force-pushed the 2023_rewind_checkpoint branch 2 times, most recently from 1453d14 to 146e72b Compare March 28, 2023 16:33
@Fuzzbawls Fuzzbawls added this to the 6.0.0 milestone Apr 4, 2023
Add newer checkpoint

New checkpoint

Add tests

Fix whitespace

Set correct permissions

Adjust test positon and fix num nodes
Copy link

@panleone panleone left a comment

Choose a reason for hiding this comment

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

Successfully tested on mainnet and code looks really good! Just a couple of comments:

@@ -182,12 +182,13 @@ static MapCheckpoints mapCheckpoints = {
{3014000, uint256S("78ad99b7225f73c42238bd7ca841ff700542b92bba75a0ef2ed351caa560f87f")}, //!< PIVX v5.3.0 enforced
{3024000, uint256S("be4bc75afcfb9136924810f7483b2695089a366cc4ee27fd6dc3ecd5396e1f0f")}, //!< Superblock
{3715200, uint256S("a676b9a598c393c82b949c37dd35013aeda55f5d18ab062349db6a8235972aaa")}, //!< Superblock for 5.5.0 mainnet rewards changeover
{3780000, uint256S("2667fa1d552999aca930ced7fd3902ae5721e5c256a607049e3c47a3137a18ee")}, //!< Fri, 10 Mar 2023 rewindblockindex testing

Choose a reason for hiding this comment

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

This checkpoint is useless

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree! I should have prefaced thats for testing since the last checkpoint was a big further back and would have been a faster sync

};

static const CCheckpointData data = {
&mapCheckpoints,
1591401645, // * UNIX timestamp of last checkpoint block
5607713, // * total number of transactions between genesis and last checkpoint
1678401150, // * UNIX timestamp of last checkpoint block

Choose a reason for hiding this comment

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

hence re-update those with last v5.5 checkpoint

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I will rebase and we just make sure to update more checkpoints more frequently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA
Development

Successfully merging this pull request may close these issues.

None yet

4 participants