apply suggestions

This commit is contained in:
UdjinM6 2024-09-18 17:42:54 +03:00
parent 600dcf3dda
commit ad35c1ab2f
No known key found for this signature in database
GPG Key ID: 83592BD1400D58D9
2 changed files with 17 additions and 15 deletions

View File

@ -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);
@ -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;
}
@ -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;
}
@ -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),
@ -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());
@ -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 {};
@ -1110,6 +1111,7 @@ void CQuorumManager::StartCleanupOldQuorumDataThread(const CBlockIndex* pIndex)
});
}
// TODO: remove in v23
void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const
{
LOCK(cs_db);
@ -1117,7 +1119,7 @@ void CQuorumManager::MigrateOldQuorumDB(CEvoDB& evoDb) const
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());
@ -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();
@ -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,

View File

@ -217,8 +217,8 @@ public:
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);
};
/**