vm: add Call method which increments invocation counter

This commit is contained in:
Anna Shaleva 2020-10-05 13:35:53 +03:00
parent 6ce00fde82
commit cbf89fbb19

View file

@ -1229,7 +1229,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
v.checkInvocationStackSize() v.checkInvocationStackSize()
// Note: jump offset must be calculated regarding to new context, // Note: jump offset must be calculated regarding to new context,
// but it is cloned and thus has the same script and instruction pointer. // but it is cloned and thus has the same script and instruction pointer.
v.Call(ctx, v.getJumpOffset(ctx, parameter)) v.call(ctx, v.getJumpOffset(ctx, parameter))
case opcode.CALLA: case opcode.CALLA:
ptr := v.estack.Pop().Item().(*stackitem.Pointer) ptr := v.estack.Pop().Item().(*stackitem.Pointer)
@ -1237,7 +1237,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
panic("invalid script in pointer") panic("invalid script in pointer")
} }
v.Call(ctx, ptr.Position()) v.call(ctx, ptr.Position())
case opcode.SYSCALL: case opcode.SYSCALL:
interopID := GetInteropID(parameter) interopID := GetInteropID(parameter)
@ -1459,8 +1459,17 @@ func (v *VM) Jump(ctx *Context, offset int) {
} }
// Call calls method by offset. It is similar to Jump but also // Call calls method by offset. It is similar to Jump but also
// pushes new context to the invocation state // pushes new context to the invocation stack and increments
// invocation counter for the corresponding context script hash.
func (v *VM) Call(ctx *Context, offset int) { func (v *VM) Call(ctx *Context, offset int) {
v.call(ctx, offset)
v.Invocations[ctx.ScriptHash()]++
}
// call is an internal representation of Call, which does not
// affect the invocation counter and is only being used by vm
// package.
func (v *VM) call(ctx *Context, offset int) {
newCtx := ctx.Copy() newCtx := ctx.Copy()
newCtx.CheckReturn = false newCtx.CheckReturn = false
newCtx.local = nil newCtx.local = nil