Skip to content

Commit 4470acf

Browse files
committed
p2p: Forget peer's reconciliation state on disconnect
1 parent 3fcf78e commit 4470acf

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
14941494
}
14951495
WITH_LOCK(g_cs_orphans, m_orphanage.EraseForPeer(nodeid));
14961496
m_txrequest.DisconnectedPeer(nodeid);
1497+
if (m_txreconciliation) m_txreconciliation->ForgetPeer(nodeid);
14971498
m_num_preferred_download_peers -= state->fPreferredDownload;
14981499
m_peers_downloading_from -= (state->nBlocksInFlight != 0);
14991500
assert(m_peers_downloading_from >= 0);

src/node/txreconciliation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ class TxReconciliationTracker::Impl
5454
Assert(m_states.emplace(peer_id, local_salt).second);
5555
return local_salt;
5656
}
57+
58+
void ForgetPeer(NodeId peer_id) EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex)
59+
{
60+
AssertLockNotHeld(m_txreconciliation_mutex);
61+
LOCK(m_txreconciliation_mutex);
62+
if (m_states.erase(peer_id)) {
63+
LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Forget txreconciliation state of peer=%d\n", peer_id);
64+
}
65+
}
5766
};
5867

5968
TxReconciliationTracker::TxReconciliationTracker() : m_impl{std::make_unique<TxReconciliationTracker::Impl>()} {}
@@ -64,3 +73,8 @@ uint64_t TxReconciliationTracker::PreRegisterPeer(NodeId peer_id)
6473
{
6574
return m_impl->PreRegisterPeer(peer_id);
6675
}
76+
77+
void TxReconciliationTracker::ForgetPeer(NodeId peer_id)
78+
{
79+
m_impl->ForgetPeer(peer_id);
80+
}

src/node/txreconciliation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class TxReconciliationTracker
6161
* This function must be called only once per peer.
6262
*/
6363
uint64_t PreRegisterPeer(NodeId peer_id);
64+
65+
/**
66+
* Attempts to forget txreconciliation-related state of the peer (if we previously stored any).
67+
* After this, we won't be able to reconcile transactions with the peer.
68+
*/
69+
void ForgetPeer(NodeId peer_id);
6470
};
6571

6672
#endif // BITCOIN_NODE_TXRECONCILIATION_H

0 commit comments

Comments
 (0)