From 1cbd0c9f26c14362cd3df09924e84d7f4aec7d36 Mon Sep 17 00:00:00 2001 From: huangyi Date: Wed, 26 Jun 2024 10:52:38 +0800 Subject: [PATCH] cleanup --- baseapp/abci_utils.go | 19 +++++++++++++------ types/mempool/mempool.go | 12 +----------- types/mempool/priority_nonce.go | 2 +- types/mempool/sender_nonce.go | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index c4b9d59ec509..5c1f350aad3d 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -270,7 +270,14 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan return nil, err } - stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, mempool.NewMempoolTx(tx), txBz) + var txGasLimit uint64 + if gasTx, ok := tx.(interface { + GetGas() uint64 + }); ok { + txGasLimit = gasTx.GetGas() + } + + stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, tx, txBz, txGasLimit) if stop { break } @@ -325,7 +332,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan return nil, err } } else { - stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz) + stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, memTx.Tx, txBz, memTx.GasWanted) if stop { break } @@ -451,7 +458,7 @@ type TxSelector interface { // a proposal based on inclusion criteria defined by the TxSelector. It must // return if the caller should halt the transaction selection loop // (typically over a mempool) or otherwise. - SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx mempool.MempoolTx, txBz []byte) bool + SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool } type defaultTxSelector struct { @@ -476,7 +483,7 @@ func (ts *defaultTxSelector) Clear() { ts.selectedTxs = nil } -func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx mempool.MempoolTx, txBz []byte) bool { +func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool { txSize := uint64(len(txBz)) // only add the transaction to the proposal if we have enough capacity @@ -484,8 +491,8 @@ func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, // If there is a max block gas limit, add the tx only if the limit has // not been met. if maxBlockGas > 0 { - if (memTx.GasWanted + ts.totalTxGas) <= maxBlockGas { - ts.totalTxGas += memTx.GasWanted + if (gasWanted + ts.totalTxGas) <= maxBlockGas { + ts.totalTxGas += gasWanted ts.totalTxBytes += txSize ts.selectedTxs = append(ts.selectedTxs, txBz) } diff --git a/types/mempool/mempool.go b/types/mempool/mempool.go index a1b7597c3cc2..b3694bb35527 100644 --- a/types/mempool/mempool.go +++ b/types/mempool/mempool.go @@ -12,17 +12,7 @@ type MempoolTx struct { GasWanted uint64 } -func NewMempoolTx(tx sdk.Tx) MempoolTx { - var txGasLimit uint64 - if gasTx, ok := tx.(interface { - GetGas() uint64 - }); ok { - txGasLimit = gasTx.GetGas() - } - return NewMempoolTxWithGasWanted(tx, txGasLimit) -} - -func NewMempoolTxWithGasWanted(tx sdk.Tx, gasWanted uint64) MempoolTx { +func NewMempoolTx(tx sdk.Tx, gasWanted uint64) MempoolTx { return MempoolTx{ Tx: tx, GasWanted: gasWanted, diff --git a/types/mempool/priority_nonce.go b/types/mempool/priority_nonce.go index 8aceb63c01fd..9d3dcb3951af 100644 --- a/types/mempool/priority_nonce.go +++ b/types/mempool/priority_nonce.go @@ -210,7 +210,7 @@ func (mp *PriorityNonceMempool[C]) InsertWithGasWanted(ctx context.Context, tx s return nil } - memTx := NewMempoolTxWithGasWanted(tx, gasWanted) + memTx := NewMempoolTx(tx, gasWanted) sigs, err := mp.cfg.SignerExtractor.GetSigners(tx) if err != nil { diff --git a/types/mempool/sender_nonce.go b/types/mempool/sender_nonce.go index bd8a0303bc16..6609263af3bf 100644 --- a/types/mempool/sender_nonce.go +++ b/types/mempool/sender_nonce.go @@ -127,7 +127,7 @@ func (snm *SenderNonceMempool) InsertWithGasWanted(_ context.Context, tx sdk.Tx, return nil } - memTx := NewMempoolTxWithGasWanted(tx, gasLimit) + memTx := NewMempoolTx(tx, gasLimit) sigs, err := tx.(signing.SigVerifiableTx).GetSignaturesV2() if err != nil {