Skip to content

Commit

Permalink
feat: migrate quorum data from evodb to the new db in llmq
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 15, 2023
1 parent fd02d2f commit f5d15af
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
59 changes: 52 additions & 7 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
utils::InitQuorumsCache(scanQuorumsCache);

quorumThreadInterrupt.reset();
EraseOldQuorumDB(_evoDb);
MigrateOldQuorumDB(_evoDb);
}

void CQuorumManager::Start()
Expand Down Expand Up @@ -1041,17 +1041,62 @@ void CQuorumManager::CleanupOldQuorumData(const CBlockIndex* pIndex) const
LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- done\n", __func__);
}

void CQuorumManager::EraseOldQuorumDB(CEvoDB& evoDb) const
void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const
{
// NOTE: We do not migrate old data here because we have no idea
// which bls scheme was used to store it originally. This is ok
// cause the data can be re-requested from other nodes, see
// TriggerQuorumDataRecoveryThreads.
LOCK(cs_db);
if (!db->IsEmpty()) return;

if (WITH_LOCK(cs_db, return !db->IsEmpty())) return;
const auto prefixes = {DB_QUORUM_QUORUM_VVEC, DB_QUORUM_SK_SHARE};

LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- start\n", __func__);

CDBBatch batch(*db);
std::unique_ptr<CDBIterator> pcursor(evoDb.GetRawDB().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;
CDataStream s(SER_DISK, CLIENT_VERSION);
CBLSSecretKey sk;

if (!pcursor->GetKey(k) || std::get<0>(k) != prefix) {
break;
}

if (prefix == DB_QUORUM_QUORUM_VVEC) {
if (!evoDb.GetRawDB().ReadDataStream(k, s)) {
break;
}
batch.Write(k, s);
}
if (prefix == DB_QUORUM_SK_SHARE) {
if (!pcursor->GetValue(sk)) {
break;
}
batch.Write(k, sk);
}

if (batch.SizeEstimate() >= (1 << 24)) {
db->WriteBatch(batch);
batch.Clear();
}

++count;
pcursor->Next();
}

db->WriteBatch(batch);

LogPrint(BCLog::LLMQ, "CQuorumManager::%d -- %s moved %d\n", __func__, prefix, count);
}

pcursor.reset();
db->CompactFull();

DataCleanupHelper(evoDb.GetRawDB(), {});
evoDb.CommitRootTransaction();

Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CQuorumManager
void StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex, uint16_t nDataMask) const;

void CleanupOldQuorumData(const CBlockIndex* pIndex) const;
void EraseOldQuorumDB(CEvoDB& evoDb) const;
void MigrateOldQuorumDB(CEvoDB& evoDb) const;
};

extern std::unique_ptr<CQuorumManager> quorumManager;
Expand Down

0 comments on commit f5d15af

Please sign in to comment.