dash/src/llmq/quorums_commitment.h
PastaPastaPasta 3f8a7b2068
Merge #12193: RPC: Consistently use UniValue.pushKV instead of push_back(Pair()) (karel-3d) (#3532)
* Begin Merge 12193 Squashed 'src/univalue/' changes from 07947ff2da..51d3ab34ba

51d3ab34ba Merge #10: Add pushKV(key, boolean) function (replaces #5)
129bad96d5 [tests] test pushKV for boolean values
b3c44c947f Pushing boolean value to univalue correctly

git-subtree-dir: src/univalue
git-subtree-split: 51d3ab34ba2857f0d03dc07250cb4a2b5e712e67

* scripted-diff: Use UniValue.pushKV instead of push_back(Pair()) (end #12193)

-BEGIN VERIFY SCRIPT-
git grep -l "push_back(Pair" | xargs sed -i "s/push_back(Pair(\(.*\)));/pushKV(\1);/g"
-END VERIFY SCRIPT-

Signed-off-by: pasta <pasta@dashboost.org>

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2020-06-18 12:17:23 +03:00

147 lines
4.1 KiB
C++

// Copyright (c) 2018-2019 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_COMMITMENT_H
#define DASH_QUORUMS_COMMITMENT_H
#include <llmq/quorums_utils.h>
#include <consensus/params.h>
#include <evo/deterministicmns.h>
#include <bls/bls.h>
#include <univalue.h>
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};
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE};
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:
CFinalCommitment() {}
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);
}
bool Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const;
bool VerifyNull() const;
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() ||
!quorumVvecHash.IsNull() ||
membersSig.IsValid() ||
quorumSig.IsValid()) {
return false;
}
return true;
}
void ToJson(UniValue& obj) const
{
obj.setObject();
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());
}
};
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);
}
void ToJson(UniValue& obj) const
{
obj.setObject();
obj.pushKV("version", (int)nVersion);
obj.pushKV("height", (int)nHeight);
UniValue qcObj;
commitment.ToJson(qcObj);
obj.pushKV("commitment", qcObj);
}
};
bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
} // namespace llmq
#endif //DASH_QUORUMS_COMMITMENT_H