Skip to content

Commit 36cf6bf

Browse files
committed
Add helper to see if a peer is registered for reconciliations
1 parent 4470acf commit 36cf6bf

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/node/txreconciliation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class TxReconciliationTracker::Impl
6363
LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Forget txreconciliation state of peer=%d\n", peer_id);
6464
}
6565
}
66+
67+
bool IsPeerRegistered(NodeId peer_id) const EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex)
68+
{
69+
AssertLockNotHeld(m_txreconciliation_mutex);
70+
LOCK(m_txreconciliation_mutex);
71+
auto recon_state = m_states.find(peer_id);
72+
return (recon_state != m_states.end() &&
73+
std::holds_alternative<TxReconciliationState>(recon_state->second));
74+
}
6675
};
6776

6877
TxReconciliationTracker::TxReconciliationTracker() : m_impl{std::make_unique<TxReconciliationTracker::Impl>()} {}
@@ -78,3 +87,8 @@ void TxReconciliationTracker::ForgetPeer(NodeId peer_id)
7887
{
7988
m_impl->ForgetPeer(peer_id);
8089
}
90+
91+
bool TxReconciliationTracker::IsPeerRegistered(NodeId peer_id) const
92+
{
93+
return m_impl->IsPeerRegistered(peer_id);
94+
}

src/node/txreconciliation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class TxReconciliationTracker
6767
* After this, we won't be able to reconcile transactions with the peer.
6868
*/
6969
void ForgetPeer(NodeId peer_id);
70+
71+
/**
72+
* Check if a peer is registered to reconcile transactions with us.
73+
*/
74+
bool IsPeerRegistered(NodeId peer_id) const;
7075
};
7176

7277
#endif // BITCOIN_NODE_TXRECONCILIATION_H

0 commit comments

Comments
 (0)