From f121a54c30526dd340bc9e51b99d185442e67a04 Mon Sep 17 00:00:00 2001 From: codchen Date: Wed, 12 Jul 2023 12:01:26 +0800 Subject: [PATCH] Use no consumption infinite gas meter for gasless --- app/antedecorators/gasless.go | 7 +++++-- app/antedecorators/gasless_test.go | 6 ++---- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/antedecorators/gasless.go b/app/antedecorators/gasless.go index e21bf3b96..e506fe4e5 100644 --- a/app/antedecorators/gasless.go +++ b/app/antedecorators/gasless.go @@ -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" @@ -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 { @@ -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) } diff --git a/app/antedecorators/gasless_test.go b/app/antedecorators/gasless_test.go index 7d367d13d..2415a9fa4 100644 --- a/app/antedecorators/gasless_test.go +++ b/app/antedecorators/gasless_test.go @@ -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) @@ -158,12 +158,11 @@ 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) @@ -171,7 +170,6 @@ 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 } func TestOracleVoteGasless(t *testing.T) { diff --git a/go.mod b/go.mod index ff194d942..fe0a6b159 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index dde6eefc8..de7069789 100644 --- a/go.sum +++ b/go.sum @@ -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=