core: fix canonicality confusion (#19514)

* core: add tests for canonicality confusion

* core: delete stale future canon number mappings during reorg to shorter+heavier chain
This commit is contained in:
Martin Holst Swende
2019-05-07 14:26:00 +02:00
committed by GitHub
parent 14868a37fb
commit c8cf360f29
2 changed files with 130 additions and 1 deletions

View File

@ -1543,8 +1543,16 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
for _, tx := range types.TxDifference(deletedTxs, addedTxs) {
rawdb.DeleteTxLookupEntry(batch, tx.Hash())
}
// Delete any canonical number assignments above the new head
number := bc.CurrentBlock().NumberU64()
for i := number + 1; ; i++ {
hash := rawdb.ReadCanonicalHash(bc.db, i)
if hash == (common.Hash{}) {
break
}
rawdb.DeleteCanonicalHash(batch, i)
}
batch.Write()
// If any logs need to be fired, do it now. In theory we could avoid creating
// this goroutine if there are no events to fire, but realistcally that only
// ever happens if we're reorging empty blocks, which will only happen on idle