From 8610f8f68cc5ec8f3ee10b0b11d7478b5e703b78 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Fri, 24 Nov 2023 19:08:42 +0330 Subject: [PATCH] add hooks for beacon block root processing --- core/blockchain.go | 2 ++ core/chain_makers.go | 2 +- core/state_processor.go | 10 ++++++++-- eth/tracers/live/printer.go | 3 +++ miner/worker.go | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 17df15f8cb..d66ca0de0a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -195,6 +195,8 @@ type BlockchainLogger interface { OnBlockStart(block *types.Block, td *big.Int, finalized *types.Header, safe *types.Header) OnBlockEnd(err error) OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc) + OnBeaconBlockRootStart(root common.Hash) + OnBeaconBlockRootEnd() } // BlockChain represents the canonical chain given a database with a genesis diff --git a/core/chain_makers.go b/core/chain_makers.go index 8f7728d66b..f0d21e9c45 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -100,7 +100,7 @@ func (b *BlockGen) SetParentBeaconRoot(root common.Hash) { blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase) vmenv = vm.NewEVM(blockContext, vm.TxContext{}, b.statedb, b.cm.config, vm.Config{}) ) - ProcessBeaconBlockRoot(root, vmenv, b.statedb) + ProcessBeaconBlockRoot(root, vmenv, b.statedb, nil) } // addTx adds a transaction to the generated block. If no coinbase has diff --git a/core/state_processor.go b/core/state_processor.go index d2740a1bdc..b468dce3af 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -79,7 +79,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg signer = types.MakeSigner(p.config, header.Number, header.Time) ) if beaconRoot := block.BeaconRoot(); beaconRoot != nil { - ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb) + ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb, p.bc.logger) } statedb.PrepareBlock(vm.ActivePrecompiles(rules)) // Iterate over and process the individual transactions @@ -185,7 +185,13 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo // ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root // contract. This method is exported to be used in tests. -func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *state.StateDB) { +func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *state.StateDB, logger BlockchainLogger) { + if logger != nil { + logger.OnBeaconBlockRootStart(beaconRoot) + defer func() { + logger.OnBeaconBlockRootEnd() + }() + } // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with // the new root msg := &Message{ diff --git a/eth/tracers/live/printer.go b/eth/tracers/live/printer.go index 27657ae56e..62129d2939 100644 --- a/eth/tracers/live/printer.go +++ b/eth/tracers/live/printer.go @@ -58,6 +58,9 @@ func (p *Printer) CaptureExit(output []byte, gasUsed uint64, err error) { fmt.Printf("CaptureExit: output=%s, gasUsed=%v, err=%v\n", hexutil.Bytes(output), gasUsed, err) } +func (p *Printer) OnBeaconBlockRootStart(root common.Hash) {} +func (p *Printer) OnBeaconBlockRootEnd() {} + func (p *Printer) CaptureTxStart(env *vm.EVM, tx *types.Transaction, from common.Address) { buf, err := json.Marshal(tx) if err != nil { diff --git a/miner/worker.go b/miner/worker.go index 95190d5c5d..a5ea9571a9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -976,7 +976,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { if header.ParentBeaconRoot != nil { context := core.NewEVMBlockContext(header, w.chain, nil) vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{}) - core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state) + core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state, nil) } return env, nil }