@@ -200,8 +200,8 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
200
200
m_mn_sync (mn_sync),
201
201
m_peerman (peerman)
202
202
{
203
- utils::InitQuorumsCache (mapQuorumsCache);
204
- utils::InitQuorumsCache (scanQuorumsCache);
203
+ utils::InitQuorumsCache (mapQuorumsCache, false );
204
+ utils::InitQuorumsCache (scanQuorumsCache, false );
205
205
206
206
quorumThreadInterrupt.reset ();
207
207
}
@@ -296,7 +296,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
296
296
}
297
297
298
298
TriggerQuorumDataRecoveryThreads (pindexNew);
299
- CleanupOldQuorumData (pindexNew);
299
+ StartCleanupOldQuorumDataThread (pindexNew);
300
300
}
301
301
302
302
void CQuorumManager::CheckQuorumConnections (const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
@@ -956,7 +956,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
956
956
});
957
957
}
958
958
959
- static void DataCleanupHelper (CDBWrapper& db, std::set<uint256> skip_list)
959
+ static void DataCleanupHelper (CDBWrapper& db, std::set<uint256> skip_list, bool compact = false )
960
960
{
961
961
const auto prefixes = {DB_QUORUM_QUORUM_VVEC, DB_QUORUM_SK_SHARE};
962
962
@@ -990,39 +990,54 @@ static void DataCleanupHelper(CDBWrapper& db, std::set<uint256> skip_list)
990
990
991
991
db.WriteBatch (batch);
992
992
993
- LogPrint (BCLog::LLMQ, " CQuorumManager::%d -- %s removed %d\n " , __func__, prefix, count);
993
+ LogPrint (BCLog::LLMQ, " CQuorumManager::%s -- %s removed %d\n " , __func__, prefix, count);
994
994
}
995
995
996
996
pcursor.reset ();
997
- db.CompactFull ();
997
+
998
+ if (compact) {
999
+ // Avoid using this on regular cleanups, use on db migrations only
1000
+ LogPrint (BCLog::LLMQ, " CQuorumManager::%s -- compact start\n " , __func__);
1001
+ db.CompactFull ();
1002
+ LogPrint (BCLog::LLMQ, " CQuorumManager::%s -- compact end\n " , __func__);
1003
+ }
998
1004
}
999
1005
1000
- void CQuorumManager::CleanupOldQuorumData (const CBlockIndex* pIndex) const
1006
+ void CQuorumManager::StartCleanupOldQuorumDataThread (const CBlockIndex* pIndex) const
1001
1007
{
1002
- if (!fMasternodeMode || pIndex == nullptr || (pIndex->nHeight % 576 != 0 )) {
1008
+ // Note: this function is CPU heavy and we don't want it to be running during DKGs.
1009
+ // The largest dkgMiningWindowStart for a related quorum type is 42 (LLMQ_60_75).
1010
+ // At the same time most quorums use dkgInterval = 24 so the next DKG for them
1011
+ // (after block 576 + 42) will start at block 576 + 24 * 2. That's only a 6 blocks
1012
+ // window and it's better to have more room so we pick next cycle.
1013
+ // dkgMiningWindowStart for small quorums is 10 i.e. a safe block to start
1014
+ // these calculations is at height 576 + 24 * 2 + 10 = 576 + 58.
1015
+ if (!fMasternodeMode || pIndex == nullptr || (pIndex->nHeight % 576 != 58 )) {
1003
1016
return ;
1004
1017
}
1005
1018
1006
- std::set<uint256> dbKeysToSkip;
1019
+ cxxtimer::Timer t (/* start=*/ true );
1020
+ LogPrint (BCLog::LLMQ, " CQuorumManager::%s -- start\n " , __func__);
1007
1021
1008
- LogPrint (BCLog::LLMQ, " CQuorumManager::%d -- start\n " , __func__);
1009
- // Platform quorums in all networks are created every 24 blocks (~1h).
1010
- // Unlike for other quorum types we want to keep data (secret key shares and vvec)
1011
- // for Platform quorums for at least 2 months because Platform can be restarted and
1012
- // it must be able to re-sign stuff. During a month, 24 * 30 quorums are created.
1013
- constexpr auto numPlatformQuorumsDataToKeep = 24 * 30 * 2 ;
1022
+ // do not block the caller thread
1023
+ workerPool.push ([pIndex, t, this ](int threadId) {
1024
+ std::set<uint256> dbKeysToSkip;
1014
1025
1015
- for (const auto & params : Params ().GetConsensus ().llmqs ) {
1016
- auto nQuorumsToKeep = params.type == Params ().GetConsensus ().llmqTypePlatform ? numPlatformQuorumsDataToKeep : params.keepOldConnections ;
1017
- const auto vecQuorums = ScanQuorums (params.type , pIndex, nQuorumsToKeep);
1018
- for (const auto & pQuorum : vecQuorums) {
1019
- dbKeysToSkip.insert (MakeQuorumKey (*pQuorum));
1026
+ for (const auto & params : Params ().GetConsensus ().llmqs ) {
1027
+ if (quorumThreadInterrupt) {
1028
+ break ;
1029
+ }
1030
+ for (const auto & pQuorum : ScanQuorums (params.type , pIndex, params.keepOldKeys )) {
1031
+ dbKeysToSkip.insert (MakeQuorumKey (*pQuorum));
1032
+ }
1020
1033
}
1021
- }
1022
1034
1023
- DataCleanupHelper (m_evoDb.GetRawDB (), dbKeysToSkip);
1035
+ if (!quorumThreadInterrupt) {
1036
+ DataCleanupHelper (m_evoDb.GetRawDB (), dbKeysToSkip);
1037
+ }
1024
1038
1025
- LogPrint (BCLog::LLMQ, " CQuorumManager::%d -- done\n " , __func__);
1039
+ LogPrint (BCLog::LLMQ, " CQuorumManager::StartCleanupOldQuorumDataThread -- done. time=%d\n " , t.count ());
1040
+ });
1026
1041
}
1027
1042
1028
1043
} // namespace llmq
0 commit comments