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

core: validate chain before writing block to avoid race condition #1319

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
status WriteStatus
)

// Before the actual db insertion happens, verify the block against the whitelisted
// milestone and checkpoint. This is to prevent a race condition where a milestone
// or checkpoint was whitelisted while the block execution happened (and wasn't
// available sometime before) and the block turns out to be inavlid (i.e. not
// honouring the milestone or checkpoint). Use the block itself as current block
// so that it's considered as a `past` chain and the validation doesn't get bypassed.
isValid, err = bc.forker.ValidateReorg(block.Header(), []*types.Header{block.Header()})
if err != nil {
return it.index, err
}
if !isValid {
return it.index, whitelist.ErrMismatch
}

if !setHead {
// Don't set the head, only insert the block
_, err = bc.writeBlockWithState(block, receipts, logs, statedb)
Expand Down
Loading