From 465577d8233e323e46bd3584ebda58bfd6800169 Mon Sep 17 00:00:00 2001 From: "nebojsa.urosevic" Date: Thu, 21 Nov 2024 22:05:16 +0100 Subject: [PATCH] core/tracing: extends tracing.Hooks with OnSystemCallStartV2 --- core/state_processor.go | 13 +++++++++---- core/tracing/hooks.go | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 74985b69a1..56ce5dd305 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -221,7 +221,9 @@ func ApplyTransaction(config *params.ChainConfig, evm *vm.EVM, gp *GasPool, stat // contract. This method is exported to be used in tests. func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb vm.StateDB) { if tracer := vmenv.Config.Tracer; tracer != nil { - if tracer.OnSystemCallStart != nil { + if tracer.OnSystemCallStartV2 != nil { + tracer.OnSystemCallStartV2(vmenv.GetVMContext()) + } else if tracer.OnSystemCallStart != nil { tracer.OnSystemCallStart() } if tracer.OnSystemCallEnd != nil { @@ -247,7 +249,9 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb vm.St // as per EIP-2935. func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb vm.StateDB) { if tracer := vmenv.Config.Tracer; tracer != nil { - if tracer.OnSystemCallStart != nil { + if tracer.OnSystemCallStartV2 != nil { + tracer.OnSystemCallStartV2(vmenv.GetVMContext()) + } else if tracer.OnSystemCallStart != nil { tracer.OnSystemCallStart() } if tracer.OnSystemCallEnd != nil { @@ -283,14 +287,15 @@ func ProcessConsolidationQueue(vmenv *vm.EVM, statedb vm.StateDB) []byte { func processRequestsSystemCall(vmenv *vm.EVM, statedb vm.StateDB, requestType byte, addr common.Address) []byte { if tracer := vmenv.Config.Tracer; tracer != nil { - if tracer.OnSystemCallStart != nil { + if tracer.OnSystemCallStartV2 != nil { + tracer.OnSystemCallStartV2(vmenv.GetVMContext()) + } else if tracer.OnSystemCallStart != nil { tracer.OnSystemCallStart() } if tracer.OnSystemCallEnd != nil { defer tracer.OnSystemCallEnd() } } - msg := &Message{ From: params.SystemAddress, GasLimit: 30_000_000, diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index a21bb1577b..d147c4efe9 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -145,6 +145,10 @@ type ( // will not be invoked. OnSystemCallStartHook = func() + // OnSystemCallStartHookV2 is called when a system call is about to be executed. Refer + // to `OnSystemCallStartHook` for more information. + OnSystemCallStartHookV2 = func(vm *VMContext) + // 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. @@ -180,14 +184,15 @@ type Hooks struct { OnFault FaultHook OnGasChange GasChangeHook // Chain events - OnBlockchainInit BlockchainInitHook - OnClose CloseHook - OnBlockStart BlockStartHook - OnBlockEnd BlockEndHook - OnSkippedBlock SkippedBlockHook - OnGenesisBlock GenesisBlockHook - OnSystemCallStart OnSystemCallStartHook - OnSystemCallEnd OnSystemCallEndHook + OnBlockchainInit BlockchainInitHook + OnClose CloseHook + OnBlockStart BlockStartHook + OnBlockEnd BlockEndHook + OnSkippedBlock SkippedBlockHook + OnGenesisBlock GenesisBlockHook + OnSystemCallStart OnSystemCallStartHook + OnSystemCallStartV2 OnSystemCallStartHookV2 + OnSystemCallEnd OnSystemCallEndHook // State events OnBalanceChange BalanceChangeHook OnNonceChange NonceChangeHook