2019-06-11 13:46:07 +02:00
|
|
|
// Copyright (c) 2018-2019 The Dash Core developers
|
2018-11-23 15:42:09 +01:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#ifndef BITCOIN_LLMQ_QUORUMS_COMMITMENT_H
|
|
|
|
#define BITCOIN_LLMQ_QUORUMS_COMMITMENT_H
|
2018-11-23 15:42:09 +01:00
|
|
|
|
Feature request #3425 - Add information to "protx diff" (#3468)
* llmq: Add more information to the result of CFinalCommitment::ToJson
Example output:
```
{
"version": 1,
"llmqType": 1,
"quorumHash":
"000002a20a35757fc467f0ebe8663f76e4c5df74411cc5f1735cfd92278071fe",
"signersCount": 49,
"signers": "03fbffffffffff",
"validMembersCount": 49,
"validMembers": "03fbffffffffff",
"quorumPublicKey":
"8db1108b50dd741076b577f6798f0bf382ca4d11dafd55ed14aaaf613f604aa55bf1da1f0469f75105376e440381ee23",
"quorumVvecHash":
"feedb15d5a7ca25a68d9c51036973d37925d8439d4769d7dd7bace7440089071",
"quorumSig":
"1879f6260ef427dc9542088b39e02a8e73e34c0484269cbc12108ab991d438f81e5be80a5b4b5595b6634113fdf060060c8fe190677627fb2d25f6e052c7f93598d36dd415f8f84c693c6a5943098616a1e135522852d8f572bb6e1470df4a94",
"membersSig":
"8ef7d881fcc1e8111dd82c556ab62dad56ea5ecb47a9ac067eb2057d92d27e39530630a7f77d19adc857d33eb485a1b601b2d78ac4c73742f2036089bfb1f25441f1dfcd3cfd1eed6e7d664c0e97bf75b7d7097ebd647791fbcef070fe3e3e91"
}
```
* llmq: Changed the byte order in ToHexStr(const std::vector<bool>& vBits)
2020-05-11 14:35:28 +02:00
|
|
|
#include <llmq/quorums_utils.h>
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <consensus/params.h>
|
2018-11-23 15:42:09 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <evo/deterministicmns.h>
|
2018-11-23 15:42:09 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <bls/bls.h>
|
2018-11-23 15:42:09 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <univalue.h>
|
2019-06-11 13:42:17 +02:00
|
|
|
|
2018-11-23 15:42:09 +01:00
|
|
|
namespace llmq
|
|
|
|
{
|
|
|
|
|
|
|
|
// This message is an aggregation of all received premature commitments and only valid if
|
|
|
|
// enough (>=threshold) premature commitments were aggregated
|
|
|
|
// This is mined on-chain as part of TRANSACTION_QUORUM_COMMITMENT
|
|
|
|
class CFinalCommitment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const uint16_t CURRENT_VERSION = 1;
|
|
|
|
|
|
|
|
public:
|
|
|
|
uint16_t nVersion{CURRENT_VERSION};
|
2019-05-28 15:34:41 +02:00
|
|
|
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE};
|
2018-11-23 15:42:09 +01:00
|
|
|
uint256 quorumHash;
|
|
|
|
std::vector<bool> signers;
|
|
|
|
std::vector<bool> validMembers;
|
|
|
|
|
|
|
|
CBLSPublicKey quorumPublicKey;
|
|
|
|
uint256 quorumVvecHash;
|
|
|
|
|
|
|
|
CBLSSignature quorumSig; // recovered threshold sig of blockHash+validMembers+pubKeyHash+vvecHash
|
|
|
|
CBLSSignature membersSig; // aggregated member sig of blockHash+validMembers+pubKeyHash+vvecHash
|
|
|
|
|
|
|
|
public:
|
2020-08-09 23:35:02 +02:00
|
|
|
CFinalCommitment() = default;
|
2018-11-23 15:42:09 +01:00
|
|
|
CFinalCommitment(const Consensus::LLMQParams& params, const uint256& _quorumHash);
|
|
|
|
|
|
|
|
int CountSigners() const
|
|
|
|
{
|
|
|
|
return (int)std::count(signers.begin(), signers.end(), true);
|
|
|
|
}
|
|
|
|
int CountValidMembers() const
|
|
|
|
{
|
|
|
|
return (int)std::count(validMembers.begin(), validMembers.end(), true);
|
|
|
|
}
|
|
|
|
|
2018-11-27 08:04:08 +01:00
|
|
|
bool Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const;
|
|
|
|
bool VerifyNull() const;
|
2018-11-23 15:42:09 +01:00
|
|
|
bool VerifySizes(const Consensus::LLMQParams& params) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ADD_SERIALIZE_METHODS
|
|
|
|
|
|
|
|
template<typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
|
|
|
{
|
|
|
|
READWRITE(nVersion);
|
|
|
|
READWRITE(llmqType);
|
|
|
|
READWRITE(quorumHash);
|
|
|
|
READWRITE(DYNBITSET(signers));
|
|
|
|
READWRITE(DYNBITSET(validMembers));
|
|
|
|
READWRITE(quorumPublicKey);
|
|
|
|
READWRITE(quorumVvecHash);
|
|
|
|
READWRITE(quorumSig);
|
|
|
|
READWRITE(membersSig);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool IsNull() const
|
|
|
|
{
|
|
|
|
if (std::count(signers.begin(), signers.end(), true) ||
|
|
|
|
std::count(validMembers.begin(), validMembers.end(), true)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (quorumPublicKey.IsValid() ||
|
2018-11-27 08:04:08 +01:00
|
|
|
!quorumVvecHash.IsNull() ||
|
2018-11-23 15:42:09 +01:00
|
|
|
membersSig.IsValid() ||
|
|
|
|
quorumSig.IsValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-11 13:42:17 +02:00
|
|
|
|
|
|
|
void ToJson(UniValue& obj) const
|
|
|
|
{
|
|
|
|
obj.setObject();
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV("version", (int)nVersion);
|
|
|
|
obj.pushKV("llmqType", (int)llmqType);
|
|
|
|
obj.pushKV("quorumHash", quorumHash.ToString());
|
|
|
|
obj.pushKV("signersCount", CountSigners());
|
|
|
|
obj.pushKV("signers", CLLMQUtils::ToHexStr(signers));
|
|
|
|
obj.pushKV("validMembersCount", CountValidMembers());
|
|
|
|
obj.pushKV("validMembers", CLLMQUtils::ToHexStr(validMembers));
|
|
|
|
obj.pushKV("quorumPublicKey", quorumPublicKey.ToString());
|
|
|
|
obj.pushKV("quorumVvecHash", quorumVvecHash.ToString());
|
|
|
|
obj.pushKV("quorumSig", quorumSig.ToString());
|
|
|
|
obj.pushKV("membersSig", membersSig.ToString());
|
2019-06-11 13:42:17 +02:00
|
|
|
}
|
2018-11-23 15:42:09 +01:00
|
|
|
};
|
|
|
|
|
2018-11-27 08:04:08 +01:00
|
|
|
class CFinalCommitmentTxPayload
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const uint16_t CURRENT_VERSION = 1;
|
|
|
|
|
|
|
|
public:
|
|
|
|
uint16_t nVersion{CURRENT_VERSION};
|
|
|
|
uint32_t nHeight{(uint32_t)-1};
|
|
|
|
CFinalCommitment commitment;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ADD_SERIALIZE_METHODS
|
|
|
|
|
|
|
|
template<typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
|
|
|
{
|
|
|
|
READWRITE(nVersion);
|
|
|
|
READWRITE(nHeight);
|
|
|
|
READWRITE(commitment);
|
|
|
|
}
|
2018-11-29 19:51:04 +01:00
|
|
|
|
2019-06-11 13:42:17 +02:00
|
|
|
void ToJson(UniValue& obj) const
|
|
|
|
{
|
|
|
|
obj.setObject();
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV("version", (int)nVersion);
|
|
|
|
obj.pushKV("height", (int)nHeight);
|
2019-06-11 13:42:17 +02:00
|
|
|
|
|
|
|
UniValue qcObj;
|
|
|
|
commitment.ToJson(qcObj);
|
2020-06-18 11:17:23 +02:00
|
|
|
obj.pushKV("commitment", qcObj);
|
2019-06-11 13:42:17 +02:00
|
|
|
}
|
2018-11-27 08:04:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
|
|
|
|
|
2019-07-15 20:55:01 +02:00
|
|
|
} // namespace llmq
|
2018-11-23 15:42:09 +01:00
|
|
|
|
2018-04-02 00:30:17 +02:00
|
|
|
#endif // BITCOIN_LLMQ_QUORUMS_COMMITMENT_H
|