Skip to content

Commit

Permalink
indicate known block
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Feb 8, 2024
1 parent 57cd0c3 commit 056f229
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ type BlockchainLogger interface {
OnBlockchainInit(chainConfig *params.ChainConfig)
// OnBlockStart is called before executing `block`.
// `td` is the total difficulty prior to `block`.
OnBlockStart(block *types.Block, td *big.Int, finalized *types.Header, safe *types.Header)
// `skip` indicates processing of this previously known block
// will be skipped. OnBlockStart and OnBlockEnd will be emitted to
// convey how chain is progressing. E.g. known blocks will be skipped
// when node is started after a crash.
OnBlockStart(block *types.Block, td *big.Int, finalized *types.Header, safe *types.Header, skip bool)
OnBlockEnd(err error)
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc)
OnBeaconBlockRootStart(root common.Hash)
Expand Down Expand Up @@ -1766,7 +1770,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
stats.processed++
if bc.logger != nil {
bc.logger.OnBlockStart(block, bc.GetTd(block.ParentHash(), block.NumberU64()-1), bc.CurrentFinalBlock(), bc.CurrentSafeBlock())
bc.logger.OnBlockStart(block, bc.GetTd(block.ParentHash(), block.NumberU64()-1), bc.CurrentFinalBlock(), bc.CurrentSafeBlock(), true)
bc.logger.OnBlockEnd(nil)
}

Expand Down Expand Up @@ -1895,7 +1899,7 @@ type blockProcessingResult struct {
func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, start time.Time, setHead bool) (_ *blockProcessingResult, blockEndErr error) {
if bc.logger != nil {
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
bc.logger.OnBlockStart(block, td, bc.CurrentFinalBlock(), bc.CurrentSafeBlock())
bc.logger.OnBlockStart(block, td, bc.CurrentFinalBlock(), bc.CurrentSafeBlock(), false)
defer func() {
bc.logger.OnBlockEnd(blockEndErr)
}()
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/live/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (t *noop) CaptureTxStart(env *vm.EVM, tx *types.Transaction, from common.Ad
func (t *noop) CaptureTxEnd(receipt *types.Receipt, err error) {
}

func (t *noop) OnBlockStart(b *types.Block, td *big.Int, finalized, safe *types.Header) {
func (t *noop) OnBlockStart(b *types.Block, td *big.Int, finalized, safe *types.Header, skip bool) {
}

func (t *noop) OnBlockEnd(err error) {
Expand Down

0 comments on commit 056f229

Please sign in to comment.