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>
This commit is contained in:
parent
f0e7382f38
commit
67a3b08795
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/misc"
|
"github.com/ethereum/go-ethereum/consensus/misc"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
@ -212,9 +213,7 @@ func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *
|
||||||
// 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, evm *vm.EVM) {
|
func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) {
|
||||||
if tracer := evm.Config.Tracer; tracer != nil {
|
if tracer := evm.Config.Tracer; tracer != nil {
|
||||||
if tracer.OnSystemCallStart != nil {
|
onSystemCallStart(tracer, evm.GetVMContext())
|
||||||
tracer.OnSystemCallStart()
|
|
||||||
}
|
|
||||||
if tracer.OnSystemCallEnd != nil {
|
if tracer.OnSystemCallEnd != nil {
|
||||||
defer tracer.OnSystemCallEnd()
|
defer tracer.OnSystemCallEnd()
|
||||||
}
|
}
|
||||||
|
@ -238,9 +237,7 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, evm *vm.EVM) {
|
||||||
// as per EIP-2935.
|
// as per EIP-2935.
|
||||||
func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM) {
|
func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM) {
|
||||||
if tracer := evm.Config.Tracer; tracer != nil {
|
if tracer := evm.Config.Tracer; tracer != nil {
|
||||||
if tracer.OnSystemCallStart != nil {
|
onSystemCallStart(tracer, evm.GetVMContext())
|
||||||
tracer.OnSystemCallStart()
|
|
||||||
}
|
|
||||||
if tracer.OnSystemCallEnd != nil {
|
if tracer.OnSystemCallEnd != nil {
|
||||||
defer tracer.OnSystemCallEnd()
|
defer tracer.OnSystemCallEnd()
|
||||||
}
|
}
|
||||||
|
@ -274,9 +271,7 @@ func ProcessConsolidationQueue(requests *[][]byte, evm *vm.EVM) {
|
||||||
|
|
||||||
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) {
|
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) {
|
||||||
if tracer := evm.Config.Tracer; tracer != nil {
|
if tracer := evm.Config.Tracer; tracer != nil {
|
||||||
if tracer.OnSystemCallStart != nil {
|
onSystemCallStart(tracer, evm.GetVMContext())
|
||||||
tracer.OnSystemCallStart()
|
|
||||||
}
|
|
||||||
if tracer.OnSystemCallEnd != nil {
|
if tracer.OnSystemCallEnd != nil {
|
||||||
defer tracer.OnSystemCallEnd()
|
defer tracer.OnSystemCallEnd()
|
||||||
}
|
}
|
||||||
|
@ -322,3 +317,11 @@ func ParseDepositLogs(requests *[][]byte, logs []*types.Log, config *params.Chai
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onSystemCallStart(tracer *tracing.Hooks, ctx *tracing.VMContext) {
|
||||||
|
if tracer.OnSystemCallStartV2 != nil {
|
||||||
|
tracer.OnSystemCallStartV2(ctx)
|
||||||
|
} else if tracer.OnSystemCallStart != nil {
|
||||||
|
tracer.OnSystemCallStart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -145,6 +145,10 @@ type (
|
||||||
// will not be invoked.
|
// will not be invoked.
|
||||||
OnSystemCallStartHook = func()
|
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,
|
// 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
|
// this hook is invoked when the EIP-4788 system call is about to be executed to set the
|
||||||
// beacon block root.
|
// beacon block root.
|
||||||
|
@ -180,14 +184,15 @@ type Hooks struct {
|
||||||
OnFault FaultHook
|
OnFault FaultHook
|
||||||
OnGasChange GasChangeHook
|
OnGasChange GasChangeHook
|
||||||
// Chain events
|
// Chain events
|
||||||
OnBlockchainInit BlockchainInitHook
|
OnBlockchainInit BlockchainInitHook
|
||||||
OnClose CloseHook
|
OnClose CloseHook
|
||||||
OnBlockStart BlockStartHook
|
OnBlockStart BlockStartHook
|
||||||
OnBlockEnd BlockEndHook
|
OnBlockEnd BlockEndHook
|
||||||
OnSkippedBlock SkippedBlockHook
|
OnSkippedBlock SkippedBlockHook
|
||||||
OnGenesisBlock GenesisBlockHook
|
OnGenesisBlock GenesisBlockHook
|
||||||
OnSystemCallStart OnSystemCallStartHook
|
OnSystemCallStart OnSystemCallStartHook
|
||||||
OnSystemCallEnd OnSystemCallEndHook
|
OnSystemCallStartV2 OnSystemCallStartHookV2
|
||||||
|
OnSystemCallEnd OnSystemCallEndHook
|
||||||
// State events
|
// State events
|
||||||
OnBalanceChange BalanceChangeHook
|
OnBalanceChange BalanceChangeHook
|
||||||
OnNonceChange NonceChangeHook
|
OnNonceChange NonceChangeHook
|
||||||
|
|
Loading…
Reference in New Issue