From 6ac49da24628260fb8530fd4979e065f14c394a3 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 26 Feb 2019 08:48:41 +0100 Subject: [PATCH] Send QSIGSESANN messages when sending first message for a session --- src/llmq/quorums_signing_shares.cpp | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/llmq/quorums_signing_shares.cpp b/src/llmq/quorums_signing_shares.cpp index 2265983d2..9652d2d59 100644 --- a/src/llmq/quorums_signing_shares.cpp +++ b/src/llmq/quorums_signing_shares.cpp @@ -961,12 +961,48 @@ bool CSigSharesManager::SendMessages() std::unordered_map> sigSharesToRequest; std::unordered_map> sigSharesToSend; std::unordered_map> sigSharesToAnnounce; + std::unordered_map> sigSessionAnnouncements; + + auto addSigSesAnnIfNeeded = [&](NodeId nodeId, const uint256& signHash) { + auto& nodeState = nodeStates[nodeId]; + auto session = nodeState.GetSessionBySignHash(signHash); + assert(session); + if (session->sendSessionId == (uint32_t)-1) { + session->sendSessionId = nodeState.nextSendSessionId++; + + CSigSesAnn sigSesAnn; + sigSesAnn.sessionId = session->sendSessionId; + sigSesAnn.llmqType = (uint8_t)session->llmqType; + sigSesAnn.quorumHash = session->quorumHash; + sigSesAnn.id = session->id; + sigSesAnn.msgHash = session->msgHash; + + sigSessionAnnouncements[nodeId].emplace_back(sigSesAnn); + } + return session->sendSessionId; + }; { LOCK(cs); CollectSigSharesToRequest(sigSharesToRequest); CollectSigSharesToSend(sigSharesToSend); CollectSigSharesToAnnounce(sigSharesToAnnounce); + + for (auto& p : sigSharesToRequest) { + for (auto& p2 : p.second) { + p2.second.sessionId = addSigSesAnnIfNeeded(p.first, p2.first); + } + } + for (auto& p : sigSharesToSend) { + for (auto& p2 : p.second) { + p2.second.sessionId = addSigSesAnnIfNeeded(p.first, p2.first); + } + } + for (auto& p : sigSharesToAnnounce) { + for (auto& p2 : p.second) { + p2.second.sessionId = addSigSesAnnIfNeeded(p.first, p2.first); + } + } } bool didSend = false; @@ -974,6 +1010,16 @@ bool CSigSharesManager::SendMessages() g_connman->ForEachNode([&](CNode* pnode) { CNetMsgMaker msgMaker(pnode->GetSendVersion()); + auto it1 = sigSessionAnnouncements.find(pnode->id); + if (it1 != sigSessionAnnouncements.end()) { + for (auto& sigSesAnn : it1->second) { + LogPrint("llmq", "CSigSharesManager::SendMessages -- QSIGSESANN signHash=%s, sessionId=%d, node=%d\n", + CLLMQUtils::BuildSignHash(sigSesAnn).ToString(), sigSesAnn.sessionId, pnode->id); + g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QSIGSESANN, sigSesAnn), false); + didSend = true; + } + } + auto it = sigSharesToRequest.find(pnode->id); if (it != sigSharesToRequest.end()) { for (auto& p : it->second) {