Skip to content

Commit

Permalink
fix: removed dependency IsQuorumEnabled on CQuorumManager
Browse files Browse the repository at this point in the history
It seems as it is an artefact from non-deterministic IS.
It used only for LLMQ_TEST_INSTANTSEND quorum and doesn't look useful.

Removing this dependency helps to:
 - simplify implementation of many classes significantly so far as
   they don't need to pass quorumManager to low-level helpers
 - achieved significant progress of de-globalization quorumManager.
   Only one step left (evo/assertlocks, evo/creditpool, evo/mnhftx)
   and we can drop global variable ::quorumManager
 - disapeared 2 circular dependencies through llmq/quorum
  • Loading branch information
knst committed Jan 10, 2024
1 parent 92b8d94 commit f52d5aa
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/llmq/dkgsessionmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <llmq/dkgsessionmgr.h>
#include <llmq/options.h>
#include <llmq/params.h>
#include <llmq/quorums.h>
#include <llmq/utils.h>

#include <chainparams.h>
Expand All @@ -15,6 +14,7 @@
#include <evo/deterministicmns.h>
#include <net_processing.h>
#include <spork.h>
#include <unordered_lru_cache.h>
#include <util/irange.h>
#include <util/underlying.h>
#include <validation.h>
Expand Down Expand Up @@ -174,7 +174,7 @@ void CDKGSessionManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fIni
}
}

void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv)
void CDKGSessionManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv)
{
static Mutex cs_indexedQuorumsCache;
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>> indexedQuorumsCache GUARDED_BY(cs_indexedQuorumsCache);
Expand Down Expand Up @@ -247,7 +247,7 @@ void CDKGSessionManager::ProcessMessage(CNode& pfrom, const CQuorumManager& quor
return;
}

if (!utils::IsQuorumTypeEnabled(llmqType, quorum_manager, pQuorumBaseBlockIndex->pprev)) {
if (!utils::IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) {
LogPrintf("CDKGSessionManager -- llmqType [%d] quorums aren't active\n", ToUnderlying(llmqType));
m_peerman->Misbehaving(pfrom.GetId(), 100);
return;
Expand Down
3 changes: 1 addition & 2 deletions src/llmq/dkgsessionmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class UniValue;

namespace llmq
{
class CQuorumManager;

class CDKGSessionManager
{
Expand Down Expand Up @@ -74,7 +73,7 @@ class CDKGSessionManager

void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload);

void ProcessMessage(CNode& pfrom, const CQuorumManager& quorum_manager, const std::string& msg_type, CDataStream& vRecv);
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv);
bool AlreadyHave(const CInv& inv) const;
bool GetContribution(const uint256& hash, CDKGContribution& ret) const;
bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const;
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp

std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t nCountRequested) const
{
if (pindexStart == nullptr || nCountRequested == 0 || !IsQuorumTypeEnabled(llmqType, *this, pindexStart)) {
if (pindexStart == nullptr || nCountRequested == 0 || !utils::IsQuorumTypeEnabled(llmqType, pindexStart)) {
return {};
}

Expand Down
22 changes: 9 additions & 13 deletions src/llmq/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqTy
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers GUARDED_BY(cs_members);
static RecursiveMutex cs_indexed_members;
static std::map<Consensus::LLMQType, unordered_lru_cache<std::pair<uint256, int>, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapIndexedQuorumMembers GUARDED_BY(cs_indexed_members);
if (!IsQuorumTypeEnabled(llmqType, *llmq::quorumManager, pQuorumBaseBlockIndex->pprev)) {
if (!IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) {
return {};
}
std::vector<CDeterministicMNCPtr> quorumMembers;
Expand Down Expand Up @@ -850,13 +850,13 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not
}
}

bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev)
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev)
{
return IsQuorumTypeEnabledInternal(llmqType, qman, pindexPrev, std::nullopt, std::nullopt);
return IsQuorumTypeEnabledInternal(llmqType, pindexPrev, std::nullopt);
}

bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev,
std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums)
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev,
std::optional<bool> optDIP0024IsActive)
{
const Consensus::Params& consensusParams = Params().GetConsensus();

Expand All @@ -868,13 +868,9 @@ bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumMana
case Consensus::LLMQType::LLMQ_50_60:
if (Params().NetworkIDString() == CBaseChainParams::TESTNET) return true;
// fall through
case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND: {
if (!fDIP0024IsActive) return true;
case Consensus::LLMQType::LLMQ_TEST_INSTANTSEND:
return !fDIP0024IsActive;

const bool fHaveDIP0024Quorums{optHaveDIP0024Quorums.value_or(!qman.ScanQuorums(
consensusParams.llmqTypeDIP0024InstantSend, pindexPrev, 1).empty())};
return !fHaveDIP0024Quorums;
}
case Consensus::LLMQType::LLMQ_TEST:
case Consensus::LLMQType::LLMQ_TEST_PLATFORM:
case Consensus::LLMQType::LLMQ_400_60:
Expand Down Expand Up @@ -909,7 +905,7 @@ std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBloc
std::vector<Consensus::LLMQType> ret;
ret.reserve(Params().GetConsensus().llmqs.size());
for (const auto& params : Params().GetConsensus().llmqs) {
if (IsQuorumTypeEnabled(params.type, *llmq::quorumManager, pindex)) {
if (IsQuorumTypeEnabled(params.type, pindex)) {
ret.push_back(params.type);
}
}
Expand All @@ -922,7 +918,7 @@ std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuoru
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, *llmq::quorumManager, pindex);});
[&pindex](const auto& params){return IsQuorumTypeEnabled(params.type, pindex);});

