Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
quorums_dkgsessionhandler.cpp
Go to the documentation of this file.
37 LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- too many messages, peer=%d\n", __func__, from);
50 LogPrint(BCLog::LLMQ_DKG, "CDKGPendingMessages::%s -- already seen %s, peer=%d\n", __func__, hash.ToString(), from);
59 std::list<CDKGPendingMessages::BinaryMessage> CDKGPendingMessages::PopPendingMessages(size_t maxCount)
88 CDKGSessionHandler::CDKGSessionHandler(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CDKGSessionManager& _dkgManager) :
93 pendingContributions((size_t)_params.size * 2, MSG_QUORUM_CONTRIB), // we allow size*2 messages as we need to make sure we see bad behavior (double messages)
125 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionHandler::%s -- %s - currentHeight=%d, quorumHeight=%d, oldPhase=%d, newPhase=%d\n", __func__,
129 void CDKGSessionHandler::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
131 // We don't handle messages in the calling thread as deserialization/processing of these would block everything
150 phaseHandlerThread = std::thread(&TraceThread<std::function<void()> >, threadName, std::function<void()>(std::bind(&CDKGSessionHandler::PhaseHandlerThread, this)));
176 LogPrintf("CDKGSessionManager::%s -- quorum initialiation failed for %s\n", __func__, curSession->params.name);
197 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, curPhase, nextPhase);
201 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due to stop/shutdown requested\n", __func__, params.name);
206 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due unexpected expectedQuorumHash change\n", __func__, params.name);
213 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due unexpected phase change\n", __func__, params.name);
221 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, curPhase, nextPhase);
226 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
240 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due to stop/shutdown requested\n", __func__, params.name);
265 // On regtest, blocks can be mined on demand without any significant time passing between these.
270 // Two blocks can come very close to each other, this happens pretty regularly. We don't want to be
271 // left behind and marked as a bad member. This means that we should not count the last block of the
272 // phase as a safe one to keep sleeping, that's why we calculate the phase sleep time as a time of
274 double phaseSleepTime = (params.dkgPhaseBlocks - 1) * Params().GetConsensus().nPowTargetSpacing * 1000;
277 // Don't expect perfect block times and thus reduce the phase time to be on the secure side (caller chooses factor)
280 int64_t sleepTime = (int64_t)(adjustedPhaseSleepTimePerMember * curSession->GetMyMemberIndex());
289 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - starting sleep for %d ms, curPhase=%d\n", __func__, params.name, sleepTime, curPhase);
293 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due to stop/shutdown requested\n", __func__, params.name);
300 int64_t expectedBlockTime = (currentHeight - heightStart) * Params().GetConsensus().nPowTargetSpacing * 1000;
309 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - aborting due unexpected phase/expectedQuorumHash change\n", __func__, params.name);
318 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - done, curPhase=%d\n", __func__, params.name, curPhase);
328 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - starting, curPhase=%d, nextPhase=%d\n", __func__, params.name, curPhase, nextPhase);
334 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionManager::%s -- %s - done, curPhase=%d, nextPhase=%d\n", __func__, params.name, curPhase, nextPhase);
339 std::set<NodeId> BatchVerifyMessageSigs(CDKGSession& session, const std::vector<std::pair<NodeId, std::shared_ptr<Message>>>& messages)
375 // 1. Someone sent us the same message twice but with differing signature, meaning that at least one of them
376 // must be invalid. In this case, we'd have to revert to single message verification nevertheless
377 // 2. Someone managed to find a way to create two different binary representations of a message that deserializes
378 // to the same object representation. This would be some form of malleability. However, this shouldn't be
424 bool valid = msg.sig.VerifyInsecure(member->dmn->pdmnState->pubKeyOperator.Get(), msg.GetSignHash());
433 bool ProcessPendingMessageBatch(CDKGSession& session, CDKGPendingMessages& pendingMessages, size_t maxCount)
465 LogPrint(BCLog::LLMQ_DKG, "%s -- banning node due to failed preverification, peer=%d\n", __func__, p.first);
471 LogPrint(BCLog::LLMQ_DKG, "%s -- skipping message due to failed preverification, peer=%d\n", __func__, p.first);
499 LogPrint(BCLog::LLMQ_DKG, "%s -- banning node after ReceiveMessage failed, peer=%d\n", __func__, nodeId);
538 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
544 CLLMQUtils::EnsureQuorumConnections(params.type, pindexQuorum, curSession->myProTxHash, gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS));
549 WaitForNextPhase(QuorumPhase_Initialized, QuorumPhase_Contribute, curQuorumHash, []{return false;});
556 return ProcessPendingMessageBatch<CDKGContribution, MSG_QUORUM_CONTRIB>(*curSession, pendingContributions, 8);
558 HandlePhase(QuorumPhase_Contribute, QuorumPhase_Complain, curQuorumHash, 0.05, fContributeStart, fContributeWait);
565 return ProcessPendingMessageBatch<CDKGComplaint, MSG_QUORUM_COMPLAINT>(*curSession, pendingComplaints, 8);
567 HandlePhase(QuorumPhase_Complain, QuorumPhase_Justify, curQuorumHash, 0.05, fComplainStart, fComplainWait);
574 return ProcessPendingMessageBatch<CDKGJustification, MSG_QUORUM_JUSTIFICATION>(*curSession, pendingJustifications, 8);
576 HandlePhase(QuorumPhase_Justify, QuorumPhase_Commit, curQuorumHash, 0.05, fJustifyStart, fJustifyWait);
583 return ProcessPendingMessageBatch<CDKGPrematureCommitment, MSG_QUORUM_PREMATURE_COMMITMENT>(*curSession, pendingPrematureCommitments, 8);
585 HandlePhase(QuorumPhase_Commit, QuorumPhase_Finalize, curQuorumHash, 0.1, fCommitStart, fCommitWait);
597 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionHandler::%s -- %s - starting HandleDKGRound\n", __func__, params.name);
600 quorumDKGDebugManager->UpdateLocalSessionStatus(params.type, [&](CDKGDebugSessionStatus& status) {
604 LogPrint(BCLog::LLMQ_DKG, "CDKGSessionHandler::%s -- %s - aborted current DKG session\n", __func__, params.name);
Acts as a FIFO queue for incoming DKG messages.
Definition: quorums_dkgsessionhandler.h:36
CDKGPendingMessages pendingComplaints
Definition: quorums_dkgsessionhandler.h:117
void AddMinableCommitment(const CFinalCommitment &fqc)
Definition: quorums_blockprocessor.cpp:487
void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function< bool(CDKGDebugSessionStatus &status)> &&func)
Definition: quorums_debug.cpp:179
Definition: util.h:138
CDKGPendingMessages pendingContributions
Definition: quorums_dkgsessionhandler.h:116
Definition: protocol.h:419
bool ProcessPendingMessageBatch(CDKGSession &session, CDKGPendingMessages &pendingMessages, size_t maxCount)
Definition: quorums_dkgsessionhandler.cpp:433
static void AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &myProTxHash)
Definition: quorums_utils.cpp:207
void PushPendingMessage(NodeId from, CDataStream &vRecv)
Definition: quorums_dkgsessionhandler.cpp:27
std::set< uint256 > seenMessages
Definition: quorums_dkgsessionhandler.h:47
void ReceiveMessage(const uint256 &hash, const CDKGContribution &qc, bool &retBan)
Definition: quorums_dkgsession.cpp:261
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: quorums_dkgsessionhandler.cpp:129
std::function< void()> StartPhaseFunc
Definition: quorums_dkgsessionhandler.h:136
bool HasSeen(const uint256 &hash) const
Definition: quorums_dkgsessionhandler.cpp:72
CQuorumBlockProcessor * quorumBlockProcessor
Definition: quorums_blockprocessor.cpp:23
Definition: bls_worker.h:21
std::vector< std::pair< NodeId, std::shared_ptr< Message > > > PopAndDeserializeMessages(size_t maxCount)
Definition: quorums_dkgsessionhandler.h:67
void ResetLocalSessionStatus(Consensus::LLMQType llmqType)
Definition: quorums_debug.cpp:146
std::function< bool()> WhileWaitFunc
Definition: quorums_dkgsessionhandler.h:137
Definition: box.hpp:161
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: util.cpp:824
Definition: deterministicmns.h:26
std::set< NodeId > BatchVerifyMessageSigs(CDKGSession &session, const std::vector< std::pair< NodeId, std::shared_ptr< Message >>> &messages)
Definition: quorums_dkgsessionhandler.cpp:339
size_t maxMessagesPerNode
Definition: quorums_dkgsessionhandler.h:44
std::unique_ptr< CDeterministicMNManager > deterministicMNManager
Definition: deterministicmns.cpp:24
bool VerifyInsecureAggregated(const std::vector< CBLSPublicKey > &pubKeys, const std::vector< uint256 > &hashes) const
Definition: bls.cpp:348
void StartThread()
Definition: quorums_dkgsessionhandler.cpp:143
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
void Misbehaving(NodeId pnode, int howmuch, const std::string &message)
Increase a node's misbehavior score.
Definition: net_processing.cpp:1024
bool PreVerifyMessage(const uint256 &hash, const CDKGContribution &qc, bool &retBan) const
Definition: quorums_dkgsession.cpp:213
void WaitForNextPhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256 &expectedQuorumHash, const WhileWaitFunc &runWhileWaiting)
Definition: quorums_dkgsessionhandler.cpp:192
std::map< NodeId, size_t > messagesPerNode
Definition: quorums_dkgsessionhandler.h:46
Definition: quorums_debug.h:48
CDKGPendingMessages pendingJustifications
Definition: quorums_dkgsessionhandler.h:118
Definition: protocol.h:420
Definition: protocol.h:418
Definition: bls.h:286
Definition: params.h:50
void SleepBeforePhase(QuorumPhase curPhase, const uint256 &expectedQuorumHash, double randomSleepFactor, const WhileWaitFunc &runWhileWaiting)
Definition: quorums_dkgsessionhandler.cpp:254
void WaitForNewQuorum(const uint256 &oldQuorumHash)
Definition: quorums_dkgsessionhandler.cpp:234
bool InitNewQuorum(const CBlockIndex *pindexQuorum)
Definition: quorums_dkgsessionhandler.cpp:161
void PhaseHandlerThread()
Definition: quorums_dkgsessionhandler.cpp:593
void UpdatedBlockTip(const CBlockIndex *pindexNew)
Definition: quorums_dkgsessionhandler.cpp:107
Definition: params.h:65
std::list< BinaryMessage > pendingMessages
Definition: quorums_dkgsessionhandler.h:45
void HandleDKGRound()
Definition: quorums_dkgsessionhandler.cpp:509
The DKG session is a single instance of the DKG process.
Definition: quorums_dkgsession.h:239
std::shared_ptr< CDKGSession > curSession
Definition: quorums_dkgsessionhandler.h:113
CBLSWorker & blsWorker
Definition: quorums_dkgsessionhandler.h:106
std::thread phaseHandlerThread
Definition: quorums_dkgsessionhandler.h:114
void AggregateInsecure(const CBLSSignature &o)
Definition: bls.cpp:277
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:947
static void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &myProTxHash, bool allowWatch)
Definition: quorums_utils.cpp:171
void HandlePhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256 &expectedQuorumHash, double randomSleepFactor, const StartPhaseFunc &startPhaseFunc, const WhileWaitFunc &runWhileWaiting)
Definition: quorums_dkgsessionhandler.cpp:321
~CDKGSessionHandler()
Definition: quorums_dkgsessionhandler.cpp:103
std::list< BinaryMessage > PopPendingMessages(size_t maxCount)
Definition: quorums_dkgsessionhandler.cpp:59
std::atomic< bool > stopRequested
Definition: quorums_dkgsessionhandler.h:103
Definition: protocol.h:421
void EraseObjectRequest(CNodeState *nodestate, const CInv &inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: net_processing.cpp:676
CDKGSessionHandler(const Consensus::LLMQParams &_params, CBLSWorker &blsWorker, CDKGSessionManager &_dkgManager)
Definition: quorums_dkgsessionhandler.cpp:88
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:54
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:110
CDKGSessionManager & dkgManager
Definition: quorums_dkgsessionhandler.h:107
CDKGPendingMessages pendingPrematureCommitments
Definition: quorums_dkgsessionhandler.h:119
std::pair< QuorumPhase, uint256 > GetPhaseAndQuorumHash() const
Definition: quorums_dkgsessionhandler.cpp:183
const Consensus::LLMQParams & params
Definition: quorums_dkgsessionhandler.h:105
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType)
Definition: quorums_utils.cpp:47
Definition: serialize.h:162
static std::vector< CDeterministicMNCPtr > GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum)
Definition: quorums_utils.cpp:18
CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType)
Definition: quorums_dkgsessionhandler.cpp:21