Skip to content
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

Problem: tx is decoded in PrepareProposal when using NopMempool #884

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#261](https://github.com/crypto-org-chain/cosmos-sdk/pull/261) `ctx.BlockHeader` don't do protobuf deep copy, shallow copy seems enough, reduce scope of mutex in `PriorityNonceMempool.Remove`.
* [#507](https://github.com/crypto-org-chain/cosmos-sdk/pull/507) mempool respect gas wanted returned by ante handler
* [#744](https://github.com/crypto-org-chain/cosmos-sdk/pull/744) Pass raw transactions to tx executor so it can do pre-estimations.
* [#]() Avoid decoding tx for in PrepareProposal if it's NopMempool.
yihuang marked this conversation as resolved.
Show resolved Hide resolved

## [Unreleased]

Expand Down
32 changes: 13 additions & 19 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,8 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
// Note, we still need to ensure the transactions returned respect req.MaxTxBytes.
_, isNoOp := h.mempool.(mempool.NoOpMempool)
if h.mempool == nil || isNoOp {
for _, txBz := range req.Txs {
tx, err := h.txVerifier.TxDecode(txBz)
if err != nil {
return nil, err
}

var txGasLimit uint64
if gasTx, ok := tx.(mempool.GasTx); ok {
txGasLimit = gasTx.GetGas()
}

stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, tx, txBz, txGasLimit)
if stop {
break
}
}

return &abci.ResponsePrepareProposal{Txs: h.txSelector.SelectedTxs(ctx)}, nil
txs := h.txSelector.SelectTxForProposalFast(ctx, req.Txs)
return &abci.ResponsePrepareProposal{Txs: txs}, nil
}

selectedTxsSignersSeqs := make(map[string]uint64)
Expand Down Expand Up @@ -464,6 +448,12 @@ type TxSelector interface {
// return <true> if the caller should halt the transaction selection loop
// (typically over a mempool) or <false> otherwise.
SelectTxForProposal(ctx context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool

// SelectTxForProposalFast is called in the case of NoOpMempool,
// where cometbft already checked the block gas/size limit,
// so the tx selector should simply accept them all to the proposal.
// But extra validations on the tx are still possible though.
SelectTxForProposalFast(ctx context.Context, txs [][]byte) [][]byte
}

type defaultTxSelector struct {
Expand All @@ -485,7 +475,7 @@ func (ts *defaultTxSelector) SelectedTxs(_ context.Context) [][]byte {
func (ts *defaultTxSelector) Clear() {
ts.totalTxBytes = 0
ts.totalTxGas = 0
ts.selectedTxs = nil
ts.selectedTxs = ts.selectedTxs[:0] // keep the allocated memory
}

func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte, gasWanted uint64) bool {
Expand All @@ -510,3 +500,7 @@ func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes,
// check if we've reached capacity; if so, we cannot select any more transactions
return ts.totalTxBytes >= maxTxBytes || (maxBlockGas > 0 && (ts.totalTxGas >= maxBlockGas))
}

func (ts *defaultTxSelector) SelectTxForProposalFast(ctx context.Context, txs [][]byte) [][]byte {
return txs
}
Loading