Skip to content

Commit 8788d37

Browse files
committed
core: check rewind head is later than older
Signed-off-by: Delweng <[email protected]>
1 parent d761aca commit 8788d37

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/blockchain.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,14 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
735735
// was snap synced or full synced and in which state, the method will try to
736736
// delete minimal data from disk whilst retaining chain consistency.
737737
func (bc *BlockChain) SetHead(head uint64) error {
738+
// Only allowed to rewind to a block that is later than the oldest state block.
739+
firstStateBlock, err := bc.triedb.FirstStateBlock()
740+
if err != nil {
741+
return err
742+
}
743+
if head < firstStateBlock {
744+
return fmt.Errorf("cannot rewind to block %d, oldest available state is at block %d", head, firstStateBlock)
745+
}
738746
if _, err := bc.setHeadBeyondRoot(head, 0, common.Hash{}, false); err != nil {
739747
return err
740748
}

0 commit comments

Comments
 (0)