Skip to content

Commit

Permalink
fix: determine mid block tx in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcre committed Oct 24, 2023
1 parent 0329fa3 commit 27d6919
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
35 changes: 27 additions & 8 deletions app/ante/msg_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,19 @@ func (d MsgFilterDecorator) ValidateMsgs(ctx sdk.Context, msgs []sdk.Msg) error
}
}

// tracking mixed batch msg with regular msg
case *exchangetypes.MsgPlaceBatchLimitOrder,
*exchangetypes.MsgPlaceMMBatchLimitOrder,
*exchangetypes.MsgCancelOrder,
*exchangetypes.MsgCancelAllOrders:
numMsg--
numBatchMsg++

// block double nested MsgExec
case *authz.MsgExec:
if nested {
return fmt.Errorf("double nested %s is not allowed", sdk.MsgTypeURL(msg))
}
default:
// tracking mixed batch msg with regular msg
if IsMidBlockMsg(msg) {
numMsg--
numBatchMsg++
return nil
}

// block deprecated module's msgs
if legacyMsg, ok := msg.(legacytx.LegacyMsg); ok {
switch legacyMsg.Route() {
Expand Down Expand Up @@ -142,3 +141,23 @@ func CalcMinInitialDeposit(minDeposit sdk.Coins, minInitialDepositFraction sdk.D
}
return
}

func IsMidBlockTx(tx sdk.Tx) bool {
for _, msg := range tx.GetMsgs() {
if !IsMidBlockMsg(msg) {
return false
}
}
return true
}

func IsMidBlockMsg(msg sdk.Msg) bool {
switch msg.(type) {
case *exchangetypes.MsgPlaceBatchLimitOrder,
*exchangetypes.MsgPlaceMMBatchLimitOrder,
*exchangetypes.MsgCancelOrder,
*exchangetypes.MsgCancelAllOrders:
return true
}
return false
}
17 changes: 2 additions & 15 deletions app/mid_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"

exchangetypes "github.com/crescent-network/crescent/v5/x/exchange/types"
"github.com/crescent-network/crescent/v5/app/ante"
)

func (app *App) MidBlocker(ctx sdk.Context, req abci.RequestMidBlock) abci.ResponseMidBlock {
Expand Down Expand Up @@ -41,24 +41,11 @@ func SplitMidBlockTxs(txs [][]byte, txDecoder sdk.TxDecoder) (midBlockTxs, norma
normalTxs = append(normalTxs, rawTx)
continue
}
if IsMidBlockTx(tx) {
if ante.IsMidBlockTx(tx) {
midBlockTxs = append(midBlockTxs, rawTx)
} else {
normalTxs = append(normalTxs, rawTx)
}
}
return midBlockTxs, normalTxs
}

func IsMidBlockTx(tx sdk.Tx) bool {
for _, msg := range tx.GetMsgs() {
switch msg.(type) {
case *exchangetypes.MsgPlaceBatchLimitOrder,
*exchangetypes.MsgPlaceMMBatchLimitOrder,
*exchangetypes.MsgCancelOrder:
default:
return false
}
}
return true
}

0 comments on commit 27d6919

Please sign in to comment.