Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

quorums_commitment.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 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_COMMITMENT_H
6 #define DASH_QUORUMS_COMMITMENT_H
7 
8 #include <llmq/quorums_utils.h>
9 
10 #include <consensus/params.h>
11 
12 #include <evo/deterministicmns.h>
13 
14 #include <bls/bls.h>
15 
16 #include <univalue.h>
17 
18 namespace llmq
19 {
20 
21 // This message is an aggregation of all received premature commitments and only valid if
22 // enough (>=threshold) premature commitments were aggregated
23 // This is mined on-chain as part of TRANSACTION_QUORUM_COMMITMENT
25 {
26 public:
27  static const uint16_t CURRENT_VERSION = 1;
28 
29 public:
33  std::vector<bool> signers;
34  std::vector<bool> validMembers;
35 
38 
39  CBLSSignature quorumSig; // recovered threshold sig of blockHash+validMembers+pubKeyHash+vvecHash
40  CBLSSignature membersSig; // aggregated member sig of blockHash+validMembers+pubKeyHash+vvecHash
41 
42 public:
44  CFinalCommitment(const Consensus::LLMQParams& params, const uint256& _quorumHash);
45 
46  int CountSigners() const
47  {
48  return (int)std::count(signers.begin(), signers.end(), true);
49  }
50  int CountValidMembers() const
51  {
52  return (int)std::count(validMembers.begin(), validMembers.end(), true);
53  }
54 
55  bool Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const;
56  bool VerifyNull() const;
57  bool VerifySizes(const Consensus::LLMQParams& params) const;
58 
59 public:
61 
62  template<typename Stream, typename Operation>
63  inline void SerializationOp(Stream& s, Operation ser_action)
64  {
74  }
75 
76 public:
77  bool IsNull() const
78  {
79  if (std::count(signers.begin(), signers.end(), true) ||
80  std::count(validMembers.begin(), validMembers.end(), true)) {
81  return false;
82  }
83  if (quorumPublicKey.IsValid() ||
85  membersSig.IsValid() ||
86  quorumSig.IsValid()) {
87  return false;
88  }
89  return true;
90  }
91 
92  void ToJson(UniValue& obj) const
93  {
94  obj.setObject();
95  obj.push_back(Pair("version", (int)nVersion));
96  obj.push_back(Pair("llmqType", (int)llmqType));
97  obj.push_back(Pair("quorumHash", quorumHash.ToString()));
98  obj.push_back(Pair("signersCount", CountSigners()));
99  obj.push_back(Pair("signers", CLLMQUtils::ToHexStr(signers)));
100  obj.push_back(Pair("validMembersCount", CountValidMembers()));
101  obj.push_back(Pair("validMembers", CLLMQUtils::ToHexStr(validMembers)));
102  obj.push_back(Pair("quorumPublicKey", quorumPublicKey.ToString()));
103  obj.push_back(Pair("quorumVvecHash", quorumVvecHash.ToString()));
104  obj.push_back(Pair("quorumSig", quorumSig.ToString()));
105  obj.push_back(Pair("membersSig", membersSig.ToString()));
106  }
107 };
108 
110 {
111 public:
112  static const uint16_t CURRENT_VERSION = 1;
113 
114 public:
116  uint32_t nHeight{(uint32_t)-1};
118 
119 public:
121 
122  template<typename Stream, typename Operation>
123  inline void SerializationOp(Stream& s, Operation ser_action)
124  {
128  }
129 
130  void ToJson(UniValue& obj) const
131  {
132  obj.setObject();
133  obj.push_back(Pair("version", (int)nVersion));
134  obj.push_back(Pair("height", (int)nHeight));
135 
136  UniValue qcObj;
137  commitment.ToJson(qcObj);
138  obj.push_back(Pair("commitment", qcObj));
139  }
140 };
141 
142 bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
143 
144 } // namespace llmq
145 
146 #endif //DASH_QUORUMS_COMMITMENT_H
#define READWRITE(obj)
Definition: serialize.h:165
Consensus::LLMQType llmqType
bool VerifySizes(const Consensus::LLMQParams &params) const
bool CheckLLMQCommitment(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state)
ADD_SERIALIZE_METHODS void SerializationOp(Stream &s, Operation ser_action)
bool IsNull() const
Definition: uint256.h:33
static const uint16_t CURRENT_VERSION
static const uint16_t CURRENT_VERSION
LLMQType
Definition: params.h:48
bool push_back(const UniValue &val)
Definition: univalue.cpp:110
std::string ToString() const
Definition: bls.h:210
#define ADD_SERIALIZE_METHODS
Implement three methods for serializable objects.
Definition: serialize.h:174
static std::string ToHexStr(const std::vector< bool > &vBits)
Definition: quorums_utils.h:74
std::string ToString() const
Definition: uint256.cpp:62
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
#define DYNBITSET(obj)
Definition: serialize.h:372
std::vector< bool > signers
Capture information about block/transaction validation.
Definition: validation.h:22
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
bool setObject()
Definition: univalue.cpp:103
static int count
Definition: tests.c:45
bool Verify(const std::vector< CDeterministicMNCPtr > &members, bool checkSigs) const
void ToJson(UniValue &obj) const
ADD_SERIALIZE_METHODS void SerializationOp(Stream &s, Operation ser_action)
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
void ToJson(UniValue &obj) const
std::vector< bool > validMembers
bool IsValid() const
Definition: bls.h:94
Released under the MIT license