Skip to content

Commit ee5318b

Browse files
authored
core: validate chain before writing block (ethereum#1319)
1 parent 4c4185c commit ee5318b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/blockchain.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23742374
status WriteStatus
23752375
)
23762376

2377+
// Before the actual db insertion happens, verify the block against the whitelisted
2378+
// milestone and checkpoint. This is to prevent a race condition where a milestone
2379+
// or checkpoint was whitelisted while the block execution happened (and wasn't
2380+
// available sometime before) and the block turns out to be inavlid (i.e. not
2381+
// honouring the milestone or checkpoint). Use the block itself as current block
2382+
// so that it's considered as a `past` chain and the validation doesn't get bypassed.
2383+
isValid, err = bc.forker.ValidateReorg(block.Header(), []*types.Header{block.Header()})
2384+
if err != nil {
2385+
return it.index, err
2386+
}
2387+
if !isValid {
2388+
return it.index, whitelist.ErrMismatch
2389+
}
2390+
23772391
if !setHead {
23782392
// Don't set the head, only insert the block
23792393
_, err = bc.writeBlockWithState(block, receipts, logs, statedb)

0 commit comments

Comments
 (0)