Skip to content

Commit

Permalink
Use no consumption infinite gas meter for gasless
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 12, 2023
1 parent 45f5026 commit f121a54
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
7 changes: 5 additions & 2 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -25,7 +26,7 @@ func NewGaslessDecorator(wrapped []sdk.AnteFullDecorator, oracleKeeper oraclekee
func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
originalGasMeter := ctx.GasMeter()
// eagerly set infinite gas meter so that queries performed by isTxGasless will not incur gas cost
ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
ctx = ctx.WithGasMeter(storetypes.NewNoConsumptionInfiniteGasMeter())

feeTx, ok := tx.(sdk.FeeTx)
if !ok {
Expand All @@ -48,7 +49,9 @@ func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
// Otherwise (i.e. in the case of checkTx), we only want to perform fee checks and fee deduction if the tx is not considered
// gasless, or if it specifies a non-zero gas limit even if it is considered gasless, so that the wrapped deduct fee
// handler will assign an appropriate priority to it.
ctx = ctx.WithGasMeter(originalGasMeter)
if !isGasless {
ctx = ctx.WithGasMeter(originalGasMeter)
}
return gd.handleWrapped(ctx, tx, simulate, next)
}

Expand Down
6 changes: 2 additions & 4 deletions app/antedecorators/gasless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestGaslessDecorator(t *testing.T) {
// gasless tx (checkTx w/ gas limit) -> wrapped should still be run
output = ""
outputDeps = ""
resCtx, err := chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
FakeMsgs: []sdk.Msg{&types.MsgPlaceOrders{}},
Gas: 100,
}, false)
Expand All @@ -158,20 +158,18 @@ func TestGaslessDecorator(t *testing.T) {
_, err = depGen([]accesscontrol.AccessOperation{}, FakeTx{}, 1)
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)
require.NotEqual(t, resCtx.GasMeter().Limit(), 0) // make sure gas meter is limited

// gasless tx (checkTx w/o gas limit) -> wrapped should not be run
output = ""
outputDeps = ""
resCtx, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
FakeMsgs: []sdk.Msg{&types.MsgPlaceOrders{}},
}, false)
require.NoError(t, err)
require.Equal(t, "onethree", output)
_, err = depGen([]accesscontrol.AccessOperation{}, FakeTx{}, 1)
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)
require.NotEqual(t, resCtx.GasMeter().Limit(), 0) // make sure gas meter is limited
}

func TestOracleVoteGasless(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ require (
replace (
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.0.2
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.59
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.59-nocons
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.7
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.1.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+f
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQpIbXDA=
github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8=
github.com/sei-protocol/sei-cosmos v0.2.59 h1:GCi8R+yuEFIzEzTe+oRUxa2Y/QUvIRCK57aXninBvDk=
github.com/sei-protocol/sei-cosmos v0.2.59/go.mod h1:XSmrSNlBQ7OQrk6VZMgARWsnD+1JSnQeDEZ7LEmexbo=
github.com/sei-protocol/sei-cosmos v0.2.59-nocons h1:mp2R65Ywhg7RIm+DQKtw0IVtzxARzdthKxE7BzyxHuA=
github.com/sei-protocol/sei-cosmos v0.2.59-nocons/go.mod h1:XSmrSNlBQ7OQrk6VZMgARWsnD+1JSnQeDEZ7LEmexbo=
github.com/sei-protocol/sei-iavl v0.1.7 h1:cUdHDBkxs0FF/kOt1qCVLm0K+Bqaw92/dbZSgn4kxiA=
github.com/sei-protocol/sei-iavl v0.1.7/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-ibc-go/v3 v3.1.0 h1:rFHk2R/3vbG9iNr7cYtVclW/UyEDSRFjNVPz60zZswU=
Expand Down

0 comments on commit f121a54

Please sign in to comment.