refactor: more LLMQ params related refactoring (#4517)

* refactor: Turn LLMQType into `enum class`

* refactor: Simplify/make LLMQ additions safer

* refactor: Move `is_serializable_enum<Consensus::LLMQType>` to `src/llmq/params.h`

* refactor: Add missing include

* refactor: Add missing comment

* Use `static_cast`

* make available_llmqs constexpr array

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

* cleanup/fixes

Co-authored-by: pasta <pasta@dashboost.org>
This commit is contained in:
UdjinM6 2021-10-15 13:28:19 +03:00 committed by GitHub
parent 38dee8b361
commit ea8d4c26b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 159 additions and 139 deletions

View File

@ -108,6 +108,19 @@ static CBlock FindDevNetGenesisBlock(const CBlock &prevBlock, const CAmount& rew
assert(false); assert(false);
} }
void CChainParams::AddLLMQ(Consensus::LLMQType llmqType)
{
assert(consensus.llmqs.count(llmqType) == 0);
for (const auto& llmq_param : Consensus::available_llmqs) {
if (llmq_param.type == llmqType) {
consensus.llmqs[llmqType] = llmq_param;
return;
}
}
error("CChainParams::%s: unknown LLMQ type %d", __func__, static_cast<uint8_t>(llmqType));
assert(false);
}
/** /**
* Main network * Main network
*/ */
@ -253,13 +266,13 @@ public:
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main)); vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
// long living quorum params // long living quorum params
consensus.llmqs[Consensus::LLMQ_50_60] = Consensus::llmq50_60; AddLLMQ(Consensus::LLMQType::LLMQ_50_60);
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq400_60; AddLLMQ(Consensus::LLMQType::LLMQ_400_60);
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq400_85; AddLLMQ(Consensus::LLMQType::LLMQ_400_85);
consensus.llmqs[Consensus::LLMQ_100_67] = Consensus::llmq100_67; AddLLMQ(Consensus::LLMQType::LLMQ_100_67);
consensus.llmqTypeChainLocks = Consensus::LLMQ_400_60; consensus.llmqTypeChainLocks = Consensus::LLMQType::LLMQ_400_60;
consensus.llmqTypeInstantSend = Consensus::LLMQ_50_60; consensus.llmqTypeInstantSend = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypePlatform = Consensus::LLMQ_100_67; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
fDefaultConsistencyChecks = false; fDefaultConsistencyChecks = false;
fRequireStandard = true; fRequireStandard = true;
@ -455,13 +468,13 @@ public:
nExtCoinType = 1; nExtCoinType = 1;
// long living quorum params // long living quorum params
consensus.llmqs[Consensus::LLMQ_50_60] = Consensus::llmq50_60; AddLLMQ(Consensus::LLMQType::LLMQ_50_60);
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq400_60; AddLLMQ(Consensus::LLMQType::LLMQ_400_60);
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq400_85; AddLLMQ(Consensus::LLMQType::LLMQ_400_85);
consensus.llmqs[Consensus::LLMQ_100_67] = Consensus::llmq100_67; AddLLMQ(Consensus::LLMQType::LLMQ_100_67);
consensus.llmqTypeChainLocks = Consensus::LLMQ_50_60; consensus.llmqTypeChainLocks = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypeInstantSend = Consensus::LLMQ_50_60; consensus.llmqTypeInstantSend = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypePlatform = Consensus::LLMQ_100_67; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
fDefaultConsistencyChecks = false; fDefaultConsistencyChecks = false;
fRequireStandard = false; fRequireStandard = false;
@ -638,14 +651,14 @@ public:
nExtCoinType = 1; nExtCoinType = 1;
// long living quorum params // long living quorum params
consensus.llmqs[Consensus::LLMQ_DEVNET] = Consensus::llmq_devnet; AddLLMQ(Consensus::LLMQType::LLMQ_DEVNET);
consensus.llmqs[Consensus::LLMQ_50_60] = Consensus::llmq50_60; AddLLMQ(Consensus::LLMQType::LLMQ_50_60);
consensus.llmqs[Consensus::LLMQ_400_60] = Consensus::llmq400_60; AddLLMQ(Consensus::LLMQType::LLMQ_400_60);
consensus.llmqs[Consensus::LLMQ_400_85] = Consensus::llmq400_85; AddLLMQ(Consensus::LLMQType::LLMQ_400_85);
consensus.llmqs[Consensus::LLMQ_100_67] = Consensus::llmq100_67; AddLLMQ(Consensus::LLMQType::LLMQ_100_67);
consensus.llmqTypeChainLocks = Consensus::LLMQ_50_60; consensus.llmqTypeChainLocks = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypeInstantSend = Consensus::LLMQ_50_60; consensus.llmqTypeInstantSend = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypePlatform = Consensus::LLMQ_100_67; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67;
UpdateDevnetLLMQChainLocksFromArgs(args); UpdateDevnetLLMQChainLocksFromArgs(args);
UpdateDevnetLLMQInstantSendFromArgs(args); UpdateDevnetLLMQInstantSendFromArgs(args);
@ -716,7 +729,7 @@ public:
*/ */
void UpdateLLMQDevnetParameters(int size, int threshold) void UpdateLLMQDevnetParameters(int size, int threshold)
{ {
auto& params = consensus.llmqs.at(Consensus::LLMQ_DEVNET); auto& params = consensus.llmqs.at(Consensus::LLMQType::LLMQ_DEVNET);
params.size = size; params.size = size;
params.minSize = threshold; params.minSize = threshold;
params.threshold = threshold; params.threshold = threshold;
@ -871,11 +884,11 @@ public:
nExtCoinType = 1; nExtCoinType = 1;
// long living quorum params // long living quorum params
consensus.llmqs[Consensus::LLMQ_TEST] = Consensus::llmq_test; AddLLMQ(Consensus::LLMQType::LLMQ_TEST);
consensus.llmqs[Consensus::LLMQ_TEST_V17] = Consensus::llmq_test_v17; AddLLMQ(Consensus::LLMQType::LLMQ_TEST_V17);
consensus.llmqTypeChainLocks = Consensus::LLMQ_TEST; consensus.llmqTypeChainLocks = Consensus::LLMQType::LLMQ_TEST;
consensus.llmqTypeInstantSend = Consensus::LLMQ_TEST; consensus.llmqTypeInstantSend = Consensus::LLMQType::LLMQ_TEST;
consensus.llmqTypePlatform = Consensus::LLMQ_TEST; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_TEST;
UpdateLLMQTestParametersFromArgs(args); UpdateLLMQTestParametersFromArgs(args);
} }
@ -937,7 +950,7 @@ public:
*/ */
void UpdateLLMQTestParameters(int size, int threshold) void UpdateLLMQTestParameters(int size, int threshold)
{ {
auto& params = consensus.llmqs.at(Consensus::LLMQ_TEST); auto& params = consensus.llmqs.at(Consensus::LLMQType::LLMQ_TEST);
params.size = size; params.size = size;
params.minSize = threshold; params.minSize = threshold;
params.threshold = threshold; params.threshold = threshold;
@ -1098,16 +1111,16 @@ void CDevNetParams::UpdateDevnetLLMQChainLocksFromArgs(const ArgsManager& args)
if (!args.IsArgSet("-llmqchainlocks")) return; if (!args.IsArgSet("-llmqchainlocks")) return;
std::string strLLMQType = gArgs.GetArg("-llmqchainlocks", std::string(consensus.llmqs.at(consensus.llmqTypeChainLocks).name)); std::string strLLMQType = gArgs.GetArg("-llmqchainlocks", std::string(consensus.llmqs.at(consensus.llmqTypeChainLocks).name));
Consensus::LLMQType llmqType = Consensus::LLMQ_NONE; Consensus::LLMQType llmqType = Consensus::LLMQType::LLMQ_NONE;
for (const auto& p : consensus.llmqs) { for (const auto& p : consensus.llmqs) {
if (p.second.name == strLLMQType) { if (p.second.name == strLLMQType) {
llmqType = p.first; llmqType = p.first;
} }
} }
if (llmqType == Consensus::LLMQ_NONE) { if (llmqType == Consensus::LLMQType::LLMQ_NONE) {
throw std::runtime_error("Invalid LLMQ type specified for -llmqchainlocks."); throw std::runtime_error("Invalid LLMQ type specified for -llmqchainlocks.");
} }
LogPrintf("Setting llmqchainlocks to size=%ld\n", llmqType); LogPrintf("Setting llmqchainlocks to size=%ld\n", static_cast<uint8_t>(llmqType));
UpdateDevnetLLMQChainLocks(llmqType); UpdateDevnetLLMQChainLocks(llmqType);
} }
@ -1116,16 +1129,16 @@ void CDevNetParams::UpdateDevnetLLMQInstantSendFromArgs(const ArgsManager& args)
if (!args.IsArgSet("-llmqinstantsend")) return; if (!args.IsArgSet("-llmqinstantsend")) return;
std::string strLLMQType = gArgs.GetArg("-llmqinstantsend", std::string(consensus.llmqs.at(consensus.llmqTypeInstantSend).name)); std::string strLLMQType = gArgs.GetArg("-llmqinstantsend", std::string(consensus.llmqs.at(consensus.llmqTypeInstantSend).name));
Consensus::LLMQType llmqType = Consensus::LLMQ_NONE; Consensus::LLMQType llmqType = Consensus::LLMQType::LLMQ_NONE;
for (const auto& p : consensus.llmqs) { for (const auto& p : consensus.llmqs) {
if (p.second.name == strLLMQType) { if (p.second.name == strLLMQType) {
llmqType = p.first; llmqType = p.first;
} }
} }
if (llmqType == Consensus::LLMQ_NONE) { if (llmqType == Consensus::LLMQType::LLMQ_NONE) {
throw std::runtime_error("Invalid LLMQ type specified for -llmqinstantsend."); throw std::runtime_error("Invalid LLMQ type specified for -llmqinstantsend.");
} }
LogPrintf("Setting llmqinstantsend to size=%ld\n", llmqType); LogPrintf("Setting llmqinstantsend to size=%ld\n", static_cast<uint8_t>(llmqType));
UpdateDevnetLLMQInstantSend(llmqType); UpdateDevnetLLMQInstantSend(llmqType);
} }

View File

@ -8,6 +8,7 @@
#include <chainparamsbase.h> #include <chainparamsbase.h>
#include <consensus/params.h> #include <consensus/params.h>
#include <llmq/params.h>
#include <primitives/block.h> #include <primitives/block.h>
#include <protocol.h> #include <protocol.h>
@ -136,6 +137,8 @@ protected:
std::vector<std::string> vSporkAddresses; std::vector<std::string> vSporkAddresses;
int nMinSporkKeys; int nMinSporkKeys;
bool fBIP9CheckMasternodesUpgraded; bool fBIP9CheckMasternodesUpgraded;
void AddLLMQ(Consensus::LLMQType llmqType);
}; };
/** /**

View File

@ -113,14 +113,9 @@ struct Params {
std::map<LLMQType, LLMQParams> llmqs; std::map<LLMQType, LLMQParams> llmqs;
LLMQType llmqTypeChainLocks; LLMQType llmqTypeChainLocks;
LLMQType llmqTypeInstantSend{LLMQ_NONE}; LLMQType llmqTypeInstantSend{LLMQType::LLMQ_NONE};
LLMQType llmqTypePlatform{LLMQ_NONE}; LLMQType llmqTypePlatform{LLMQType::LLMQ_NONE};
}; };
} // namespace Consensus } // namespace Consensus
// This must be outside of all namespaces. We must also duplicate the forward declaration of is_serializable_enum to
// avoid inclusion of serialize.h here.
template<typename T> struct is_serializable_enum;
template<> struct is_serializable_enum<Consensus::LLMQType> : std::true_type {};
#endif // BITCOIN_CONSENSUS_PARAMS_H #endif // BITCOIN_CONSENSUS_PARAMS_H

View File

@ -59,7 +59,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
if (!Params().GetConsensus().llmqs.count(qc.llmqType)) { if (!Params().GetConsensus().llmqs.count(qc.llmqType)) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__, LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
qc.llmqType, pfrom->GetId()); static_cast<uint8_t>(qc.llmqType), pfrom->GetId());
LOCK(cs_main); LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100); Misbehaving(pfrom->GetId(), 100);
return; return;
@ -109,14 +109,14 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
if (!qc.Verify(pquorumIndex, true)) { if (!qc.Verify(pquorumIndex, true)) {
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__, LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__,
qc.quorumHash.ToString(), qc.llmqType, pfrom->GetId()); qc.quorumHash.ToString(), static_cast<uint8_t>(qc.llmqType), pfrom->GetId());
LOCK(cs_main); LOCK(cs_main);
Misbehaving(pfrom->GetId(), 100); Misbehaving(pfrom->GetId(), 100);
return; return;
} }
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- received commitment for quorum %s:%d, validMembers=%d, signers=%d, peer=%d\n", __func__, LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- received commitment for quorum %s:%d, validMembers=%d, signers=%d, peer=%d\n", __func__,
qc.quorumHash.ToString(), qc.llmqType, qc.CountValidMembers(), qc.CountSigners(), pfrom->GetId()); qc.quorumHash.ToString(), static_cast<uint8_t>(qc.llmqType), qc.CountValidMembers(), qc.CountSigners(), pfrom->GetId());
AddMineableCommitment(qc); AddMineableCommitment(qc);
} }
@ -245,7 +245,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
} }
LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__, LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__,
qc.llmqType, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString()); static_cast<uint8_t>(qc.llmqType), quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString());
return true; return true;
} }

View File

@ -34,7 +34,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) c
} }
if (!Params().GetConsensus().llmqs.count(llmqType)) { if (!Params().GetConsensus().llmqs.count(llmqType)) {
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType); LogPrintfFinalCommitment("invalid llmqType=%d\n", static_cast<uint8_t>(llmqType));
return false; return false;
} }
const auto& llmq_params = GetLLMQParams(llmqType); const auto& llmq_params = GetLLMQParams(llmqType);
@ -109,7 +109,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumIndex, bool checkSigs) c
bool CFinalCommitment::VerifyNull() const bool CFinalCommitment::VerifyNull() const
{ {
if (!Params().GetConsensus().llmqs.count(llmqType)) { if (!Params().GetConsensus().llmqs.count(llmqType)) {
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType); LogPrintfFinalCommitment("invalid llmqType=%d\n", static_cast<uint8_t>(llmqType));
return false; return false;
} }

View File

@ -25,7 +25,7 @@ public:
public: public:
uint16_t nVersion{CURRENT_VERSION}; uint16_t nVersion{CURRENT_VERSION};
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE}; Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash; uint256 quorumHash;
std::vector<bool> signers; std::vector<bool> signers;
std::vector<bool> validMembers; std::vector<bool> validMembers;

View File

@ -31,7 +31,7 @@ UniValue CDKGDebugSessionStatus::ToJson(int detailLevel) const
} }
} }
ret.pushKV("llmqType", llmqType); ret.pushKV("llmqType", static_cast<uint8_t>(llmqType));
ret.pushKV("quorumHash", quorumHash.ToString()); ret.pushKV("quorumHash", quorumHash.ToString());
ret.pushKV("quorumHeight", (int)quorumHeight); ret.pushKV("quorumHeight", (int)quorumHeight);
ret.pushKV("phase", (int)phase); ret.pushKV("phase", (int)phase);

View File

@ -48,7 +48,7 @@ public:
class CDKGDebugSessionStatus class CDKGDebugSessionStatus
{ {
public: public:
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE}; Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash; uint256 quorumHash;
uint32_t quorumHeight{0}; uint32_t quorumHeight{0};
uint8_t phase{0}; uint8_t phase{0};

View File

@ -84,7 +84,7 @@ public:
class CDKGComplaint class CDKGComplaint
{ {
public: public:
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE}; Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash; uint256 quorumHash;
uint256 proTxHash; uint256 proTxHash;
std::vector<bool> badMembers; std::vector<bool> badMembers;
@ -145,7 +145,7 @@ public:
class CDKGPrematureCommitment class CDKGPrematureCommitment
{ {
public: public:
Consensus::LLMQType llmqType{Consensus::LLMQ_NONE}; Consensus::LLMQType llmqType{Consensus::LLMQType::LLMQ_NONE};
uint256 quorumHash; uint256 quorumHash;
uint256 proTxHash; uint256 proTxHash;
std::vector<bool> validMembers; std::vector<bool> validMembers;

View File

@ -96,7 +96,7 @@ CDKGSessionHandler::CDKGSessionHandler(const Consensus::LLMQParams& _params, CBL
pendingJustifications((size_t)_params.size * 2, MSG_QUORUM_JUSTIFICATION), pendingJustifications((size_t)_params.size * 2, MSG_QUORUM_JUSTIFICATION),
pendingPrematureCommitments((size_t)_params.size * 2, MSG_QUORUM_PREMATURE_COMMITMENT) pendingPrematureCommitments((size_t)_params.size * 2, MSG_QUORUM_PREMATURE_COMMITMENT)
{ {
if (params.type == Consensus::LLMQ_NONE) { if (params.type == Consensus::LLMQType::LLMQ_NONE) {
throw std::runtime_error("Can't initialize CDKGSessionHandler with LLMQ_NONE type."); throw std::runtime_error("Can't initialize CDKGSessionHandler with LLMQ_NONE type.");
} }
} }

View File

@ -487,7 +487,7 @@ void CInstantSendManager::ProcessTx(const CTransaction& tx, bool fRetroactive, c
} }
auto llmqType = params.llmqTypeInstantSend; auto llmqType = params.llmqTypeInstantSend;
if (llmqType == Consensus::LLMQ_NONE) { if (llmqType == Consensus::LLMQType::LLMQ_NONE) {
return; return;
} }
@ -642,7 +642,7 @@ void CInstantSendManager::HandleNewRecoveredSig(const CRecoveredSig& recoveredSi
} }
auto llmqType = Params().GetConsensus().llmqTypeInstantSend; auto llmqType = Params().GetConsensus().llmqTypeInstantSend;
if (llmqType == Consensus::LLMQ_NONE) { if (llmqType == Consensus::LLMQType::LLMQ_NONE) {
return; return;
} }

View File

@ -5,12 +5,13 @@
#ifndef BITCOIN_LLMQ_PARAMS_H #ifndef BITCOIN_LLMQ_PARAMS_H
#define BITCOIN_LLMQ_PARAMS_H #define BITCOIN_LLMQ_PARAMS_H
#include <array>
#include <cstdint> #include <cstdint>
#include <string_view> #include <string_view>
namespace Consensus { namespace Consensus {
enum LLMQType : uint8_t enum class LLMQType : uint8_t
{ {
LLMQ_NONE = 0xff, LLMQ_NONE = 0xff,
@ -94,13 +95,15 @@ struct LLMQParams {
}; };
/** static constexpr std::array<LLMQParams, 7> available_llmqs = {
/**
* llmq_test * llmq_test
* This quorum is only used for testing * This quorum is only used for testing
* *
*/ */
static constexpr LLMQParams llmq_test = { LLMQParams{
.type = LLMQ_TEST, .type = LLMQType::LLMQ_TEST,
.name = "llmq_test", .name = "llmq_test",
.size = 3, .size = 3,
.minSize = 2, .minSize = 2,
@ -116,15 +119,15 @@ static constexpr LLMQParams llmq_test = {
.keepOldConnections = 3, .keepOldConnections = 3,
.recoveryMembers = 3, .recoveryMembers = 3,
}; },
/** /**
* llmq_test (Dash Core 0.17) aka llmq_test_v17 * llmq_test (Dash Core 0.17) aka llmq_test_v17
* This quorum is only used for testing * This quorum is only used for testing
* *
*/ */
static constexpr LLMQParams llmq_test_v17 = { LLMQParams{
.type = LLMQ_TEST_V17, .type = LLMQType::LLMQ_TEST_V17,
.name = "llmq_test_v17", .name = "llmq_test_v17",
.size = 3, .size = 3,
.minSize = 2, .minSize = 2,
@ -140,15 +143,15 @@ static constexpr LLMQParams llmq_test_v17 = {
.keepOldConnections = 3, .keepOldConnections = 3,
.recoveryMembers = 3, .recoveryMembers = 3,
}; },
/** /**
* llmq_devnet * llmq_devnet
* This quorum is only used for testing on devnets * This quorum is only used for testing on devnets
* *
*/ */
static constexpr LLMQParams llmq_devnet = { LLMQParams{
.type = LLMQ_DEVNET, .type = LLMQType::LLMQ_DEVNET,
.name = "llmq_devnet", .name = "llmq_devnet",
.size = 10, .size = 10,
.minSize = 7, .minSize = 7,
@ -164,16 +167,16 @@ static constexpr LLMQParams llmq_devnet = {
.keepOldConnections = 4, .keepOldConnections = 4,
.recoveryMembers = 6, .recoveryMembers = 6,
}; },
/** /**
* llmq50_60 * llmq_50_60
* This quorum is deployed on mainnet and requires * This quorum is deployed on mainnet and requires
* 40 - 50 participants * 40 - 50 participants
* *
*/ */
static constexpr LLMQParams llmq50_60 = { LLMQParams{
.type = LLMQ_50_60, .type = LLMQType::LLMQ_50_60,
.name = "llmq_50_60", .name = "llmq_50_60",
.size = 50, .size = 50,
.minSize = 40, .minSize = 40,
@ -186,19 +189,18 @@ static constexpr LLMQParams llmq50_60 = {
.dkgBadVotesThreshold = 40, .dkgBadVotesThreshold = 40,
.signingActiveQuorumCount = 24, // a full day worth of LLMQs .signingActiveQuorumCount = 24, // a full day worth of LLMQs
.keepOldConnections = 25, .keepOldConnections = 25,
.recoveryMembers = 25, .recoveryMembers = 25,
}; },
/** /**
* llmq400_60 * llmq_400_60
* This quorum is deployed on mainnet and requires * This quorum is deployed on mainnet and requires
* 300 - 400 participants * 300 - 400 participants
* *
*/ */
static constexpr LLMQParams llmq400_60 = { LLMQParams{
.type = LLMQ_400_60, .type = LLMQType::LLMQ_400_60,
.name = "llmq_400_60", .name = "llmq_400_60",
.size = 400, .size = 400,
.minSize = 300, .minSize = 300,
@ -214,17 +216,17 @@ static constexpr LLMQParams llmq400_60 = {
.keepOldConnections = 5, .keepOldConnections = 5,
.recoveryMembers = 100, .recoveryMembers = 100,
}; },
/** /**
* llmq400_85 * llmq_400_85
* This quorum is deployed on mainnet and requires * This quorum is deployed on mainnet and requires
* 300 - 400 participants _with_ a supermajority * 300 - 400 participants _with_ a supermajority
* *
* Used for deployment and min-proto-version signalling * Used for deployment and min-proto-version signalling
*/ */
static constexpr LLMQParams llmq400_85 = { LLMQParams{
.type = LLMQ_400_85, .type = LLMQType::LLMQ_400_85,
.name = "llmq_400_85", .name = "llmq_400_85",
.size = 400, .size = 400,
.minSize = 350, .minSize = 350,
@ -240,17 +242,17 @@ static constexpr LLMQParams llmq400_85 = {
.keepOldConnections = 5, .keepOldConnections = 5,
.recoveryMembers = 100, .recoveryMembers = 100,
}; },
/** /**
* llmq100_67 * llmq_100_67
* This quorum is deployed on mainnet and requires * This quorum is deployed on mainnet and requires
* 80 - 100 participants * 80 - 100 participants
* *
* Used by Dash Platform * Used by Dash Platform
*/ */
static constexpr LLMQParams llmq100_67 = { LLMQParams{
.type = LLMQ_100_67, .type = LLMQType::LLMQ_100_67,
.name = "llmq_100_67", .name = "llmq_100_67",
.size = 100, .size = 100,
.minSize = 80, .minSize = 80,
@ -266,8 +268,15 @@ static constexpr LLMQParams llmq100_67 = {
.keepOldConnections = 25, .keepOldConnections = 25,
.recoveryMembers = 50, .recoveryMembers = 50,
}; },
} }; // available_llmqs
} // namespace Consensus
// This must be outside of all namespaces. We must also duplicate the forward declaration of is_serializable_enum to
// avoid inclusion of serialize.h here.
template<typename T> struct is_serializable_enum;
template<> struct is_serializable_enum<Consensus::LLMQType> : std::true_type {};
#endif // BITCOIN_LLMQ_PARAMS_H #endif // BITCOIN_LLMQ_PARAMS_H

View File

@ -240,7 +240,7 @@ void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex)
if (nDataMask == 0) { if (nDataMask == 0) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- No data needed from (%d, %s) at height %d\n", LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- No data needed from (%d, %s) at height %d\n",
__func__, pQuorum->qc->llmqType, pQuorum->qc->quorumHash.ToString(), pIndex->nHeight); __func__, static_cast<uint8_t>(pQuorum->qc->llmqType), pQuorum->qc->quorumHash.ToString(), pIndex->nHeight);
continue; continue;
} }
@ -394,7 +394,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp
return false; return false;
} }
if (Params().GetConsensus().llmqs.count(llmqType) == 0) { if (Params().GetConsensus().llmqs.count(llmqType) == 0) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid llmqType: %d\n", __func__, llmqType); LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid llmqType: %d\n", __func__, static_cast<uint8_t>(llmqType));
return false; return false;
} }
if (pQuorumIndex == nullptr) { if (pQuorumIndex == nullptr) {
@ -402,7 +402,7 @@ bool CQuorumManager::RequestQuorumData(CNode* pFrom, Consensus::LLMQType llmqTyp
return false; return false;
} }
if (GetQuorum(llmqType, pQuorumIndex) == nullptr) { if (GetQuorum(llmqType, pQuorumIndex) == nullptr) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Quorum not found: %s, %d\n", __func__, pQuorumIndex->GetBlockHash().ToString(), llmqType); LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Quorum not found: %s, %d\n", __func__, pQuorumIndex->GetBlockHash().ToString(), static_cast<uint8_t>(llmqType));
return false; return false;
} }
@ -766,7 +766,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(const CQuorumCPtr pQuorum, co
auto printLog = [&](const std::string& strMessage) { auto printLog = [&](const std::string& strMessage) {
const std::string strMember{pCurrentMemberHash == nullptr ? "nullptr" : pCurrentMemberHash->ToString()}; const std::string strMember{pCurrentMemberHash == nullptr ? "nullptr" : pCurrentMemberHash->ToString()};
LogPrint(BCLog::LLMQ, "CQuorumManager::StartQuorumDataRecoveryThread -- %s - for llmqType %d, quorumHash %s, nDataMask (%d/%d), pCurrentMemberHash %s, nTries %d\n", LogPrint(BCLog::LLMQ, "CQuorumManager::StartQuorumDataRecoveryThread -- %s - for llmqType %d, quorumHash %s, nDataMask (%d/%d), pCurrentMemberHash %s, nTries %d\n",
strMessage, pQuorum->qc->llmqType, pQuorum->qc->quorumHash.ToString(), nDataMask, nDataMaskIn, strMember, nTries); strMessage, static_cast<uint8_t>(pQuorum->qc->llmqType), pQuorum->qc->quorumHash.ToString(), nDataMask, nDataMaskIn, strMember, nTries);
}; };
printLog("Start"); printLog("Start");

View File

@ -33,7 +33,7 @@ void CSigShare::UpdateKey()
std::string CSigSesAnn::ToString() const std::string CSigSesAnn::ToString() const
{ {
return strprintf("sessionId=%d, llmqType=%d, quorumHash=%s, id=%s, msgHash=%s", return strprintf("sessionId=%d, llmqType=%d, quorumHash=%s, id=%s, msgHash=%s",
sessionId, llmqType, quorumHash.ToString(), id.ToString(), msgHash.ToString()); sessionId, static_cast<uint8_t>(llmqType), quorumHash.ToString(), id.ToString(), msgHash.ToString());
} }
void CSigSharesInv::Merge(const CSigSharesInv& inv2) void CSigSharesInv::Merge(const CSigSharesInv& inv2)
@ -1599,7 +1599,7 @@ CSigShare CSigSharesManager::CreateSigShare(const CQuorumCPtr& quorum, const uin
sigShare.UpdateKey(); sigShare.UpdateKey();
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- created sigShare. signHash=%s, id=%s, msgHash=%s, llmqType=%d, quorum=%s, time=%s\n", __func__, LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- created sigShare. signHash=%s, id=%s, msgHash=%s, llmqType=%d, quorum=%s, time=%s\n", __func__,
signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), quorum->params.type, quorum->qc->quorumHash.ToString(), t.count()); signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), static_cast<uint8_t>(quorum->params.type), quorum->qc->quorumHash.ToString(), t.count());
return sigShare; return sigShare;
} }

View File

@ -76,7 +76,7 @@ static bool EvalSpork(Consensus::LLMQType llmqType, int64_t spork_value)
if (spork_value == 0) { if (spork_value == 0) {
return true; return true;
} }
if (spork_value == 1 && llmqType != Consensus::LLMQ_100_67 && llmqType != Consensus::LLMQ_400_60 && llmqType != Consensus::LLMQ_400_85) { if (spork_value == 1 && llmqType != Consensus::LLMQType::LLMQ_100_67 && llmqType != Consensus::LLMQType::LLMQ_400_60 && llmqType != Consensus::LLMQType::LLMQ_400_85) {
return true; return true;
} }
return false; return false;
@ -306,21 +306,21 @@ bool CLLMQUtils::IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockI
switch (llmqType) switch (llmqType)
{ {
case Consensus::LLMQ_50_60: case Consensus::LLMQType::LLMQ_50_60:
case Consensus::LLMQ_400_60: case Consensus::LLMQType::LLMQ_400_60:
case Consensus::LLMQ_400_85: case Consensus::LLMQType::LLMQ_400_85:
break; break;
case Consensus::LLMQ_100_67: case Consensus::LLMQType::LLMQ_100_67:
case Consensus::LLMQ_TEST_V17: case Consensus::LLMQType::LLMQ_TEST_V17:
if (!f_dip0020_Active) { if (!f_dip0020_Active) {
return false; return false;
} }
break; break;
case Consensus::LLMQ_TEST: case Consensus::LLMQType::LLMQ_TEST:
case Consensus::LLMQ_DEVNET: case Consensus::LLMQType::LLMQ_DEVNET:
break; break;
default: default:
throw std::runtime_error(strprintf("%s: Unknown LLMQ type %d", __func__, llmqType)); throw std::runtime_error(strprintf("%s: Unknown LLMQ type %d", __func__, static_cast<uint8_t>(llmqType)));
} }
return true; return true;
@ -352,7 +352,7 @@ std::map<Consensus::LLMQType, QvvecSyncMode> CLLMQUtils::GetEnabledQuorumVvecSyn
{ {
std::map<Consensus::LLMQType, QvvecSyncMode> mapQuorumVvecSyncEntries; std::map<Consensus::LLMQType, QvvecSyncMode> mapQuorumVvecSyncEntries;
for (const auto& strEntry : gArgs.GetArgs("-llmq-qvvec-sync")) { for (const auto& strEntry : gArgs.GetArgs("-llmq-qvvec-sync")) {
Consensus::LLMQType llmqType = Consensus::LLMQ_NONE; Consensus::LLMQType llmqType = Consensus::LLMQType::LLMQ_NONE;
QvvecSyncMode mode{QvvecSyncMode::Invalid}; QvvecSyncMode mode{QvvecSyncMode::Invalid};
std::istringstream ssEntry(strEntry); std::istringstream ssEntry(strEntry);
std::string strLLMQType, strMode, strTest; std::string strLLMQType, strMode, strTest;
@ -368,7 +368,7 @@ std::map<Consensus::LLMQType, QvvecSyncMode> CLLMQUtils::GetEnabledQuorumVvecSyn
break; break;
} }
} }
if (llmqType == Consensus::LLMQ_NONE) { if (llmqType == Consensus::LLMQType::LLMQ_NONE) {
throw std::invalid_argument(strprintf("Invalid llmqType in -llmq-qvvec-sync: %s", strEntry)); throw std::invalid_argument(strprintf("Invalid llmqType in -llmq-qvvec-sync: %s", strEntry));
} }
if (mapQuorumVvecSyncEntries.count(llmqType) > 0) { if (mapQuorumVvecSyncEntries.count(llmqType) > 0) {

View File

@ -476,7 +476,7 @@ static UniValue quorum_sigs_cmd(const JSONRPCRequest& request)
} }
UniValue obj(UniValue::VOBJ); UniValue obj(UniValue::VOBJ);
obj.pushKV("llmqType", llmqType); obj.pushKV("llmqType", static_cast<uint8_t>(llmqType));
obj.pushKV("quorumHash", sigShare.quorumHash.ToString()); obj.pushKV("quorumHash", sigShare.quorumHash.ToString());
obj.pushKV("quorumMember", sigShare.quorumMember); obj.pushKV("quorumMember", sigShare.quorumMember);
obj.pushKV("id", id.ToString()); obj.pushKV("id", id.ToString());

View File

@ -266,7 +266,7 @@ void CRPCTable::InitPlatformRestrictions()
{"getblockhash", {}}, {"getblockhash", {}},
{"getblockcount", {}}, {"getblockcount", {}},
{"getbestchainlock", {}}, {"getbestchainlock", {}},
{"quorum", {"sign", Params().GetConsensus().llmqTypePlatform}}, {"quorum", {"sign", static_cast<uint8_t>(Params().GetConsensus().llmqTypePlatform)}},
{"quorum", {"verify"}}, {"quorum", {"verify"}},
{"verifyislock", {}}, {"verifyislock", {}},
}; };