diff --git a/src/llmq/quorums_signing.cpp b/src/llmq/quorums_signing.cpp index 21eb2c577..1d29890da 100644 --- a/src/llmq/quorums_signing.cpp +++ b/src/llmq/quorums_signing.cpp @@ -414,8 +414,10 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re connman.RemoveAskFor(recoveredSig.GetHash()); } + std::vector listeners; { LOCK(cs); + listeners = recoveredSigsListeners; auto signHash = CLLMQUtils::BuildSignHash(recoveredSig); @@ -435,6 +437,10 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash()); g_connman->RelayInv(inv); + + for (auto& l : listeners) { + l->HandleNewRecoveredSig(recoveredSig); + } } void CSigningManager::Cleanup() @@ -451,6 +457,19 @@ void CSigningManager::Cleanup() lastCleanupTime = GetTimeMillis(); } +void CSigningManager::RegisterRecoveredSigsListener(CRecoveredSigsListener* l) +{ + LOCK(cs); + recoveredSigsListeners.emplace_back(l); +} + +void CSigningManager::UnregisterRecoveredSigsListener(CRecoveredSigsListener* l) +{ + LOCK(cs); + auto itRem = std::remove(recoveredSigsListeners.begin(), recoveredSigsListeners.end(), l); + recoveredSigsListeners.erase(itRem, recoveredSigsListeners.end()); +} + bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash) { auto& params = Params().GetConsensus().llmqs.at(llmqType); diff --git a/src/llmq/quorums_signing.h b/src/llmq/quorums_signing.h index 4fcab756a..33dc16561 100644 --- a/src/llmq/quorums_signing.h +++ b/src/llmq/quorums_signing.h @@ -91,6 +91,14 @@ private: bool ReadRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, CRecoveredSig& ret); }; +class CRecoveredSigsListener +{ +public: + virtual ~CRecoveredSigsListener() {} + + virtual void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) = 0; +}; + class CSigningManager { friend class CSigSharesManager; @@ -109,6 +117,8 @@ private: int64_t lastCleanupTime{0}; + std::vector recoveredSigsListeners; + public: CSigningManager(bool fMemory); @@ -128,6 +138,9 @@ private: public: // public interface + void RegisterRecoveredSigsListener(CRecoveredSigsListener* l); + void UnregisterRecoveredSigsListener(CRecoveredSigsListener* l); + bool AsyncSignIfMember(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash); bool HasRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash); bool HasRecoveredSigForId(Consensus::LLMQType llmqType, const uint256& id);