@@ -26,12 +26,34 @@ type Mempool interface {
2626
2727// ExtMempool is an extension of Mempool interface introduced in v0.50
2828// for not be breaking in a patch release.
29- // In v0.52 +, this interface will be merged into Mempool interface.
29+ // In v0.54 +, this function is removed and RemoveWithReason is merged into Mempool interface.
3030type ExtMempool interface {
3131 Mempool
3232
3333 // SelectBy use callback to iterate over the mempool, it's thread-safe to use.
3434 SelectBy (context.Context , [][]byte , func (sdk.Tx ) bool )
35+
36+ // RemoveWithReason removes a transaction from the mempool with specific reason
37+ // allowing the mempool to handle the removal differently.
38+ RemoveWithReason (context.Context , sdk.Tx , RemoveReason ) error
39+ }
40+
41+ // RemovalCaller is the origin of the removal
42+ type RemovalCaller string
43+
44+ // Various callers
45+ const (
46+ CallerRunTxRecheck RemovalCaller = "run_tx.recheck"
47+ CallerRunTxFinalize RemovalCaller = "run_tx.finalize"
48+ CallerPrepareProposalRemoveInvalid RemovalCaller = "prepare_proposal.remove_invalid"
49+ )
50+
51+ // RemoveReason is the reason for removing a transaction from the mempool.
52+ type RemoveReason struct {
53+ Caller RemovalCaller
54+
55+ // Error is an optional error that caused the removal.
56+ Error error
3557}
3658
3759// Iterator defines an app-side mempool iterator interface that is as minimal as
@@ -65,3 +87,13 @@ func SelectBy(ctx context.Context, mempool Mempool, txs [][]byte, callback func(
6587 iter = iter .Next ()
6688 }
6789}
90+
91+ // RemoveWithReason is compatible with old interface to avoid breaking api.
92+ // In v0.54+, this function is removed and RemoveWithReason is merged into Mempool interface.
93+ func RemoveWithReason (ctx context.Context , mempool Mempool , tx sdk.Tx , reason RemoveReason ) error {
94+ if ext , ok := mempool .(ExtMempool ); ok {
95+ return ext .RemoveWithReason (ctx , tx , reason )
96+ }
97+
98+ return mempool .Remove (tx )
99+ }
0 commit comments