From 4b0036495f39a94a6ec90160a33172c4f40de02d Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Tue, 2 Jan 2024 15:58:19 -0500 Subject: [PATCH] feat: no refund if gasPrice is too low --- app/posthandler/refund_gas_remaining.go | 5 ++++- app/posthandler/suite_test.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/posthandler/refund_gas_remaining.go b/app/posthandler/refund_gas_remaining.go index 498ac22326..d7300e3f50 100644 --- a/app/posthandler/refund_gas_remaining.go +++ b/app/posthandler/refund_gas_remaining.go @@ -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 { @@ -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) } diff --git a/app/posthandler/suite_test.go b/app/posthandler/suite_test.go index 9abf5cee58..347857194e 100644 --- a/app/posthandler/suite_test.go +++ b/app/posthandler/suite_test.go @@ -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" @@ -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 {