diff --git a/app/app.go b/app/app.go index 0a6278bc..9f01e57f 100644 --- a/app/app.go +++ b/app/app.go @@ -164,9 +164,11 @@ func NewTerraApp( // option for mempool baseAppOptions = append(baseAppOptions, func(app *baseapp.BaseApp) { - mempool := appmempool.NewFifoMempool() + var mempool *appmempool.FifoMempool if maxTxs := cast.ToInt(appOpts.Get(server.FlagMempoolMaxTxs)); maxTxs >= 0 { mempool = appmempool.NewFifoMempool(appmempool.FifoMaxTxOpt(maxTxs)) + } else { + mempool = appmempool.NewFifoMempool() } handler := baseapp.NewDefaultProposalHandler(mempool, app) app.SetMempool(mempool) diff --git a/app/helper/helper.go b/app/helper/helper.go new file mode 100644 index 00000000..b445d07d --- /dev/null +++ b/app/helper/helper.go @@ -0,0 +1,24 @@ +package helper + +import ( + oracleexported "github.com/classic-terra/core/v3/x/oracle/exported" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func IsOracleTx(msgs []sdk.Msg) bool { + if len(msgs) == 0 { + return false + } + for _, msg := range msgs { + switch msg.(type) { + case *oracleexported.MsgAggregateExchangeRatePrevote: + continue + case *oracleexported.MsgAggregateExchangeRateVote: + continue + default: + return false + } + } + + return true +} diff --git a/app/mempool/mempool_fifo.go b/app/mempool/mempool_fifo.go index 4d9d7ea9..20556a1a 100644 --- a/app/mempool/mempool_fifo.go +++ b/app/mempool/mempool_fifo.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - "github.com/classic-terra/core/v3/custom/auth/ante" + "github.com/classic-terra/core/v3/app/helper" "github.com/cometbft/cometbft/libs/clist" cmtsync "github.com/cometbft/cometbft/libs/sync" sdk "github.com/cosmos/cosmos-sdk/types" @@ -81,7 +81,7 @@ func (mp *FifoMempool) Insert(_ context.Context, tx sdk.Tx) error { return err } // Add to appropriate queue based on transaction type - if ante.IsOracleTx(tx.GetMsgs()) { + if helper.IsOracleTx(tx.GetMsgs()) { e := mp.txsOracle.PushBack(tx) mp.txsMapOracle.Store(txKey, e) } else { @@ -166,7 +166,7 @@ func (mp *FifoMempool) Remove(tx sdk.Tx) error { return err } - isOracle := ante.IsOracleTx(tx.GetMsgs()) + isOracle := helper.IsOracleTx(tx.GetMsgs()) if isOracle { if elem, ok := mp.txsMapOracle.LoadAndDelete(txKey); ok { mp.txsOracle.Remove(elem.(*clist.CElement)) diff --git a/app/mempool/mempool_fifo_test.go b/app/mempool/mempool_fifo_test.go index a0363743..8f1f009a 100644 --- a/app/mempool/mempool_fifo_test.go +++ b/app/mempool/mempool_fifo_test.go @@ -8,7 +8,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/classic-terra/core/v3/custom/auth/ante" + "github.com/classic-terra/core/v3/app/helper" oracleexported "github.com/classic-terra/core/v3/x/oracle/exported" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -268,7 +268,7 @@ func (s *MempoolTestSuite) TestTxOrderWithOracle() { orderedTxs := fetchTxs(itr, 1000) numberTxOracle := 0 for _, tx := range orderedTxs { - if ante.IsOracleTx(tx.GetMsgs()) { + if helper.IsOracleTx(tx.GetMsgs()) { numberTxOracle += +1 } else { break @@ -334,9 +334,9 @@ func (s *MempoolTestSuite) TestOracleTx() { } require.Equal(t, 3, len(orderedTxs)) - require.True(t, ante.IsOracleTx(orderedTxs[0].GetMsgs())) - require.True(t, ante.IsOracleTx(orderedTxs[1].GetMsgs())) - require.False(t, ante.IsOracleTx(orderedTxs[2].GetMsgs())) + require.True(t, helper.IsOracleTx(orderedTxs[0].GetMsgs())) + require.True(t, helper.IsOracleTx(orderedTxs[1].GetMsgs())) + require.False(t, helper.IsOracleTx(orderedTxs[2].GetMsgs())) require.Equal(t, 0, mp.CountTx()) } @@ -473,7 +473,7 @@ func (s *MempoolTestSuite) TestBatchTx_WhenEnoughMemPool() { // Count oracle transactions in first batch oracleCount := 0 for _, tx := range orderedTxs[:50] { - if ante.IsOracleTx(tx.GetMsgs()) { + if helper.IsOracleTx(tx.GetMsgs()) { oracleCount++ } } @@ -575,7 +575,7 @@ func (s *MempoolTestSuite) TestBatchTx_WhenNotEnoughMemPool() { firstRegularIndex := -1 for i, tx := range orderedTxs { - if ante.IsOracleTx(tx.GetMsgs()) { + if helper.IsOracleTx(tx.GetMsgs()) { lastOracleIndex = i // If we've already seen a regular transaction, this is an error require.Equal(t, -1, firstRegularIndex, diff --git a/custom/auth/ante/fee.go b/custom/auth/ante/fee.go index 617fdf50..36fb7521 100644 --- a/custom/auth/ante/fee.go +++ b/custom/auth/ante/fee.go @@ -6,6 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" + "github.com/classic-terra/core/v3/app/helper" taxkeeper "github.com/classic-terra/core/v3/x/tax/keeper" taxtypes "github.com/classic-terra/core/v3/x/tax/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -234,7 +235,7 @@ func (fd FeeDecorator) checkTxFee(ctx sdk.Context, tx sdk.Tx, taxes sdk.Coins, n feeCoins := feeTx.GetFee() gas := feeTx.GetGas() msgs := feeTx.GetMsgs() - isOracleTx := IsOracleTx(msgs) + isOracleTx := helper.IsOracleTx(msgs) reverseCharge := false refundNonTaxableTaxes := false diff --git a/custom/auth/ante/fee_tax.go b/custom/auth/ante/fee_tax.go index f8777512..37970cd7 100644 --- a/custom/auth/ante/fee_tax.go +++ b/custom/auth/ante/fee_tax.go @@ -10,7 +10,6 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" marketexported "github.com/classic-terra/core/v3/x/market/exported" - oracleexported "github.com/classic-terra/core/v3/x/oracle/exported" ) var IBCRegexp = regexp.MustCompile("^ibc/[a-fA-F0-9]{64}$") @@ -121,21 +120,3 @@ func computeTax(ctx sdk.Context, tk TreasuryKeeper, th TaxKeeper, principal sdk. return taxes } - -func IsOracleTx(msgs []sdk.Msg) bool { - if len(msgs) == 0 { - return false - } - for _, msg := range msgs { - switch msg.(type) { - case *oracleexported.MsgAggregateExchangeRatePrevote: - continue - case *oracleexported.MsgAggregateExchangeRateVote: - continue - default: - return false - } - } - - return true -}