Skip to content

Commit

Permalink
Renamed variable to avoid confusion with Quorum Index
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Sep 29, 2021
1 parent 7e2151e commit 38425ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
48 changes: 28 additions & 20 deletions src/llmq/quorums_dkgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool CDKGSession::ShouldSimulateError(const std::string& type) const
}

CDKGLogger::CDKGLogger(const CDKGSession& _quorumDkg, const std::string& _func) :
CDKGLogger(_quorumDkg.params.name, _quorumDkg.pindexQuorum->GetBlockHash(), _quorumDkg.pindexQuorum->nHeight, _quorumDkg.AreWeMember(), _func)
CDKGLogger(_quorumDkg.params.name, _quorumDkg.pblockIndexQuorum->GetBlockHash(), _quorumDkg.pblockIndexQuorum->nHeight, _quorumDkg.AreWeMember(), _func)
{
}

Expand Down Expand Up @@ -90,16 +90,24 @@ CDKGMember::CDKGMember(CDeterministicMNCPtr _dmn, size_t _idx) :

}

bool CDKGSession::Init(const CBlockIndex* _pindexQuorum, const std::vector<CDeterministicMNCPtr>& mns, const uint256& _myProTxHash)
bool CDKGSession::Init(const CBlockIndex* _pblockIndexQuorum, const std::vector<CDeterministicMNCPtr>& mns, const uint256& _myProTxHash)
{
pindexQuorum = _pindexQuorum;
pblockIndexQuorum = _pblockIndexQuorum;

members.resize(mns.size());
memberIds.resize(members.size());
receivedVvecs.resize(members.size());
receivedSkContributions.resize(members.size());
vecEncryptedContributions.resize(members.size());


if(params.type == Consensus::LLMQ_50_60){

}

std::vector<CDeterministicMNCPtr> quorum_members = CLLMQUtils::GetAllQuorumMembers(params.type, pblockIndexQuorum);
deterministicMNManager->GetListAtChainTip();

for (size_t i = 0; i < mns.size(); i++) {
members[i] = std::make_unique<CDKGMember>(mns[i], i);
membersMap.emplace(members[i]->dmn->proTxHash, i);
Expand All @@ -126,8 +134,8 @@ bool CDKGSession::Init(const CBlockIndex* _pindexQuorum, const std::vector<CDete
}

if (!myProTxHash.IsNull()) {
quorumDKGDebugManager->InitLocalSessionStatus(params.type, pindexQuorum->GetBlockHash(), pindexQuorum->nHeight);
relayMembers = CLLMQUtils::GetQuorumRelayMembers(params.type, pindexQuorum, myProTxHash, true);
quorumDKGDebugManager->InitLocalSessionStatus(params.type, pblockIndexQuorum->GetBlockHash(), pblockIndexQuorum->nHeight);
relayMembers = CLLMQUtils::GetQuorumRelayMembers(params.type, pblockIndexQuorum, myProTxHash, true);
}

if (myProTxHash.IsNull()) {
Expand Down Expand Up @@ -174,7 +182,7 @@ void CDKGSession::SendContributions(CDKGPendingMessages& pendingMessages)

CDKGContribution qc;
qc.llmqType = params.type;
qc.quorumHash = pindexQuorum->GetBlockHash();
qc.quorumHash = pblockIndexQuorum->GetBlockHash();
qc.proTxHash = myProTxHash;
qc.vvec = vvecContribution;

Expand Down Expand Up @@ -218,7 +226,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGContribution& qc, bool& retBan) con

retBan = false;

if (qc.quorumHash != pindexQuorum->GetBlockHash()) {
if (qc.quorumHash != pblockIndexQuorum->GetBlockHash()) {
logger.Batch("contribution for wrong quorum, rejecting");
return false;
}
Expand Down Expand Up @@ -320,7 +328,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc, bool& retBan)
return;
}

dkgManager.WriteVerifiedVvecContribution(params.type, pindexQuorum, qc.proTxHash, qc.vvec);
dkgManager.WriteVerifiedVvecContribution(params.type, pblockIndexQuorum, qc.proTxHash, qc.vvec);

bool complain = false;
CBLSSecretKey skContribution;
Expand Down Expand Up @@ -388,7 +396,7 @@ void CDKGSession::VerifyPendingContributions()
skContributions.emplace_back(receivedSkContributions[idx]);
// Write here to definitely store one contribution for each member no matter if
// our share is valid or not, could be that others are still correct
dkgManager.WriteEncryptedContributions(params.type, pindexQuorum, m->dmn->proTxHash, *vecEncryptedContributions[idx]);
dkgManager.WriteEncryptedContributions(params.type, pblockIndexQuorum, m->dmn->proTxHash, *vecEncryptedContributions[idx]);
}

auto result = blsWorker.VerifyContributionShares(myId, vvecs, skContributions);
Expand All @@ -408,7 +416,7 @@ void CDKGSession::VerifyPendingContributions()
});
} else {
size_t memberIdx = memberIndexes[i];
dkgManager.WriteVerifiedSkContribution(params.type, pindexQuorum, members[memberIdx]->dmn->proTxHash, skContributions[i]);
dkgManager.WriteVerifiedSkContribution(params.type, pblockIndexQuorum, members[memberIdx]->dmn->proTxHash, skContributions[i]);
}
}

