Skip to content

Commit e5ab795

Browse files
committed
feat: override vm.NewEVM() args
1 parent 81e109a commit e5ab795

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

core/vm/evm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
143143
blockCtx.BlobBaseFee = new(big.Int)
144144
}
145145
}
146+
blockCtx, txCtx, statedb, chainConfig, config = overrideNewEVMArgs(blockCtx, txCtx, statedb, chainConfig, config)
146147
evm := &EVM{
147148
Context: blockCtx,
148149
TxContext: txCtx,

core/vm/hooks.libevm.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package vm
2+
3+
import "github.com/ethereum/go-ethereum/params"
4+
5+
// RegisterHooks registers the Hooks. It is expected to be called in an `init()`
6+
// function and MUST NOT be called more than once.
7+
func RegisterHooks(h Hooks) {
8+
if libevmHooks != nil {
9+
panic("already registered")
10+
}
11+
libevmHooks = h
12+
}
13+
14+
var libevmHooks Hooks
15+
16+
// Hooks are arbitrary configuration functions to modify default VM behaviour.
17+
type Hooks interface {
18+
OverrideNewEVMArgs(BlockContext, TxContext, StateDB, *params.ChainConfig, Config) (BlockContext, TxContext, StateDB, *params.ChainConfig, Config)
19+
}
20+
21+
func overrideNewEVMArgs(
22+
blockCtx BlockContext,
23+
txCtx TxContext,
24+
statedb StateDB,
25+
chainConfig *params.ChainConfig,
26+
config Config,
27+
) (BlockContext, TxContext, StateDB, *params.ChainConfig, Config) {
28+
if libevmHooks == nil {
29+
return blockCtx, txCtx, statedb, chainConfig, config
30+
}
31+
return libevmHooks.OverrideNewEVMArgs(blockCtx, txCtx, statedb, chainConfig, config)
32+
}

0 commit comments

Comments
 (0)