add hooks for beacon block root processing
This commit is contained in:
parent
cd8c4c589f
commit
8610f8f68c
|
@ -195,6 +195,8 @@ type BlockchainLogger interface {
|
||||||
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)
|
||||||
OnBlockEnd(err error)
|
OnBlockEnd(err error)
|
||||||
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc)
|
OnGenesisBlock(genesis *types.Block, alloc GenesisAlloc)
|
||||||
|
OnBeaconBlockRootStart(root common.Hash)
|
||||||
|
OnBeaconBlockRootEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockChain represents the canonical chain given a database with a genesis
|
// BlockChain represents the canonical chain given a database with a genesis
|
||||||
|
|
|
@ -100,7 +100,7 @@ func (b *BlockGen) SetParentBeaconRoot(root common.Hash) {
|
||||||
blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
|
blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
|
||||||
vmenv = vm.NewEVM(blockContext, vm.TxContext{}, b.statedb, b.cm.config, vm.Config{})
|
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
|
// addTx adds a transaction to the generated block. If no coinbase has
|
||||||
|
|
|
@ -79,7 +79,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||||
signer = types.MakeSigner(p.config, header.Number, header.Time)
|
signer = types.MakeSigner(p.config, header.Number, header.Time)
|
||||||
)
|
)
|
||||||
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
|
||||||
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
|
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb, p.bc.logger)
|
||||||
}
|
}
|
||||||
statedb.PrepareBlock(vm.ActivePrecompiles(rules))
|
statedb.PrepareBlock(vm.ActivePrecompiles(rules))
|
||||||
// Iterate over and process the individual transactions
|
// 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
|
// ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root
|
||||||
// contract. This method is exported to be used in tests.
|
// 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
|
// If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with
|
||||||
// the new root
|
// the new root
|
||||||
msg := &Message{
|
msg := &Message{
|
||||||
|
|
|
@ -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)
|
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) {
|
func (p *Printer) CaptureTxStart(env *vm.EVM, tx *types.Transaction, from common.Address) {
|
||||||
buf, err := json.Marshal(tx)
|
buf, err := json.Marshal(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -976,7 +976,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
|
||||||
if header.ParentBeaconRoot != nil {
|
if header.ParentBeaconRoot != nil {
|
||||||
context := core.NewEVMBlockContext(header, w.chain, nil)
|
context := core.NewEVMBlockContext(header, w.chain, nil)
|
||||||
vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{})
|
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
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue