@@ -1163,7 +1163,42 @@ void CSigSharesManager::Cleanup()
1163
1163
return ;
1164
1164
}
1165
1165
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
+ }
1167
1202
1168
1203
{
1169
1204
LOCK (cs);
@@ -1201,41 +1236,29 @@ void CSigSharesManager::Cleanup()
1201
1236
assert (m);
1202
1237
1203
1238
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);
1206
1256
} else {
1207
1257
LogPrintf (" CSigSharesManager::%s -- signing session timed out. signHash=%s, sigShareCount=%d\n " , __func__,
1208
1258
signHash.ToString (), count);
1209
1259
}
1210
1260
RemoveSigSharesForSession (signHash);
1211
1261
}
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
- }
1239
1262
}
1240
1263
1241
1264
// Find node states for peers that disappeared from CConnman
0 commit comments