core: truncate chain before the cutoff

This commit is contained in:
Gary Rong 2025-03-20 21:35:26 +08:00
parent e447da2305
commit 1e7f405fc5

View file

@ -2534,6 +2534,11 @@ func (bc *BlockChain) InsertHeadersBeforeCutoff(headers []*types.Header) (int, e
if err := batch.Write(); err != nil { if err := batch.Write(); err != nil {
return 0, err return 0, err
} }
// Truncate the useless chain segment (zero bodies and receipts) in the
// ancient store.
if _, err := bc.db.TruncateTail(last.Number.Uint64() + 1); err != nil {
return 0, err
}
// Last step update all in-memory markers // Last step update all in-memory markers
bc.hc.currentHeader.Store(last) bc.hc.currentHeader.Store(last)
bc.currentSnapBlock.Store(last) bc.currentSnapBlock.Store(last)