diff options
author | Gleb Naumenko <naumenko.gs@gmail.com> | 2022-01-11 09:34:19 +0200 |
---|---|---|
committer | Gleb Naumenko <naumenko.gs@gmail.com> | 2022-10-17 12:35:44 +0300 |
commit | 36cf6bf2168f9f154a652c91bbb96480c2e1d044 (patch) | |
tree | b6864e4421943b520937904dd1231abf9e3f2136 | |
parent | 4470acf076289831ac60bcbafb6b3afa0e98e99d (diff) |
Add helper to see if a peer is registered for reconciliations
-rw-r--r-- | src/node/txreconciliation.cpp | 14 | ||||
-rw-r--r-- | src/node/txreconciliation.h | 5 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp index d8cb156475..f35beae28b 100644 --- a/src/node/txreconciliation.cpp +++ b/src/node/txreconciliation.cpp @@ -63,6 +63,15 @@ public: LogPrintLevel(BCLog::TXRECONCILIATION, BCLog::Level::Debug, "Forget txreconciliation state of peer=%d\n", peer_id); } } + + bool IsPeerRegistered(NodeId peer_id) const EXCLUSIVE_LOCKS_REQUIRED(!m_txreconciliation_mutex) + { + AssertLockNotHeld(m_txreconciliation_mutex); + LOCK(m_txreconciliation_mutex); + auto recon_state = m_states.find(peer_id); + return (recon_state != m_states.end() && + std::holds_alternative<TxReconciliationState>(recon_state->second)); + } }; TxReconciliationTracker::TxReconciliationTracker() : m_impl{std::make_unique<TxReconciliationTracker::Impl>()} {} @@ -78,3 +87,8 @@ void TxReconciliationTracker::ForgetPeer(NodeId peer_id) { m_impl->ForgetPeer(peer_id); } + +bool TxReconciliationTracker::IsPeerRegistered(NodeId peer_id) const +{ + return m_impl->IsPeerRegistered(peer_id); +} diff --git a/src/node/txreconciliation.h b/src/node/txreconciliation.h index b8e9b649c0..1bffbea9db 100644 --- a/src/node/txreconciliation.h +++ b/src/node/txreconciliation.h @@ -67,6 +67,11 @@ public: * After this, we won't be able to reconcile transactions with the peer. */ void ForgetPeer(NodeId peer_id); + + /** + * Check if a peer is registered to reconcile transactions with us. + */ + bool IsPeerRegistered(NodeId peer_id) const; }; #endif // BITCOIN_NODE_TXRECONCILIATION_H |