mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: fix import errors on clique crashes + empty blocks
This commit is contained in:
parent
c94d582aa7
commit
feb8029e4e
1 changed files with 37 additions and 2 deletions
|
|
@ -1169,7 +1169,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
if localTd.Cmp(externTd) < 0 {
|
if localTd.Cmp(externTd) < 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
log.Debug("Ignoring already known block", "number", block.Number(), "hash", block.Hash())
|
||||||
stats.ignored++
|
stats.ignored++
|
||||||
|
|
||||||
block, err = it.next()
|
block, err = it.next()
|
||||||
}
|
}
|
||||||
// The remaining blocks are still known blocks, the only scenario here is:
|
// The remaining blocks are still known blocks, the only scenario here is:
|
||||||
|
|
@ -1181,6 +1183,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
// `insertChain` while a part of them have higher total difficulty than current
|
// `insertChain` while a part of them have higher total difficulty than current
|
||||||
// head full block(new pivot point).
|
// head full block(new pivot point).
|
||||||
for block != nil && err == ErrKnownBlock {
|
for block != nil && err == ErrKnownBlock {
|
||||||
|
log.Debug("Writing previously known block", "number", block.Number(), "hash", block.Hash())
|
||||||
if err := bc.writeKnownBlock(block); err != nil {
|
if err := bc.writeKnownBlock(block); err != nil {
|
||||||
return it.index, nil, nil, err
|
return it.index, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1190,15 +1193,16 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
}
|
}
|
||||||
// Falls through to the block import
|
// Falls through to the block import
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// First block is pruned, insert as sidechain and reorg only if TD grows enough
|
// First block is pruned, insert as sidechain and reorg only if TD grows enough
|
||||||
case err == consensus.ErrPrunedAncestor:
|
case err == consensus.ErrPrunedAncestor:
|
||||||
|
log.Debug("Pruned ancestor, inserting as sidechain", "number", block.Number(), "hash", block.Hash())
|
||||||
return bc.insertSideChain(block, it)
|
return bc.insertSideChain(block, it)
|
||||||
|
|
||||||
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
|
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
|
||||||
case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
|
case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
|
||||||
for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) {
|
for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) {
|
||||||
|
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash())
|
||||||
if err := bc.addFutureBlock(block); err != nil {
|
if err := bc.addFutureBlock(block); err != nil {
|
||||||
return it.index, events, coalescedLogs, err
|
return it.index, events, coalescedLogs, err
|
||||||
}
|
}
|
||||||
|
|
@ -1217,7 +1221,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
return it.index, events, coalescedLogs, err
|
return it.index, events, coalescedLogs, err
|
||||||
}
|
}
|
||||||
// No validation errors for the first block (or chain prefix skipped)
|
// No validation errors for the first block (or chain prefix skipped)
|
||||||
for ; block != nil && err == nil; block, err = it.next() {
|
for ; block != nil && err == nil || err == ErrKnownBlock; block, err = it.next() {
|
||||||
// If the chain is terminating, stop processing blocks
|
// If the chain is terminating, stop processing blocks
|
||||||
if atomic.LoadInt32(&bc.procInterrupt) == 1 {
|
if atomic.LoadInt32(&bc.procInterrupt) == 1 {
|
||||||
log.Debug("Premature abort during blocks processing")
|
log.Debug("Premature abort during blocks processing")
|
||||||
|
|
@ -1228,6 +1232,29 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
bc.reportBlock(block, nil, ErrBlacklistedHash)
|
bc.reportBlock(block, nil, ErrBlacklistedHash)
|
||||||
return it.index, events, coalescedLogs, ErrBlacklistedHash
|
return it.index, events, coalescedLogs, ErrBlacklistedHash
|
||||||
}
|
}
|
||||||
|
// If the block is known (in the middle of the chain), it's a special case for
|
||||||
|
// Clique blocks where they can share state among each other, so importing an
|
||||||
|
// older block might complete the state of the subsequent one. In this case,
|
||||||
|
// just skip the block (we already validated it once fully (and crashed), since
|
||||||
|
// its header and body was already in the database).
|
||||||
|
if err == ErrKnownBlock {
|
||||||
|
log.Debug("Inserted known block", "number", block.Number(), "hash", block.Hash(),
|
||||||
|
"uncles", len(block.Uncles()), "txs", len(block.Transactions()), "gas", block.GasUsed(),
|
||||||
|
"root", block.Root())
|
||||||
|
|
||||||
|
if err := bc.writeKnownBlock(block); err != nil {
|
||||||
|
return it.index, nil, nil, err
|
||||||
|
}
|
||||||
|
stats.processed++
|
||||||
|
|
||||||
|
// TODO(karalabe): Can we assume canonicalness here? Can we assume no logs?
|
||||||
|
// In theory I can make a block *with* transactions but *no* state change if
|
||||||
|
// the only transactions are miner-self-sends or 0-price-self-sends.
|
||||||
|
events = append(events, ChainEvent{block, block.Hash(), nil})
|
||||||
|
lastCanon = block
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Retrieve the parent block and it's state to execute on top
|
// Retrieve the parent block and it's state to execute on top
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
|
|
@ -1327,6 +1354,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
|
||||||
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
|
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
|
||||||
"root", block.Root())
|
"root", block.Root())
|
||||||
events = append(events, ChainSideEvent{block})
|
events = append(events, ChainSideEvent{block})
|
||||||
|
|
||||||
|
default:
|
||||||
|
// This in theory is impossible, but lets be nice to our future selves and leave
|
||||||
|
// a log, instead of trying to track down blocks imports that don't emit logs.
|
||||||
|
log.Warn("Inserted block with unknown status", "number", block.Number(), "hash", block.Hash(),
|
||||||
|
"diff", block.Difficulty(), "elapsed", common.PrettyDuration(time.Since(start)),
|
||||||
|
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
|
||||||
|
"root", block.Root())
|
||||||
}
|
}
|
||||||
stats.processed++
|
stats.processed++
|
||||||
stats.usedGas += usedGas
|
stats.usedGas += usedGas
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue