From 68442e8dfe0854102c7e412c2f50a505dc1714bf Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 4 Dec 2023 15:03:51 +0700 Subject: [PATCH 01/34] chore: add TODO for llmq/utils.h refactoring --- src/llmq/utils.cpp | 1 + src/llmq/utils.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 60522a51b8..e40bc91fa5 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -25,6 +25,7 @@ #include #include +// TODO remove this const static constexpr int TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT = 847000; /** diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 188b917336..7093f25485 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -52,7 +52,9 @@ uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, gsl::not_null& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash); uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash); +// TODO options bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType); +// TODO options bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType); uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2); std::set GetQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); @@ -63,23 +65,36 @@ bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_n void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash); bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, const uint256& quorumHash); +// TODO options maybe not bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex); +// TODO options maybe not bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex, std::optional optDIP0024IsActive, std::optional optHaveDIP0024Quorums); +// TODO options maybe not std::vector GetEnabledQuorumTypes(gsl::not_null pindex); +// TODO options maybe not std::vector> GetEnabledQuorumParams(gsl::not_null pindex); +// TODO options bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null pindex); +// TODO deployments bool IsDIP0024Active(gsl::not_null pindex); +// TODO deployments bool IsV19Active(gsl::not_null pindex); +// TODO deployments bool IsV20Active(gsl::not_null pindex); +// TODO deployments bool IsMNRewardReallocationActive(gsl::not_null pindex); +// TODO deployments ThresholdState GetV20State(gsl::not_null pindex); +// TODO deployments int GetV20Since(gsl::not_null pindex); /// Returns the state of `-llmq-data-recovery` +// TODO options bool QuorumDataRecoveryEnabled(); +// TODO options /// Returns the state of `-watchquorums` bool IsWatchQuorumsEnabled(); From a7ad399824b5344922312637857a371b9abeeb4d Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 4 Dec 2023 15:40:01 +0700 Subject: [PATCH 02/34] refactor: drop IsDIP0024Active and its usage of llmq_vbc --- src/llmq/utils.cpp | 25 ++++++++++--------------- src/llmq/utils.h | 6 ++---- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index e40bc91fa5..62caee6940 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -678,12 +679,7 @@ bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_n return false; } // It should activate at least 1 block prior to the cycle start - return IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1)); -} - -bool IsDIP0024Active(gsl::not_null pindex) -{ - return pindex->nHeight + 1 >= Params().GetConsensus().DIP0024Height; + return DeploymentActiveAfter(pindex->GetAncestor(cycleQuorumBaseHeight - 1), Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024); } bool IsV19Active(gsl::not_null pindex) @@ -942,16 +938,17 @@ bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, co return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; }); } -bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex) +bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindexPrev) { - return IsQuorumTypeEnabledInternal(llmqType, qman, pindex, std::nullopt, std::nullopt); + return IsQuorumTypeEnabledInternal(llmqType, qman, pindexPrev, std::nullopt, std::nullopt); } -bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex, +bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindexPrev, std::optional optDIP0024IsActive, std::optional optHaveDIP0024Quorums) { const Consensus::Params& consensusParams = Params().GetConsensus(); + bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0024); switch (llmqType) { case Consensus::LLMQType::LLMQ_DEVNET: @@ -960,12 +957,11 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana if (Params().NetworkIDString() == CBaseChainParams::TESTNET) return true; // fall through case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND: { - bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex); if (!fDIP0024IsActive) return true; bool fHaveDIP0024Quorums = optHaveDIP0024Quorums.has_value() ? *optHaveDIP0024Quorums : !qman.ScanQuorums( - consensusParams.llmqTypeDIP0024InstantSend, pindex, 1).empty(); + consensusParams.llmqTypeDIP0024InstantSend, pindexPrev, 1).empty(); return !fHaveDIP0024Quorums; } case Consensus::LLMQType::LLMQ_TEST: @@ -976,19 +972,18 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana return true; case Consensus::LLMQType::LLMQ_TEST_V17: { - return llmq_versionbitscache.State(pindex, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY) == ThresholdState::ACTIVE; + return llmq_versionbitscache.State(pindexPrev, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY) == ThresholdState::ACTIVE; } case Consensus::LLMQType::LLMQ_100_67: - return pindex->nHeight + 1 >= consensusParams.DIP0020Height; + return pindexPrev->nHeight + 1 >= consensusParams.DIP0020Height; case Consensus::LLMQType::LLMQ_60_75: case Consensus::LLMQType::LLMQ_DEVNET_DIP0024: case Consensus::LLMQType::LLMQ_TEST_DIP0024: { - bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex); return fDIP0024IsActive; } case Consensus::LLMQType::LLMQ_25_67: - return pindex->nHeight >= TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT; + return pindexPrev->nHeight >= TESTNET_LLMQ_25_67_ACTIVATION_HEIGHT; default: throw std::runtime_error(strprintf("%s: Unknown LLMQ type %d", __func__, ToUnderlying(llmqType))); diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 7093f25485..83d633088e 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -66,9 +66,9 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not bool IsQuorumActive(Consensus::LLMQType llmqType, const CQuorumManager& qman, const uint256& quorumHash); // TODO options maybe not -bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex); +bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindexPrev); // TODO options maybe not -bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindex, std::optional optDIP0024IsActive, std::optional optHaveDIP0024Quorums); +bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null pindexPrev, std::optional optDIP0024IsActive, std::optional optHaveDIP0024Quorums); // TODO options maybe not std::vector GetEnabledQuorumTypes(gsl::not_null pindex); @@ -78,8 +78,6 @@ std::vector> GetEnabledQuoru // TODO options bool IsQuorumRotationEnabled(const Consensus::LLMQParams& llmqParams, gsl::not_null pindex); // TODO deployments -bool IsDIP0024Active(gsl::not_null pindex); -// TODO deployments bool IsV19Active(gsl::not_null pindex); // TODO deployments bool IsV20Active(gsl::not_null pindex); From c32961558432270112c4199f0c43cfe62ee49285 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 18 Dec 2023 15:17:13 +0700 Subject: [PATCH 03/34] refactor: use value_or in std::optional --- src/llmq/utils.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 62caee6940..62ce2b9d63 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -948,7 +948,7 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana { const Consensus::Params& consensusParams = Params().GetConsensus(); - bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0024); + const bool fDIP0024IsActive{optDIP0024IsActive.value_or(DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_DIP0024))}; switch (llmqType) { case Consensus::LLMQType::LLMQ_DEVNET: @@ -959,9 +959,8 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND: { if (!fDIP0024IsActive) return true; - bool fHaveDIP0024Quorums = optHaveDIP0024Quorums.has_value() ? *optHaveDIP0024Quorums - : !qman.ScanQuorums( - consensusParams.llmqTypeDIP0024InstantSend, pindexPrev, 1).empty(); + const bool fHaveDIP0024Quorums{optHaveDIP0024Quorums.value_or(!qman.ScanQuorums( + consensusParams.llmqTypeDIP0024InstantSend, pindexPrev, 1).empty())}; return !fHaveDIP0024Quorums; } case Consensus::LLMQType::LLMQ_TEST: From 8f3d3db9a4c2e08e25ab62281d7736aaffed417f Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Mon, 4 Dec 2023 15:48:21 +0700 Subject: [PATCH 04/34] refactor: drop dependency governance/classes on llmq/utils --- src/governance/classes.cpp | 6 +++--- src/llmq/utils.cpp | 10 ---------- src/llmq/utils.h | 4 ---- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/governance/classes.cpp b/src/governance/classes.cpp index b8fe9b4b08..6ee0c2b7f7 100644 --- a/src/governance/classes.cpp +++ b/src/governance/classes.cpp @@ -7,9 +7,9 @@ #include #include #include +#include #include #include -#include #include #include