return ret;
}
Expand Down
5 changes: 2 additions & 3 deletions src/llmq/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using CDeterministicMNCPtr = std::shared_ptr<const CDeterministicMN>;
namespace llmq
{

class CQuorumManager;
class CQuorumSnapshot;

namespace utils
Expand All @@ -41,8 +40,8 @@ std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType,
bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);
void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);

bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev);
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CQuorumManager& qman, gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums);
bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev);
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindexPrev, std::optional<bool> optDIP0024IsActive);

std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(gsl::not_null<const CBlockIndex*> pindex);
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(gsl::not_null<const CBlockIndex*> pindex);
Expand Down
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4354,7 +4354,7 @@ void PeerManagerImpl::ProcessMessage(
ProcessPeerMsgRet(m_govman.ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom);
ProcessPeerMsgRet(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, *m_llmq_ctx->qman, msg_type, vRecv);
m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, msg_type, vRecv);
ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
m_llmq_ctx->shareman->ProcessMessage(pfrom, *sporkManager, msg_type, vRecv);
m_llmq_ctx->sigman->ProcessMessage(pfrom, msg_type, vRecv);
Expand Down
30 changes: 11 additions & 19 deletions src/test/evo_utils_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include <test/util/setup_common.h>

#include <llmq/context.h>
#include <llmq/params.h>
#include <llmq/quorums.h>
#include <llmq/utils.h>

#include <chainparams.h>
Expand All @@ -18,35 +16,29 @@
/* TODO: rename this file and test to llmq_utils_test */
BOOST_AUTO_TEST_SUITE(evo_utils_tests)

void Test(llmq::CQuorumManager& qman, NodeContext& node)
void Test(NodeContext& node)
{
using namespace llmq::utils;
auto tip = node.chainman->ActiveTip();
const auto& consensus_params = Params().GetConsensus();
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, false, false), false);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, qman, tip, true, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, false, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, qman, tip, true, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, false, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, true, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, qman, tip, true, true), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, false, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, true, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, qman, tip, true, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, tip, false), false);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, tip, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, tip, false ), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, tip, true), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, tip, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, tip, true), Params().IsTestChain());
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, tip, false), true);
BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, tip, true), true);
}

BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup)
{
assert(m_node.llmq_ctx->qman);
Test(*m_node.llmq_ctx->qman, m_node);
Test(m_node);
}

BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_mainnet, TestingSetup)
{
assert(m_node.llmq_ctx->qman);
Test(*m_node.llmq_ctx->qman, m_node);
Test(m_node);
}

BOOST_AUTO_TEST_SUITE_END()
5 changes: 2 additions & 3 deletions test/functional/feature_llmq_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ def run_test(self):

q_100_0 = QuorumId(100, int(quorum_info_0_0["quorumHash"], 16))
q_102_0 = QuorumId(102, int(quorum_info_0_0["quorumHash"], 16))
q_104_0 = QuorumId(104, int(quorum_info_0_0["quorumHash"], 16))
q_103_0_0 = QuorumId(103, int(quorum_info_0_0["quorumHash"], 16))
q_103_0_1 = QuorumId(103, int(quorum_info_0_1["quorumHash"], 16))

b_1 = self.nodes[0].getbestblockhash()
expectedDeleted = [h_100_0, h_104_0]
expectedNew = [q_100_0, q_102_0, q_104_0, q_103_0_0, q_103_0_1]
expectedDeleted = [h_100_0]
expectedNew = [q_100_0, q_102_0, q_103_0_0, q_103_0_1]
quorumList = self.test_getmnlistdiff_quorums(b_0, b_1, quorumList, expectedDeleted, expectedNew)

self.log.info("Wait for chainlock")
Expand Down
2 changes: 0 additions & 2 deletions test/lint/lint-circular-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"evo/simplifiedmns -> llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns"
"llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> llmq/blockprocessor"
"llmq/context -> llmq/dkgsessionmgr -> net_processing -> llmq/context"
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/quorums -> llmq/dkgsession"
"llmq/dkgsessionmgr -> llmq/quorums -> llmq/dkgsessionmgr"
"llmq/commitment -> llmq/utils -> llmq/snapshot -> llmq/commitment"
"spork -> validation -> spork"
"governance/governance -> validation -> governance/governance"
Expand Down

0 comments on commit f52d5aa

Please sign in to comment.