mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
use defer for OnBlockEnd
This commit is contained in:
parent
0be6e22eaf
commit
abd880712b
1 changed files with 102 additions and 105 deletions
|
|
@ -1774,18 +1774,20 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
|||
// Process block using the parent state as reference point
|
||||
pstart := time.Now()
|
||||
|
||||
// The traced section of block import.
|
||||
err, stop := func() (blockEndErr error, _ bool) {
|
||||
if bc.logger != nil {
|
||||
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
|
||||
bc.logger.OnBlockStart(block, td, bc.CurrentFinalBlock(), bc.CurrentSafeBlock())
|
||||
defer func() {
|
||||
bc.logger.OnBlockEnd(blockEndErr)
|
||||
}()
|
||||
}
|
||||
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
|
||||
if err != nil {
|
||||
bc.reportBlock(block, receipts, err)
|
||||
followupInterrupt.Store(true)
|
||||
if bc.logger != nil {
|
||||
bc.logger.OnBlockEnd(err)
|
||||
}
|
||||
return it.index, err
|
||||
return err, true
|
||||
}
|
||||
ptime := time.Since(pstart)
|
||||
|
||||
|
|
@ -1793,10 +1795,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
|||
if err := bc.validator.ValidateState(block, statedb, receipts, usedGas); err != nil {
|
||||
bc.reportBlock(block, receipts, err)
|
||||
followupInterrupt.Store(true)
|
||||
if bc.logger != nil {
|
||||
bc.logger.OnBlockEnd(err)
|
||||
}
|
||||
return it.index, err
|
||||
return err, true
|
||||
}
|
||||
vtime := time.Since(vstart)
|
||||
proctime := time.Since(start) // processing + validation
|
||||
|
|
@ -1830,10 +1829,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
|||
}
|
||||
followupInterrupt.Store(true)
|
||||
if err != nil {
|
||||
if bc.logger != nil {
|
||||
bc.logger.OnBlockEnd(err)
|
||||
}
|
||||
return it.index, err
|
||||
return err, true
|
||||
}
|
||||
// Update the metrics touched during block commit
|
||||
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
|
||||
|
|
@ -1851,16 +1847,12 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
|||
dirty, _ := bc.triedb.Size()
|
||||
stats.report(chain, it.index, dirty, setHead)
|
||||
|
||||
if bc.logger != nil {
|
||||
bc.logger.OnBlockEnd(nil)
|
||||
}
|
||||
|
||||
if !setHead {
|
||||
// After merge we expect few side chains. Simply count
|
||||
// all blocks the CL gives us for GC processing time
|
||||
bc.gcproc += proctime
|
||||
|
||||
return it.index, nil // Direct block insertion of a single block
|
||||
return nil, true // Direct block insertion of a single block
|
||||
}
|
||||
switch status {
|
||||
case CanonStatTy:
|
||||
|
|
@ -1888,6 +1880,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
|||
"txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()),
|
||||
"root", block.Root())
|
||||
}
|
||||
return nil, false
|
||||
}()
|
||||
if err != nil || stop {
|
||||
return it.index, err
|
||||
}
|
||||
}
|
||||
|
||||
// Any blocks remaining here? The only ones we care about are the future ones
|
||||
|
|
|
|||
Loading…
Reference in a new issue