Skip to content

Commit 67a3b08

Browse files
nebojsa94s1na
andauthored
core/tracing: extends tracing.Hooks with OnSystemCallStartV2 (#30786)
This PR extends the Hooks interface with a new method, `OnSystemCallStartV2`, which takes `VMContext` as its parameter. Motivation By including `VMContext` as a parameter, the `OnSystemCallStartV2` hook achieves parity with the `OnTxStart` hook in terms of provided insights. This alignment simplifies the inner tracer logic, enabling consistent handling of state changes and internal calls within the same framework. --------- Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
1 parent f0e7382 commit 67a3b08

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

core/state_processor.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/consensus/misc"
2525
"github.com/ethereum/go-ethereum/core/state"
26+
"github.com/ethereum/go-ethereum/core/tracing"
2627
"github.com/ethereum/go-ethereum/core/types"
2728
"github.com/ethereum/go-ethereum/core/vm"
2829
"github.com/ethereum/go-ethereum/crypto"
@@ -212,9 +213,7 @@ func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *
212213
// contract. This method is exported to be used in tests.
213214
func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) {
214215
if tracer := evm.Config.Tracer; tracer != nil {
215-
if tracer.OnSystemCallStart != nil {
216-
tracer.OnSystemCallStart()
217-
}
216+
onSystemCallStart(tracer, evm.GetVMContext())
218217
if tracer.OnSystemCallEnd != nil {
219218
defer tracer.OnSystemCallEnd()
220219
}
@@ -238,9 +237,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) {
238237
// as per EIP-2935.
239238
func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM) {
240239
if tracer := evm.Config.Tracer; tracer != nil {
241-
if tracer.OnSystemCallStart != nil {
242-
tracer.OnSystemCallStart()
243-
}
240+
onSystemCallStart(tracer, evm.GetVMContext())
244241
if tracer.OnSystemCallEnd != nil {
245242
defer tracer.OnSystemCallEnd()
246243
}
@@ -274,9 +271,7 @@ func ProcessConsolidationQueue(requests *[][]byte, evm *vm.EVM) {
274271

275272
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) {
276273
if tracer := evm.Config.Tracer; tracer != nil {
277-
if tracer.OnSystemCallStart != nil {
278-
tracer.OnSystemCallStart()
279-
}
274+
onSystemCallStart(tracer, evm.GetVMContext())
280275
if tracer.OnSystemCallEnd != nil {
281276
defer tracer.OnSystemCallEnd()
282277
}
@@ -322,3 +317,11 @@ func ParseDepositLogs(requests *[][]byte, logs []*types.Log, config *params.Chai
322317
}
323318
return nil
324319
}
320+
321+
func onSystemCallStart(tracer *tracing.Hooks, ctx *tracing.VMContext) {
322+
if tracer.OnSystemCallStartV2 != nil {
323+
tracer.OnSystemCallStartV2(ctx)
324+
} else if tracer.OnSystemCallStart != nil {
325+
tracer.OnSystemCallStart()
326+
}
327+
}

core/tracing/hooks.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ type (
145145
// will not be invoked.
146146
OnSystemCallStartHook = func()
147147

148+
// OnSystemCallStartHookV2 is called when a system call is about to be executed. Refer
149+
// to `OnSystemCallStartHook` for more information.
150+
OnSystemCallStartHookV2 = func(vm *VMContext)
151+
148152
// OnSystemCallEndHook is called when a system call has finished executing. Today,
149153
// this hook is invoked when the EIP-4788 system call is about to be executed to set the
150154
// beacon block root.
@@ -180,14 +184,15 @@ type Hooks struct {
180184
OnFault FaultHook
181185
OnGasChange GasChangeHook
182186
// Chain events
183-
OnBlockchainInit BlockchainInitHook
184-
OnClose CloseHook
185-
OnBlockStart BlockStartHook
186-
OnBlockEnd BlockEndHook
187-
OnSkippedBlock SkippedBlockHook
188-
OnGenesisBlock GenesisBlockHook
189-
OnSystemCallStart OnSystemCallStartHook
190-
OnSystemCallEnd OnSystemCallEndHook
187+
OnBlockchainInit BlockchainInitHook
188+
OnClose CloseHook
189+
OnBlockStart BlockStartHook
190+
OnBlockEnd BlockEndHook
191+
OnSkippedBlock SkippedBlockHook
192+
OnGenesisBlock GenesisBlockHook
193+
OnSystemCallStart OnSystemCallStartHook
194+
OnSystemCallStartV2 OnSystemCallStartHookV2
195+
OnSystemCallEnd OnSystemCallEndHook
191196
// State events
192197
OnBalanceChange BalanceChangeHook
193198
OnNonceChange NonceChangeHook

0 commit comments

Comments
 (0)