refactor(mempool)!: match server/v2/cometbft and sdk mempool interface (#21744)
Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
@@ -19,13 +19,18 @@ type Mempool[T transaction.Tx] interface {
|
||||
Insert(context.Context, T) error
|
||||
|
||||
// Select returns an Iterator over the app-side mempool. If txs are specified,
|
||||
// then they shall be incorporated into the Iterator. The Iterator must be
|
||||
// closed by the caller.
|
||||
// then they shall be incorporated into the Iterator. The Iterator is not thread-safe to use.
|
||||
Select(context.Context, []T) Iterator[T]
|
||||
|
||||
// SelectBy use callback to iterate over the mempool, it's thread-safe to use.
|
||||
SelectBy(context.Context, []T, func(T) bool)
|
||||
|
||||
// CountTx returns the number of transactions currently in the mempool.
|
||||
CountTx() int
|
||||
|
||||
// Remove attempts to remove a transaction from the mempool, returning an error
|
||||
// upon failure.
|
||||
Remove([]T) error
|
||||
Remove(T) error
|
||||
}
|
||||
|
||||
// Iterator defines an app-side mempool iterator interface that is as minimal as
|
||||
|
||||
@@ -4,8 +4,11 @@ import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/transaction"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _ Mempool[sdk.Tx] = (*NoOpMempool[sdk.Tx])(nil) // verify interface at compile time
|
||||
var _ Mempool[transaction.Tx] = (*NoOpMempool[transaction.Tx])(nil)
|
||||
|
||||
// NoOpMempool defines a no-op mempool. Transactions are completely discarded and
|
||||
@@ -16,7 +19,8 @@ var _ Mempool[transaction.Tx] = (*NoOpMempool[transaction.Tx])(nil)
|
||||
// is FIFO-ordered by default.
|
||||
type NoOpMempool[T transaction.Tx] struct{}
|
||||
|
||||
func (NoOpMempool[T]) Insert(context.Context, T) error { return nil }
|
||||
func (NoOpMempool[T]) Select(context.Context, []T) Iterator[T] { return nil }
|
||||
func (NoOpMempool[T]) CountTx() int { return 0 }
|
||||
func (NoOpMempool[T]) Remove([]T) error { return nil }
|
||||
func (NoOpMempool[T]) Insert(context.Context, T) error { return nil }
|
||||
func (NoOpMempool[T]) Select(context.Context, []T) Iterator[T] { return nil }
|
||||
func (NoOpMempool[T]) SelectBy(context.Context, []T, func(T) bool) {}
|
||||
func (NoOpMempool[T]) CountTx() int { return 0 }
|
||||
func (NoOpMempool[T]) Remove(T) error { return nil }
|
||||
|
||||
Reference in New Issue
Block a user