Skip to content

Commit a0d8ef9

Browse files
committed
refactor: move hooks logic to its own file
1 parent 58ded5b commit a0d8ef9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/vm/hooks.libevm.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// OverrideJumpTable will only be called if
19+
// [params.RulesHooks.OverrideJumpTable] returns true. This allows for
20+
// recursive calling into [LookupInstructionSet].
21+
OverrideJumpTable(params.Rules, *JumpTable) *JumpTable
22+
}
23+
24+
// overrideJumpTable returns `libevmHooks.OverrideJumpTable(r,jt)“ i.f.f. the
25+
// Rules' hooks indicate that it must, otherwise it echoes `jt` unchanged.
26+
func overrideJumpTable(r params.Rules, jt *JumpTable) *JumpTable {
27+
if !r.Hooks().OverrideJumpTable() {
28+
return jt
29+
}
30+
// We don't check that libevmHooks is non-nil because the user has clearly
31+
// signified that they want an override. A nil-pointer dereference will
32+
// occur in tests whereas graceful degradation would frustrate the user with
33+
// a hard-to-find bug.
34+
return libevmHooks.OverrideJumpTable(r, jt)
35+
}

0 commit comments

Comments
 (0)