-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: use harcoded global min gas price check in ProcessProposal #2985
Changes from all commits
10352cd
f382ad6
617e7ff
2f89d0c
4136c46
d20fe1a
488bb7f
fae5c79
070c51e
189f19b
6640341
4f804cd
6c62e68
9156b77
d805575
ad1912f
37ca150
4302fa4
34c9628
cb0d51b
9d5739c
a07b827
f65ce02
c476541
a480db0
97616e0
91f1b42
9f6a379
1e2bd44
9aeccb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package ante_test | ||
ninabarbakadze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/ante" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
"github.com/celestiaorg/celestia-app/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/test/util/testnode" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/require" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
version "github.com/tendermint/tendermint/proto/tendermint/version" | ||
) | ||
|
||
func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { | ||
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) | ||
|
||
builder := encCfg.TxConfig.NewTxBuilder() | ||
err := builder.SetMsgs(banktypes.NewMsgSend( | ||
testnode.RandomAddress().(sdk.AccAddress), | ||
testnode.RandomAddress().(sdk.AccAddress), | ||
sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 10))), | ||
) | ||
require.NoError(t, err) | ||
|
||
feeAmount := int64(1000) | ||
|
||
ctx := sdk.Context{} | ||
|
||
testCases := []struct { | ||
name string | ||
fee sdk.Coins | ||
gasLimit uint64 | ||
appVersion uint64 | ||
expErr bool | ||
}{ | ||
{ | ||
name: "bad tx; fee below required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount-1)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "good tx; fee equal to required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; fee above required minimum", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount+1)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; with no fee (v1)", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), | ||
appVersion: uint64(1), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; gas limit and fee are maximum values", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, math.MaxInt64)), | ||
gasLimit: math.MaxUint64, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "bad tx; gas limit and fee are 0", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 0)), | ||
gasLimit: 0, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
{ | ||
name: "good tx; minFee = 0.8, rounds up to 1", | ||
fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), | ||
gasLimit: 400, | ||
appVersion: uint64(2), | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
builder.SetGasLimit(tc.gasLimit) | ||
builder.SetFeeAmount(tc.fee) | ||
tx := builder.GetTx() | ||
|
||
ctx = ctx.WithBlockHeader(tmproto.Header{ | ||
Version: version.Consensus{ | ||
App: tc.appVersion, | ||
}, | ||
}) | ||
_, _, err := ante.CheckTxFeeWithGlobalMinGasPrices(ctx, tx) | ||
if tc.expErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ func (s *MaxTotalBlobSizeSuite) TestErrTotalBlobSizeTooLarge() { | |
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
blobTx, err := signer.CreatePayForBlob([]*blob.Blob{tc.blob}, user.SetGasLimit(1e9)) | ||
blobTx, err := signer.CreatePayForBlob([]*blob.Blob{tc.blob}, user.SetGasLimit(1e9), user.SetFee(2000000)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Since the minimum gas price is hardcoded, you could probably create a function that takes the gas limit and returns the minimum fee instead of having to calculate it yourself There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you suggest I put that helper in a separate package or do you have a specific spot in mind?
ninabarbakadze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
require.NoError(t, err) | ||
subCtx, cancel := context.WithTimeout(s.cctx.GoContext(), 30*time.Second) | ||
defer cancel() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] for @cmwaters @evan-forbes for single binary syncs and rolling upgrades, do we need to make the
NewAnteHandler
invocation version aware?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we will ever be able to to remove an antehandler, so I don't think that we need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about having a generic version wrapper that wraps the decorator and only executes it for certain versions. This might be more cleaner than having version checks sporadically added to every decorator