From 7b10aa443b6a62b5b7fd2f3e52af0be472bb82c0 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Wed, 29 May 2024 13:56:05 +0800 Subject: [PATCH] allow rewinding to block 0 --- core/genesis.go | 2 +- core/genesis_test.go | 1 + params/config.go | 4 ++++ params/config_test.go | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/genesis.go b/core/genesis.go index f1b4490f2e..956ea66a89 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -354,7 +354,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g return newcfg, stored, errors.New("missing head header") } compatErr := storedcfg.CheckCompatible(newcfg, head.Number.Uint64(), head.Time) - if compatErr != nil && ((head.Number.Uint64() != 0 && compatErr.RewindToBlock != 0) || (head.Time != 0 && compatErr.RewindToTime != 0)) { + if compatErr != nil && ((head.Number.Uint64() != 0 && compatErr.RewindByBlock) || (head.Time != 0 && compatErr.RewindToTime != 0)) { return newcfg, stored, compatErr } // Don't overwrite if the old is identical to the new diff --git a/core/genesis_test.go b/core/genesis_test.go index 31401e214c..828a99f1f2 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -148,6 +148,7 @@ func testSetupGenesis(t *testing.T, scheme string) { What: "Homestead fork block", StoredBlock: big.NewInt(2), NewBlock: big.NewInt(3), + RewindByBlock: true, RewindToBlock: 1, }, }, diff --git a/params/config.go b/params/config.go index 871782399d..59060a0966 100644 --- a/params/config.go +++ b/params/config.go @@ -843,6 +843,9 @@ type ConfigCompatError struct { // the block number to which the local chain must be rewound to correct the error RewindToBlock uint64 + // the flag to tell whether it's rewinding by block or time + RewindByBlock bool + // the timestamp to which the local chain must be rewound to correct the error RewindToTime uint64 } @@ -862,6 +865,7 @@ func newBlockCompatError(what string, storedblock, newblock *big.Int) *ConfigCom StoredBlock: storedblock, NewBlock: newblock, RewindToBlock: 0, + RewindByBlock: true, } if rew != nil && rew.Sign() > 0 { err.RewindToBlock = rew.Uint64() - 1 diff --git a/params/config_test.go b/params/config_test.go index fa444a1d0b..82f872bdfb 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -52,6 +52,7 @@ func TestCheckCompatible(t *testing.T) { StoredBlock: big.NewInt(0), NewBlock: nil, RewindToBlock: 0, + RewindByBlock: true, }, }, { @@ -63,6 +64,7 @@ func TestCheckCompatible(t *testing.T) { StoredBlock: big.NewInt(0), NewBlock: big.NewInt(1), RewindToBlock: 0, + RewindByBlock: true, }, }, { @@ -74,6 +76,7 @@ func TestCheckCompatible(t *testing.T) { StoredBlock: big.NewInt(10), NewBlock: big.NewInt(20), RewindToBlock: 9, + RewindByBlock: true, }, }, { @@ -91,6 +94,7 @@ func TestCheckCompatible(t *testing.T) { StoredBlock: nil, NewBlock: big.NewInt(31), RewindToBlock: 30, + RewindByBlock: true, }, }, {