Skip to content

Commit ebb57c7

Browse files
committed
Limit setting head to within chain state
1 parent 394ae82 commit ebb57c7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/blockchain.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,15 @@ func (bc *BlockChain) SetShardEndHeight(height *uint64) error {
26282628
return fmt.Errorf("End height cannot be before start height")
26292629
}
26302630

2631-
if height != nil && bc.CurrentHeader().Number.Uint64() > *height {
2631+
currentHeight := bc.CurrentHeader().Number.Uint64()
2632+
2633+
if height != nil && currentHeight > *height {
2634+
2635+
// Check that if its not an archive node and that the height is still within state range.
2636+
// TrieDirtyDisabled is set to true for archive nodes.
2637+
if !bc.cacheConfig.TrieDirtyDisabled && currentHeight > bc.cacheConfig.StateHistory && *height < currentHeight - bc.cacheConfig.StateHistory {
2638+
return errors.New("Cannot set height before chain state.")
2639+
}
26322640
// rollback
26332641
if err := bc.SetHead(*height); err != nil {
26342642
return err

0 commit comments

Comments
 (0)