From af85b86241706423bb3672daf149af8b4cda9cb1 Mon Sep 17 00:00:00 2001 From: David Terpay Date: Tue, 15 Aug 2023 11:28:02 -0400 Subject: [PATCH] renaming mempool --- abci/abci_test.go | 2 +- block/constructor/mempool.go | 20 ++++++++++---------- lanes/base/lane.go | 2 +- lanes/base/mempool_test.go | 8 ++++---- lanes/free/lane.go | 2 +- lanes/mev/lane.go | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/abci/abci_test.go b/abci/abci_test.go index f7499c5..0131a63 100644 --- a/abci/abci_test.go +++ b/abci/abci_test.go @@ -771,7 +771,7 @@ func (s *ProposalsTestSuite) setUpPanicLane(maxBlockSpace math.LegacyDec) *const lane := constructor.NewLaneConstructor[string]( cfg, "panic", - constructor.NewConstructorMempool[string](constructor.DefaultTxPriority(), cfg.TxEncoder, 0), + constructor.NewMempool[string](constructor.DefaultTxPriority(), cfg.TxEncoder, 0), constructor.DefaultMatchHandler(), ) diff --git a/block/constructor/mempool.go b/block/constructor/mempool.go index 7a9d6e4..8bcb098 100644 --- a/block/constructor/mempool.go +++ b/block/constructor/mempool.go @@ -16,7 +16,7 @@ type ( // It include's additional helper functions that allow users to determine if a // transaction is already in the mempool and to compare the priority of two // transactions. - ConstructorMempool[C comparable] struct { + Mempool[C comparable] struct { // index defines an index of transactions. index sdkmempool.Mempool @@ -79,9 +79,9 @@ func DefaultTxPriority() TxPriority[string] { } } -// NewConstructorMempool returns a new ConstructorMempool. -func NewConstructorMempool[C comparable](txPriority TxPriority[C], txEncoder sdk.TxEncoder, maxTx int) *ConstructorMempool[C] { - return &ConstructorMempool[C]{ +// NewMempool returns a new ConstructorMempool. +func NewMempool[C comparable](txPriority TxPriority[C], txEncoder sdk.TxEncoder, maxTx int) *Mempool[C] { + return &Mempool[C]{ index: NewPriorityMempool( PriorityNonceMempoolConfig[C]{ TxPriority: txPriority, @@ -95,7 +95,7 @@ func NewConstructorMempool[C comparable](txPriority TxPriority[C], txEncoder sdk } // Insert inserts a transaction into the mempool. -func (cm *ConstructorMempool[C]) Insert(ctx context.Context, tx sdk.Tx) error { +func (cm *Mempool[C]) Insert(ctx context.Context, tx sdk.Tx) error { if err := cm.index.Insert(ctx, tx); err != nil { return fmt.Errorf("failed to insert tx into auction index: %w", err) } @@ -112,7 +112,7 @@ func (cm *ConstructorMempool[C]) Insert(ctx context.Context, tx sdk.Tx) error { } // Remove removes a transaction from the mempool. -func (cm *ConstructorMempool[C]) Remove(tx sdk.Tx) error { +func (cm *Mempool[C]) Remove(tx sdk.Tx) error { if err := cm.index.Remove(tx); err != nil && !errors.Is(err, sdkmempool.ErrTxNotFound) { return fmt.Errorf("failed to remove transaction from the mempool: %w", err) } @@ -131,17 +131,17 @@ func (cm *ConstructorMempool[C]) Remove(tx sdk.Tx) error { // remove a transaction from the mempool while iterating over the transactions, // the iterator will not be aware of the removal and will continue to iterate // over the removed transaction. Be sure to reset the iterator if you remove a transaction. -func (cm *ConstructorMempool[C]) Select(ctx context.Context, txs [][]byte) sdkmempool.Iterator { +func (cm *Mempool[C]) Select(ctx context.Context, txs [][]byte) sdkmempool.Iterator { return cm.index.Select(ctx, txs) } // CountTx returns the number of transactions in the mempool. -func (cm *ConstructorMempool[C]) CountTx() int { +func (cm *Mempool[C]) CountTx() int { return cm.index.CountTx() } // Contains returns true if the transaction is contained in the mempool. -func (cm *ConstructorMempool[C]) Contains(tx sdk.Tx) bool { +func (cm *Mempool[C]) Contains(tx sdk.Tx) bool { _, txHashStr, err := utils.GetTxHashStr(cm.txEncoder, tx) if err != nil { return false @@ -152,7 +152,7 @@ func (cm *ConstructorMempool[C]) Contains(tx sdk.Tx) bool { } // Compare determines the relative priority of two transactions belonging in the same lane. -func (cm *ConstructorMempool[C]) Compare(ctx sdk.Context, this sdk.Tx, other sdk.Tx) int { +func (cm *Mempool[C]) Compare(ctx sdk.Context, this sdk.Tx, other sdk.Tx) int { firstPriority := cm.txPriority.GetTxPriority(ctx, this) secondPriority := cm.txPriority.GetTxPriority(ctx, other) return cm.txPriority.Compare(firstPriority, secondPriority) diff --git a/lanes/base/lane.go b/lanes/base/lane.go index 5afcce9..0819506 100644 --- a/lanes/base/lane.go +++ b/lanes/base/lane.go @@ -27,7 +27,7 @@ func NewDefaultLane(cfg block.LaneConfig) *DefaultLane { lane := constructor.NewLaneConstructor[string]( cfg, LaneName, - constructor.NewConstructorMempool[string]( + constructor.NewMempool[string]( constructor.DefaultTxPriority(), cfg.TxEncoder, cfg.MaxTxs, diff --git a/lanes/base/mempool_test.go b/lanes/base/mempool_test.go index 1ca2b1e..fef9ee1 100644 --- a/lanes/base/mempool_test.go +++ b/lanes/base/mempool_test.go @@ -84,7 +84,7 @@ func (s *BaseTestSuite) TestCompareTxPriority() { } func (s *BaseTestSuite) TestInsert() { - mempool := constructor.NewConstructorMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) + mempool := constructor.NewMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) s.Run("should be able to insert a transaction", func() { tx, err := testutils.CreateRandomTx( @@ -136,7 +136,7 @@ func (s *BaseTestSuite) TestInsert() { } func (s *BaseTestSuite) TestRemove() { - mempool := constructor.NewConstructorMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) + mempool := constructor.NewMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) s.Run("should be able to remove a transaction", func() { tx, err := testutils.CreateRandomTx( @@ -174,7 +174,7 @@ func (s *BaseTestSuite) TestRemove() { func (s *BaseTestSuite) TestSelect() { s.Run("should be able to select transactions in the correct order", func() { - mempool := constructor.NewConstructorMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) + mempool := constructor.NewMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) tx1, err := testutils.CreateRandomTx( s.encodingConfig.TxConfig, @@ -213,7 +213,7 @@ func (s *BaseTestSuite) TestSelect() { }) s.Run("should be able to select a single transaction", func() { - mempool := constructor.NewConstructorMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) + mempool := constructor.NewMempool[string](constructor.DefaultTxPriority(), s.encodingConfig.TxConfig.TxEncoder(), 3) tx1, err := testutils.CreateRandomTx( s.encodingConfig.TxConfig, diff --git a/lanes/free/lane.go b/lanes/free/lane.go index 1608524..e08f3d3 100644 --- a/lanes/free/lane.go +++ b/lanes/free/lane.go @@ -29,7 +29,7 @@ func NewFreeLane( lane := constructor.NewLaneConstructor[string]( cfg, LaneName, - constructor.NewConstructorMempool[string]( + constructor.NewMempool[string]( txPriority, cfg.TxEncoder, cfg.MaxTxs, diff --git a/lanes/mev/lane.go b/lanes/mev/lane.go index 455e865..54e8779 100644 --- a/lanes/mev/lane.go +++ b/lanes/mev/lane.go @@ -52,7 +52,7 @@ func NewMEVLane( LaneConstructor: constructor.NewLaneConstructor[string]( cfg, LaneName, - constructor.NewConstructorMempool[string]( + constructor.NewMempool[string]( TxPriority(factory), cfg.TxEncoder, cfg.MaxTxs,