Skip to content

Commit a2fb276

Browse files
codablockpanleone
authored andcommitted
On timeout, print members proTxHashes from members which did not send a share (#2731)
* On timeout, print members proTxHashes from members which did not send a share * Move inactive quorums check above timeout checks This allows to reuse things in the next commit * Avoid locking cs_main through GetQuorum by using a pre-filled map * Use find() instead of [] to access quorums map
1 parent d1084e0 commit a2fb276

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

src/llmq/quorums_signing_shares.cpp

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,42 @@ void CSigSharesManager::Cleanup()
11631163
return;
11641164
}
11651165

1166-
std::unordered_set<std::pair<Consensus::LLMQType, uint256>, StaticSaltedHasher> quorumsToCheck;
1166+
// This map is first filled with all quorums found in all sig shares. Then we remove all inactive quorums and
1167+
// loop through all sig shares again to find the ones belonging to the inactive quorums. We then delete the
1168+
// sessions belonging to the sig shares. At the same time, we use this map as a cache when we later need to resolve
1169+
// quorumHash -> quorumPtr (as GetQuorum() requires cs_main, leading to deadlocks with cs held)
1170+
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher> quorums;
1171+
1172+
{
1173+
LOCK(cs);
1174+
sigShares.ForEach([&](const SigShareKey& k, const CSigShare& sigShare) {
1175+
quorums.emplace(std::make_pair((Consensus::LLMQType) sigShare.llmqType, sigShare.quorumHash), nullptr);
1176+
});
1177+
}
1178+
1179+
// Find quorums which became inactive
1180+
for (auto it = quorums.begin(); it != quorums.end(); ) {
1181+
if (llmq::utils::IsQuorumActive(it->first.first, it->first.second)) {
1182+
it->second = quorumManager->GetQuorum(it->first.first, it->first.second);
1183+
++it;
1184+
} else {
1185+
it = quorums.erase(it);
1186+
}
1187+
}
1188+
1189+
{
1190+
// Now delete sessions which are for inactive quorums
1191+
LOCK(cs);
1192+
std::unordered_set<uint256, StaticSaltedHasher> inactiveQuorumSessions;
1193+
sigShares.ForEach([&](const SigShareKey& k, const CSigShare& sigShare) {
1194+
if (!quorums.count(std::make_pair((Consensus::LLMQType)sigShare.llmqType, sigShare.quorumHash))) {
1195+
inactiveQuorumSessions.emplace(sigShare.GetSignHash());
1196+
}
1197+
});
1198+
for (auto& signHash : inactiveQuorumSessions) {
1199+
RemoveSigSharesForSession(signHash);
1200+
}
1201+
}
11671202

11681203
{
11691204
LOCK(cs);
@@ -1201,41 +1236,29 @@ void CSigSharesManager::Cleanup()
12011236
assert(m);
12021237

12031238
auto& oneSigShare = m->begin()->second;
1204-
LogPrintf("CSigSharesManager::%s -- signing session timed out. signHash=%s, id=%s, msgHash=%s, sigShareCount=%d\n", __func__,
1205-
signHash.ToString(), oneSigShare.id.ToString(), oneSigShare.msgHash.ToString(), count);
1239+
1240+
std::string strMissingMembers;
1241+
if (LogAcceptCategory(BCLog::LogFlags::LLMQ)) {
1242+
auto quorumIt = quorums.find(std::make_pair((Consensus::LLMQType)oneSigShare.llmqType, oneSigShare.quorumHash));
1243+
if (quorumIt != quorums.end()) {
1244+
auto& quorum = quorumIt->second;
1245+
for (size_t i = 0; i < quorum->members.size(); i++) {
1246+
if (!m->count((uint16_t)i)) {
1247+
auto& dmn = quorum->members[i];
1248+
strMissingMembers += strprintf("\n %s", dmn->proTxHash.ToString());
1249+
}
1250+
}
1251+
}
1252+
}
1253+
1254+
LogPrintf("CSigSharesManager::%s -- signing session timed out. signHash=%s, id=%s, msgHash=%s, sigShareCount=%d, missingMembers=%s\n", __func__,
1255+
signHash.ToString(), oneSigShare.id.ToString(), oneSigShare.msgHash.ToString(), count, strMissingMembers);
12061256
} else {
12071257
LogPrintf("CSigSharesManager::%s -- signing session timed out. signHash=%s, sigShareCount=%d\n", __func__,
12081258
signHash.ToString(), count);
12091259
}
12101260
RemoveSigSharesForSession(signHash);
12111261
}
1212-
1213-
sigShares.ForEach([&](const SigShareKey& k, const CSigShare& sigShare) {
1214-
quorumsToCheck.emplace((Consensus::LLMQType)sigShare.llmqType, sigShare.quorumHash);
1215-
});
1216-
}
1217-
1218-
// Find quorums which became inactive
1219-
for (auto it = quorumsToCheck.begin(); it != quorumsToCheck.end();) {
1220-
if (llmq::utils::IsQuorumActive(it->first, it->second)) {
1221-
it = quorumsToCheck.erase(it);
1222-
} else {
1223-
++it;
1224-
}
1225-
}
1226-
1227-
{
1228-
// Now delete sessions which are for inactive quorums
1229-
LOCK(cs);
1230-
std::unordered_set<uint256, StaticSaltedHasher> inactiveQuorumSessions;
1231-
sigShares.ForEach([&](const SigShareKey& k, const CSigShare& sigShare) {
1232-
if (quorumsToCheck.count(std::make_pair((Consensus::LLMQType)sigShare.llmqType, sigShare.quorumHash))) {
1233-
inactiveQuorumSessions.emplace(sigShare.GetSignHash());
1234-
}
1235-
});
1236-
for (auto& signHash : inactiveQuorumSessions) {
1237-
RemoveSigSharesForSession(signHash);
1238-
}
12391262
}
12401263

12411264
// Find node states for peers that disappeared from CConnman

0 commit comments

Comments
 (0)