Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

quorums_utils.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Dash Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef DASH_QUORUMS_UTILS_H
6 #define DASH_QUORUMS_UTILS_H
7 
8 #include <consensus/params.h>
9 #include <net.h>
10 
11 #include <evo/deterministicmns.h>
12 
13 #include <vector>
14 
15 namespace llmq
16 {
17 
19 {
20 public:
21  // includes members which failed DKG
22  static std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum);
23 
24  static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
25  static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
26 
27  // works for sig shares and recovered sigs
28  template<typename T>
29  static uint256 BuildSignHash(const T& s)
30  {
31  return BuildSignHash((Consensus::LLMQType)s.llmqType, s.quorumHash, s.id, s.msgHash);
32  }
33 
35  static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
36  static std::set<uint256> GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound);
37  static std::set<uint256> GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound);
38  static std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, size_t memberCount, size_t connectionCount);
39 
40  static void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& myProTxHash, bool allowWatch);
41  static void AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& myProTxHash);
42 
43  static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash);
44 
45  template<typename NodesContainer, typename Continue, typename Callback>
46  static void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&& callback, FastRandomContext& rnd)
47  {
48  std::vector<typename NodesContainer::iterator> rndNodes;
49  rndNodes.reserve(nodeStates.size());
50  for (auto it = nodeStates.begin(); it != nodeStates.end(); ++it) {
51  rndNodes.emplace_back(it);
52  }
53  if (rndNodes.empty()) {
54  return;
55  }
56  std::random_shuffle(rndNodes.begin(), rndNodes.end(), rnd);
57 
58  size_t idx = 0;
59  while (!rndNodes.empty() && cont()) {
60  auto nodeId = rndNodes[idx]->first;
61  auto& ns = rndNodes[idx]->second;
62 
63  if (callback(nodeId, ns)) {
64  idx = (idx + 1) % rndNodes.size();
65  } else {
66  rndNodes.erase(rndNodes.begin() + idx);
67  if (rndNodes.empty()) {
68  break;
69  }
70  idx %= rndNodes.size();
71  }
72  }
73  }
74  static std::string ToHexStr(const std::vector<bool>& vBits)
75  {
76  std::vector<uint8_t> vBytes((vBits.size() + 7) / 8);
77  for (size_t i = 0; i < vBits.size(); i++) {
78  vBytes[i / 8] |= vBits[i] << (i % 8);
79  }
80  return HexStr(vBytes);
81  }
82 };
83 
84 } // namespace llmq
85 
86 #endif//DASH_QUORUMS_UTILS_H
static std::set< uint256 > GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &forMember, bool onlyOutbound)
static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256 &quorumHash, const uint256 &id, const uint256 &msgHash)
static void AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &myProTxHash)
static uint256 BuildSignHash(const T &s)
Definition: quorums_utils.h:29
static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256 &quorumHash)
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
LLMQType
Definition: params.h:48
static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256 &blockHash, const std::vector< bool > &validMembers, const CBLSPublicKey &pubKey, const uint256 &vvecHash)
Fast randomness source.
Definition: random.h:48
static std::string ToHexStr(const std::vector< bool > &vBits)
Definition: quorums_utils.h:74
static void IterateNodesRandom(NodesContainer &nodeStates, Continue &&cont, Callback &&callback, FastRandomContext &rnd)
Definition: quorums_utils.h:46
256-bit opaque blob.
Definition: uint256.h:123
static uint256 DeterministicOutboundConnection(const uint256 &proTxHash1, const uint256 &proTxHash2)
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
static void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &myProTxHash, bool allowWatch)
static std::set< size_t > CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, size_t memberCount, size_t connectionCount)
static std::set< uint256 > GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &forMember, bool onlyOutbound)
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType)
static std::vector< CDeterministicMNCPtr > GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum)
Released under the MIT license