From b50bd72c42bc664478c325a7e606cb36826973b1 Mon Sep 17 00:00:00 2001 From: glozow Date: Mon, 9 Jun 2025 16:01:15 -0400 Subject: [PATCH] [prep] change return type of EraseTx to bool This function only ever returns 0 or 1 (number of unique orphans erased). --- src/node/txdownloadman_impl.cpp | 2 +- src/node/txorphanage.cpp | 8 ++++---- src/node/txorphanage.h | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index 6abc7f8d90..4a8de25e54 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -491,7 +491,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction // If the tx failed in ProcessOrphanTx, it should be removed from the orphanage unless the // tx was still missing inputs. If the tx was not in the orphanage, EraseTx does nothing and returns 0. - if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS && m_orphanage->EraseTx(ptx->GetWitnessHash()) > 0) { + if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS && m_orphanage->EraseTx(ptx->GetWitnessHash())) { LogDebug(BCLog::TXPACKAGES, " removed orphan tx %s (wtxid=%s)\n", ptx->GetHash().ToString(), ptx->GetWitnessHash().ToString()); } diff --git a/src/node/txorphanage.cpp b/src/node/txorphanage.cpp index e230cbc1ba..f4fe22e480 100644 --- a/src/node/txorphanage.cpp +++ b/src/node/txorphanage.cpp @@ -76,7 +76,7 @@ public: bool HaveTx(const Wtxid& wtxid) const override; bool HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const override; CTransactionRef GetTxToReconsider(NodeId peer) override; - int EraseTx(const Wtxid& wtxid) override; + bool EraseTx(const Wtxid& wtxid) override; void EraseForPeer(NodeId peer) override; void EraseForBlock(const CBlock& block) override; void LimitOrphans(FastRandomContext& rng) override; @@ -147,11 +147,11 @@ bool TxOrphanageImpl::AddAnnouncer(const Wtxid& wtxid, NodeId peer) return false; } -int TxOrphanageImpl::EraseTx(const Wtxid& wtxid) +bool TxOrphanageImpl::EraseTx(const Wtxid& wtxid) { std::map::iterator it = m_orphans.find(wtxid); if (it == m_orphans.end()) - return 0; + return false; for (const CTxIn& txin : it->second.tx->vin) { auto itPrev = m_outpoint_to_orphan_it.find(txin.prevout); @@ -190,7 +190,7 @@ int TxOrphanageImpl::EraseTx(const Wtxid& wtxid) m_orphan_list.pop_back(); m_orphans.erase(it); - return 1; + return true; } void TxOrphanageImpl::EraseForPeer(NodeId peer) diff --git a/src/node/txorphanage.h b/src/node/txorphanage.h index 6a13b6239b..8567b178dd 100644 --- a/src/node/txorphanage.h +++ b/src/node/txorphanage.h @@ -67,8 +67,9 @@ public: */ virtual CTransactionRef GetTxToReconsider(NodeId peer) = 0; - /** Erase an orphan by wtxid */ - virtual int EraseTx(const Wtxid& wtxid) = 0; + /** Erase an orphan by wtxid, including all announcements if there are multiple. + * Returns true if an orphan was erased, false if no tx with this wtxid exists. */ + virtual bool EraseTx(const Wtxid& wtxid) = 0; /** Maybe erase all orphans announced by a peer (eg, after that peer disconnects). If an orphan * has been announced by another peer, don't erase, just remove this peer from the list of announcers. */