From 779144426fa8c4fca19bd5f560b6510801ed9517 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Thu, 26 Sep 2024 22:39:53 +0900 Subject: [PATCH] fix to charge gas first before returnning errorg --- x/move/keeper/handler.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/move/keeper/handler.go b/x/move/keeper/handler.go index 6ee457b9..69c01380 100644 --- a/x/move/keeper/handler.go +++ b/x/move/keeper/handler.go @@ -584,6 +584,7 @@ func (k Keeper) executeViewFunction( sdkCtx := sdk.UnwrapSDKContext(ctx) gasMeter := sdkCtx.GasMeter() gasForRuntime := gasMeter.Limit() - gasMeter.GasConsumedToLimit() + gasBalance := gasForRuntime viewRes, err := execVM(ctx, k, func(vm types.VMEngine) (vmtypes.ViewOutput, error) { return vm.ExecuteViewFunction( @@ -594,13 +595,13 @@ func (k Keeper) executeViewFunction( payload, ) }) - if err != nil { - return vmtypes.ViewOutput{}, 0, err - } // consume gas first and check error gasUsed := gasForRuntime - gasBalance gasMeter.ConsumeGas(gasUsed, "view; move runtime") + if err != nil { + return vmtypes.ViewOutput{}, gasUsed, err + } return viewRes, gasUsed, nil }