mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 23:25:22 +00:00
vm, core: move invocation counter from InteropContext to VM
This commit is contained in:
parent
45bfce60a5
commit
6ce00fde82
5 changed files with 8 additions and 6 deletions
|
@ -35,7 +35,6 @@ type Context struct {
|
|||
DAO *dao.Cached
|
||||
Notifications []state.NotificationEvent
|
||||
Log *zap.Logger
|
||||
Invocations map[util.Uint160]int
|
||||
VM *vm.VM
|
||||
Functions [][]Function
|
||||
}
|
||||
|
@ -53,7 +52,6 @@ func NewContext(trigger trigger.Type, bc blockchainer.Blockchainer, d dao.DAO, n
|
|||
DAO: dao,
|
||||
Notifications: nes,
|
||||
Log: log,
|
||||
Invocations: make(map[util.Uint160]int),
|
||||
// Functions is a slice of slices of interops sorted by ID.
|
||||
Functions: [][]Function{},
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func CallExInternal(ic *interop.Context, cs *state.Contract,
|
|||
}
|
||||
|
||||
u := cs.ScriptHash()
|
||||
ic.Invocations[u]++
|
||||
ic.VM.Invocations[u]++
|
||||
ic.VM.LoadScriptWithHash(cs.Script, u, ic.VM.Context().GetCallFlags()&f)
|
||||
var isNative bool
|
||||
for i := range ic.Natives {
|
||||
|
|
|
@ -59,10 +59,10 @@ func GetNotifications(ic *interop.Context) error {
|
|||
// GetInvocationCounter returns how many times current contract was invoked during current tx execution.
|
||||
func GetInvocationCounter(ic *interop.Context) error {
|
||||
currentScriptHash := ic.VM.GetCurrentScriptHash()
|
||||
count, ok := ic.Invocations[currentScriptHash]
|
||||
count, ok := ic.VM.Invocations[currentScriptHash]
|
||||
if !ok {
|
||||
count = 1
|
||||
ic.Invocations[currentScriptHash] = count
|
||||
ic.VM.Invocations[currentScriptHash] = count
|
||||
}
|
||||
ic.VM.Estack().PushVal(count)
|
||||
return nil
|
||||
|
|
|
@ -296,7 +296,7 @@ func TestRuntimeGetInvocationCounter(t *testing.T) {
|
|||
v, ic, chain := createVM(t)
|
||||
defer chain.Close()
|
||||
|
||||
ic.Invocations[hash.Hash160([]byte{2})] = 42
|
||||
ic.VM.Invocations[hash.Hash160([]byte{2})] = 42
|
||||
|
||||
t.Run("No invocations", func(t *testing.T) {
|
||||
v.LoadScript([]byte{1})
|
||||
|
|
|
@ -80,6 +80,9 @@ type VM struct {
|
|||
SyscallHandler func(v *VM, id uint32) error
|
||||
|
||||
trigger trigger.Type
|
||||
|
||||
// Invocations is a script invocation counter.
|
||||
Invocations map[util.Uint160]int
|
||||
}
|
||||
|
||||
// New returns a new VM object ready to load AVM bytecode scripts.
|
||||
|
@ -96,6 +99,7 @@ func NewWithTrigger(t trigger.Type) *VM {
|
|||
trigger: t,
|
||||
|
||||
SyscallHandler: defaultSyscallHandler,
|
||||
Invocations: make(map[util.Uint160]int),
|
||||
}
|
||||
|
||||
vm.estack = vm.newItemStack("evaluation")
|
||||
|
|
Loading…
Reference in a new issue