Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

quorums_dkgsessionhandler.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2020 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef DASH_QUORUMS_DKGSESSIONHANDLER_H
6 #define DASH_QUORUMS_DKGSESSIONHANDLER_H
7 
9 
10 #include <validation.h>
11 
12 #include <ctpl.h>
13 
14 namespace llmq
15 {
16 
26 };
27 
37 {
38 public:
39  typedef std::pair<NodeId, std::shared_ptr<CDataStream>> BinaryMessage;
40 
41 private:
43  int invType;
45  std::list<BinaryMessage> pendingMessages;
46  std::map<NodeId, size_t> messagesPerNode;
47  std::set<uint256> seenMessages;
48 
49 public:
50  explicit CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType);
51 
52  void PushPendingMessage(NodeId from, CDataStream& vRecv);
53  std::list<BinaryMessage> PopPendingMessages(size_t maxCount);
54  bool HasSeen(const uint256& hash) const;
55  void Clear();
56 
57  template<typename Message>
58  void PushPendingMessage(NodeId from, Message& msg)
59  {
61  ds << msg;
62  PushPendingMessage(from, ds);
63  }
64 
65  // Might return nullptr messages, which indicates that deserialization failed for some reason
66  template<typename Message>
67  std::vector<std::pair<NodeId, std::shared_ptr<Message>>> PopAndDeserializeMessages(size_t maxCount)
68  {
69  auto binaryMessages = PopPendingMessages(maxCount);
70  if (binaryMessages.empty()) {
71  return {};
72  }
73 
74  std::vector<std::pair<NodeId, std::shared_ptr<Message>>> ret;
75  ret.reserve(binaryMessages.size());
76  for (const auto& bm : binaryMessages) {
77  auto msg = std::make_shared<Message>();
78  try {
79  *bm.second >> *msg;
80  } catch (...) {
81  msg = nullptr;
82  }
83  ret.emplace_back(std::make_pair(bm.first, std::move(msg)));
84  }
85 
86  return std::move(ret);
87  }
88 };
89 
97 {
98 private:
99  friend class CDKGSessionManager;
100 
101 private:
103  std::atomic<bool> stopRequested{false};
104 
108 
110  int currentHeight{-1};
111  int quorumHeight{-1};
113  std::shared_ptr<CDKGSession> curSession;
114  std::thread phaseHandlerThread;
115 
120 
121 public:
124 
125  void UpdatedBlockTip(const CBlockIndex *pindexNew);
126  void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman);
127 
128  void StartThread();
129  void StopThread();
130 
131 private:
132  bool InitNewQuorum(const CBlockIndex* pindexQuorum);
133 
134  std::pair<QuorumPhase, uint256> GetPhaseAndQuorumHash() const;
135 
136  typedef std::function<void()> StartPhaseFunc;
137  typedef std::function<bool()> WhileWaitFunc;
138  void WaitForNextPhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256& expectedQuorumHash, const WhileWaitFunc& runWhileWaiting);
139  void WaitForNewQuorum(const uint256& oldQuorumHash);
140  void SleepBeforePhase(QuorumPhase curPhase, const uint256& expectedQuorumHash, double randomSleepFactor, const WhileWaitFunc& runWhileWaiting);
141  void HandlePhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256& expectedQuorumHash, double randomSleepFactor, const StartPhaseFunc& startPhaseFunc, const WhileWaitFunc& runWhileWaiting);
142  void HandleDKGRound();
143  void PhaseHandlerThread();
144 };
145 
146 } // namespace llmq
147 
148 #endif //DASH_QUORUMS_DKGSESSIONHANDLER_H
Acts as a FIFO queue for incoming DKG messages.
CDKGPendingMessages pendingContributions
void PushPendingMessage(NodeId from, CDataStream &vRecv)
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
void PushPendingMessage(NodeId from, Message &msg)
std::function< void()> StartPhaseFunc
bool HasSeen(const uint256 &hash) const
std::vector< std::pair< NodeId, std::shared_ptr< Message > > > PopAndDeserializeMessages(size_t maxCount)
std::function< bool()> WhileWaitFunc
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
void WaitForNextPhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256 &expectedQuorumHash, const WhileWaitFunc &runWhileWaiting)
std::map< NodeId, size_t > messagesPerNode
CDKGPendingMessages pendingJustifications
void SleepBeforePhase(QuorumPhase curPhase, const uint256 &expectedQuorumHash, double randomSleepFactor, const WhileWaitFunc &runWhileWaiting)
std::pair< NodeId, std::shared_ptr< CDataStream > > BinaryMessage
void WaitForNewQuorum(const uint256 &oldQuorumHash)
bool InitNewQuorum(const CBlockIndex *pindexQuorum)
int64_t NodeId
Definition: net.h:109
Definition: net.h:136
void UpdatedBlockTip(const CBlockIndex *pindexNew)
std::list< BinaryMessage > pendingMessages
std::shared_ptr< CDKGSession > curSession
256-bit opaque blob.
Definition: uint256.h:123
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
void HandlePhase(QuorumPhase curPhase, QuorumPhase nextPhase, const uint256 &expectedQuorumHash, double randomSleepFactor, const StartPhaseFunc &startPhaseFunc, const WhileWaitFunc &runWhileWaiting)
std::list< BinaryMessage > PopPendingMessages(size_t maxCount)
CDKGSessionHandler(const Consensus::LLMQParams &_params, CBLSWorker &blsWorker, CDKGSessionManager &_dkgManager)
Information about a peer.
Definition: net.h:800
Handles multiple sequential sessions of one specific LLMQ type.
CDKGPendingMessages pendingPrematureCommitments
std::pair< QuorumPhase, uint256 > GetPhaseAndQuorumHash() const
const Consensus::LLMQParams & params
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType)
Released under the MIT license