From 1e56a22b325cd058ceab790e85b172f98dbedc39 Mon Sep 17 00:00:00 2001 From: Svarog Date: Sun, 13 Mar 2022 18:01:13 +0200 Subject: [PATCH] Ignore not found errors from tp.transactionsOrderedByFeeRate.Remove. (#1974) * Fix error message referencing wrong function name * Ignore not found errors from tp.transactionsOrderedByFeeRate.Remove. Co-authored-by: stasatdaglabs <39559713+stasatdaglabs@users.noreply.github.com> --- .../mempool/model/ordered_transactions_by_fee_rate.go | 8 ++++++-- domain/miningmanager/mempool/transactions_pool.go | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go b/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go index 7202b98ee..ef3d34264 100644 --- a/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go +++ b/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go @@ -29,6 +29,9 @@ func (tobf *TransactionsOrderedByFeeRate) Push(transaction *MempoolTransaction) return nil } +// ErrTransactionNotFound is returned bt tobf.TransactionsOrderedByFeeRate +var ErrTransactionNotFound = errors.New("Couldn't find transaction in mp.orderedTransactionsByFeeRate") + // Remove removes the given transaction from the set. // Returns an error if transaction does not exist in the set, or if the given transaction does not have mass // and fee filled in. @@ -39,7 +42,8 @@ func (tobf *TransactionsOrderedByFeeRate) Remove(transaction *MempoolTransaction } if !wasFound { - return errors.Errorf("Couldn't find %s in mp.orderedTransactionsByFeeRate", transaction.TransactionID()) + return errors.Wrapf(ErrTransactionNotFound, + "Couldn't find %s in mp.orderedTransactionsByFeeRate", transaction.TransactionID()) } return tobf.RemoveAtIndex(index) @@ -60,7 +64,7 @@ func (tobf *TransactionsOrderedByFeeRate) RemoveAtIndex(index int) error { // while preserving the order. func (tobf *TransactionsOrderedByFeeRate) findTransactionIndex(transaction *MempoolTransaction) (index int, wasFound bool, err error) { if transaction.Transaction().Fee == 0 || transaction.Transaction().Mass == 0 { - return 0, false, errors.Errorf("findTxIndexInOrderedTransactionsByFeeRate expects a transaction with " + + return 0, false, errors.Errorf("findTransactionIndex expects a transaction with " + "populated fee and mass") } txID := transaction.TransactionID() diff --git a/domain/miningmanager/mempool/transactions_pool.go b/domain/miningmanager/mempool/transactions_pool.go index e13a448b6..bad4e7f7c 100644 --- a/domain/miningmanager/mempool/transactions_pool.go +++ b/domain/miningmanager/mempool/transactions_pool.go @@ -3,6 +3,8 @@ package mempool import ( "time" + "github.com/pkg/errors" + "github.com/kaspanet/kaspad/domain/consensus/model/externalapi" "github.com/kaspanet/kaspad/domain/miningmanager/mempool/model" ) @@ -79,7 +81,12 @@ func (tp *transactionsPool) removeTransaction(transaction *model.MempoolTransact err := tp.transactionsOrderedByFeeRate.Remove(transaction) if err != nil { - return err + if errors.Is(err, model.ErrTransactionNotFound) { + log.Errorf("Transaction %s not found in tp.transactionsOrderedByFeeRate. This should never happen but sometime does", + transaction.TransactionID()) + } else { + return err + } } delete(tp.highPriorityTransactions, *transaction.TransactionID())