Skip to content

Commit

Permalink
bet
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 committed Dec 7, 2024
1 parent 719eaf5 commit 2c6b614
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions app/helper/helper.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions app/mempool/mempool_fifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions app/mempool/mempool_fifo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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++
}
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion custom/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
19 changes: 0 additions & 19 deletions custom/auth/ante/fee_tax.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}$")
Expand Down Expand Up @@ -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
}

0 comments on commit 2c6b614

Please sign in to comment.