From 914c555ff54824c75ece120f7278304c11293c78 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 8 Mar 2022 12:10:42 -0500 Subject: [PATCH] initial logic to remove txs from the mempool --- abci/types/types.go | 12 ++++++++++++ internal/state/execution.go | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/abci/types/types.go b/abci/types/types.go index dd266e1ce..53146adc5 100644 --- a/abci/types/types.go +++ b/abci/types/types.go @@ -221,6 +221,18 @@ func (rpp *ResponsePrepareProposal) IncludedTxs() []*TxRecord { return trs } +// RemovedTxs returns all of the TxRecords that are marked for removal from the +// mempool. +func (rpp *ResponsePrepareProposal) RemovedTxs() []*TxRecord { + trs := []*TxRecord{} + for _, tr := range rpp.TxRecords { + if tr.Action == TxRecord_REMOVED { + trs = append(trs, tr) + } + } + return trs +} + // Validate checks that the fields of the ResponsePrepareProposal are properly // constructed. Validate returns an error if any of the validation checks fail. func (rpp *ResponsePrepareProposal) Validate(maxSizeBytes int64, otxs [][]byte) error { diff --git a/internal/state/execution.go b/internal/state/execution.go index 9623e18a1..ce18f7ed0 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -144,7 +144,11 @@ func (blockExec *BlockExecutor) CreateProposalBlock( if err := rpp.Validate(maxDataBytes, txs.ToSliceOfBytes()); err != nil { return nil, err } - + for _, rtx := range rpp.RemovedTxs() { + if err := blockExec.mempool.RemoveTxByKey(types.Tx(rtx.Tx).Key()); err != nil { + blockExec.logger.Debug("error removing transaction from the mempool", "error", err) + } + } return state.MakeBlock(height, types.TxRecordsToTxs(rpp.IncludedTxs()), commit, evidence, proposerAddr) }