Skip to content

Commit b9ac746

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

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
@@ -715,6 +715,14 @@ func (bc *BlockChain) initializeHistoryPruning(latest uint64) error {
715715
// was snap synced or full synced and in which state, the method will try to
716716
// delete minimal data from disk whilst retaining chain consistency.
717717
func (bc *BlockChain) SetHead(head uint64) error {
718+
// Only allowed to rewind to a block that is later than the oldest state block.
719+
firstStateBlock, err := bc.triedb.FirstStateBlock()
720+
if err != nil {
721+
return err
722+
}
723+
if head < firstStateBlock {
724+
return fmt.Errorf("cannot rewind to block %d, oldest available state is at block %d", head, firstStateBlock)
725+
}
718726
if _, err := bc.setHeadBeyondRoot(head, 0, common.Hash{}, false); err != nil {
719727
return err
720728
}

0 commit comments

Comments
 (0)