Skip to content

Commit

Permalink
feat: no refund if gasPrice is too low
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Jan 2, 2024
1 parent 59ca0da commit 4b00364
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/posthandler/refund_gas_remaining.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (d RefundGasRemainingDecorator) maybeRefund(ctx sdk.Context, tx sdk.Tx, sim
}

refund := getRefund(gasMeter, feeTx)
if len(refund) == 0 {
return nil
}
recipient := getRecipient(feeTx)

if err := d.processRefund(ctx, refund, recipient); err != nil {
Expand Down Expand Up @@ -139,7 +142,7 @@ func getRecipient(feeTx sdk.FeeTx) sdk.AccAddress {
func getGasPrice(feeTx sdk.FeeTx) sdk.DecCoin {
feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()
gasPrice := sdk.NewDecFromInt(feeCoins.AmountOf(appconsts.BondDenom)).Quo(sdk.NewDec(int64(gas)))
gasPrice := sdk.NewDecFromInt(feeCoins.AmountOf(appconsts.BondDenom)).Quo(sdk.NewDecFromInt(sdk.NewIntFromUint64(gas)))
return sdk.NewDecCoinFromDec(appconsts.BondDenom, gasPrice)
}

Expand Down
8 changes: 8 additions & 0 deletions app/posthandler/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/celestiaorg/celestia-app/test/util/testnode"
upgradetypes "github.com/celestiaorg/celestia-app/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -120,6 +121,13 @@ func (s *RefundGasRemainingSuite) TestDecorator() {
wantRefund: 0,
wantRefundRecipient: s.signer.Address(),
},
{
name: "no refund should be sent if gasPrice is extremely low because the refund amount truncates to zero",
gasLimit: tx.MaxGasWanted,
fee: utia,
wantRefund: 0,
wantRefundRecipient: s.signer.Address(),
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 4b00364

Please sign in to comment.