Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Snapshot delete operation flag added #2064

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 19 additions & 18 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,27 +643,28 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, root common.Hash, repair bo
if err := bc.hc.SetHead(head, updateFn, delFn); err != nil {
return 0, err
}
}

// Delete istanbul snapshot database further two epochs
var (
curBlkNum = bc.CurrentBlock().Number().Uint64()
epoch = bc.Config().Istanbul.Epoch
votingEpoch = curBlkNum - (curBlkNum % epoch)
)
if votingEpoch == 0 {
votingEpoch = 1
}
// Delete the snapshot state beyond the block number of the previous epoch on the right
for i := curBlkNum; i >= votingEpoch; i-- {
if params.IsCheckpointInterval(i) {
// delete from sethead number to previous two epoch block nums
// to handle a block that contains non-empty vote data to make sure
// the `HandleGovernanceVote()` cannot be skipped
bc.db.DeleteIstanbulSnapshot(bc.GetBlockByNumber(i).Hash())
// Delete istanbul snapshot database further two epochs
// Invoked only if the sethead was originated from explicit API call
var (
curBlkNum = bc.CurrentBlock().Number().Uint64()
epoch = bc.Config().Istanbul.Epoch
votingEpoch = curBlkNum - (curBlkNum % epoch)
)
if votingEpoch == 0 {
votingEpoch = 1
}
// Delete the snapshot state beyond the block number of the previous epoch on the right
for i := curBlkNum; i >= votingEpoch; i-- {
if params.IsCheckpointInterval(i) {
// delete from sethead number to previous two epoch block nums
// to handle a block that contains non-empty vote data to make sure
// the `HandleGovernanceVote()` cannot be skipped
bc.db.DeleteIstanbulSnapshot(bc.GetBlockByNumber(i).Hash())
}
}
logger.Trace("[SetHead] Snapshot database deleted", "from", originLatestBlkNum, "to", votingEpoch)
}
logger.Trace("[SetHead] Snapshot database deleted", "from", originLatestBlkNum, "to", votingEpoch)

// Clear out any stale content from the caches
bc.futureBlocks.Purge()
Expand Down