From c084c6977184159b7aabadeb367f6237cd1bc221 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Tue, 9 Mar 2021 12:30:35 +0200 Subject: [PATCH] Don't swallow orphan errors (#1581) Co-authored-by: Svarog --- domain/miningmanager/mempool/mempool.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/domain/miningmanager/mempool/mempool.go b/domain/miningmanager/mempool/mempool.go index e7f7a28fe..bb935dc35 100644 --- a/domain/miningmanager/mempool/mempool.go +++ b/domain/miningmanager/mempool/mempool.go @@ -771,7 +771,7 @@ func (mp *mempool) maybeAcceptTransaction(tx *consensusexternalapi.DomainTransac // no transactions were moved from the orphan pool to the mempool. // // This function MUST be called with the mempool lock held (for writes). -func (mp *mempool) processOrphans(acceptedTx *consensusexternalapi.DomainTransaction) []*txDescriptor { +func (mp *mempool) processOrphans(acceptedTx *consensusexternalapi.DomainTransaction) ([]*txDescriptor, error) { var acceptedTxns []*txDescriptor // Start with processing at least the passed transaction. @@ -806,6 +806,11 @@ func (mp *mempool) processOrphans(acceptedTx *consensusexternalapi.DomainTransac missing, txD, err := mp.maybeAcceptTransaction( tx, false) if err != nil { + if !errors.As(err, &RuleError{}) { + return nil, err + } + + log.Warnf("Invalid orphan transaction: %s", err) // The orphan is now invalid, so there // is no way any other orphans which // redeem any of its outputs can be @@ -847,7 +852,7 @@ func (mp *mempool) processOrphans(acceptedTx *consensusexternalapi.DomainTransac mp.removeOrphanDoubleSpends(txDescriptor.DomainTransaction) } - return acceptedTxns + return acceptedTxns, nil } // ProcessTransaction is the main workhorse for handling insertion of new @@ -879,7 +884,11 @@ func (mp *mempool) ValidateAndInsertTransaction(tx *consensusexternalapi.DomainT // transaction (they may no longer be orphans if all inputs // are now available) and repeat for those accepted // transactions until there are no more. - newTxs := mp.processOrphans(tx) + newTxs, err := mp.processOrphans(tx) + if err != nil { + return err + } + acceptedTxs := make([]*txDescriptor, len(newTxs)+1) // Add the parent transaction first so remote nodes @@ -980,7 +989,11 @@ func (mp *mempool) HandleNewBlockTransactions(txs []*consensusexternalapi.Domain return nil, errors.Wrapf(err, "Failed removing tx from mempool: %s", consensushashing.TransactionID(tx)) } mp.removeOrphan(tx, false) - acceptedOrphans := mp.processOrphans(tx) + acceptedOrphans, err := mp.processOrphans(tx) + if err != nil { + return nil, err + } + for _, acceptedOrphan := range acceptedOrphans { acceptedTxs = append(acceptedTxs, acceptedOrphan.DomainTransaction) }