Skip to content

Commit

Permalink
fix ProcessBeaconBlockRoot tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed May 15, 2024
1 parent 8c9f33d commit a0e75ee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
7 changes: 7 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,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) {
if vmenv.Config.Tracer != nil && vmenv.Config.Tracer.OnSystemCallStart != nil {
vmenv.Config.Tracer.OnSystemCallStart()
}
if vmenv.Config.Tracer != nil && vmenv.Config.Tracer.OnSystemCallEnd != nil {
defer vmenv.Config.Tracer.OnSystemCallEnd()
}

// If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with
// the new root
msg := &Message{
Expand Down
31 changes: 25 additions & 6 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ type (
// GenesisBlockHook is called when the genesis block is being processed.
GenesisBlockHook = func(genesis *types.Block, alloc types.GenesisAlloc)

// OnSystemCallStartHook is called when a system call is about to be executed. Today,
// this hook is invoked when the EIP-4788 system call is about to be executed to set the
// beacon block root.
//
// After this hook, the EVM call tracing will happened as usual so you will receive a `OnEnter/OnExit`
// as well as state hooks between this hook and the `OnSystemCallEndHook`.
//
// Note that system call happens outside normal transaction execution, so the `OnTxStart/OnTxEnd` hooks
// will not be invoked.
OnSystemCallStartHook = func()

// OnSystemCallEndHook is called when a system call has finished executing. Today,
// this hook is invoked when the EIP-4788 system call is about to be executed to set the
// beacon block root.
OnSystemCallEndHook = func()

/*
- State events -
*/
Expand Down Expand Up @@ -155,12 +171,15 @@ type Hooks struct {
OnFault FaultHook
OnGasChange GasChangeHook
// Chain events
OnBlockchainInit BlockchainInitHook
OnClose CloseHook
OnBlockStart BlockStartHook
OnBlockEnd BlockEndHook
OnSkippedBlock SkippedBlockHook
OnGenesisBlock GenesisBlockHook
OnBlockchainInit BlockchainInitHook
OnClose CloseHook
OnBlockStart BlockStartHook
OnBlockEnd BlockEndHook
OnSkippedBlock SkippedBlockHook
OnGenesisBlock GenesisBlockHook
OnSystemCallStart OnSystemCallStartHook
OnSystemCallEnd OnSystemCallEndHook

// State events
OnBalanceChange BalanceChangeHook
OnNonceChange NonceChangeHook
Expand Down
16 changes: 9 additions & 7 deletions eth/tracers/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ func NewTracingHooksFromFirehose(tracer *Firehose) *tracing.Hooks {
OnOpcode: tracer.OnOpcode,
OnFault: tracer.OnOpcodeFault,

OnBalanceChange: tracer.OnBalanceChange,
OnNonceChange: tracer.OnNonceChange,
OnCodeChange: tracer.OnCodeChange,
OnStorageChange: tracer.OnStorageChange,
OnGasChange: tracer.OnGasChange,
OnLog: tracer.OnLog,
OnBalanceChange: tracer.OnBalanceChange,
OnNonceChange: tracer.OnNonceChange,
OnCodeChange: tracer.OnCodeChange,
OnStorageChange: tracer.OnStorageChange,
OnGasChange: tracer.OnGasChange,
OnLog: tracer.OnLog,
OnSystemCallStart: tracer.OnBeaconBlockRootStart,
OnSystemCallEnd: tracer.OnBeaconBlockRootEnd,

// This should actually be conditional but it's not possible to do it in the hooks
// directly because the chain ID will be known only after the `OnBlockchainInit` call.
Expand Down Expand Up @@ -514,7 +516,7 @@ func (f *Firehose) reorderCallOrdinals(call *pbeth.Call, ordinalBase uint64) (or
return call.EndOrdinal
}

func (f *Firehose) OnBeaconBlockRootStart(root common.Hash) {
func (f *Firehose) OnBeaconBlockRootStart() {
firehoseInfo("system call start (for=%s)", "beacon_block_root")
f.ensureInBlockAndNotInTrx()

Expand Down

0 comments on commit a0e75ee

Please sign in to comment.