22b5952c5a
* Add LLMQ parameters to consensus params * Add DIP6 quorum commitment special TX * Implement CQuorumBlockProcessor which validates and handles commitments * Add quorum commitments to new blocks * Propagate QFCOMMITMENT messages to all nodes * Allow special transactions in blocks which have no inputs/outputs But only for TRANSACTION_QUORUM_COMMITMENT for now. * Add quorum commitments to self-crafted blocks in DIP3 tests * Add simple fork logic for current testnet This should avoid a fork on the current testnet. It only applies to the current chain which activated DIP3 at height 264000 and block 00000048e6e71d4bd90e7c456dcb94683ae832fcad13e1760d8283f7e89f332f. When we revert the chain to retest the DIP3 deployment, this fork logic can be removed again. * Use quorumVvecHash instead of quorumHash to make null commitments unique Implementation of https://github.com/dashpay/dips/pull/31 * Re-add quorum commitments after pruning mempool selected blocks * Refactor CQuorumBlockProcessor::ProcessBlock to have less nested if/else statements Also add BEGIN/END markers for temporary code. * Add comments/documentation to LLMQParams * Move code which determines if a commitment is required into IsCommitmentRequired This should make the code easier to read and also removes some duplication. The also changes the error types that are possible from 3 to 2 now. Instead of having "bad-qc-already-mined" and "bad-qc-not-mining-phase", there is only "bad-qc-not-allowed" now. * Use new parameter from consensus parames for the temporary fork
147 lines
4.5 KiB
C++
147 lines
4.5 KiB
C++
// Copyright (c) 2018 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.
|
|
|
|
#include "quorums_commitment.h"
|
|
#include "quorums_utils.h"
|
|
|
|
#include "chainparams.h"
|
|
|
|
#include <univalue.h>
|
|
|
|
namespace llmq
|
|
{
|
|
|
|
CFinalCommitment::CFinalCommitment(const Consensus::LLMQParams& params, const uint256& _quorumHash) :
|
|
llmqType(params.type),
|
|
quorumHash(_quorumHash),
|
|
signers(params.size),
|
|
validMembers(params.size)
|
|
{
|
|
}
|
|
|
|
#define LogPrintfFinalCommitment(...) do { \
|
|
LogPrintStr(strprintf("CFinalCommitment::%s -- %s", __func__, tinyformat::format(__VA_ARGS__))); \
|
|
} while(0)
|
|
|
|
bool CFinalCommitment::Verify(const std::vector<CDeterministicMNCPtr>& members) const
|
|
{
|
|
if (nVersion == 0 || nVersion > CURRENT_VERSION) {
|
|
return false;
|
|
}
|
|
|
|
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)llmqType)) {
|
|
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType);
|
|
return false;
|
|
}
|
|
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)llmqType);
|
|
|
|
if (!VerifySizes(params)) {
|
|
return false;
|
|
}
|
|
|
|
if (CountValidMembers() < params.minSize) {
|
|
LogPrintfFinalCommitment("invalid validMembers count. validMembersCount=%d\n", CountValidMembers());
|
|
return false;
|
|
}
|
|
if (CountSigners() < params.minSize) {
|
|
LogPrintfFinalCommitment("invalid signers count. signersCount=%d\n", CountSigners());
|
|
return false;
|
|
}
|
|
if (!quorumPublicKey.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid quorumPublicKey\n");
|
|
return false;
|
|
}
|
|
if (quorumVvecHash.IsNull()) {
|
|
LogPrintfFinalCommitment("invalid quorumVvecHash\n");
|
|
return false;
|
|
}
|
|
if (!membersSig.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid membersSig\n");
|
|
return false;
|
|
}
|
|
if (!quorumSig.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid vvecSig\n");
|
|
return false;
|
|
}
|
|
|
|
for (size_t i = members.size(); i < params.size; i++) {
|
|
if (validMembers[i]) {
|
|
LogPrintfFinalCommitment("invalid validMembers bitset. bit %d should not be set\n", i);
|
|
return false;
|
|
}
|
|
if (signers[i]) {
|
|
LogPrintfFinalCommitment("invalid signers bitset. bit %d should not be set\n", i);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash((uint8_t)params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
|
|
|
|
std::vector<CBLSPublicKey> memberPubKeys;
|
|
for (size_t i = 0; i < members.size(); i++) {
|
|
if (!signers[i]) {
|
|
continue;
|
|
}
|
|
memberPubKeys.emplace_back(members[i]->pdmnState->pubKeyOperator);
|
|
}
|
|
|
|
if (!membersSig.VerifySecureAggregated(memberPubKeys, commitmentHash)) {
|
|
LogPrintfFinalCommitment("invalid aggregated members signature\n");
|
|
return false;
|
|
}
|
|
|
|
if (!quorumSig.VerifyInsecure(quorumPublicKey, commitmentHash)) {
|
|
LogPrintfFinalCommitment("invalid quorum signature\n");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CFinalCommitment::VerifyNull(int nHeight) const
|
|
{
|
|
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)llmqType)) {
|
|
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType);
|
|
return false;
|
|
}
|
|
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)llmqType);
|
|
|
|
if (!IsNull() || !VerifySizes(params)) {
|
|
return false;
|
|
}
|
|
|
|
uint256 expectedQuorumVvecHash = ::SerializeHash(std::make_pair(quorumHash, nHeight));
|
|
if (quorumVvecHash != expectedQuorumVvecHash) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CFinalCommitment::VerifySizes(const Consensus::LLMQParams& params) const
|
|
{
|
|
if (signers.size() != params.size) {
|
|
LogPrintfFinalCommitment("invalid signers.size=%d\n", signers.size());
|
|
return false;
|
|
}
|
|
if (validMembers.size() != params.size) {
|
|
LogPrintfFinalCommitment("invalid signers.size=%d\n", signers.size());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void CFinalCommitment::ToJson(UniValue& obj) const
|
|
{
|
|
obj.setObject();
|
|
obj.push_back(Pair("version", (int)nVersion));
|
|
obj.push_back(Pair("llmqType", (int)llmqType));
|
|
obj.push_back(Pair("quorumHash", quorumHash.ToString()));
|
|
obj.push_back(Pair("signersCount", CountSigners()));
|
|
obj.push_back(Pair("validMembersCount", CountValidMembers()));
|
|
obj.push_back(Pair("quorumPublicKey", quorumPublicKey.ToString()));
|
|
}
|
|
|
|
}
|