From a186d70fdd1bbbac42a6ca3a0d074c01f9d08bd5 Mon Sep 17 00:00:00 2001 From: Mike Zak Date: Sun, 13 Mar 2022 10:26:28 +0200 Subject: [PATCH 1/2] Fix error message referencing wrong function name --- .../mempool/model/ordered_transactions_by_fee_rate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7202b98ee3..79a6f4b26d 100644 --- a/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go +++ b/domain/miningmanager/mempool/model/ordered_transactions_by_fee_rate.go @@ -60,7 +60,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() From 224fbf19a90760624bc1bf120fcb20aede2a8a23 Mon Sep 17 00:00:00 2001 From: Mike Zak Date: Sun, 13 Mar 2022 10:51:18 +0200 Subject: [PATCH 2/2] Ignore not found errors from tp.transactionsOrderedByFeeRate.Remove. --- .../mempool/model/ordered_transactions_by_fee_rate.go | 6 +++++- domain/miningmanager/mempool/transactions_pool.go | 9 ++++++++- 2 files changed, 13 insertions(+), 2 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 79a6f4b26d..ef3d342640 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) diff --git a/domain/miningmanager/mempool/transactions_pool.go b/domain/miningmanager/mempool/transactions_pool.go index e13a448b6b..bad4e7f7c2 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())