Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -83,6 +83,7 @@ This patch update also includes minor dependency bumps.

### Improvements

* [#24207](https://github.com/cosmos/cosmos-sdk/pull/24207) Avoid decoding tx for in PrepareProposal if it's NoOpMempool.
* (types) [#25342](https://github.com/cosmos/cosmos-sdk/pull/25342) Undeprecated `EmitEvent` and `EmitEvents` on the `EventManager`. These functions will continue to be maintained.
* (types) [#24668](https://github.com/cosmos/cosmos-sdk/pull/24668) Scope the global config to a particular binary so that multiple SDK binaries can be properly run on the same machine.
* (baseapp) [#24655](https://github.com/cosmos/cosmos-sdk/pull/24655) Add mutex locks for `state` and make `lastCommitInfo` atomic to prevent race conditions between `Commit` and `CreateQueryContext`.
Expand Down
25 changes: 24 additions & 1 deletion baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ type (
txVerifier ProposalTxVerifier
txSelector TxSelector
signerExtAdapter mempool.SignerExtractionAdapter

// fastPrepareProposal together with NoOpMempool will bypass tx selector
fastPrepareProposal bool
}
)

Expand All @@ -225,6 +228,12 @@ func NewDefaultProposalHandler(mp mempool.Mempool, txVerifier ProposalTxVerifier
}
}

func NewDefaultProposalHandlerFast(mp mempool.Mempool, txVerifier ProposalTxVerifier) *DefaultProposalHandler {
h := NewDefaultProposalHandler(mp, txVerifier)
h.fastPrepareProposal = true
return h
}

// SetTxSelector sets the TxSelector function on the DefaultProposalHandler.
func (h *DefaultProposalHandler) SetTxSelector(ts TxSelector) {
h.txSelector = ts
Expand Down Expand Up @@ -270,6 +279,11 @@ 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 {
if h.fastPrepareProposal {
txs := h.txSelector.SelectTxForProposalFast(ctx, req.Txs)
return &abci.ResponsePrepareProposal{Txs: txs}, nil
}

for _, txBz := range req.Txs {
tx, err := h.txVerifier.TxDecode(txBz)
if err != nil {
Expand Down Expand Up @@ -478,6 +492,11 @@ 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) 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// But extra validations on the tx are still possible though.

is it still possible because i can implement my own TxSelector? i'm a bit confused on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SelectTxForProposalFast(ctx context.Context, txs [][]byte) [][]byte
}

type defaultTxSelector struct {
Expand All @@ -499,7 +518,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) bool {
Expand Down Expand Up @@ -531,3 +550,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
}
7 changes: 7 additions & 0 deletions baseapp/abci_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()
ph := baseapp.NewDefaultProposalHandler(mempool.NoOpMempool{}, app)
handler := ph.PrepareProposalHandler()

phf := baseapp.NewDefaultProposalHandlerFast(mempool.NoOpMempool{}, app)
handlerFast := phf.PrepareProposalHandler()

// build a tx
_, _, addr := testdata.KeyTestPubAddr()
builder := txConfig.NewTxBuilder()
Expand Down Expand Up @@ -558,6 +561,10 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection()
resp, err := handler(tc.ctx, tc.req)
s.Require().NoError(err)
s.Require().Len(resp.Txs, tc.expectedTxs)

resp, err = handlerFast(tc.ctx, tc.req)
s.Require().NoError(err)
s.Require().Equal(resp.Txs, tc.req.Txs)
}
})
}
Expand Down
14 changes: 14 additions & 0 deletions baseapp/testutil/mock/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading