Skip to content

Commit

Permalink
fix to charge gas first before returnning errorg
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Sep 26, 2024
1 parent aebda95 commit 7791444
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions x/move/keeper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}

Check warning on line 604 in x/move/keeper/handler.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/handler.go#L603-L604

Added lines #L603 - L604 were not covered by tests

return viewRes, gasUsed, nil
}
Expand Down

0 comments on commit 7791444

Please sign in to comment.