Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 12, 2023
1 parent 2525de2 commit 6e9d38e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
16 changes: 4 additions & 12 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@ func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
// eagerly set infinite gas meter so that queries performed by isTxGasless will not incur gas cost
ctx = ctx.WithGasMeter(storetypes.NewNoConsumptionInfiniteGasMeter())

feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
gas := feeTx.GetGas()
// If non-zero gas limit is provided by the TX, we then consider it exempt from the gasless TX, and then prioritize it accordingly
isGasless, err := isTxGasless(tx, ctx, gd.oracleKeeper)
if err != nil {
return ctx, err
}
if !isGasless {
ctx = ctx.WithGasMeter(originalGasMeter)
}
isDeliverTx := !ctx.IsCheckTx() && !ctx.IsReCheckTx() && !simulate
shouldCheckTxSkipFeeDeduct := gas == 0 && isGasless // whether the tx should be subject to min fee check AND priority assignment. Applicable to CheckTx only.
if isDeliverTx || !shouldCheckTxSkipFeeDeduct {
if isDeliverTx || !isGasless {
// In the case of deliverTx, we want to deduct fees regardless of whether the tx is considered gasless or not, since
// gasless txs will be subject to application-specific fee requirements in later stage of ante, for which the payment
// of those app-specific fees happens here. Note that the minimum fee check in the wrapped deduct fee handler is only
Expand All @@ -49,13 +45,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.
if !isGasless {
ctx = ctx.WithGasMeter(originalGasMeter)
}
return gd.handleWrapped(ctx, tx, simulate, next)
}

// must be gasless if this part is reached, so no need to overwrite gas meter back
return next(ctx, tx, simulate)
}

Expand Down
15 changes: 1 addition & 14 deletions app/antedecorators/gasless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,7 @@ func TestGaslessDecorator(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)

// gasless tx (checkTx w/ gas limit) -> wrapped should still be run
output = ""
outputDeps = ""
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
FakeMsgs: []sdk.Msg{&types.MsgPlaceOrders{}},
Gas: 100,
}, false)
require.NoError(t, err)
require.Equal(t, "onetwothree", output)
_, err = depGen([]accesscontrol.AccessOperation{}, FakeTx{}, 1)
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)

// gasless tx (checkTx w/o gas limit) -> wrapped should not be run
// gasless tx (checkTx) -> wrapped should not be run
output = ""
outputDeps = ""
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
Expand Down

0 comments on commit 6e9d38e

Please sign in to comment.