-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(baseapp): avoid decoding tx in PrepareProposal when using NopMempool #24207
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
c2853a7
b283aad
e9c9cc2
0627b6f
13ff5f3
f52cab9
15b4774
0c04f1b
6d6898f
1700a0b
a32b1cc
f8f309f
000f26d
0dba131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,9 @@ type ( | |
| txVerifier ProposalTxVerifier | ||
| txSelector TxSelector | ||
| signerExtAdapter mempool.SignerExtractionAdapter | ||
|
|
||
| // fastPrepareProposal together with NoOpMempool will bypass tx selector | ||
| fastPrepareProposal bool | ||
| } | ||
| ) | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -265,6 +274,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 { | ||
|
|
@@ -473,6 +487,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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
is it still possible because i can implement my own TxSelector? i'm a bit confused on this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| SelectTxForProposalFast(ctx context.Context, txs [][]byte) [][]byte | ||
| } | ||
|
|
||
| type defaultTxSelector struct { | ||
|
|
@@ -494,7 +513,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 { | ||
|
|
@@ -526,3 +545,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 | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.