add chainConfig to block events

This commit is contained in:
Sina Mahmoodi 2023-12-05 16:31:16 +03:30
parent 5190cfc5cb
commit 9e5c96fdff
3 changed files with 9 additions and 8 deletions

View file

@ -192,9 +192,9 @@ type BlockchainLogger interface {
state.StateLogger
// 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)
OnBlockStart(block *types.Block, td *big.Int, finalized *types.Header, safe *types.Header, chainConfig *params.ChainConfig)
OnBlockEnd(err error)
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc)
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc, chainConfig *params.ChainConfig)
OnBeaconBlockRootStart(root common.Hash)
OnBeaconBlockRootEnd()
}
@ -461,7 +461,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set")
}
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc, bc.chainConfig)
}
}
@ -1804,7 +1804,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(), bc.chainConfig)
bc.logger.OnBlockEnd(nil)
}
@ -1932,7 +1932,7 @@ type blockProcessingResult struct {
func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, followupInterrupt *atomic.Bool, start time.Time, setHead bool) (blockEndErr error, _ bool, _ *blockProcessingResult) {
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(), bc.chainConfig)
defer func() {
bc.logger.OnBlockEnd(blockEndErr)
}()

View file

@ -540,7 +540,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database, bcLogger Bloc
return nil, errors.New("can't start clique chain without signers")
}
if bcLogger != nil {
bcLogger.OnGenesisBlock(block, g.Alloc)
bcLogger.OnGenesisBlock(block, g.Alloc, config)
}
// All the checks has passed, flush the states derived from the genesis
// specification as well as the specification itself into the provided

View file

@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers/directory"
"github.com/ethereum/go-ethereum/params"
)
func init() {
@ -84,7 +85,7 @@ func (p *Printer) CaptureTxEnd(receipt *types.Receipt, err error) {
fmt.Printf("CaptureTxEnd: receipt=%s\n", buf)
}
func (p *Printer) OnBlockStart(b *types.Block, td *big.Int, finalized, safe *types.Header) {
func (p *Printer) OnBlockStart(b *types.Block, td *big.Int, finalized, safe *types.Header, _ *params.ChainConfig) {
if finalized != nil && safe != nil {
fmt.Printf("OnBlockStart: b=%v, td=%v, finalized=%v, safe=%v\n", b.NumberU64(), td, finalized.Number.Uint64(), safe.Number.Uint64())
} else {
@ -96,7 +97,7 @@ func (p *Printer) OnBlockEnd(err error) {
fmt.Printf("OnBlockEnd: err=%v\n", err)
}
func (p *Printer) OnGenesisBlock(b *types.Block, alloc core.GenesisAlloc) {
func (p *Printer) OnGenesisBlock(b *types.Block, alloc core.GenesisAlloc, _ *params.ChainConfig) {
fmt.Printf("OnGenesisBlock: b=%v, allocLength=%d\n", b.NumberU64(), len(alloc))
}