Skip to content

Commit 1d2e1d7

Browse files
committed
[refactor] move creation of unique_parents to helper function
This function will be reused in a later commit.
1 parent c6893b0 commit 1d2e1d7

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/node/txdownloadman_impl.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ void TxDownloadManagerImpl::MempoolAcceptedTx(const CTransactionRef& tx)
301301
m_orphanage.EraseTx(tx->GetWitnessHash());
302302
}
303303

304+
std::vector<Txid> TxDownloadManagerImpl::GetUniqueParents(const CTransaction& tx)
305+
{
306+
std::vector<Txid> unique_parents;
307+
unique_parents.reserve(tx.vin.size());
308+
for (const CTxIn& txin : tx.vin) {
309+
// We start with all parents, and then remove duplicates below.
310+
unique_parents.push_back(txin.prevout.hash);
311+
}
312+
313+
std::sort(unique_parents.begin(), unique_parents.end());
314+
unique_parents.erase(std::unique(unique_parents.begin(), unique_parents.end()), unique_parents.end());
315+
316+
return unique_parents;
317+
}
318+
304319
node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransactionRef& ptx, const TxValidationState& state, NodeId nodeid, bool first_time_failure)
305320
{
306321
const CTransaction& tx{*ptx};
@@ -320,13 +335,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
320335

321336
// Deduplicate parent txids, so that we don't have to loop over
322337
// the same parent txid more than once down below.
323-
unique_parents.reserve(tx.vin.size());
324-
for (const CTxIn& txin : tx.vin) {
325-
// We start with all parents, and then remove duplicates below.
326-
unique_parents.push_back(txin.prevout.hash);
327-
}
328-
std::sort(unique_parents.begin(), unique_parents.end());
329-
unique_parents.erase(std::unique(unique_parents.begin(), unique_parents.end()), unique_parents.end());
338+
unique_parents = GetUniqueParents(tx);
330339

331340
// Distinguish between parents in m_lazy_recent_rejects and m_lazy_recent_rejects_reconsiderable.
332341
// We can tolerate having up to 1 parent in m_lazy_recent_rejects_reconsiderable since we

src/node/txdownloadman_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ class TxDownloadManagerImpl {
189189
void CheckIsEmpty(NodeId nodeid);
190190

191191
std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions() const;
192+
193+
protected:
194+
/** Helper for getting deduplicated vector of Txids in vin. */
195+
std::vector<Txid> GetUniqueParents(const CTransaction& tx);
192196
};
193197
} // namespace node
194198
#endif // BITCOIN_NODE_TXDOWNLOADMAN_IMPL_H

0 commit comments

Comments
 (0)