Skip to content

Commit

Permalink
fix(logic): handle and return out of gas error at GRPC level
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jul 18, 2024
1 parent c13d9c4 commit ff3de76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions x/logic/keeper/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"fmt"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"io"
"math"
"strings"
Expand Down Expand Up @@ -107,12 +108,12 @@ func (k Keeper) newInterpreter(ctx context.Context) (*prolog.Interpreter, fmt.St

defer func() {
if r := recover(); r != nil {
if gasError, ok := r.(storetypes.ErrorOutOfGas); ok {
err = engine.ResourceError(prolog2.ResourceGas(gasError.Descriptor, gasMeter.GasConsumed(), gasMeter.Limit()), env)
return
switch rType := r.(type) {
case storetypes.ErrorOutOfGas:
err = errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", rType.Descriptor)
default:
panic(r)
}

panic(r)
}
}()

Expand Down
10 changes: 10 additions & 0 deletions x/logic/util/prolog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package util

import (
"context"
errorsmod "cosmossdk.io/errors"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"strings"

"github.com/ichiban/prolog"
Expand Down Expand Up @@ -48,6 +52,12 @@ func QueryInterpreter(
if callErr != nil {
if sdkmath.NewUint(uint64(len(results))).LT(solutionsLimit) {
// error is not part of the look-ahead and should be included in the solutions
if errors.Is(callErr, sdkerrors.ErrOutOfGas) {
return nil, callErr
} else if sdk.UnwrapSDKContext(ctx).GasMeter().IsOutOfGas() {
return nil, errorsmod.Wrapf(sdkerrors.ErrOutOfGas, "out of gas in location: %v", callErr.Error())
}

results = append(results, types.Result{Error: callErr.Error()})
} else {
// error is part of the look-ahead, so let's consider that there's one more solution
Expand Down

0 comments on commit ff3de76

Please sign in to comment.