mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
feat: Remove outdated quorum data from evodb (#5576)
## Issue being fixed or feature implemented Grabbed this from #5480. ## What was done? Cleans quorum data from evoDB for old quorums. ## How Has This Been Tested? ## Breaking Changes ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
135be62d44
commit
19aa3ab31a
@ -295,6 +295,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
|
||||
}
|
||||
|
||||
TriggerQuorumDataRecoveryThreads(pindexNew);
|
||||
CleanupOldQuorumData(pindexNew);
|
||||
}
|
||||
|
||||
void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
|
||||
@ -958,4 +959,67 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
|
||||
});
|
||||
}
|
||||
|
||||
static void DataCleanupHelper(CDBWrapper& db, std::set<uint256> skip_list)
|
||||
{
|
||||
const auto prefixes = {DB_QUORUM_QUORUM_VVEC, DB_QUORUM_SK_SHARE};
|
||||
|
||||
CDBBatch batch(db);
|
||||
std::unique_ptr<CDBIterator> pcursor(db.NewIterator());
|
||||
|
||||
for (const auto& prefix : prefixes) {
|
||||
auto start = std::make_tuple(prefix, uint256());
|
||||
pcursor->Seek(start);
|
||||
|
||||
int count{0};
|
||||
while (pcursor->Valid()) {
|
||||
decltype(start) k;
|
||||
|
||||
if (!pcursor->GetKey(k) || std::get<0>(k) != prefix) {
|
||||
break;
|
||||
}
|
||||
|
||||
pcursor->Next();
|
||||
|
||||
if (skip_list.find(std::get<1>(k)) != skip_list.end()) continue;
|
||||
|
||||
++count;
|
||||
batch.Erase(k);
|
||||
|
||||
if (batch.SizeEstimate() >= (1 << 24)) {
|
||||
db.WriteBatch(batch);
|
||||
batch.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
db.WriteBatch(batch);
|
||||
|
||||
LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- %s removed %d\n", __func__, prefix, count);
|
||||
}
|
||||
|
||||
pcursor.reset();
|
||||
db.CompactFull();
|
||||
}
|
||||
|
||||
void CQuorumManager::CleanupOldQuorumData(const CBlockIndex* pIndex) const
|
||||
{
|
||||
if (!fMasternodeMode || pIndex == nullptr || (pIndex->nHeight % 576 != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<uint256> dbKeys;
|
||||
|
||||
LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- start\n", __func__);
|
||||
|
||||
for (const auto& params : Params().GetConsensus().llmqs) {
|
||||
const auto vecQuorums = ScanQuorums(params.type, pIndex, params.keepOldConnections);
|
||||
for (const auto& pQuorum : vecQuorums) {
|
||||
dbKeys.insert(MakeQuorumKey(*pQuorum));
|
||||
}
|
||||
}
|
||||
|
||||
DataCleanupHelper(m_evoDb.GetRawDB(), dbKeys);
|
||||
|
||||
LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- done\n", __func__);
|
||||
}
|
||||
|
||||
} // namespace llmq
|
||||
|
@ -274,6 +274,8 @@ private:
|
||||
|
||||
void StartCachePopulatorThread(const CQuorumCPtr pQuorum) const;
|
||||
void StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex, uint16_t nDataMask) const;
|
||||
|
||||
void CleanupOldQuorumData(const CBlockIndex* pIndex) const;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<CQuorumManager> quorumManager;
|
||||
|
Loading…
Reference in New Issue
Block a user