Skip to content

Commit

Permalink
remove tx out of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Aug 30, 2024
1 parent 22717eb commit 1539827
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions baseapp/abci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
var (
err error
selectedTxsNums int
invalidTxs []sdk.Tx // invalid txs to be removed after the iteration
)
h.mempool.SelectBy(ctx, req.Txs, func(memTx sdk.Tx) bool {
var signerData []mempool.SignerData
Expand Down Expand Up @@ -328,10 +329,7 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
var txBz []byte
txBz, err = h.txVerifier.PrepareProposalVerifyTx(memTx)
if err != nil {
err = h.mempool.Remove(memTx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
return false
}
invalidTxs = append(invalidTxs, memTx)
} else {
stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
if stop {
Expand Down Expand Up @@ -363,6 +361,13 @@ func (h *DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHan
return nil, err
}

for _, tx := range invalidTxs {
err := h.mempool.Remove(tx)
if err != nil && !errors.Is(err, mempool.ErrTxNotFound) {
return nil, err
}
}

return &abci.PrepareProposalResponse{Txs: h.txSelector.SelectedTxs(ctx)}, nil
}
}
Expand Down

0 comments on commit 1539827

Please sign in to comment.