Skip to content

Commit

Permalink
Do not hold cs_vNodes in CSigSharesManager::SendMessages() for too lo…
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored and panleone committed Nov 5, 2024
1 parent cd1809f commit ed463a6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ bool CSigSharesManager::SendMessages()

bool didSend = false;

g_connman->ForEachNode([&](CNode* pnode) {
std::vector<CNode*> vNodesCopy = g_connman->CopyNodeVector(CConnman::FullyConnectedOnly);

for (auto& pnode : vNodesCopy) {
CNetMsgMaker msgMaker(pnode->GetSendVersion());

auto it1 = sigSessionAnnouncements.find(pnode->GetId());
Expand Down Expand Up @@ -1133,9 +1135,10 @@ bool CSigSharesManager::SendMessages()
didSend = true;
}
}
}

return true;
});
// looped through all nodes, release them
g_connman->ReleaseNodeVector(vNodesCopy);

return didSend;
}
Expand Down
27 changes: 27 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,33 @@ int64_t PoissonNextSend(int64_t nNow, int average_interval_seconds) {
return nNow + (int64_t)(log1p(GetRand(1ULL << 48) * -0.0000000000000035527136788 /* -1/2^48 */) * average_interval_seconds * -1000000.0 + 0.5);
}

std::vector<CNode*> CConnman::CopyNodeVector(std::function<bool(const CNode* pnode)> cond)
{
std::vector<CNode*> vecNodesCopy;
LOCK(cs_vNodes);
for (size_t i = 0; i < vNodes.size(); ++i) {
CNode* pnode = vNodes[i];
if (!cond(pnode))
continue;
pnode->AddRef();
vecNodesCopy.push_back(pnode);
}
return vecNodesCopy;
}

std::vector<CNode*> CConnman::CopyNodeVector()
{
return CopyNodeVector(AllNodes);
}

void CConnman::ReleaseNodeVector(const std::vector<CNode*>& vecNodes)
{
for (size_t i = 0; i < vecNodes.size(); ++i) {
CNode* pnode = vecNodes[i];
pnode->Release();
}
}

CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id)
{
return CSipHasher(nSeed0, nSeed1).Write(id);
Expand Down
4 changes: 4 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ class CConnman
post();
};

std::vector<CNode*> CopyNodeVector(std::function<bool(const CNode* pnode)> cond);
std::vector<CNode*> CopyNodeVector();
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);

// Clears AskFor requests for every known peer
void RemoveAskFor(const uint256& invHash, int invType);

Expand Down

0 comments on commit ed463a6

Please sign in to comment.