Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Sep 18, 2024
1 parent 600dcf3 commit ad35c1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 15 additions & 13 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int CQuorum::GetMemberIndex(const uint256& proTxHash) const
return -1;
}

void CQuorum::WriteContributions(const std::unique_ptr<CDBWrapper>& db) const
void CQuorum::WriteContributions(CDBWrapper& db) const
{
uint256 dbKey = MakeQuorumKey(*this);

Expand All @@ -175,19 +175,19 @@ void CQuorum::WriteContributions(const std::unique_ptr<CDBWrapper>& db) const
for (auto& pubkey : *quorumVvec) {
s << CBLSPublicKeyVersionWrapper(pubkey, false);
}
db->Write(std::make_pair(DB_QUORUM_QUORUM_VVEC, dbKey), s);
db.Write(std::make_pair(DB_QUORUM_QUORUM_VVEC, dbKey), s);
}
if (skShare.IsValid()) {
db->Write(std::make_pair(DB_QUORUM_SK_SHARE, dbKey), skShare);
db.Write(std::make_pair(DB_QUORUM_SK_SHARE, dbKey), skShare);
}
}

bool CQuorum::ReadContributions(const std::unique_ptr<CDBWrapper>& db)
bool CQuorum::ReadContributions(const CDBWrapper& db)
{
uint256 dbKey = MakeQuorumKey(*this);
CDataStream s(SER_DISK, CLIENT_VERSION);

if (!db->ReadDataStream(std::make_pair(DB_QUORUM_QUORUM_VVEC, dbKey), s)) {
if (!db.ReadDataStream(std::make_pair(DB_QUORUM_QUORUM_VVEC, dbKey), s)) {
return false;
}

Expand All @@ -203,7 +203,7 @@ bool CQuorum::ReadContributions(const std::unique_ptr<CDBWrapper>& db)
quorumVvec = std::make_shared<std::vector<CBLSPublicKey>>(std::move(qv));
// We ignore the return value here as it is ok if this fails. If it fails, it usually means that we are not a
// member of the quorum but observed the whole DKG process to have the quorum verification vector.
db->Read(std::make_pair(DB_QUORUM_SK_SHARE, dbKey), skShare);
db.Read(std::make_pair(DB_QUORUM_SK_SHARE, dbKey), skShare);

return true;
}
Expand All @@ -213,7 +213,8 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
CQuorumBlockProcessor& _quorumBlockProcessor,
const CActiveMasternodeManager* const mn_activeman, const CMasternodeSync& mn_sync,
const CSporkManager& sporkman, bool unit_tests, bool wipe) :
db(std::make_unique<CDBWrapper>(unit_tests ? "" : (gArgs.GetDataDirNet() / "llmq/quorumdb"), 1 << 20, unit_tests, wipe)),
db(std::make_unique<CDBWrapper>(unit_tests ? "" : (gArgs.GetDataDirNet() / "llmq" / "quorumdb"), 1 << 20,
unit_tests, wipe)),
blsWorker(_blsWorker),
m_chainstate(chainstate),
connman(_connman),
Expand Down Expand Up @@ -407,11 +408,11 @@ CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType l
quorum->Init(std::move(qc), pQuorumBaseBlockIndex, minedBlockHash, members);

bool hasValidVvec = false;
if (WITH_LOCK(cs_db, return quorum->ReadContributions(db))) {
if (WITH_LOCK(cs_db, return quorum->ReadContributions(*db))) {
hasValidVvec = true;
} else {
if (BuildQuorumContributions(quorum->qc, quorum)) {
WITH_LOCK(cs_db, quorum->WriteContributions(db));
WITH_LOCK(cs_db, quorum->WriteContributions(*db));
hasValidVvec = true;
} else {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] quorumIndex[%d] quorum.ReadContributions and BuildQuorumContributions for quorumHash[%s] failed\n", __func__, ToUnderlying(llmqType), quorum->qc->quorumIndex, quorum->qc->quorumHash.ToString());
Expand Down Expand Up @@ -849,7 +850,7 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t
return errorHandler("Invalid secret key share received");
}
}
WITH_LOCK(cs_db, pQuorum->WriteContributions(db));
WITH_LOCK(cs_db, pQuorum->WriteContributions(*db));
return {};
}
return {};
Expand Down Expand Up @@ -1110,14 +1111,15 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex)
});
}

// TODO: remove in v23
void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const
{
LOCK(cs_db);
if (!db->IsEmpty()) return;

const auto prefixes = {DB_QUORUM_QUORUM_VVEC, DB_QUORUM_SK_SHARE};

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

CDBBatch batch(*db);
std::unique_ptr<CDBIterator> pcursor(evoDb.GetRawDB().NewIterator());
Expand Down Expand Up @@ -1160,7 +1162,7 @@ void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const

db->WriteBatch(batch);

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

pcursor.reset();
Expand All @@ -1169,7 +1171,7 @@ void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const
DataCleanupHelper(evoDb.GetRawDB(), {});
evoDb.CommitRootTransaction();

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

CQuorumCPtr SelectQuorumForSigning(const Consensus::LLMQParams& llmq_params, const CChain& active_chain, const CQuorumManager& qman,
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ class CQuorum

private:
bool HasVerificationVectorInternal() const EXCLUSIVE_LOCKS_REQUIRED(cs_vvec_shShare);
void WriteContributions(const std::unique_ptr<CDBWrapper>& db) const;
bool ReadContributions(const std::unique_ptr<CDBWrapper>& db);
void WriteContributions(CDBWrapper& db) const;
bool ReadContributions(const CDBWrapper& db);
};

/**
Expand Down

0 comments on commit ad35c1a

Please sign in to comment.