Skip to content

Commit a4fe099

Browse files
committed
txorphanage: index workset by originating peer
1 parent d415b72 commit a4fe099

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
29032903
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
29042904
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
29052905
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
2906-
m_orphanage.AddChildrenToWorkSet(*porphanTx, peer.m_id);
2906+
m_orphanage.AddChildrenToWorkSet(*porphanTx);
29072907
m_orphanage.EraseTx(orphanHash);
29082908
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
29092909
AddToCompactExtraTransactions(removedTx);
@@ -4030,7 +4030,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
40304030
m_txrequest.ForgetTxHash(tx.GetHash());
40314031
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
40324032
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
4033-
m_orphanage.AddChildrenToWorkSet(tx, peer->m_id);
4033+
m_orphanage.AddChildrenToWorkSet(tx);
40344034

40354035
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
40364036

src/test/fuzz/txorphan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ FUZZ_TARGET_INIT(txorphan, initialize_orphanage)
8585
CallOneOf(
8686
fuzzed_data_provider,
8787
[&] {
88-
orphanage.AddChildrenToWorkSet(*tx, peer_id);
88+
orphanage.AddChildrenToWorkSet(*tx);
8989
},
9090
[&] {
9191
{

src/txorphanage.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,19 @@ void TxOrphanage::LimitOrphans(unsigned int max_orphans)
145145
if (nEvicted > 0) LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted);
146146
}
147147

148-
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx, NodeId peer)
148+
void TxOrphanage::AddChildrenToWorkSet(const CTransaction& tx)
149149
{
150150
LOCK(m_mutex);
151151

152-
// Get this peer's work set, emplacing an empty set it didn't exist
153-
std::set<uint256>& orphan_work_set = m_peer_work_set.try_emplace(peer).first->second;
154152

155153
for (unsigned int i = 0; i < tx.vout.size(); i++) {
156154
const auto it_by_prev = m_outpoint_to_orphan_it.find(COutPoint(tx.GetHash(), i));
157155
if (it_by_prev != m_outpoint_to_orphan_it.end()) {
158156
for (const auto& elem : it_by_prev->second) {
157+
// Get this source peer's work set, emplacing an empty set if it didn't exist
158+
// (note: if this peer wasn't still connected, we would have removed the orphan tx already)
159+
std::set<uint256>& orphan_work_set = m_peer_work_set.try_emplace(elem->second.fromPeer).first->second;
160+
// Add this tx to the work set
159161
orphan_work_set.insert(elem->first);
160162
}
161163
}

src/txorphanage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class TxOrphanage {
4747
/** Limit the orphanage to the given maximum */
4848
void LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
4949

50-
/** Add any orphans that list a particular tx as a parent into a peer's work set */
51-
void AddChildrenToWorkSet(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
50+
/** Add any orphans that list a particular tx as a parent into the from peer's work set */
51+
void AddChildrenToWorkSet(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);;
5252

5353
/** Return how many entries exist in the orphange */
5454
size_t Size() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
@@ -72,7 +72,7 @@ class TxOrphanage {
7272
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
7373
std::map<uint256, OrphanTx> m_orphans GUARDED_BY(m_mutex);
7474

75-
/** Which peer provided a parent tx of orphans that need to be reconsidered */
75+
/** Which peer provided the orphans that need to be reconsidered */
7676
std::map<NodeId, std::set<uint256>> m_peer_work_set GUARDED_BY(m_mutex);
7777

7878
using OrphanMap = decltype(m_orphans);

0 commit comments

Comments
 (0)