dash/src/llmq/options.cpp

191 lines
7.5 KiB
C++
Raw Normal View History

// Copyright (c) 2018-2024 The Dash Core developers
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <llmq/options.h>
#include <chainparams.h>
#include <consensus/params.h>
#include <deploymentstatus.h>
#include <spork.h>
#include <util/ranges.h>
#include <util/system.h>
#include <util/underlying.h>
#include <string>
#include <stdexcept>
static constexpr int TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT = 847000;
namespace llmq
{
static bool EvalSpork(const Consensus::LLMQType llmqType, const int64_t spork_value)
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
{
if (spork_value == 0) {
return true;
}
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 false;
}
bool IsAllMembersConnectedEnabled(const Consensus::LLMQType llmqType, const CSporkManager& sporkman)
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
{
return EvalSpork(llmqType, sporkman.GetSporkValue(SPORK_21_QUORUM_ALL_CONNECTED));
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
}
bool IsQuorumPoseEnabled(const Consensus::LLMQType llmqType, const CSporkManager& sporkman)
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
{
return EvalSpork(llmqType, sporkman.GetSporkValue(SPORK_23_QUORUM_POSE));
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
}
bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pindex)
{
if (!llmqParams.useRotation) {
return false;
}
int cycleQuorumBaseHeight = pindex->nHeight - (pindex->nHeight % llmqParams.dkgInterval);
if (cycleQuorumBaseHeight < 1) {
return false;
}
// It should activate at least 1 block prior to the cycle start
return DeploymentActiveAfter(pindex->GetAncestor(cycleQuorumBaseHeight - 1), Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024);
}
bool QuorumDataRecoveryEnabled()
{
return gArgs.GetBoolArg("-llmq-data-recovery", DEFAULT_ENABLE_QUORUM_DATA_RECOVERY);
}
bool IsWatchQuorumsEnabled()
{
static bool fIsWatchQuroumsEnabled = gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS);
return fIsWatchQuroumsEnabled;
}
std::map<Consensus::LLMQType, QvvecSyncMode> GetEnabledQuorumVvecSyncEntries()
{
std::map<Consensus::LLMQType, QvvecSyncMode> mapQuorumVvecSyncEntries;
for (const auto& strEntry : gArgs.GetArgs("-llmq-qvvec-sync")) {
Consensus::LLMQType llmqType = Consensus::LLMQType::LLMQ_NONE;
QvvecSyncMode mode{QvvecSyncMode::Invalid};
std::istringstream ssEntry(strEntry);
std::string strLLMQType, strMode, strTest;
const bool fLLMQTypePresent = std::getline(ssEntry, strLLMQType, ':') && strLLMQType != "";
const bool fModePresent = std::getline(ssEntry, strMode, ':') && strMode != "";
const bool fTooManyEntries = static_cast<bool>(std::getline(ssEntry, strTest, ':'));
if (!fLLMQTypePresent || !fModePresent || fTooManyEntries) {
throw std::invalid_argument(strprintf("Invalid format in -llmq-qvvec-sync: %s", strEntry));
}
if (auto optLLMQParams = ranges::find_if_opt(Params().GetConsensus().llmqs,
[&strLLMQType](const auto& params){return params.name == strLLMQType;})) {
llmqType = optLLMQParams->type;
} else {
throw std::invalid_argument(strprintf("Invalid llmqType in -llmq-qvvec-sync: %s", strEntry));
}
if (mapQuorumVvecSyncEntries.count(llmqType) > 0) {
throw std::invalid_argument(strprintf("Duplicated llmqType in -llmq-qvvec-sync: %s", strEntry));
}
int32_t nMode;
if (ParseInt32(strMode, &nMode)) {
switch (nMode) {
case (int32_t)QvvecSyncMode::Always:
mode = QvvecSyncMode::Always;
break;
case (int32_t)QvvecSyncMode::OnlyIfTypeMember:
mode = QvvecSyncMode::OnlyIfTypeMember;
break;
default:
mode = QvvecSyncMode::Invalid;
break;
}
}
if (mode == QvvecSyncMode::Invalid) {
throw std::invalid_argument(strprintf("Invalid mode in -llmq-qvvec-sync: %s", strEntry));
}
mapQuorumVvecSyncEntries.emplace(llmqType, mode);
}
return mapQuorumVvecSyncEntries;
}
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev)
{
return IsQuorumTypeEnabledInternal(llmqType, pindexPrev, std::nullopt, std::nullopt);
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
}
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev,
std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums)
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
{
const Consensus::Params& consensusParams = Params().GetConsensus();
const bool fDIP0024IsActive{optDIP0024IsActive.value_or(DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0024))};
const bool fHaveDIP0024Quorums{optHaveDIP0024Quorums.value_or(pindexPrev->nHeight >= consensusParams.DIP0024QuorumsHeight)};
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
switch (llmqType)
{
case Consensus::LLMQType::LLMQ_DEVNET:
return true;
case Consensus::LLMQType::LLMQ_50_60:
return !fDIP0024IsActive || !fHaveDIP0024Quorums ||
Params().NetworkIDString() == CBaseChainParams::TESTNET;
fix: make llmq_test_instantsend great again (#5832) ## Issue being fixed or feature implemented Running 3 nodes on RegTest as platform does uses do not let to create `llmq_test_instantsend` quorum: ``` 1. switch to `llmq_test_instantsend`: + self.extra_args = [["-llmqtestinstantsenddip0024=llmq_test_instantsend"]] * 5 2. removed cycle-quorum related code: - self.move_to_next_cycle() - self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount())) - self.move_to_next_cycle() - self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount())) - self.move_to_next_cycle() - self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount())) - - self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) 3. added new quorum: + self.mine_quorum(llmq_type_name='llmq_test_instantsend', llmq_type=104) and eventually it stucked, no quorum happens 2024-01-13T19:18:49.317000Z TestFramework (INFO): Expected quorum_0 at:984 2024-01-13T19:18:49.317000Z TestFramework (INFO): Expected quorum_0 hash:6788e18f0235a5c85f3d3c6233fe132a80e74a2912256db3ad876a8ebf026048 2024-01-13T19:18:49.317000Z TestFramework (INFO): quorumIndex 0: Waiting for phase 1 (init) <frozen> ``` ## What was done? Updated condition to enable "llmq_test_instantsend": - it is RegTest and DIP0024 is not active - it is RegTest, DIP0024 is active, and specified as `llmqTypeDIP0024InstantSend` ## How Has This Been Tested? Run unit and functional tests. Beside that functional test feature_asset_locks.py now uses this quorum for instant send and that's an arrow that hit 2 birds: we have test for command line option `-llmqtestinstantsenddip0024` and code of feature_asset_locks.py is simplified. ## Breaking Changes yes, that's a bugfix that fix quorum `llmq_test_instantsend` absentance on regtest after dip-0024 activation. ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
2024-01-19 16:14:04 +01:00
case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND:
return !fDIP0024IsActive || !fHaveDIP0024Quorums ||
consensusParams.llmqTypeDIP0024InstantSend == Consensus::LLMQType::LLMQ_TEST_INSTANTSEND;
refactor: split llmq/utils to Quorum Calculation and llmq/options (#5790) ## Issue being fixed or feature implemented `llmq/utils` has simple util code that used all over code base and also have too heavy code for calculation quorums such as: `GetAllQuorumMembers`, `EnsureQuorumConnections` and other. These helpers for calculation quorums are used only by evo/deterministicmns, evo/simplifiedmns and llmq/* modules, but llmq/utils is included in many other modules for various trivial helpers. ## What was done? Prior work: - https://github.com/dashpay/dash/pull/5753 - #5486 See also #4798 This PR remove all non-quorum calculation code from llmq/utils. Eventually it happens that easier to take everything out rather than move Quorum Calculation to new place atm: - new module llmq/options have a code related to various params, command line options, spork-related etc - llmq/utils is not included in various files which do not use any llmq/utils code - helper `BuildCommitmentHash` goes to llmq/commitment - helper `BuildSignHash` goes to llmq/signing - helper `GetLLMQParam` inlined since it's trivial (it has not been trivial when introduced ages ago) - removed dependency of `IsQuorumEnabled` on CQuorumManager which means `quorumManager` deglobalization is done for 90% ## How Has This Been Tested? - Run unit functional tests - updated circular dependencies `test/lint/lint-circular-dependencies.sh` - check that llmq/utils is not included without needs to calculate Quorums Members ``` $ grep -r include src/ 2> /dev/null | grep -v .Po: | grep -vE 'llmq/utils.(h|cpp)': | grep llmq/utils src/evo/mnauth.cpp:#include <llmq/utils.h> src/evo/deterministicmns.cpp:#include <llmq/utils.h> src/llmq/quorums.cpp:#include <llmq/utils.h> src/llmq/blockprocessor.cpp:#include <llmq/utils.h> src/llmq/commitment.cpp:#include <llmq/utils.h> src/llmq/debug.cpp:#include <llmq/utils.h> src/llmq/dkgsessionhandler.cpp:#include <llmq/utils.h> src/llmq/dkgsession.cpp:#include <llmq/utils.h> src/llmq/dkgsessionmgr.cpp:#include <llmq/utils.h> src/rpc/quorums.cpp:#include <llmq/utils.h> ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone
2024-01-18 02:56:41 +01:00
case Consensus::LLMQType::LLMQ_TEST:
case Consensus::LLMQType::LLMQ_TEST_PLATFORM:
case Consensus::LLMQType::LLMQ_400_60:
case Consensus::LLMQType::LLMQ_400_85:
case Consensus::LLMQType::LLMQ_DEVNET_PLATFORM:
return true;
case Consensus::LLMQType::LLMQ_TEST_V17: {
return DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
}
case Consensus::LLMQType::LLMQ_100_67:
return DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0020);
case Consensus::LLMQType::LLMQ_60_75:
case Consensus::LLMQType::LLMQ_DEVNET_DIP0024:
case Consensus::LLMQType::LLMQ_TEST_DIP0024: {
return fDIP0024IsActive;
}
case Consensus::LLMQType::LLMQ_25_67:
return pindexPrev->nHeight >= TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT;
default:
throw std::runtime_error(strprintf("%s: Unknown LLMQ type %d", __func__, ToUnderlying(llmqType)));
}
// Something wrong with conditions above, they are not consistent
assert(false);
}
std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBlockIndex*> pindex)
{
std::vector<Consensus::LLMQType> ret;
ret.reserve(Params().GetConsensus().llmqs.size());
for (const auto& params : Params().GetConsensus().llmqs) {
if (IsQuorumTypeEnabled(params.type, pindex)) {
ret.push_back(params.type);
}
}
return ret;
}
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(gsl::not_null<const CBlockIndex*> pindex)
{
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret;
ret.reserve(Params().GetConsensus().llmqs.size());
std::copy_if(Params().GetConsensus().llmqs.begin(), Params().GetConsensus().llmqs.end(), std::back_inserter(ret),
[&pindex](const auto& params){return IsQuorumTypeEnabled(params.type, pindex);});
return ret;
}
} // namespace llmq