Expand Down Expand Up @@ -504,7 +512,7 @@ void CDKGSession::SendComplaint(CDKGPendingMessages& pendingMessages)

CDKGComplaint qc(params);
qc.llmqType = params.type;
qc.quorumHash = pindexQuorum->GetBlockHash();
qc.quorumHash = pblockIndexQuorum->GetBlockHash();
qc.proTxHash = myProTxHash;

int badCount = 0;
Expand Down Expand Up @@ -545,7 +553,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGComplaint& qc, bool& retBan) const

retBan = false;

if (qc.quorumHash != pindexQuorum->GetBlockHash()) {
if (qc.quorumHash != pblockIndexQuorum->GetBlockHash()) {
logger.Batch("complaint for wrong quorum, rejecting");
return false;
}
Expand Down Expand Up @@ -700,7 +708,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const

CDKGJustification qj;
qj.llmqType = params.type;
qj.quorumHash = pindexQuorum->GetBlockHash();
qj.quorumHash = pblockIndexQuorum->GetBlockHash();
qj.proTxHash = myProTxHash;
qj.contributions.reserve(forMembers.size());

Expand Down Expand Up @@ -745,7 +753,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co

retBan = false;

if (qj.quorumHash != pindexQuorum->GetBlockHash()) {
if (qj.quorumHash != pblockIndexQuorum->GetBlockHash()) {
logger.Batch("justification for wrong quorum, rejecting");
return false;
}
Expand Down Expand Up @@ -881,7 +889,7 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj, bool& retBan)
receivedSkContributions[member->idx] = skContribution;
member->weComplain = false;

dkgManager.WriteVerifiedSkContribution(params.type, pindexQuorum, member->dmn->proTxHash, skContribution);
dkgManager.WriteVerifiedSkContribution(params.type, pblockIndexQuorum, member->dmn->proTxHash, skContribution);
}
member->complaintsFromOthers.erase(member2->dmn->proTxHash);
}
Expand Down Expand Up @@ -956,7 +964,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)

CDKGPrematureCommitment qc(params);
qc.llmqType = params.type;
qc.quorumHash = pindexQuorum->GetBlockHash();
qc.quorumHash = pblockIndexQuorum->GetBlockHash();
qc.proTxHash = myProTxHash;

for (size_t i = 0; i < members.size(); i++) {
Expand All @@ -982,7 +990,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
std::vector<uint16_t> memberIndexes;
std::vector<BLSVerificationVectorPtr> vvecs;
BLSSecretKeyVector skContributions;
if (!dkgManager.GetVerifiedContributions(params.type, pindexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
if (!dkgManager.GetVerifiedContributions(params.type, pblockIndexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
logger.Batch("failed to get valid contributions");
return;
}
Expand Down Expand Up @@ -1065,7 +1073,7 @@ bool CDKGSession::PreVerifyMessage(const CDKGPrematureCommitment& qc, bool& retB

retBan = false;

if (qc.quorumHash != pindexQuorum->GetBlockHash()) {
if (qc.quorumHash != pblockIndexQuorum->GetBlockHash()) {
logger.Batch("commitment for wrong quorum, rejecting");
return false;
}
Expand Down Expand Up @@ -1145,7 +1153,7 @@ void CDKGSession::ReceiveMessage(const CDKGPrematureCommitment& qc, bool& retBan
std::vector<BLSVerificationVectorPtr> vvecs;
BLSSecretKeyVector skContributions;
BLSVerificationVectorPtr quorumVvec;
if (dkgManager.GetVerifiedContributions(params.type, pindexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
if (dkgManager.GetVerifiedContributions(params.type, pblockIndexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
quorumVvec = cache.BuildQuorumVerificationVector(::SerializeHash(memberIndexes), vvecs);
}

Expand Down Expand Up @@ -1290,7 +1298,7 @@ std::vector<CFinalCommitment> CDKGSession::FinalizeCommitments()
t2.stop();

cxxtimer::Timer t3(true);
if (!fqc.Verify(pindexQuorum, true)) {
if (!fqc.Verify(pblockIndexQuorum, true)) {
logger.Batch("failed to verify final commitment");
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums_dkgsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class CDKGSession
CBLSWorkerCache cache;
CDKGSessionManager& dkgManager;

const CBlockIndex* pindexQuorum{nullptr};
const CBlockIndex* pblockIndexQuorum{nullptr};

private:
std::vector<std::unique_ptr<CDKGMember>> members;
Expand Down Expand Up @@ -276,7 +276,7 @@ class CDKGSession
CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CDKGSessionManager& _dkgManager) :
params(_params), blsWorker(_blsWorker), cache(_blsWorker), dkgManager(_dkgManager) {}

bool Init(const CBlockIndex* pindexQuorum, const std::vector<CDeterministicMNCPtr>& mns, const uint256& _myProTxHash);
bool Init(const CBlockIndex* pblockIndexQuorum, const std::vector<CDeterministicMNCPtr>& mns, const uint256& _myProTxHash);

size_t GetMyMemberIndex() const { return myIdx; }

Expand Down

0 comments on commit 38425ed

Please sign in to comment.