From b8f67f7e6f5f8a35eb76fac37dafe2517232bcd2 Mon Sep 17 00:00:00 2001 From: Bernardo Ramos Date: Sat, 1 Jun 2024 12:08:53 -0300 Subject: [PATCH] check error when creating contract executor --- contract/vm.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/contract/vm.go b/contract/vm.go index b52b354f0..bb340eaf5 100644 --- a/contract/vm.go +++ b/contract/vm.go @@ -828,11 +828,13 @@ func Call( ce := newExecutor(contract, contractAddress, ctx, &ci, ctx.curContract.amount, false, false, contractState) defer ce.close() - startTime := time.Now() - // execute the contract call - ce.call(callMaxInstLimit, nil) - vmExecTime := time.Now().Sub(startTime).Microseconds() - vmLogger.Trace().Int64("execµs", vmExecTime).Stringer("txHash", types.LogBase58(ce.ctx.txHash)).Msg("tx execute time in vm") + if ce.err == nil { + startTime := time.Now() + // execute the contract call + ce.call(callMaxInstLimit, nil) + vmExecTime := time.Now().Sub(startTime).Microseconds() + vmLogger.Trace().Int64("execµs", vmExecTime).Stringer("txHash", types.LogBase58(ce.ctx.txHash)).Msg("tx execute time in vm") + } // check if there is an error err = ce.err @@ -975,8 +977,10 @@ func Create( ce := newExecutor(contract, contractAddress, ctx, &ci, ctx.curContract.amount, true, false, contractState) defer ce.close() - // call the constructor - ce.call(callMaxInstLimit, nil) + if err == nil { + // call the constructor + ce.call(callMaxInstLimit, nil) + } // check if the call failed err = ce.err @@ -1103,7 +1107,9 @@ func Query(contractAddress []byte, bs *state.BlockState, cdb ChainAccessor, cont } }() - ce.call(queryMaxInstLimit, nil) + if err == nil { + ce.call(queryMaxInstLimit, nil) + } return []byte(ce.jsonRet), ce.err } @@ -1177,7 +1183,9 @@ func CheckFeeDelegation(contractAddress []byte, bs *state.BlockState, bi *types. } }() - ce.call(queryMaxInstLimit, nil) + if err == nil { + ce.call(queryMaxInstLimit, nil) + } if ce.err != nil { return ce.err