Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
quorums_dkgsession.cpp
Go to the documentation of this file.
64 CDKGLogger(_quorumDkg.params.name, _quorumDkg.pindexQuorum->GetBlockHash(), _quorumDkg.pindexQuorum->nHeight, _quorumDkg.AreWeMember(), _func)
68 CDKGLogger::CDKGLogger(const std::string& _llmqTypeName, const uint256& _quorumHash, int _height, bool _areWeMember, const std::string& _func) :
69 CBatchedLogger(BCLog::LLMQ_DKG, strprintf("QuorumDKG(type=%s, height=%d, member=%d, func=%s)", _llmqTypeName, _height, _areWeMember, _func))
92 bool CDKGSession::Init(const CBlockIndex* _pindexQuorum, const std::vector<CDeterministicMNCPtr>& mns, const uint256& _myProTxHash)
127 quorumDKGDebugManager->InitLocalSessionStatus(params.type, pindexQuorum->GetBlockHash(), pindexQuorum->nHeight);
150 if (!blsWorker.GenerateContributions(params.threshold, memberIds, vvecContribution, skContributions)) {
192 if (!qc.contributions->Encrypt(i, m->dmn->pdmnState->pubKeyOperator.Get(), skContrib, PROTOCOL_VERSION)) {
204 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
212 // only performs cheap verifications, but not the signature of the message. this is checked with batched verification
213 bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGContribution& qc, bool& retBan) const
252 // this is a DoS protection against members sending multiple contributions with valid signatures to us
254 logger.Batch("dropping contribution from %s as we already got %d contributions", member->dmn->proTxHash.ToString(), member->contributions.size());
278 // only relay up to 2 contributions, that's enough to let the other members know about his bad behavior
288 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, member->idx, [&](CDKGDebugMemberStatus& status) {
311 logger.Batch("received and relayed contribution. received=%d/%d, time=%d", receivedCount, members.size(), t1.count());
324 if (!qc.contributions->Decrypt(myIdx, *activeMasternodeInfo.blsKeyOperator, skContribution, PROTOCOL_VERSION)) {
334 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, member->idx, [&](CDKGDebugMemberStatus& status) {
356 // This is done by aggregating the verification vectors belonging to the secret key contributions
358 // The public key share must match the public key belonging to the aggregated secret key contributions
387 logger.Batch("VerifyContributionShares returned result of size %d but size %d was expected, something is wrong", result.size(), memberIndexes.size());
394 logger.Batch("invalid contribution from %s. will complain later", m->dmn->proTxHash.ToString());
396 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, m->idx, [&](CDKGDebugMemberStatus& status) {
402 dkgManager.WriteVerifiedSkContribution(params.type, pindexQuorum, members[memberIdx]->dmn->proTxHash, skContributions[i]);
423 // as propagation will ensure that all nodes see the same vvecs/contributions. In case nodes come to
474 logger.Batch("%s does not have min proto version %d (has %d)", m->dmn->proTxHash.ToString(), MIN_MASTERNODE_PROTO_VERSION, it->second);
480 logger.Batch("%s no outbound connection since %d seconds", m->dmn->proTxHash.ToString(), GetAdjustedTime() - lastOutbound);
519 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
527 // only performs cheap verifications, but not the signature of the message. this is checked with batched verification
528 bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGComplaint& qc, bool& retBan) const
560 // this is a DoS protection against members sending multiple complaints with valid signatures to us
584 // only relay up to 2 complaints, that's enough to let the other members know about his bad behavior
594 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, member->idx, [&](CDKGDebugMemberStatus& status) {
612 logger.Batch("%s voted for %s to be bad", member->dmn->proTxHash.ToString(), m->dmn->proTxHash.ToString());
621 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, m->idx, [&](CDKGDebugMemberStatus& status) {
651 logger.Batch("%s marked as bad as %d other members voted for this", m->dmn->proTxHash.ToString(), m->badMemberVotes.size());
676 void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const std::set<uint256>& forMembers)
716 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
724 // only performs cheap verifications, but not the signature of the message. this is checked with batched verification
725 bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGJustification& qj, bool& retBan) const
773 // this is a DoS protection against members sending multiple justifications with valid signatures to us
783 void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGJustification& qj, bool& retBan)
797 // only relay up to 2 justifications, that's enough to let the other members know about his bad behavior
808 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, member->idx, [&](CDKGDebugMemberStatus& status) {
823 // don't give him a second chance (but we relay the justification in case other members disagree)
849 futures.emplace_back(blsWorker.AsyncVerifyContributionShare(member2->id, receivedVvecs[member->idx], skContribution));
858 logger.Batch(" %s did send an invalid justification for %s", member->dmn->proTxHash.ToString(), member2->dmn->proTxHash.ToString());
861 logger.Batch(" %s justified for %s", member->dmn->proTxHash.ToString(), member2->dmn->proTxHash.ToString());
866 dkgManager.WriteVerifiedSkContribution(params.type, pindexQuorum, member->dmn->proTxHash, skContribution);
885 logger.Batch("verified justification: received=%d/%d time=%d", receivedCount, expectedCount, t1.count());
967 if (!dkgManager.GetVerifiedContributions(params.type, pindexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
972 BLSVerificationVectorPtr vvec = cache.BuildQuorumVerificationVector(::SerializeHash(memberIndexes), vvecs);
980 CBLSSecretKey skShare = cache.AggregateSecretKeys(::SerializeHash(memberIndexes), skContributions);
1007 uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(qc.llmqType, qc.quorumHash, qc.validMembers, qc.quorumPublicKey, qc.quorumVvecHash);
1037 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
1045 // only performs cheap verifications, but not the signature of the message. this is checked with batched verification
1046 bool CDKGSession::PreVerifyMessage(const uint256& hash, const CDKGPrematureCommitment& qc, bool& retBan) const
1098 // this is a DoS protection against members sending multiple commitments with valid signatures to us
1108 void CDKGSession::ReceiveMessage(const uint256& hash, const CDKGPrematureCommitment& qc, bool& retBan)
1116 logger.Batch("received premature commitment from %s. validMembers=%d", qc.proTxHash.ToString(), qc.CountValidMembers());
1133 if (dkgManager.GetVerifiedContributions(params.type, pindexQuorum, qc.validMembers, memberIndexes, vvecs, skContributions)) {
1139 // we might be the unlucky one who didn't receive all contributions, but we still have to relay
1142 // we got all information that is needed to verify everything (even though we might not be a member of the quorum)
1143 // if any of this verification fails, we won't relay this message. This ensures that invalid messages are lost
1144 // in the network. Nodes relaying such invalid messages to us are not punished as they might have not known
1145 // all contributions. We only handle up to 2 commitments per member, so a DoS shouldn't be possible
1157 CBLSPublicKey pubKeyShare = cache.BuildPubKeyShare(::SerializeHash(std::make_pair(memberIndexes, member->id)), quorumVvec, member->id);
1175 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, member->idx, [&](CDKGDebugMemberStatus& status) {
1189 logger.Batch("verified premature commitment. received=%d/%d, time=%d", receivedCount, members.size(), t1.count());
1240 uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(fqc.llmqType, fqc.quorumHash, fqc.validMembers, fqc.quorumPublicKey, fqc.quorumVvecHash);
1250 if (qc.quorumPublicKey != first.quorumPublicKey || qc.quorumVvecHash != first.quorumVvecHash) {
1279 logger.Batch("final commitment: validMembers=%d, signers=%d, quorumPublicKey=%s, time1=%d, time2=%d",
1304 quorumDKGDebugManager->UpdateLocalMemberStatus(params.type, idx, [&](CDKGDebugMemberStatus& status) {
1318 } else if (!pnode->verifiedProRegTxHash.IsNull() && relayMembers.count(pnode->verifiedProRegTxHash)) {
bool GetBlockHash(uint256 &hashRet, int nBlockHeight)
Return true if hash can be found in chainActive at nBlockHeight height.
Definition: validation.cpp:1894
Acts as a FIFO queue for incoming DKG messages.
Definition: quorums_dkgsessionhandler.h:36
void InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256 &quorumHash, int quorumHeight)
Definition: quorums_debug.cpp:159
void SetSimulatedDKGErrorRate(const std::string &type, double rate)
Definition: quorums_dkgsession.cpp:41
void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function< bool(CDKGDebugSessionStatus &status)> &&func)
Definition: quorums_debug.cpp:179
Definition: util.h:138
Definition: quorums_commitment.h:24
BLSSecretKeyVector skContributions
Definition: quorums_dkgsession.h:259
Definition: protocol.h:419
void PushPendingMessage(NodeId from, CDataStream &vRecv)
Definition: quorums_dkgsessionhandler.cpp:27
void ReceiveMessage(const uint256 &hash, const CDKGContribution &qc, bool &retBan)
Definition: quorums_dkgsession.cpp:261
Definition: bls.h:238
Definition: util.h:107
void WriteVerifiedSkContribution(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &proTxHash, const CBLSSecretKey &skContribution)
Definition: quorums_dkgsessionmgr.cpp:208
static CBLSSignature AggregateSecure(const std::vector< CBLSSignature > &sigs, const std::vector< CBLSPublicKey > &pks, const uint256 &hash)
Definition: bls.cpp:304
std::map< uint256, CDKGComplaint > complaints
Definition: quorums_dkgsession.h:276
static std::map< std::string, double > simDkgErrorMap
Definition: quorums_dkgsession.cpp:39
std::map< uint256, CDKGPrematureCommitment > prematureCommitments
Definition: quorums_dkgsession.h:278
CDKGPrematureCommitment()
Definition: quorums_dkgsession.h:172
void SendCommitment(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:931
bool VerifyInsecure(const CBLSPublicKey &pubKey, const uint256 &hash) const
Definition: bls.cpp:335
std::vector< std::unique_ptr< CDKGMember > > members
Definition: quorums_dkgsession.h:255
std::shared_ptr< const CDeterministicMN > CDeterministicMNCPtr
Definition: deterministicmns.h:249
Definition: deterministicmns.h:26
Definition: quorums_dkgsession.h:202
std::vector< bool > validMembers
Definition: quorums_dkgsession.h:163
static bool ShouldSimulateError(const std::string &type)
Definition: quorums_dkgsession.cpp:57
bool VerifyVerificationVector(const BLSVerificationVector &vvec, size_t start=0, size_t count=0)
Definition: bls_worker.cpp:788
bool GenerateContributions(int threshold, const BLSIdVector &ids, BLSVerificationVectorPtr &vvecRet, BLSSecretKeyVector &skShares)
Definition: bls_worker.cpp:75
void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function< bool(CDKGDebugMemberStatus &status)> &&func)
Definition: quorums_debug.cpp:193
std::map< uint256, CDKGJustification > justifications
Definition: quorums_dkgsession.h:277
int CountValidMembers() const
Definition: quorums_dkgsession.h:175
CBLSSecretKey AggregateSecretKeys(const uint256 &cacheKey, const BLSSecretKeyVector &skShares)
Definition: bls_worker.h:170
bool GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const std::vector< bool > &validMembers, std::vector< uint16_t > &memberIndexesRet, std::vector< BLSVerificationVectorPtr > &vvecsRet, BLSSecretKeyVector &skContributionsRet)
Definition: quorums_dkgsessionmgr.cpp:213
std::map< uint256, CDKGContribution > contributions
Definition: quorums_dkgsession.h:275
CDKGMember * GetMember(const uint256 &proTxHash) const
Definition: quorums_dkgsession.cpp:1289
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
Definition: hash.h:254
bool PreVerifyMessage(const uint256 &hash, const CDKGContribution &qc, bool &retBan) const
Definition: quorums_dkgsession.cpp:213
std::shared_ptr< BLSVerificationVector > BLSVerificationVectorPtr
Definition: bls.h:471
static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256 &blockHash, const std::vector< bool > &validMembers, const CBLSPublicKey &pubKey, const uint256 &vvecHash)
Definition: quorums_utils.cpp:26
Definition: quorums_debug.h:48
CBLSPublicKey quorumPublicKey
Definition: quorums_dkgsession.h:165
void MarkBadMember(size_t idx)
Definition: quorums_dkgsession.cpp:1298
Definition: bls.h:263
void VerifyPendingContributions()
Definition: quorums_dkgsession.cpp:360
Definition: protocol.h:420
Definition: protocol.h:418
CBLSPublicKey quorumPublicKey
Definition: quorums_commitment.h:36
Definition: quorums_dkgsession.h:123
void VerifyAndComplain(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:409
std::vector< bool > VerifyContributionShares(const CBLSId &forId, const std::vector< BLSVerificationVectorPtr > &vvecs, const BLSSecretKeyVector &skShares, bool parallel=true, bool aggregated=true)
Definition: bls_worker.cpp:748
void VerifyAndJustify(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:636
void VerifyConnectionAndMinProtoVersions()
Definition: quorums_dkgsession.cpp:447
CBLSPublicKey BuildPubKeyShare(const uint256 &cacheKey, const BLSVerificationVectorPtr &vvec, const CBLSId &id)
Definition: bls_worker.h:176
std::vector< BLSVerificationVectorPtr > receivedVvecs
Definition: quorums_dkgsession.h:262
Definition: params.h:65
Definition: quorums_debug.h:22
void RelayInvToParticipants(const CInv &inv) const
Definition: quorums_dkgsession.cpp:1311
std::vector< size_t > pendingContributionVerifications
Definition: quorums_dkgsession.h:280
The DKG session is a single instance of the DKG process.
Definition: quorums_dkgsession.h:239
Definition: quorums_dkgsession.h:29
void Contribute(CDKGPendingMessages &pendingMessages)
The following sets of methods are for the first 4 phases handled in the session.
Definition: quorums_dkgsession.cpp:140
Definition: quorums_dkgsession.h:36
int CountValidMembers() const
Definition: quorums_commitment.h:50
CDKGMember(CDeterministicMNCPtr _dmn, size_t _idx)
Definition: quorums_dkgsession.cpp:84
void WriteVerifiedVvecContribution(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &proTxHash, const BLSVerificationVectorPtr &vvec)
Definition: quorums_dkgsessionmgr.cpp:203
BLSSecretKeyVector receivedSkContributions
Definition: quorums_dkgsession.h:264
std::vector< CFinalCommitment > FinalizeCommitments()
Definition: quorums_dkgsession.cpp:1192
void Batch(const std::string &fmt, const Args &... args)
Definition: batchedlogger.h:21
void SendComplaint(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:485
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
Definition: quorums_dkgsession.h:88
void VerifyAndCommit(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:888
bool Init(const CBlockIndex *pindexQuorum, const std::vector< CDeterministicMNCPtr > &mns, const uint256 &_myProTxHash)
Definition: quorums_dkgsession.cpp:92
std::vector< std::pair< uint32_t, CBLSSecretKey > > contributions
Definition: quorums_dkgsession.h:129
Consensus::LLMQType llmqType
Definition: quorums_dkgsession.h:160
Definition: protocol.h:421
std::future< bool > AsyncVerifyContributionShare(const CBLSId &forId, const BLSVerificationVectorPtr &vvec, const CBLSSecretKey &skContribution)
Definition: bls_worker.cpp:754
std::map< uint256, size_t > membersMap
Definition: quorums_dkgsession.h:256
BLSVerificationVectorPtr vvecContribution
Definition: quorums_dkgsession.h:258
static const int MIN_MASTERNODE_PROTO_VERSION
minimum proto version of masternode to accept in DKGs
Definition: version.h:26
std::vector< bool > complainForMembers
Definition: quorums_dkgsession.h:95
uint256 quorumVvecHash
Definition: quorums_dkgsession.h:166
BLSVerificationVectorPtr BuildQuorumVerificationVector(const uint256 &cacheKey, const std::vector< BLSVerificationVectorPtr > &vvecs)
Definition: bls_worker.h:164
static std::set< uint256 > GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &forMember, bool onlyOutbound)
Definition: quorums_utils.cpp:107
bool Recover(const std::vector< CBLSSignature > &sigs, const std::vector< CBLSId > &ids)
Definition: bls.cpp:393
static double GetSimulatedErrorRate(const std::string &type)
Definition: quorums_dkgsession.cpp:47
uint256 GetSignHash() const
Definition: quorums_dkgsession.h:196
std::set< uint256 > validCommitments
Definition: quorums_dkgsession.h:283
std::unique_ptr< CBLSSecretKey > blsKeyOperator
Definition: activemasternode.h:26
void SendJustification(CDKGPendingMessages &pendingMessages, const std::set< uint256 > &forMembers)
Definition: quorums_dkgsession.cpp:676
std::vector< bool > validMembers
Definition: quorums_commitment.h:34
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType)
Definition: quorums_utils.cpp:47
CMasternodeMetaInfoPtr GetMetaInfo(const uint256 &proTxHash, bool fCreate=true)
Definition: masternode-meta.cpp:45
void SendContributions(CDKGPendingMessages &pendingMessages)
Definition: quorums_dkgsession.cpp:160
CDKGLogger(const CDKGSession &_quorumDkg, const std::string &_func)
Definition: quorums_dkgsession.cpp:63
Definition: batchedlogger.h:10
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
std::shared_ptr< CBLSIESMultiRecipientObjects< CBLSSecretKey > > contributions
Definition: quorums_dkgsession.h:43