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>
This commit is contained in:
Svarog 2022-03-13 18:01:13 +02:00 committed by GitHub
parent 7a95f0c7a4
commit 1e56a22b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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()

View File

@ -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())