refactor(llmq): substitute memberless class llmq::CLLMQUtils with namespace llmq::utils (#4931)

* refactor(llmq): substitute memberless class llmq::CLLMQUtils with namespace llmq::utils

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* chore: mark functions internal to `llmq::utils` as `static`

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
Kittywhiskers Van Gogh 2022-08-02 22:44:25 +05:30 committed by GitHub
parent 7588c5a441
commit bb7d6aed99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 259 additions and 245 deletions

View File

@ -7,7 +7,7 @@
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <evo/specialtx.h> #include <evo/specialtx.h>
#include <evo/providertx.h> #include <evo/providertx.h>
#include <llmq/commitment.h> #include <logging.h>
#include <hash.h> #include <hash.h>
#include <script/script.h> #include <script/script.h>
#include <script/standard.h> #include <script/standard.h>

View File

@ -6,6 +6,7 @@
#include <evo/deterministicmns.h> #include <evo/deterministicmns.h>
#include <llmq/blockprocessor.h> #include <llmq/blockprocessor.h>
#include <llmq/commitment.h> #include <llmq/commitment.h>
#include <llmq/utils.h>
#include <evo/simplifiedmns.h> #include <evo/simplifiedmns.h>
#include <evo/specialtx.h> #include <evo/specialtx.h>
#include <consensus/validation.h> #include <consensus/validation.h>
@ -183,7 +184,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
uint256 minedBlockHash; uint256 minedBlockHash;
llmq::CFinalCommitmentPtr qc = llmq::quorumBlockProcessor->GetMinedCommitment(p.first, p2->GetBlockHash(), minedBlockHash); llmq::CFinalCommitmentPtr qc = llmq::quorumBlockProcessor->GetMinedCommitment(p.first, p2->GetBlockHash(), minedBlockHash);
if (qc == nullptr) return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "commitment-not-found"); if (qc == nullptr) return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "commitment-not-found");
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(qc->llmqType, pindexPrev)) { if (llmq::utils::IsQuorumRotationEnabled(qc->llmqType, pindexPrev)) {
auto& qi = qcIndexedHashes[p.first]; auto& qi = qcIndexedHashes[p.first];
qi.insert(std::make_pair(qc->quorumIndex, ::SerializeHash(*qc))); qi.insert(std::make_pair(qc->quorumIndex, ::SerializeHash(*qc)));
continue; continue;
@ -213,7 +214,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
auto qcHash = ::SerializeHash(qc.commitment); auto qcHash = ::SerializeHash(qc.commitment);
const auto& llmq_params = llmq::GetLLMQParams(qc.commitment.llmqType); const auto& llmq_params = llmq::GetLLMQParams(qc.commitment.llmqType);
auto& v = qcHashes[llmq_params.type]; auto& v = qcHashes[llmq_params.type];
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(qc.commitment.llmqType, pindexPrev)) { if (llmq::utils::IsQuorumRotationEnabled(qc.commitment.llmqType, pindexPrev)) {
auto& qi = qcIndexedHashes[qc.commitment.llmqType]; auto& qi = qcIndexedHashes[qc.commitment.llmqType];
qi[qc.commitment.quorumIndex] = qcHash; qi[qc.commitment.quorumIndex] = qcHash;
continue; continue;

View File

@ -878,7 +878,7 @@ void CDeterministicMNManager::HandleQuorumCommitment(const llmq::CFinalCommitmen
{ {
// The commitment has already been validated at this point, so it's safe to use members of it // The commitment has already been validated at this point, so it's safe to use members of it
auto members = llmq::CLLMQUtils::GetAllQuorumMembers(qc.llmqType, pQuorumBaseBlockIndex); auto members = llmq::utils::GetAllQuorumMembers(qc.llmqType, pQuorumBaseBlockIndex);
for (size_t i = 0; i < members.size(); i++) { for (size_t i = 0; i < members.size(); i++) {
if (!mnList.HasMN(members[i]->proTxHash)) { if (!mnList.HasMN(members[i]->proTxHash)) {

View File

@ -139,7 +139,7 @@ void CMNAuth::ProcessMessage(CNode* pnode, const std::string& msg_type, CDataStr
if (pnode2->GetVerifiedProRegTxHash() == mnauth.proRegTxHash) { if (pnode2->GetVerifiedProRegTxHash() == mnauth.proRegTxHash) {
if (fMasternodeMode) { if (fMasternodeMode) {
const auto deterministicOutbound = WITH_LOCK(activeMasternodeInfoCs, return llmq::CLLMQUtils::DeterministicOutboundConnection(activeMasternodeInfo.proTxHash, mnauth.proRegTxHash)); const auto deterministicOutbound = WITH_LOCK(activeMasternodeInfoCs, return llmq::utils::DeterministicOutboundConnection(activeMasternodeInfo.proTxHash, mnauth.proRegTxHash));
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, deterministicOutbound=%s. peer=%d\n", LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode %s has already verified as peer %d, deterministicOutbound=%s. peer=%d\n",
mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), pnode->GetId()); mnauth.proRegTxHash.ToString(), pnode2->GetId(), deterministicOutbound.ToString(), pnode->GetId());
if (WITH_LOCK(activeMasternodeInfoCs, return deterministicOutbound == activeMasternodeInfo.proTxHash)) { if (WITH_LOCK(activeMasternodeInfoCs, return deterministicOutbound == activeMasternodeInfo.proTxHash)) {

View File

@ -7,6 +7,7 @@
#include <evo/specialtx.h> #include <evo/specialtx.h>
#include <llmq/commitment.h> #include <llmq/commitment.h>
#include <llmq/signing.h> #include <llmq/signing.h>
#include <llmq/utils.h>
#include <chain.h> #include <chain.h>
#include <chainparams.h> #include <chainparams.h>

View File

@ -1519,8 +1519,8 @@ bool AppInitParameterInteraction(const ArgsManager& args)
nMaxTipAge = args.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE); nMaxTipAge = args.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
try { try {
const bool fRecoveryEnabled{llmq::CLLMQUtils::QuorumDataRecoveryEnabled()}; const bool fRecoveryEnabled{llmq::utils::QuorumDataRecoveryEnabled()};
const bool fQuorumVvecRequestsEnabled{llmq::CLLMQUtils::GetEnabledQuorumVvecSyncEntries().size() > 0}; const bool fQuorumVvecRequestsEnabled{llmq::utils::GetEnabledQuorumVvecSyncEntries().size() > 0};
if (!fRecoveryEnabled && fQuorumVvecRequestsEnabled) { if (!fRecoveryEnabled && fQuorumVvecRequestsEnabled) {
InitWarning(Untranslated("-llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0")); InitWarning(Untranslated("-llmq-qvvec-sync set but recovery is disabled due to -llmq-data-recovery=0"));
} }

View File

@ -4,6 +4,7 @@
#include <llmq/blockprocessor.h> #include <llmq/blockprocessor.h>
#include <llmq/commitment.h> #include <llmq/commitment.h>
#include <llmq/utils.h>
#include <evo/evodb.h> #include <evo/evodb.h>
#include <evo/specialtx.h> #include <evo/specialtx.h>
@ -37,7 +38,7 @@ static const std::string DB_BEST_BLOCK_UPGRADE = "q_bbu2";
CQuorumBlockProcessor::CQuorumBlockProcessor(CEvoDB &_evoDb, CConnman& _connman) : CQuorumBlockProcessor::CQuorumBlockProcessor(CEvoDB &_evoDb, CConnman& _connman) :
evoDb(_evoDb), connman(_connman) evoDb(_evoDb), connman(_connman)
{ {
CLLMQUtils::InitQuorumsCache(mapHasMinedCommitmentCache); utils::InitQuorumsCache(mapHasMinedCommitmentCache);
} }
void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv) void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv)
@ -130,7 +131,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
return true; return true;
} }
llmq::CLLMQUtils::PreComputeQuorumMembers(pindex); llmq::utils::PreComputeQuorumMembers(pindex);
std::multimap<Consensus::LLMQType, CFinalCommitment> qcs; std::multimap<Consensus::LLMQType, CFinalCommitment> qcs;
if (!GetCommitmentsFromBlock(block, pindex, qcs, state)) { if (!GetCommitmentsFromBlock(block, pindex, qcs, state)) {
@ -143,7 +144,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
// until the first non-null commitment has been mined. After the non-null commitment, no other commitments are // until the first non-null commitment has been mined. After the non-null commitment, no other commitments are
// allowed, including null commitments. // allowed, including null commitments.
// Note: must only check quorums that were enabled at the _previous_ block height to match mining logic // Note: must only check quorums that were enabled at the _previous_ block height to match mining logic
for (const Consensus::LLMQParams& params : CLLMQUtils::GetEnabledQuorumParams(pindex->pprev)) { for (const Consensus::LLMQParams& params : utils::GetEnabledQuorumParams(pindex->pprev)) {
// skip these checks when replaying blocks after the crash // skip these checks when replaying blocks after the crash
if (::ChainActive().Tip() == nullptr) { if (::ChainActive().Tip() == nullptr) {
break; break;
@ -159,7 +160,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
if (numCommitmentsRequired > numCommitmentsInNewBlock) { if (numCommitmentsRequired > numCommitmentsInNewBlock) {
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-qc-missing"); return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-qc-missing");
} }
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(params.type, pindex)) { if (llmq::utils::IsQuorumRotationEnabled(params.type, pindex)) {
LogPrintf("[ProcessBlock] h[%d] numCommitmentsRequired[%d] numCommitmentsInNewBlock[%d]\n", pindex->nHeight, numCommitmentsRequired, numCommitmentsInNewBlock); LogPrintf("[ProcessBlock] h[%d] numCommitmentsRequired[%d] numCommitmentsInNewBlock[%d]\n", pindex->nHeight, numCommitmentsRequired, numCommitmentsInNewBlock);
} }
} }
@ -249,7 +250,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
return true; return true;
} }
bool rotation_enabled = CLLMQUtils::IsQuorumRotationEnabled(llmq_params.type, pQuorumBaseBlockIndex); bool rotation_enabled = utils::IsQuorumRotationEnabled(llmq_params.type, pQuorumBaseBlockIndex);
if (rotation_enabled) { if (rotation_enabled) {
LogPrint(BCLog::LLMQ, "[ProcessCommitment] height[%d] pQuorumBaseBlockIndex[%d] quorumIndex[%d] qversion[%d] Built\n", LogPrint(BCLog::LLMQ, "[ProcessCommitment] height[%d] pQuorumBaseBlockIndex[%d] quorumIndex[%d] qversion[%d] Built\n",
@ -297,7 +298,7 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
evoDb.Erase(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash))); evoDb.Erase(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)));
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(qc.llmqType, pindex)) { if (llmq::utils::IsQuorumRotationEnabled(qc.llmqType, pindex)) {
evoDb.Erase(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex))); evoDb.Erase(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex)));
} else { } else {
evoDb.Erase(BuildInversedHeightKey(qc.llmqType, pindex->nHeight)); evoDb.Erase(BuildInversedHeightKey(qc.llmqType, pindex->nHeight));
@ -356,7 +357,7 @@ bool CQuorumBlockProcessor::UpgradeDB()
} }
const auto* pQuorumBaseBlockIndex = LookupBlockIndex(qc.quorumHash); const auto* pQuorumBaseBlockIndex = LookupBlockIndex(qc.quorumHash);
evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash())); evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash()));
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(qc.llmqType, pQuorumBaseBlockIndex)) { if (llmq::utils::IsQuorumRotationEnabled(qc.llmqType, pQuorumBaseBlockIndex)) {
evoDb.GetRawDB().Write(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex)), pQuorumBaseBlockIndex->nHeight); evoDb.GetRawDB().Write(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex)), pQuorumBaseBlockIndex->nHeight);
} else { } else {
evoDb.GetRawDB().Write(BuildInversedHeightKey(qc.llmqType, pindex->nHeight), pQuorumBaseBlockIndex->nHeight); evoDb.GetRawDB().Write(BuildInversedHeightKey(qc.llmqType, pindex->nHeight), pQuorumBaseBlockIndex->nHeight);
@ -391,7 +392,7 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const C
} }
// only allow one commitment per type and per block (This was changed with rotation) // only allow one commitment per type and per block (This was changed with rotation)
if (!CLLMQUtils::IsQuorumRotationEnabled(qc.commitment.llmqType, pindex)) { if (!utils::IsQuorumRotationEnabled(qc.commitment.llmqType, pindex)) {
if (ret.count(qc.commitment.llmqType) != 0) { if (ret.count(qc.commitment.llmqType) != 0) {
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-qc-dup"); return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-qc-dup");
} }
@ -438,7 +439,7 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar
assert(nHeight <= ::ChainActive().Height() + 1); assert(nHeight <= ::ChainActive().Height() + 1);
const auto *const pindex = ::ChainActive().Height() < nHeight ? ::ChainActive().Tip() : ::ChainActive().Tip()->GetAncestor(nHeight); const auto *const pindex = ::ChainActive().Height() < nHeight ? ::ChainActive().Tip() : ::ChainActive().Tip()->GetAncestor(nHeight);
bool rotation_enabled = CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindex); bool rotation_enabled = utils::IsQuorumRotationEnabled(llmqParams.type, pindex);
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1; size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;
size_t ret{0}; size_t ret{0};
@ -640,7 +641,7 @@ std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> CQuorumBlockProce
for (const auto& params : Params().GetConsensus().llmqs) { for (const auto& params : Params().GetConsensus().llmqs) {
auto& v = ret[params.type]; auto& v = ret[params.type];
v.reserve(params.signingActiveQuorumCount); v.reserve(params.signingActiveQuorumCount);
if (CLLMQUtils::IsQuorumRotationEnabled(params.type, pindex)) { if (utils::IsQuorumRotationEnabled(params.type, pindex)) {
std::vector<std::pair<int, const CBlockIndex*>> commitments = GetLastMinedCommitmentsPerQuorumIndexUntilBlock(params.type, pindex, 0); std::vector<std::pair<int, const CBlockIndex*>> commitments = GetLastMinedCommitmentsPerQuorumIndexUntilBlock(params.type, pindex, 0);
std::transform(commitments.begin(), commitments.end(), std::back_inserter(v), std::transform(commitments.begin(), commitments.end(), std::back_inserter(v),
[](const std::pair<int, const CBlockIndex*>& p) { return p.second; }); [](const std::pair<int, const CBlockIndex*>& p) { return p.second; });
@ -719,7 +720,7 @@ std::optional<std::vector<CFinalCommitment>> CQuorumBlockProcessor::GetMineableC
assert(nHeight <= ::ChainActive().Height() + 1); assert(nHeight <= ::ChainActive().Height() + 1);
const auto *const pindex = ::ChainActive().Height() < nHeight ? ::ChainActive().Tip() : ::ChainActive().Tip()->GetAncestor(nHeight); const auto *const pindex = ::ChainActive().Height() < nHeight ? ::ChainActive().Tip() : ::ChainActive().Tip()->GetAncestor(nHeight);
bool rotation_enabled = CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindex); bool rotation_enabled = utils::IsQuorumRotationEnabled(llmqParams.type, pindex);
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1; size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;
std::stringstream ss; std::stringstream ss;

View File

@ -9,8 +9,8 @@
#include <chainparams.h> #include <chainparams.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <llmq/utils.h>
#include <logging.h> #include <logging.h>
#include <util/irange.h>
#include <validation.h> #include <validation.h>
namespace llmq namespace llmq
@ -30,7 +30,7 @@ CFinalCommitment::CFinalCommitment(const Consensus::LLMQParams& params, const ui
bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool checkSigs) const bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool checkSigs) const
{ {
if (nVersion == 0 || nVersion != (CLLMQUtils::IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex) ? INDEXED_QUORUM_VERSION : CURRENT_VERSION)) { if (nVersion == 0 || nVersion != (utils::IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex) ? INDEXED_QUORUM_VERSION : CURRENT_VERSION)) {
LogPrintfFinalCommitment("q[%s] invalid nVersion=%d\n", quorumHash.ToString(), nVersion); LogPrintfFinalCommitment("q[%s] invalid nVersion=%d\n", quorumHash.ToString(), nVersion);
return false; return false;
} }
@ -79,7 +79,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool che
LogPrintfFinalCommitment("q[%s] invalid vvecSig\n"); LogPrintfFinalCommitment("q[%s] invalid vvecSig\n");
return false; return false;
} }
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); auto members = utils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
if (LogAcceptCategory(BCLog::LLMQ)) { if (LogAcceptCategory(BCLog::LLMQ)) {
std::stringstream ss; std::stringstream ss;
std::stringstream ss2; std::stringstream ss2;
@ -103,7 +103,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool che
// sigs are only checked when the block is processed // sigs are only checked when the block is processed
if (checkSigs) { if (checkSigs) {
uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(llmq_params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash); uint256 commitmentHash = utils::BuildCommitmentHash(llmq_params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
if (LogAcceptCategory(BCLog::LLMQ)) { if (LogAcceptCategory(BCLog::LLMQ)) {
std::stringstream ss3; std::stringstream ss3;
for (const auto &mn: members) { for (const auto &mn: members) {

View File

@ -5,11 +5,15 @@
#ifndef BITCOIN_LLMQ_COMMITMENT_H #ifndef BITCOIN_LLMQ_COMMITMENT_H
#define BITCOIN_LLMQ_COMMITMENT_H #define BITCOIN_LLMQ_COMMITMENT_H
#include <llmq/utils.h>
#include <bls/bls.h> #include <bls/bls.h>
#include <consensus/params.h>
#include <primitives/transaction.h>
#include <util/irange.h>
#include <util/strencodings.h>
#include <univalue.h> #include <univalue.h>
class CBlockIndex;
class CValidationState; class CValidationState;
namespace llmq namespace llmq
@ -105,14 +109,24 @@ public:
obj.pushKV("quorumHash", quorumHash.ToString()); obj.pushKV("quorumHash", quorumHash.ToString());
obj.pushKV("quorumIndex", quorumIndex); obj.pushKV("quorumIndex", quorumIndex);
obj.pushKV("signersCount", CountSigners()); obj.pushKV("signersCount", CountSigners());
obj.pushKV("signers", CLLMQUtils::ToHexStr(signers)); obj.pushKV("signers", BitsVectorToHexStr(signers));
obj.pushKV("validMembersCount", CountValidMembers()); obj.pushKV("validMembersCount", CountValidMembers());
obj.pushKV("validMembers", CLLMQUtils::ToHexStr(validMembers)); obj.pushKV("validMembers", BitsVectorToHexStr(validMembers));
obj.pushKV("quorumPublicKey", quorumPublicKey.ToString()); obj.pushKV("quorumPublicKey", quorumPublicKey.ToString());
obj.pushKV("quorumVvecHash", quorumVvecHash.ToString()); obj.pushKV("quorumVvecHash", quorumVvecHash.ToString());
obj.pushKV("quorumSig", quorumSig.ToString()); obj.pushKV("quorumSig", quorumSig.ToString());
obj.pushKV("membersSig", membersSig.ToString()); obj.pushKV("membersSig", membersSig.ToString());
} }
private:
static std::string BitsVectorToHexStr(const std::vector<bool>& vBits)
{
std::vector<uint8_t> vBytes((vBits.size() + 7) / 8);
for (const auto i : irange::range(vBits.size())) {
vBytes[i / 8] |= vBits[i] << (i % 8);
}
return HexStr(vBytes);
}
}; };
using CFinalCommitmentPtr = std::unique_ptr<CFinalCommitment>; using CFinalCommitmentPtr = std::unique_ptr<CFinalCommitment>;

View File

@ -28,7 +28,7 @@ UniValue CDKGDebugSessionStatus::ToJson(int quorumIndex, int detailLevel) const
if (detailLevel == 2) { if (detailLevel == 2) {
const CBlockIndex* pindex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash)); const CBlockIndex* pindex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash));
if (pindex != nullptr) { if (pindex != nullptr) {
dmnMembers = CLLMQUtils::GetAllQuorumMembers(llmqType, pindex); dmnMembers = utils::GetAllQuorumMembers(llmqType, pindex);
} }
} }

View File

@ -100,7 +100,7 @@ bool CDKGSession::Init(const CBlockIndex* _pQuorumBaseBlockIndex, const std::vec
CDKGLogger logger(*this, __func__); CDKGLogger logger(*this, __func__);
if (CLLMQUtils::IsQuorumRotationEnabled(params.type, m_quorum_base_block_index)) { if (utils::IsQuorumRotationEnabled(params.type, m_quorum_base_block_index)) {
int cycleQuorumBaseHeight = m_quorum_base_block_index->nHeight - quorumIndex; int cycleQuorumBaseHeight = m_quorum_base_block_index->nHeight - quorumIndex;
const CBlockIndex* pCycleQuorumBaseBlockIndex = m_quorum_base_block_index->GetAncestor(cycleQuorumBaseHeight); const CBlockIndex* pCycleQuorumBaseBlockIndex = m_quorum_base_block_index->GetAncestor(cycleQuorumBaseHeight);
std::stringstream ss; std::stringstream ss;
@ -117,7 +117,7 @@ bool CDKGSession::Init(const CBlockIndex* _pQuorumBaseBlockIndex, const std::vec
if (!myProTxHash.IsNull()) { if (!myProTxHash.IsNull()) {
quorumDKGDebugManager->InitLocalSessionStatus(params, quorumIndex, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight); quorumDKGDebugManager->InitLocalSessionStatus(params, quorumIndex, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight);
relayMembers = CLLMQUtils::GetQuorumRelayMembers(params, m_quorum_base_block_index, myProTxHash, true); relayMembers = utils::GetQuorumRelayMembers(params, m_quorum_base_block_index, myProTxHash, true);
std::stringstream ss; std::stringstream ss;
for (const auto& r : relayMembers) { for (const auto& r : relayMembers) {
ss << r.ToString().substr(0, 4) << " | "; ss << r.ToString().substr(0, 4) << " | ";
@ -445,7 +445,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
void CDKGSession::VerifyConnectionAndMinProtoVersions() const void CDKGSession::VerifyConnectionAndMinProtoVersions() const
{ {
if (!CLLMQUtils::IsQuorumPoseEnabled(params.type)) { if (!utils::IsQuorumPoseEnabled(params.type)) {
return; return;
} }
@ -460,7 +460,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions() const
protoMap.emplace(verifiedProRegTxHash, pnode->nVersion); protoMap.emplace(verifiedProRegTxHash, pnode->nVersion);
}); });
bool fShouldAllMembersBeConnected = CLLMQUtils::IsAllMembersConnectedEnabled(params.type); bool fShouldAllMembersBeConnected = utils::IsAllMembersConnectedEnabled(params.type);
for (const auto& m : members) { for (const auto& m : members) {
if (m->dmn->proTxHash == myProTxHash) { if (m->dmn->proTxHash == myProTxHash) {
continue; continue;
@ -992,7 +992,7 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
(*qc.quorumVvecHash.begin())++; (*qc.quorumVvecHash.begin())++;
} }
uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(qc.llmqType, qc.quorumHash, qc.validMembers, qc.quorumPublicKey, qc.quorumVvecHash); uint256 commitmentHash = utils::BuildCommitmentHash(qc.llmqType, qc.quorumHash, qc.validMembers, qc.quorumPublicKey, qc.quorumVvecHash);
if (lieType == 2) { if (lieType == 2) {
(*commitmentHash.begin())++; (*commitmentHash.begin())++;
@ -1219,14 +1219,14 @@ std::vector<CFinalCommitment> CDKGSession::FinalizeCommitments()
fqc.quorumPublicKey = first.quorumPublicKey; fqc.quorumPublicKey = first.quorumPublicKey;
fqc.quorumVvecHash = first.quorumVvecHash; fqc.quorumVvecHash = first.quorumVvecHash;
if (CLLMQUtils::IsQuorumRotationEnabled(fqc.llmqType, m_quorum_base_block_index)) { if (utils::IsQuorumRotationEnabled(fqc.llmqType, m_quorum_base_block_index)) {
fqc.nVersion = CFinalCommitment::INDEXED_QUORUM_VERSION; fqc.nVersion = CFinalCommitment::INDEXED_QUORUM_VERSION;
fqc.quorumIndex = quorumIndex; fqc.quorumIndex = quorumIndex;
} else { } else {
fqc.quorumIndex = 0; fqc.quorumIndex = 0;
} }
uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(fqc.llmqType, fqc.quorumHash, fqc.validMembers, fqc.quorumPublicKey, fqc.quorumVvecHash); uint256 commitmentHash = utils::BuildCommitmentHash(fqc.llmqType, fqc.quorumHash, fqc.validMembers, fqc.quorumPublicKey, fqc.quorumVvecHash);
std::vector<CBLSSignature> aggSigs; std::vector<CBLSSignature> aggSigs;
std::vector<CBLSPublicKey> aggPks; std::vector<CBLSPublicKey> aggPks;

View File

@ -183,7 +183,7 @@ public:
[[nodiscard]] uint256 GetSignHash() const [[nodiscard]] uint256 GetSignHash() const
{ {
return CLLMQUtils::BuildCommitmentHash(llmqType, quorumHash, validMembers, quorumPublicKey, quorumVvecHash); return utils::BuildCommitmentHash(llmqType, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
} }
}; };

View File

@ -84,7 +84,7 @@ void CDKGSessionHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
{ {
//AssertLockNotHeld(cs_main); //AssertLockNotHeld(cs_main);
//Indexed quorums (greater than 0) are enabled with Quorum Rotation //Indexed quorums (greater than 0) are enabled with Quorum Rotation
if (quorumIndex > 0 && !CLLMQUtils::IsQuorumRotationEnabled(params.type, pindexNew)) { if (quorumIndex > 0 && !utils::IsQuorumRotationEnabled(params.type, pindexNew)) {
return; return;
} }
LOCK(cs); LOCK(cs);
@ -147,7 +147,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
return false; return false;
} }
auto mns = CLLMQUtils::GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex); auto mns = utils::GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex);
if (!curSession->Init(pQuorumBaseBlockIndex, mns, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash), quorumIndex)) { if (!curSession->Init(pQuorumBaseBlockIndex, mns, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash), quorumIndex)) {
LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size()); LogPrintf("CDKGSessionManager::%s -- height[%d] quorum initialization failed for %s qi[%d] mns[%d]\n", __func__, pQuorumBaseBlockIndex->nHeight, curSession->params.name, quorumIndex, mns.size());
return false; return false;
@ -487,9 +487,9 @@ void CDKGSessionHandler::HandleDKGRound()
return changed; return changed;
}); });
CLLMQUtils::EnsureQuorumConnections(params, pQuorumBaseBlockIndex, connman, curSession->myProTxHash); utils::EnsureQuorumConnections(params, pQuorumBaseBlockIndex, connman, curSession->myProTxHash);
if (curSession->AreWeMember()) { if (curSession->AreWeMember()) {
CLLMQUtils::AddQuorumProbeConnections(params, pQuorumBaseBlockIndex, connman, curSession->myProTxHash); utils::AddQuorumProbeConnections(params, pQuorumBaseBlockIndex, connman, curSession->myProTxHash);
} }
WaitForNextPhase(QuorumPhase::Initialized, QuorumPhase::Contribute, curQuorumHash); WaitForNextPhase(QuorumPhase::Initialized, QuorumPhase::Contribute, curQuorumHash);

View File

@ -207,7 +207,7 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
{ {
LOCK(cs_indexedQuorumsCache); LOCK(cs_indexedQuorumsCache);
if (indexedQuorumsCache.empty()) { if (indexedQuorumsCache.empty()) {
CLLMQUtils::InitQuorumsCache(indexedQuorumsCache); utils::InitQuorumsCache(indexedQuorumsCache);
} }
indexedQuorumsCache[llmqType].get(quorumHash, quorumIndex); indexedQuorumsCache[llmqType].get(quorumHash, quorumIndex);
} }
@ -223,7 +223,7 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
return; return;
} }
if (!CLLMQUtils::IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) { if (!utils::IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) {
LOCK(cs_main); LOCK(cs_main);
LogPrintf("CDKGSessionManager -- llmqType [%d] quorums aren't active\n", uint8_t(llmqType)); LogPrintf("CDKGSessionManager -- llmqType [%d] quorums aren't active\n", uint8_t(llmqType));
Misbehaving(pfrom->GetId(), 100); Misbehaving(pfrom->GetId(), 100);
@ -232,7 +232,7 @@ void CDKGSessionManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType); const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType);
quorumIndex = pQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval; quorumIndex = pQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval;
int quorumIndexMax = CLLMQUtils::IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex) ? int quorumIndexMax = utils::IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex) ?
llmqParams.signingActiveQuorumCount - 1 : 0; llmqParams.signingActiveQuorumCount - 1 : 0;
if (quorumIndex > quorumIndexMax) { if (quorumIndex > quorumIndexMax) {
@ -374,7 +374,7 @@ void CDKGSessionManager::WriteEncryptedContributions(Consensus::LLMQType llmqTyp
bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector<bool>& validMembers, std::vector<uint16_t>& memberIndexesRet, std::vector<BLSVerificationVectorPtr>& vvecsRet, BLSSecretKeyVector& skContributionsRet) const bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector<bool>& validMembers, std::vector<uint16_t>& memberIndexesRet, std::vector<BLSVerificationVectorPtr>& vvecsRet, BLSSecretKeyVector& skContributionsRet) const
{ {
LOCK(contributionsCacheCs); LOCK(contributionsCacheCs);
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); auto members = utils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
memberIndexesRet.clear(); memberIndexesRet.clear();
vvecsRet.clear(); vvecsRet.clear();
@ -408,7 +408,7 @@ bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType,
bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector<bool>& validMembers, const uint256& nProTxHash, std::vector<CBLSIESEncryptedObject<CBLSSecretKey>>& vecRet) const bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector<bool>& validMembers, const uint256& nProTxHash, std::vector<CBLSIESEncryptedObject<CBLSSecretKey>>& vecRet) const
{ {
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); auto members = utils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
vecRet.clear(); vecRet.clear();
vecRet.reserve(members.size()); vecRet.reserve(members.size());

View File

@ -509,7 +509,7 @@ void CInstantSendManager::ProcessTx(const CTransaction& tx, bool fRetroactive, c
// block after we retroactively locked all transactions. // block after we retroactively locked all transactions.
if (!IsInstantSendMempoolSigningEnabled() && !fRetroactive) return; if (!IsInstantSendMempoolSigningEnabled() && !fRetroactive) return;
if (!TrySignInputLocks(tx, fRetroactive, CLLMQUtils::GetInstantSendLLMQType(WITH_LOCK(cs_main, return ::ChainActive().Tip())), params)) { if (!TrySignInputLocks(tx, fRetroactive, utils::GetInstantSendLLMQType(WITH_LOCK(cs_main, return ::ChainActive().Tip())), params)) {
return; return;
} }
@ -683,7 +683,7 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
void CInstantSendManager::TrySignInstantSendLock(const CTransaction& tx) void CInstantSendManager::TrySignInstantSendLock(const CTransaction& tx)
{ {
const auto llmqType = CLLMQUtils::GetInstantSendLLMQType(WITH_LOCK(cs_main, return ::ChainActive().Tip())); const auto llmqType = utils::GetInstantSendLLMQType(WITH_LOCK(cs_main, return ::ChainActive().Tip()));
for (const auto& in : tx.vin) { for (const auto& in : tx.vin) {
auto id = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in.prevout)); auto id = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in.prevout));
@ -783,7 +783,7 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode* pfrom, cons
{ {
LOCK(cs_main); LOCK(cs_main);
EraseObjectRequest(pfrom->GetId(), CInv(islock->IsDeterministic() ? MSG_ISDLOCK : MSG_ISLOCK, hash)); EraseObjectRequest(pfrom->GetId(), CInv(islock->IsDeterministic() ? MSG_ISDLOCK : MSG_ISLOCK, hash));
fDIP0024IsActive = CLLMQUtils::IsDIP0024Active(::ChainActive().Tip()); fDIP0024IsActive = utils::IsDIP0024Active(::ChainActive().Tip());
} }
if (!PreVerifyInstantSendLock(*islock)) { if (!PreVerifyInstantSendLock(*islock)) {
@ -810,7 +810,7 @@ void CInstantSendManager::ProcessMessageInstantSendLock(const CNode* pfrom, cons
} }
// WE MUST STILL PROCESS OLD ISLOCKS? // WE MUST STILL PROCESS OLD ISLOCKS?
// else if (CLLMQUtils::IsDIP0024Active(WITH_LOCK(cs_main, return ::ChainActive().Tip()))) { // else if (utils::IsDIP0024Active(WITH_LOCK(cs_main, return ::ChainActive().Tip()))) {
// // Ignore non-deterministic islocks once rotation is active // // Ignore non-deterministic islocks once rotation is active
// return; // return;
// } // }
@ -852,7 +852,7 @@ bool CInstantSendManager::PreVerifyInstantSendLock(const llmq::CInstantSendLock&
bool CInstantSendManager::ProcessPendingInstantSendLocks() bool CInstantSendManager::ProcessPendingInstantSendLocks()
{ {
const CBlockIndex* pBlockIndexTip = WITH_LOCK(cs_main, return ::ChainActive().Tip()); const CBlockIndex* pBlockIndexTip = WITH_LOCK(cs_main, return ::ChainActive().Tip());
if (pBlockIndexTip && CLLMQUtils::GetInstantSendLLMQType(pBlockIndexTip) == Params().GetConsensus().llmqTypeDIP0024InstantSend) { if (pBlockIndexTip && utils::GetInstantSendLLMQType(pBlockIndexTip) == Params().GetConsensus().llmqTypeDIP0024InstantSend) {
// Don't short circuit. Try to process deterministic and not deterministic islocks // Don't short circuit. Try to process deterministic and not deterministic islocks
return ProcessPendingInstantSendLocks(true) & ProcessPendingInstantSendLocks(false); return ProcessPendingInstantSendLocks(true) & ProcessPendingInstantSendLocks(false);
} else { } else {
@ -903,7 +903,7 @@ bool CInstantSendManager::ProcessPendingInstantSendLocks(bool deterministic)
} }
//TODO Investigate if leaving this is ok //TODO Investigate if leaving this is ok
auto llmqType = CLLMQUtils::GetInstantSendLLMQType(deterministic); auto llmqType = utils::GetInstantSendLLMQType(deterministic);
auto dkgInterval = GetLLMQParams(llmqType).dkgInterval; auto dkgInterval = GetLLMQParams(llmqType).dkgInterval;
// First check against the current active set and don't ban // First check against the current active set and don't ban
@ -976,7 +976,7 @@ std::unordered_set<uint256, StaticSaltedHasher> CInstantSendManager::ProcessPend
// should not happen, but if one fails to select, all others will also fail to select // should not happen, but if one fails to select, all others will also fail to select
return {}; return {};
} }
uint256 signHash = CLLMQUtils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, islock->txid); uint256 signHash = utils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, islock->txid);
batchVerifier.PushMessage(nodeId, hash, signHash, islock->sig.Get(), quorum->qc->quorumPublicKey); batchVerifier.PushMessage(nodeId, hash, signHash, islock->sig.Get(), quorum->qc->quorumPublicKey);
verifyCount++; verifyCount++;
@ -1306,7 +1306,7 @@ void CInstantSendManager::TruncateRecoveredSigsForInputs(const llmq::CInstantSen
for (const auto& in : islock.inputs) { for (const auto& in : islock.inputs) {
auto inputRequestId = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in)); auto inputRequestId = ::SerializeHash(std::make_pair(INPUTLOCK_REQUESTID_PREFIX, in));
WITH_LOCK(cs_inputReqests, inputRequestIds.erase(inputRequestId)); WITH_LOCK(cs_inputReqests, inputRequestIds.erase(inputRequestId));
quorumSigningManager->TruncateRecoveredSig(CLLMQUtils::GetInstantSendLLMQType(islock.IsDeterministic()), inputRequestId); quorumSigningManager->TruncateRecoveredSig(utils::GetInstantSendLLMQType(islock.IsDeterministic()), inputRequestId);
} }
} }
@ -1357,7 +1357,7 @@ void CInstantSendManager::HandleFullyConfirmedBlock(const CBlockIndex* pindex)
// And we don't need the recovered sig for the ISLOCK anymore, as the block in which it got mined is considered // And we don't need the recovered sig for the ISLOCK anymore, as the block in which it got mined is considered
// fully confirmed now // fully confirmed now
quorumSigningManager->TruncateRecoveredSig(CLLMQUtils::GetInstantSendLLMQType(islock->IsDeterministic()), islock->GetRequestId()); quorumSigningManager->TruncateRecoveredSig(utils::GetInstantSendLLMQType(islock->IsDeterministic()), islock->GetRequestId());
} }
db.RemoveArchivedInstantSendLocks(pindex->nHeight - 100); db.RemoveArchivedInstantSendLocks(pindex->nHeight - 100);

View File

@ -192,8 +192,8 @@ CQuorumManager::CQuorumManager(CEvoDB& _evoDb, CConnman& _connman, CBLSWorker& _
blsWorker(_blsWorker), blsWorker(_blsWorker),
dkgManager(_dkgManager) dkgManager(_dkgManager)
{ {
CLLMQUtils::InitQuorumsCache(mapQuorumsCache); utils::InitQuorumsCache(mapQuorumsCache);
CLLMQUtils::InitQuorumsCache(scanQuorumsCache); utils::InitQuorumsCache(scanQuorumsCache);
quorumThreadInterrupt.reset(); quorumThreadInterrupt.reset();
} }
@ -215,11 +215,11 @@ void CQuorumManager::Stop()
void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const void CQuorumManager::TriggerQuorumDataRecoveryThreads(const CBlockIndex* pIndex) const
{ {
if (!fMasternodeMode || !CLLMQUtils::QuorumDataRecoveryEnabled() || pIndex == nullptr) { if (!fMasternodeMode || !utils::QuorumDataRecoveryEnabled() || pIndex == nullptr) {
return; return;
} }
const std::map<Consensus::LLMQType, QvvecSyncMode> mapQuorumVvecSync = CLLMQUtils::GetEnabledQuorumVvecSyncEntries(); const std::map<Consensus::LLMQType, QvvecSyncMode> mapQuorumVvecSync = utils::GetEnabledQuorumVvecSyncEntries();
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Process block %s\n", __func__, pIndex->GetBlockHash().ToString()); LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Process block %s\n", __func__, pIndex->GetBlockHash().ToString());
@ -297,7 +297,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type); auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type);
// don't remove connections for the currently in-progress DKG round // don't remove connections for the currently in-progress DKG round
if (CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindexNew)) { if (utils::IsQuorumRotationEnabled(llmqParams.type, pindexNew)) {
int cycleIndexTipHeight = pindexNew->nHeight % llmqParams.dkgInterval; int cycleIndexTipHeight = pindexNew->nHeight % llmqParams.dkgInterval;
int cycleQuorumBaseHeight = pindexNew->nHeight - cycleIndexTipHeight; int cycleQuorumBaseHeight = pindexNew->nHeight - cycleIndexTipHeight;
std::stringstream ss; std::stringstream ss;
@ -327,13 +327,13 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
}); });
for (const auto& quorum : lastQuorums) { for (const auto& quorum : lastQuorums) {
if (CLLMQUtils::EnsureQuorumConnections(llmqParams, quorum->m_quorum_base_block_index, connman, myProTxHash)) { if (utils::EnsureQuorumConnections(llmqParams, quorum->m_quorum_base_block_index, connman, myProTxHash)) {
if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) { if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, int(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString()); LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, int(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
} }
} else if (watchOtherISQuorums && !quorum->IsMember(myProTxHash)) { } else if (watchOtherISQuorums && !quorum->IsMember(myProTxHash)) {
std::set<uint256> connections; std::set<uint256> connections;
const auto& cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqParams.type, quorum->m_quorum_base_block_index, quorum->members.size(), 1); const auto& cindexes = utils::CalcDeterministicWatchConnections(llmqParams.type, quorum->m_quorum_base_block_index, quorum->members.size(), 1);
for (auto idx : cindexes) { for (auto idx : cindexes) {
connections.emplace(quorum->members[idx]->proTxHash); connections.emplace(quorum->members[idx]->proTxHash);
} }
@ -370,7 +370,7 @@ CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType l
assert(qc->quorumHash == pQuorumBaseBlockIndex->GetBlockHash()); assert(qc->quorumHash == pQuorumBaseBlockIndex->GetBlockHash());
auto quorum = std::make_shared<CQuorum>(llmq::GetLLMQParams(llmqType), blsWorker); auto quorum = std::make_shared<CQuorum>(llmq::GetLLMQParams(llmqType), blsWorker);
auto members = CLLMQUtils::GetAllQuorumMembers(qc->llmqType, pQuorumBaseBlockIndex); auto members = utils::GetAllQuorumMembers(qc->llmqType, pQuorumBaseBlockIndex);
quorum->Init(std::move(qc), pQuorumBaseBlockIndex, minedBlockHash, members); quorum->Init(std::move(qc), pQuorumBaseBlockIndex, minedBlockHash, members);
@ -487,7 +487,7 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp
std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t nCountRequested) const std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t nCountRequested) const
{ {
if (pindexStart == nullptr || nCountRequested == 0 || !CLLMQUtils::IsQuorumTypeEnabled(llmqType, pindexStart)) { if (pindexStart == nullptr || nCountRequested == 0 || !utils::IsQuorumTypeEnabled(llmqType, pindexStart)) {
return {}; return {};
} }
@ -684,7 +684,7 @@ void CQuorumManager::ProcessMessage(CNode* pFrom, const std::string& msg_type, C
} }
if (msg_type == NetMsgType::QDATA) { if (msg_type == NetMsgType::QDATA) {
if ((!fMasternodeMode && !CLLMQUtils::IsWatchQuorumsEnabled()) || pFrom == nullptr || (pFrom->GetVerifiedProRegTxHash().IsNull() && !pFrom->qwatch)) { if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled()) || pFrom == nullptr || (pFrom->GetVerifiedProRegTxHash().IsNull() && !pFrom->qwatch)) {
errorHandler("Not a verified masternode or a qwatch connection"); errorHandler("Not a verified masternode or a qwatch connection");
return; return;
} }

View File

@ -553,7 +553,7 @@ bool CSigningManager::GetRecoveredSigForGetData(const uint256& hash, CRecoveredS
if (!db.GetRecoveredSigByHash(hash, ret)) { if (!db.GetRecoveredSigByHash(hash, ret)) {
return false; return false;
} }
if (!CLLMQUtils::IsQuorumActive(ret.getLlmqType(), ret.getQuorumHash())) { if (!utils::IsQuorumActive(ret.getLlmqType(), ret.getQuorumHash())) {
// we don't want to propagate sigs from inactive quorums // we don't want to propagate sigs from inactive quorums
return false; return false;
} }
@ -621,7 +621,7 @@ bool CSigningManager::PreVerifyRecoveredSig(const CRecoveredSig& recoveredSig, b
recoveredSig.getQuorumHash().ToString()); recoveredSig.getQuorumHash().ToString());
return false; return false;
} }
if (!CLLMQUtils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) { if (!utils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) {
return false; return false;
} }
@ -640,7 +640,7 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
} }
std::unordered_set<std::pair<NodeId, uint256>, StaticSaltedHasher> uniqueSignHashes; std::unordered_set<std::pair<NodeId, uint256>, StaticSaltedHasher> uniqueSignHashes;
CLLMQUtils::IterateNodesRandom(pendingRecoveredSigs, [&]() { utils::IterateNodesRandom(pendingRecoveredSigs, [&]() {
return uniqueSignHashes.size() < maxUniqueSessions; return uniqueSignHashes.size() < maxUniqueSessions;
}, [&](NodeId nodeId, std::list<std::shared_ptr<const CRecoveredSig>>& ns) { }, [&](NodeId nodeId, std::list<std::shared_ptr<const CRecoveredSig>>& ns) {
if (ns.empty()) { if (ns.empty()) {
@ -679,7 +679,7 @@ void CSigningManager::CollectPendingRecoveredSigsToVerify(
it = v.erase(it); it = v.erase(it);
continue; continue;
} }
if (!CLLMQUtils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) { if (!utils::IsQuorumActive(llmqType, quorum->qc->quorumHash)) {
LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not active anymore, node=%d\n", __func__, LogPrint(BCLog::LLMQ, "CSigningManager::%s -- quorum %s not active anymore, node=%d\n", __func__,
recSig->getQuorumHash().ToString(), nodeId); recSig->getQuorumHash().ToString(), nodeId);
it = v.erase(it); it = v.erase(it);
@ -999,7 +999,7 @@ CQuorumCPtr CSigningManager::SelectQuorumForSigning(Consensus::LLMQType llmqType
pindexStart = ::ChainActive()[startBlockHeight]; pindexStart = ::ChainActive()[startBlockHeight];
} }
if (CLLMQUtils::IsQuorumRotationEnabled(llmqType, pindexStart)) { if (utils::IsQuorumRotationEnabled(llmqType, pindexStart)) {
auto quorums = quorumManager->ScanQuorums(llmqType, pindexStart, poolSize); auto quorums = quorumManager->ScanQuorums(llmqType, pindexStart, poolSize);
if (quorums.empty()) { if (quorums.empty()) {
return nullptr; return nullptr;
@ -1050,13 +1050,13 @@ bool CSigningManager::VerifyRecoveredSig(Consensus::LLMQType llmqType, int signe
return false; return false;
} }
uint256 signHash = CLLMQUtils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash); uint256 signHash = utils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash);
return sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash); return sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash);
} }
uint256 CSigBase::buildSignHash() const uint256 CSigBase::buildSignHash() const
{ {
return CLLMQUtils::BuildSignHash(llmqType, quorumHash, id, msgHash); return utils::BuildSignHash(llmqType, quorumHash, id, msgHash);
} }

View File

@ -460,7 +460,7 @@ void CSigSharesManager::ProcessMessageSigShare(NodeId fromId, const CSigShare& s
if (!quorum) { if (!quorum) {
return; return;
} }
if (!CLLMQUtils::IsQuorumActive(sigShare.getLlmqType(), quorum->qc->quorumHash)) { if (!utils::IsQuorumActive(sigShare.getLlmqType(), quorum->qc->quorumHash)) {
// quorum is too old // quorum is too old
return; return;
} }
@ -509,7 +509,7 @@ bool CSigSharesManager::PreVerifyBatchedSigShares(const CSigSharesNodeState::Ses
{ {
retBan = false; retBan = false;
if (!CLLMQUtils::IsQuorumActive(session.llmqType, session.quorum->qc->quorumHash)) { if (!utils::IsQuorumActive(session.llmqType, session.quorum->qc->quorumHash)) {
// quorum is too old // quorum is too old
return false; return false;
} }
@ -564,7 +564,7 @@ void CSigSharesManager::CollectPendingSigSharesToVerify(
// the whole verification process // the whole verification process
std::unordered_set<std::pair<NodeId, uint256>, StaticSaltedHasher> uniqueSignHashes; std::unordered_set<std::pair<NodeId, uint256>, StaticSaltedHasher> uniqueSignHashes;
CLLMQUtils::IterateNodesRandom(nodeStates, [&]() { utils::IterateNodesRandom(nodeStates, [&]() {
return uniqueSignHashes.size() < maxUniqueSessions; return uniqueSignHashes.size() < maxUniqueSessions;
}, [&](NodeId nodeId, CSigSharesNodeState& ns) { }, [&](NodeId nodeId, CSigSharesNodeState& ns) {
if (ns.pendingIncomingSigShares.Empty()) { if (ns.pendingIncomingSigShares.Empty()) {
@ -697,7 +697,7 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
// prepare node set for direct-push in case this is our sig share // prepare node set for direct-push in case this is our sig share
std::set<NodeId> quorumNodes; std::set<NodeId> quorumNodes;
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType) && sigShare.getQuorumMember() == quorum->GetMemberIndex(WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) { if (!utils::IsAllMembersConnectedEnabled(llmqType) && sigShare.getQuorumMember() == quorum->GetMemberIndex(WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash()); quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash());
} }
@ -711,7 +711,7 @@ void CSigSharesManager::ProcessSigShare(const CSigShare& sigShare, const CConnma
if (!sigShares.Add(sigShare.GetKey(), sigShare)) { if (!sigShares.Add(sigShare.GetKey(), sigShare)) {
return; return;
} }
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType)) { if (!utils::IsAllMembersConnectedEnabled(llmqType)) {
sigSharesQueuedToAnnounce.Add(sigShare.GetKey(), true); sigSharesQueuedToAnnounce.Add(sigShare.GetKey(), true);
} }
@ -752,7 +752,7 @@ void CSigSharesManager::TryRecoverSig(const CQuorumCPtr& quorum, const uint256&
{ {
LOCK(cs); LOCK(cs);
auto signHash = CLLMQUtils::BuildSignHash(quorum->params.type, quorum->qc->quorumHash, id, msgHash); auto signHash = utils::BuildSignHash(quorum->params.type, quorum->qc->quorumHash, id, msgHash);
const auto* sigSharesForSignHash = sigShares.GetAllForSignHash(signHash); const auto* sigSharesForSignHash = sigShares.GetAllForSignHash(signHash);
if (sigSharesForSignHash == nullptr) { if (sigSharesForSignHash == nullptr) {
return; return;
@ -856,7 +856,7 @@ void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, std
decltype(sigSharesToRequest.begin()->second)* invMap = nullptr; decltype(sigSharesToRequest.begin()->second)* invMap = nullptr;
for (auto& [signHash, session] : nodeState.sessions) { for (auto& [signHash, session] : nodeState.sessions) {
if (CLLMQUtils::IsAllMembersConnectedEnabled(session.llmqType)) { if (utils::IsAllMembersConnectedEnabled(session.llmqType)) {
continue; continue;
} }
@ -925,7 +925,7 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::u
decltype(sigSharesToSend.begin()->second)* sigSharesToSend2 = nullptr; decltype(sigSharesToSend.begin()->second)* sigSharesToSend2 = nullptr;
for (auto& [signHash, session] : nodeState.sessions) { for (auto& [signHash, session] : nodeState.sessions) {
if (CLLMQUtils::IsAllMembersConnectedEnabled(session.llmqType)) { if (utils::IsAllMembersConnectedEnabled(session.llmqType)) {
continue; continue;
} }
@ -979,7 +979,7 @@ void CSigSharesManager::CollectSigSharesToSendConcentrated(std::unordered_map<No
auto curTime = GetTime<std::chrono::milliseconds>().count(); auto curTime = GetTime<std::chrono::milliseconds>().count();
for (auto& [_, signedSession] : signedSessions) { for (auto& [_, signedSession] : signedSessions) {
if (!CLLMQUtils::IsAllMembersConnectedEnabled(signedSession.quorum->params.type)) { if (!utils::IsAllMembersConnectedEnabled(signedSession.quorum->params.type)) {
continue; continue;
} }
@ -1257,7 +1257,7 @@ void CSigSharesManager::Cleanup()
// Find quorums which became inactive // Find quorums which became inactive
for (auto it = quorums.begin(); it != quorums.end(); ) { for (auto it = quorums.begin(); it != quorums.end(); ) {
if (CLLMQUtils::IsQuorumActive(it->first.first, it->first.second)) { if (utils::IsQuorumActive(it->first.first, it->first.second)) {
it->second = quorumManager->GetQuorum(it->first.first, it->first.second); it->second = quorumManager->GetQuorum(it->first.first, it->first.second);
++it; ++it;
} else { } else {
@ -1481,7 +1481,7 @@ void CSigSharesManager::SignPendingSigShares()
auto sigShare = *opt_sigShare; auto sigShare = *opt_sigShare;
ProcessSigShare(sigShare, connman, pQuorum); ProcessSigShare(sigShare, connman, pQuorum);
if (CLLMQUtils::IsAllMembersConnectedEnabled(pQuorum->params.type)) { if (utils::IsAllMembersConnectedEnabled(pQuorum->params.type)) {
LOCK(cs); LOCK(cs);
auto& session = signedSessions[sigShare.GetSignHash()]; auto& session = signedSessions[sigShare.GetSignHash()];
session.sigShare = sigShare; session.sigShare = sigShare;
@ -1535,12 +1535,12 @@ std::optional<CSigShare> CSigSharesManager::CreateSigShare(const CQuorumCPtr& qu
// causes all known sigShares to be re-announced // causes all known sigShares to be re-announced
void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash) void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
{ {
if (CLLMQUtils::IsAllMembersConnectedEnabled(llmqType)) { if (utils::IsAllMembersConnectedEnabled(llmqType)) {
return; return;
} }
LOCK(cs); LOCK(cs);
auto signHash = CLLMQUtils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash); auto signHash = utils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash);
if (const auto *const sigs = sigShares.GetAllForSignHash(signHash)) { if (const auto *const sigs = sigShares.GetAllForSignHash(signHash)) {
for (const auto& [quorumMemberIndex, _] : *sigs) { for (const auto& [quorumMemberIndex, _] : *sigs) {
// re-announce every sigshare to every node // re-announce every sigshare to every node

View File

@ -164,7 +164,7 @@ bool BuildQuorumRotationInfo(const CGetQuorumRotationInfo& request, CQuorumRotat
} }
//Quorum rotation is enabled only for InstantSend atm. //Quorum rotation is enabled only for InstantSend atm.
Consensus::LLMQType llmqType = CLLMQUtils::GetInstantSendLLMQType(blockIndex); Consensus::LLMQType llmqType = utils::GetInstantSendLLMQType(blockIndex);
// Since the returned quorums are in reversed order, the most recent one is at index 0 // Since the returned quorums are in reversed order, the most recent one is at index 0
const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType); const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType);

View File

@ -29,16 +29,20 @@ namespace llmq
CCriticalSection cs_llmq_vbc; CCriticalSection cs_llmq_vbc;
VersionBitsCache llmq_versionbitscache; VersionBitsCache llmq_versionbitscache;
void CLLMQUtils::PreComputeQuorumMembers(const CBlockIndex* pQuorumBaseBlockIndex) namespace utils
{ {
for (const Consensus::LLMQParams& params : CLLMQUtils::GetEnabledQuorumParams(pQuorumBaseBlockIndex->pprev)) {
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(params.type, pQuorumBaseBlockIndex) && (pQuorumBaseBlockIndex->nHeight % params.dkgInterval == 0)) { void PreComputeQuorumMembers(const CBlockIndex* pQuorumBaseBlockIndex)
CLLMQUtils::GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex); {
for (const Consensus::LLMQParams& params : GetEnabledQuorumParams(pQuorumBaseBlockIndex->pprev)) {
if (IsQuorumRotationEnabled(params.type, pQuorumBaseBlockIndex) && (pQuorumBaseBlockIndex->nHeight % params.dkgInterval == 0)) {
GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex);
} }
} }
} }
std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex)
{ {
static CCriticalSection cs_members; static CCriticalSection cs_members;
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers GUARDED_BY(cs_members); static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers GUARDED_BY(cs_members);
@ -58,7 +62,7 @@ std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(Consensus::LLM
} }
} }
if (CLLMQUtils::IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex)) { if (IsQuorumRotationEnabled(llmqType, pQuorumBaseBlockIndex)) {
if (LOCK(cs_indexed_members); mapIndexedQuorumMembers.empty()) { if (LOCK(cs_indexed_members); mapIndexedQuorumMembers.empty()) {
InitQuorumsCache(mapIndexedQuorumMembers); InitQuorumsCache(mapIndexedQuorumMembers);
} }
@ -105,14 +109,14 @@ std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(Consensus::LLM
return quorumMembers; return quorumMembers;
} }
std::vector<CDeterministicMNCPtr> CLLMQUtils::ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) std::vector<CDeterministicMNCPtr> ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex)
{ {
auto allMns = deterministicMNManager->GetListForBlock(pQuorumBaseBlockIndex); auto allMns = deterministicMNManager->GetListForBlock(pQuorumBaseBlockIndex);
auto modifier = ::SerializeHash(std::make_pair(llmqType, pQuorumBaseBlockIndex->GetBlockHash())); auto modifier = ::SerializeHash(std::make_pair(llmqType, pQuorumBaseBlockIndex->GetBlockHash()));
return allMns.CalculateQuorum(GetLLMQParams(llmqType).size, modifier); return allMns.CalculateQuorum(GetLLMQParams(llmqType).size, modifier);
} }
std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex) std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex)
{ {
const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType); const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType);
@ -125,14 +129,14 @@ std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::ComputeQuorumMembersB
LOCK(deterministicMNManager->cs); LOCK(deterministicMNManager->cs);
const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(pCycleQuorumBaseBlockIndex->nHeight - 8); const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(pCycleQuorumBaseBlockIndex->nHeight - 8);
auto allMns = deterministicMNManager->GetListForBlock(pWorkBlockIndex); auto allMns = deterministicMNManager->GetListForBlock(pWorkBlockIndex);
LogPrint(BCLog::LLMQ, "CLLMQUtils::ComputeQuorumMembersByQuarterRotation llmqType[%d] nHeight[%d] allMns[%d]\n", static_cast<int>(llmqType), pCycleQuorumBaseBlockIndex->nHeight, allMns.GetValidMNsCount()); LogPrint(BCLog::LLMQ, "ComputeQuorumMembersByQuarterRotation llmqType[%d] nHeight[%d] allMns[%d]\n", static_cast<int>(llmqType), pCycleQuorumBaseBlockIndex->nHeight, allMns.GetValidMNsCount());
PreviousQuorumQuarters previousQuarters = GetPreviousQuorumQuarterMembers(llmqParams, pBlockHMinusCIndex, pBlockHMinus2CIndex, pBlockHMinus3CIndex, pCycleQuorumBaseBlockIndex->nHeight); PreviousQuorumQuarters previousQuarters = GetPreviousQuorumQuarterMembers(llmqParams, pBlockHMinusCIndex, pBlockHMinus2CIndex, pBlockHMinus3CIndex, pCycleQuorumBaseBlockIndex->nHeight);
auto nQuorums = size_t(llmqParams.signingActiveQuorumCount); auto nQuorums = size_t(llmqParams.signingActiveQuorumCount);
std::vector<std::vector<CDeterministicMNCPtr>> quorumMembers(nQuorums); std::vector<std::vector<CDeterministicMNCPtr>> quorumMembers(nQuorums);
auto newQuarterMembers = CLLMQUtils::BuildNewQuorumQuarterMembers(llmqParams, pCycleQuorumBaseBlockIndex, previousQuarters); auto newQuarterMembers = BuildNewQuorumQuarterMembers(llmqParams, pCycleQuorumBaseBlockIndex, previousQuarters);
//TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice //TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice
//assert (!newQuarterMembers.empty()); //assert (!newQuarterMembers.empty());
@ -191,7 +195,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::ComputeQuorumMembersB
return quorumMembers; return quorumMembers;
} }
PreviousQuorumQuarters CLLMQUtils::GetPreviousQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams,
const CBlockIndex* pBlockHMinusCIndex, const CBlockIndex* pBlockHMinusCIndex,
const CBlockIndex* pBlockHMinus2CIndex, const CBlockIndex* pBlockHMinus2CIndex,
const CBlockIndex* pBlockHMinus3CIndex, const CBlockIndex* pBlockHMinus3CIndex,
@ -202,19 +206,19 @@ PreviousQuorumQuarters CLLMQUtils::GetPreviousQuorumQuarterMembers(const Consens
std::optional<llmq::CQuorumSnapshot> quSnapshotHMinusC = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinusCIndex); std::optional<llmq::CQuorumSnapshot> quSnapshotHMinusC = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinusCIndex);
if (quSnapshotHMinusC.has_value()) { if (quSnapshotHMinusC.has_value()) {
quarters.quarterHMinusC = CLLMQUtils::GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinusCIndex, quSnapshotHMinusC.value(), nHeight); quarters.quarterHMinusC = GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinusCIndex, quSnapshotHMinusC.value(), nHeight);
//TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice //TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice
//assert (!quarterHMinusC.empty()); //assert (!quarterHMinusC.empty());
std::optional<llmq::CQuorumSnapshot> quSnapshotHMinus2C = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinus2CIndex); std::optional<llmq::CQuorumSnapshot> quSnapshotHMinus2C = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinus2CIndex);
if (quSnapshotHMinus2C.has_value()) { if (quSnapshotHMinus2C.has_value()) {
quarters.quarterHMinus2C = CLLMQUtils::GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinus2CIndex, quSnapshotHMinus2C.value(), nHeight); quarters.quarterHMinus2C = GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinus2CIndex, quSnapshotHMinus2C.value(), nHeight);
//TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice //TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice
//assert (!quarterHMinusC.empty()); //assert (!quarterHMinusC.empty());
std::optional<llmq::CQuorumSnapshot> quSnapshotHMinus3C = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinus3CIndex); std::optional<llmq::CQuorumSnapshot> quSnapshotHMinus3C = quorumSnapshotManager->GetSnapshotForBlock(llmqParams.type, pBlockHMinus3CIndex);
if (quSnapshotHMinus3C.has_value()) { if (quSnapshotHMinus3C.has_value()) {
quarters.quarterHMinus3C = CLLMQUtils::GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinus3CIndex, quSnapshotHMinus3C.value(), nHeight); quarters.quarterHMinus3C = GetQuorumQuarterMembersBySnapshot(llmqParams, pBlockHMinus3CIndex, quSnapshotHMinus3C.value(), nHeight);
//TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice //TODO Check if it is triggered from outside (P2P, block validation). Throwing an exception is probably a wiser choice
//assert (!quarterHMinusC.empty()); //assert (!quarterHMinusC.empty());
} }
@ -224,7 +228,7 @@ PreviousQuorumQuarters CLLMQUtils::GetPreviousQuorumQuarterMembers(const Consens
return quarters; return quarters;
} }
std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, std::vector<std::vector<CDeterministicMNCPtr>> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams,
const CBlockIndex* pQuorumBaseBlockIndex, const CBlockIndex* pQuorumBaseBlockIndex,
const PreviousQuorumQuarters& previousQuarters) const PreviousQuorumQuarters& previousQuarters)
{ {
@ -342,14 +346,14 @@ std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::BuildNewQuorumQuarter
CQuorumSnapshot quorumSnapshot = {}; CQuorumSnapshot quorumSnapshot = {};
CLLMQUtils::BuildQuorumSnapshot(llmqParams, allMns, MnsUsedAtH, sortedCombinedMnsList, quorumSnapshot, pQuorumBaseBlockIndex->nHeight, skipList, pQuorumBaseBlockIndex); BuildQuorumSnapshot(llmqParams, allMns, MnsUsedAtH, sortedCombinedMnsList, quorumSnapshot, pQuorumBaseBlockIndex->nHeight, skipList, pQuorumBaseBlockIndex);
quorumSnapshotManager->StoreSnapshotForBlock(llmqParams.type, pQuorumBaseBlockIndex, quorumSnapshot); quorumSnapshotManager->StoreSnapshotForBlock(llmqParams.type, pQuorumBaseBlockIndex, quorumSnapshot);
return quarterQuorumMembers; return quarterQuorumMembers;
} }
void CLLMQUtils::BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns, void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns,
const CDeterministicMNList& mnUsedAtH, std::vector<CDeterministicMNCPtr>& sortedCombinedMns, const CDeterministicMNList& mnUsedAtH, std::vector<CDeterministicMNCPtr>& sortedCombinedMns,
CQuorumSnapshot& quorumSnapshot, int nHeight, std::vector<int>& skipList, const CBlockIndex* pQuorumBaseBlockIndex) CQuorumSnapshot& quorumSnapshot, int nHeight, std::vector<int>& skipList, const CBlockIndex* pQuorumBaseBlockIndex)
{ {
@ -380,7 +384,7 @@ void CLLMQUtils::BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, co
} }
} }
std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::GetQuorumQuarterMembersBySnapshot(const Consensus::LLMQParams& llmqParams, std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot(const Consensus::LLMQParams& llmqParams,
const CBlockIndex* pQuorumBaseBlockIndex, const CBlockIndex* pQuorumBaseBlockIndex,
const llmq::CQuorumSnapshot& snapshot, const llmq::CQuorumSnapshot& snapshot,
int nHeight) int nHeight)
@ -389,7 +393,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::GetQuorumQuarterMembe
{ {
const CBlockIndex* pWorkBlockIndex = pQuorumBaseBlockIndex->GetAncestor(pQuorumBaseBlockIndex->nHeight - 8); const CBlockIndex* pWorkBlockIndex = pQuorumBaseBlockIndex->GetAncestor(pQuorumBaseBlockIndex->nHeight - 8);
const auto modifier = ::SerializeHash(std::make_pair(llmqParams.type, pWorkBlockIndex->GetBlockHash())); const auto modifier = ::SerializeHash(std::make_pair(llmqParams.type, pWorkBlockIndex->GetBlockHash()));
const auto [MnsUsedAtH, MnsNotUsedAtH] = CLLMQUtils::GetMNUsageBySnapshot(llmqParams.type, pQuorumBaseBlockIndex, snapshot, nHeight); const auto [MnsUsedAtH, MnsNotUsedAtH] = GetMNUsageBySnapshot(llmqParams.type, pQuorumBaseBlockIndex, snapshot, nHeight);
// the list begins with all the unused MNs // the list begins with all the unused MNs
auto sortedMnsNotUsedAtH = MnsNotUsedAtH.CalculateQuorum(MnsNotUsedAtH.GetAllMNsCount(), modifier); auto sortedMnsNotUsedAtH = MnsNotUsedAtH.CalculateQuorum(MnsNotUsedAtH.GetAllMNsCount(), modifier);
sortedCombinedMns = std::move(sortedMnsNotUsedAtH); sortedCombinedMns = std::move(sortedMnsNotUsedAtH);
@ -471,7 +475,7 @@ std::vector<std::vector<CDeterministicMNCPtr>> CLLMQUtils::GetQuorumQuarterMembe
} }
} }
std::pair<CDeterministicMNList, CDeterministicMNList> CLLMQUtils::GetMNUsageBySnapshot(Consensus::LLMQType llmqType, std::pair<CDeterministicMNList, CDeterministicMNList> GetMNUsageBySnapshot(Consensus::LLMQType llmqType,
const CBlockIndex* pQuorumBaseBlockIndex, const CBlockIndex* pQuorumBaseBlockIndex,
const llmq::CQuorumSnapshot& snapshot, const llmq::CQuorumSnapshot& snapshot,
int nHeight) int nHeight)
@ -507,7 +511,7 @@ std::pair<CDeterministicMNList, CDeterministicMNList> CLLMQUtils::GetMNUsageBySn
return std::make_pair(usedMNs, nonUsedMNs); return std::make_pair(usedMNs, nonUsedMNs);
} }
uint256 CLLMQUtils::BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash,
const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey,
const uint256& vvecHash) const uint256& vvecHash)
{ {
@ -520,7 +524,7 @@ uint256 CLLMQUtils::BuildCommitmentHash(Consensus::LLMQType llmqType, const uint
return hw.GetHash(); return hw.GetHash();
} }
uint256 CLLMQUtils::BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash) uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash)
{ {
CHashWriter h(SER_GETHASH, 0); CHashWriter h(SER_GETHASH, 0);
h << llmqType; h << llmqType;
@ -541,17 +545,17 @@ static bool EvalSpork(Consensus::LLMQType llmqType, int64_t spork_value)
return false; return false;
} }
bool CLLMQUtils::IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType) bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType)
{ {
return EvalSpork(llmqType, sporkManager.GetSporkValue(SPORK_21_QUORUM_ALL_CONNECTED)); return EvalSpork(llmqType, sporkManager.GetSporkValue(SPORK_21_QUORUM_ALL_CONNECTED));
} }
bool CLLMQUtils::IsQuorumPoseEnabled(Consensus::LLMQType llmqType) bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType)
{ {
return EvalSpork(llmqType, sporkManager.GetSporkValue(SPORK_23_QUORUM_POSE)); return EvalSpork(llmqType, sporkManager.GetSporkValue(SPORK_23_QUORUM_POSE));
} }
bool CLLMQUtils::IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex) bool IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex)
{ {
assert(pindex); assert(pindex);
@ -565,10 +569,10 @@ bool CLLMQUtils::IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBl
return false; return false;
} }
// It should activate at least 1 block prior to the cycle start // It should activate at least 1 block prior to the cycle start
return CLLMQUtils::IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1)); return IsDIP0024Active(pindex->GetAncestor(cycleQuorumBaseHeight - 1));
} }
Consensus::LLMQType CLLMQUtils::GetInstantSendLLMQType(const CBlockIndex* pindex) Consensus::LLMQType GetInstantSendLLMQType(const CBlockIndex* pindex)
{ {
if (IsDIP0024Active(pindex) && !quorumManager->ScanQuorums(Params().GetConsensus().llmqTypeDIP0024InstantSend, pindex, 1).empty()) { if (IsDIP0024Active(pindex) && !quorumManager->ScanQuorums(Params().GetConsensus().llmqTypeDIP0024InstantSend, pindex, 1).empty()) {
return Params().GetConsensus().llmqTypeDIP0024InstantSend; return Params().GetConsensus().llmqTypeDIP0024InstantSend;
@ -576,12 +580,12 @@ Consensus::LLMQType CLLMQUtils::GetInstantSendLLMQType(const CBlockIndex* pindex
return Params().GetConsensus().llmqTypeInstantSend; return Params().GetConsensus().llmqTypeInstantSend;
} }
Consensus::LLMQType CLLMQUtils::GetInstantSendLLMQType(bool deterministic) Consensus::LLMQType GetInstantSendLLMQType(bool deterministic)
{ {
return deterministic ? Params().GetConsensus().llmqTypeDIP0024InstantSend : Params().GetConsensus().llmqTypeInstantSend; return deterministic ? Params().GetConsensus().llmqTypeDIP0024InstantSend : Params().GetConsensus().llmqTypeInstantSend;
} }
bool CLLMQUtils::IsDIP0024Active(const CBlockIndex* pindex) bool IsDIP0024Active(const CBlockIndex* pindex)
{ {
assert(pindex); assert(pindex);
@ -589,7 +593,7 @@ bool CLLMQUtils::IsDIP0024Active(const CBlockIndex* pindex)
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024, llmq_versionbitscache) == ThresholdState::ACTIVE; return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0024, llmq_versionbitscache) == ThresholdState::ACTIVE;
} }
bool CLLMQUtils::IsInstantSendLLMQTypeShared() bool IsInstantSendLLMQTypeShared()
{ {
if (Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypeChainLocks || if (Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypeChainLocks ||
Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypePlatform || Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypePlatform ||
@ -600,7 +604,7 @@ bool CLLMQUtils::IsInstantSendLLMQTypeShared()
return false; return false;
} }
uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2) uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2)
{ {
// We need to deterministically select who is going to initiate the connection. The naive way would be to simply // We need to deterministically select who is going to initiate the connection. The naive way would be to simply
// return the min(proTxHash1, proTxHash2), but this would create a bias towards MNs with a numerically low // return the min(proTxHash1, proTxHash2), but this would create a bias towards MNs with a numerically low
@ -622,7 +626,7 @@ uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, c
return proTxHash2; return proTxHash2;
} }
std::set<uint256> CLLMQUtils::GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex,
const uint256& forMember, bool onlyOutbound) const uint256& forMember, bool onlyOutbound)
{ {
if (IsAllMembersConnectedEnabled(llmqParams.type)) { if (IsAllMembersConnectedEnabled(llmqParams.type)) {
@ -646,7 +650,7 @@ std::set<uint256> CLLMQUtils::GetQuorumConnections(const Consensus::LLMQParams&
return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound); return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound);
} }
std::set<uint256> CLLMQUtils::GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex,
const uint256& forMember, bool onlyOutbound) const uint256& forMember, bool onlyOutbound)
{ {
auto mns = GetAllQuorumMembers(llmqParams.type, pQuorumBaseBlockIndex); auto mns = GetAllQuorumMembers(llmqParams.type, pQuorumBaseBlockIndex);
@ -701,7 +705,7 @@ std::set<uint256> CLLMQUtils::GetQuorumRelayMembers(const Consensus::LLMQParams&
return result; return result;
} }
std::set<size_t> CLLMQUtils::CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex,
size_t memberCount, size_t connectionCount) size_t memberCount, size_t connectionCount)
{ {
static uint256 qwatchConnectionSeed; static uint256 qwatchConnectionSeed;
@ -722,10 +726,10 @@ std::set<size_t> CLLMQUtils::CalcDeterministicWatchConnections(Consensus::LLMQTy
return result; return result;
} }
bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex,
CConnman& connman, const uint256& myProTxHash) CConnman& connman, const uint256& myProTxHash)
{ {
if (!fMasternodeMode && !CLLMQUtils::IsWatchQuorumsEnabled()) { if (!fMasternodeMode && !IsWatchQuorumsEnabled()) {
return false; return false;
} }
@ -736,20 +740,20 @@ bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams
bool isMember = ranges::find_if(members, [&](const auto& dmn) { return dmn->proTxHash == myProTxHash; }) != members.end(); bool isMember = ranges::find_if(members, [&](const auto& dmn) { return dmn->proTxHash == myProTxHash; }) != members.end();
if (!isMember && !CLLMQUtils::IsWatchQuorumsEnabled()) { if (!isMember && !IsWatchQuorumsEnabled()) {
return false; return false;
} }
LogPrint(BCLog::NET_NETCONN, "CLLMQUtils::%s -- isMember=%d for quorum %s:\n", LogPrint(BCLog::NET_NETCONN, "%s -- isMember=%d for quorum %s:\n",
__func__, isMember, pQuorumBaseBlockIndex->GetBlockHash().ToString()); __func__, isMember, pQuorumBaseBlockIndex->GetBlockHash().ToString());
std::set<uint256> connections; std::set<uint256> connections;
std::set<uint256> relayMembers; std::set<uint256> relayMembers;
if (isMember) { if (isMember) {
connections = CLLMQUtils::GetQuorumConnections(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true); connections = GetQuorumConnections(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true);
relayMembers = CLLMQUtils::GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true); relayMembers = GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true);
} else { } else {
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqParams.type, pQuorumBaseBlockIndex, members.size(), 1); auto cindexes = CalcDeterministicWatchConnections(llmqParams.type, pQuorumBaseBlockIndex, members.size(), 1);
for (auto idx : cindexes) { for (auto idx : cindexes) {
connections.emplace(members[idx]->proTxHash); connections.emplace(members[idx]->proTxHash);
} }
@ -758,7 +762,7 @@ bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams
if (!connections.empty()) { if (!connections.empty()) {
if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) { if (!connman.HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) {
auto mnList = deterministicMNManager->GetListAtChainTip(); auto mnList = deterministicMNManager->GetListAtChainTip();
std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); std::string debugMsg = strprintf("%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
for (const auto& c : connections) { for (const auto& c : connections) {
auto dmn = mnList.GetValidMN(c); auto dmn = mnList.GetValidMN(c);
if (!dmn) { if (!dmn) {
@ -777,10 +781,10 @@ bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams
return true; return true;
} }
void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex,
CConnman& connman, const uint256 &myProTxHash) CConnman& connman, const uint256 &myProTxHash)
{ {
if (!CLLMQUtils::IsQuorumPoseEnabled(llmqParams.type)) { if (!IsQuorumPoseEnabled(llmqParams.type)) {
return; return;
} }
@ -803,7 +807,7 @@ void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqPara
if (!probeConnections.empty()) { if (!probeConnections.empty()) {
if (LogAcceptCategory(BCLog::LLMQ)) { if (LogAcceptCategory(BCLog::LLMQ)) {
auto mnList = deterministicMNManager->GetListAtChainTip(); auto mnList = deterministicMNManager->GetListAtChainTip();
std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes probes for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); std::string debugMsg = strprintf("%s -- adding masternodes probes for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
for (const auto& c : probeConnections) { for (const auto& c : probeConnections) {
auto dmn = mnList.GetValidMN(c); auto dmn = mnList.GetValidMN(c);
if (!dmn) { if (!dmn) {
@ -818,7 +822,7 @@ void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqPara
} }
} }
bool CLLMQUtils::IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash) bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash)
{ {
// sig shares and recovered sigs are only accepted from recent/active quorums // sig shares and recovered sigs are only accepted from recent/active quorums
// we allow one more active quorum as specified in consensus, as otherwise there is a small window where things could // we allow one more active quorum as specified in consensus, as otherwise there is a small window where things could
@ -827,12 +831,12 @@ bool CLLMQUtils::IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quo
return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; }); return ranges::any_of(quorums, [&quorumHash](const auto& q){ return q->qc->quorumHash == quorumHash; });
} }
bool CLLMQUtils::IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex) bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex)
{ {
return IsQuorumTypeEnabledInternal(llmqType, pindex, std::nullopt, std::nullopt); return IsQuorumTypeEnabledInternal(llmqType, pindex, std::nullopt, std::nullopt);
} }
bool CLLMQUtils::IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CBlockIndex* pindex, bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CBlockIndex* pindex,
std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums) std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums)
{ {
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
@ -845,7 +849,7 @@ bool CLLMQUtils::IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const
if (IsInstantSendLLMQTypeShared()) { if (IsInstantSendLLMQTypeShared()) {
break; break;
} }
bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : CLLMQUtils::IsDIP0024Active(pindex); bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex);
if (fDIP0024IsActive) { if (fDIP0024IsActive) {
bool fHaveDIP0024Quorums = optHaveDIP0024Quorums.has_value() ? *optHaveDIP0024Quorums bool fHaveDIP0024Quorums = optHaveDIP0024Quorums.has_value() ? *optHaveDIP0024Quorums
: !quorumManager->ScanQuorums( : !quorumManager->ScanQuorums(
@ -869,7 +873,7 @@ bool CLLMQUtils::IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const
case Consensus::LLMQType::LLMQ_60_75: case Consensus::LLMQType::LLMQ_60_75:
case Consensus::LLMQType::LLMQ_DEVNET_DIP0024: case Consensus::LLMQType::LLMQ_DEVNET_DIP0024:
case Consensus::LLMQType::LLMQ_TEST_DIP0024: { case Consensus::LLMQType::LLMQ_TEST_DIP0024: {
bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : CLLMQUtils::IsDIP0024Active(pindex); bool fDIP0024IsActive = optDIP0024IsActive.has_value() ? *optDIP0024IsActive : IsDIP0024Active(pindex);
if (!fDIP0024IsActive) { if (!fDIP0024IsActive) {
return false; return false;
} }
@ -882,7 +886,7 @@ bool CLLMQUtils::IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const
return true; return true;
} }
std::vector<Consensus::LLMQType> CLLMQUtils::GetEnabledQuorumTypes(const CBlockIndex* pindex) std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex)
{ {
std::vector<Consensus::LLMQType> ret; std::vector<Consensus::LLMQType> ret;
ret.reserve(Params().GetConsensus().llmqs.size()); ret.reserve(Params().GetConsensus().llmqs.size());
@ -894,7 +898,7 @@ std::vector<Consensus::LLMQType> CLLMQUtils::GetEnabledQuorumTypes(const CBlockI
return ret; return ret;
} }
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> CLLMQUtils::GetEnabledQuorumParams(const CBlockIndex* pindex) std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex)
{ {
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret; std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret;
ret.reserve(Params().GetConsensus().llmqs.size()); ret.reserve(Params().GetConsensus().llmqs.size());
@ -905,18 +909,18 @@ std::vector<std::reference_wrapper<const Consensus::LLMQParams>> CLLMQUtils::Get
return ret; return ret;
} }
bool CLLMQUtils::QuorumDataRecoveryEnabled() bool QuorumDataRecoveryEnabled()
{ {
return gArgs.GetBoolArg("-llmq-data-recovery", DEFAULT_ENABLE_QUORUM_DATA_RECOVERY); return gArgs.GetBoolArg("-llmq-data-recovery", DEFAULT_ENABLE_QUORUM_DATA_RECOVERY);
} }
bool CLLMQUtils::IsWatchQuorumsEnabled() bool IsWatchQuorumsEnabled()
{ {
static bool fIsWatchQuroumsEnabled = gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS); static bool fIsWatchQuroumsEnabled = gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS);
return fIsWatchQuroumsEnabled; return fIsWatchQuroumsEnabled;
} }
std::map<Consensus::LLMQType, QvvecSyncMode> CLLMQUtils::GetEnabledQuorumVvecSyncEntries() std::map<Consensus::LLMQType, QvvecSyncMode> GetEnabledQuorumVvecSyncEntries()
{ {
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")) {
@ -964,17 +968,19 @@ std::map<Consensus::LLMQType, QvvecSyncMode> CLLMQUtils::GetEnabledQuorumVvecSyn
} }
template <typename CacheType> template <typename CacheType>
void CLLMQUtils::InitQuorumsCache(CacheType& cache) void InitQuorumsCache(CacheType& cache)
{ {
for (const auto& llmq : Params().GetConsensus().llmqs) { for (const auto& llmq : Params().GetConsensus().llmqs) {
cache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type), cache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type),
std::forward_as_tuple(llmq.keepOldConnections)); std::forward_as_tuple(llmq.keepOldConnections));
} }
} }
template void CLLMQUtils::InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>>& cache); template void InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>>& cache);
template void CLLMQUtils::InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>>& cache); template void InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>>& cache);
template void CLLMQUtils::InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>, std::less<Consensus::LLMQType>, std::allocator<std::pair<Consensus::LLMQType const, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>>>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>, std::less<Consensus::LLMQType>, std::allocator<std::pair<Consensus::LLMQType const, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>>>>&); template void InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>, std::less<Consensus::LLMQType>, std::allocator<std::pair<Consensus::LLMQType const, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>>>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>, std::less<Consensus::LLMQType>, std::allocator<std::pair<Consensus::LLMQType const, unordered_lru_cache<uint256, std::shared_ptr<llmq::CQuorum>, StaticSaltedHasher, 0ul, 0ul>>>>&);
template void CLLMQUtils::InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>>& cache); template void InitQuorumsCache<std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>>>(std::map<Consensus::LLMQType, unordered_lru_cache<uint256, int, StaticSaltedHasher>>& cache);
} // namespace utils
const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType) const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType)
{ {

View File

@ -6,7 +6,6 @@
#define BITCOIN_LLMQ_UTILS_H #define BITCOIN_LLMQ_UTILS_H
#include <consensus/params.h> #include <consensus/params.h>
#include <util/irange.h>
#include <dbwrapper.h> #include <dbwrapper.h>
#include <random.h> #include <random.h>
@ -50,62 +49,62 @@ struct PreviousQuorumQuarters {
quarterHMinusC(s), quarterHMinus2C(s), quarterHMinus3C(s) {} quarterHMinusC(s), quarterHMinus2C(s), quarterHMinus3C(s) {}
}; };
class CLLMQUtils namespace utils
{ {
public:
// includes members which failed DKG
static std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex);
static void PreComputeQuorumMembers(const CBlockIndex* pQuorumBaseBlockIndex); // includes members which failed DKG
static std::vector<CDeterministicMNCPtr> ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex); std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex);
static std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex);
static std::vector<std::vector<CDeterministicMNCPtr>> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const PreviousQuorumQuarters& quarters); void PreComputeQuorumMembers(const CBlockIndex* pQuorumBaseBlockIndex);
static std::vector<CDeterministicMNCPtr> ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex);
static std::vector<std::vector<CDeterministicMNCPtr>> ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex);
static PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pBlockHMinusCIndex, const CBlockIndex* pBlockHMinus2CIndex, const CBlockIndex* pBlockHMinus3CIndex, int nHeight); static std::vector<std::vector<CDeterministicMNCPtr>> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const PreviousQuorumQuarters& quarters);
static std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeights);
static std::pair<CDeterministicMNList, CDeterministicMNList> GetMNUsageBySnapshot(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeight);
static void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns, const CDeterministicMNList& mnUsedAtH, std::vector<CDeterministicMNCPtr>& sortedCombinedMns, CQuorumSnapshot& quorumSnapshot, int nHeight, std::vector<int>& skipList, const CBlockIndex* pQuorumBaseBlockIndex); static PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pBlockHMinusCIndex, const CBlockIndex* pBlockHMinus2CIndex, const CBlockIndex* pBlockHMinus3CIndex, int nHeight);
static std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeights);
static std::pair<CDeterministicMNList, CDeterministicMNList> GetMNUsageBySnapshot(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeight);
static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash); static void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns, const CDeterministicMNList& mnUsedAtH, std::vector<CDeterministicMNCPtr>& sortedCombinedMns, CQuorumSnapshot& quorumSnapshot, int nHeight, std::vector<int>& skipList, const CBlockIndex* pQuorumBaseBlockIndex);
static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType); uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
static bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType); uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
static std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
static std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
static std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount);
static bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash); bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType);
static void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash); bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType);
uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
std::set<uint256> GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
std::set<uint256> GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount);
static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash); bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);
static bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex); void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, CConnman& connman, const uint256& myProTxHash);
static bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CBlockIndex* pindex, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums);
static std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex); bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash);
static std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex); bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
bool IsQuorumTypeEnabledInternal(Consensus::LLMQType llmqType, const CBlockIndex* pindex, std::optional<bool> optDIP0024IsActive, std::optional<bool> optHaveDIP0024Quorums);
static bool IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex); std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex);
static Consensus::LLMQType GetInstantSendLLMQType(const CBlockIndex* pindex); std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex);
static Consensus::LLMQType GetInstantSendLLMQType(bool deterministic);
static bool IsDIP0024Active(const CBlockIndex* pindex);
static bool IsInstantSendLLMQTypeShared();
/// Returns the state of `-llmq-data-recovery` bool IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
static bool QuorumDataRecoveryEnabled(); Consensus::LLMQType GetInstantSendLLMQType(const CBlockIndex* pindex);
Consensus::LLMQType GetInstantSendLLMQType(bool deterministic);
bool IsDIP0024Active(const CBlockIndex* pindex);
static bool IsInstantSendLLMQTypeShared();
/// Returns the state of `-watchquorums` /// Returns the state of `-llmq-data-recovery`
static bool IsWatchQuorumsEnabled(); bool QuorumDataRecoveryEnabled();
/// Returns the parsed entries given by `-llmq-qvvec-sync` /// Returns the state of `-watchquorums`
static std::map<Consensus::LLMQType, QvvecSyncMode> GetEnabledQuorumVvecSyncEntries(); bool IsWatchQuorumsEnabled();
template<typename NodesContainer, typename Continue, typename Callback> /// Returns the parsed entries given by `-llmq-qvvec-sync`
static void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&& callback, FastRandomContext& rnd) std::map<Consensus::LLMQType, QvvecSyncMode> GetEnabledQuorumVvecSyncEntries();
{
template<typename NodesContainer, typename Continue, typename Callback>
static void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&& callback, FastRandomContext& rnd)
{
std::vector<typename NodesContainer::iterator> rndNodes; std::vector<typename NodesContainer::iterator> rndNodes;
rndNodes.reserve(nodeStates.size()); rndNodes.reserve(nodeStates.size());
for (auto it = nodeStates.begin(); it != nodeStates.end(); ++it) { for (auto it = nodeStates.begin(); it != nodeStates.end(); ++it) {
@ -131,18 +130,12 @@ public:
idx %= rndNodes.size(); idx %= rndNodes.size();
} }
} }
} }
static std::string ToHexStr(const std::vector<bool>& vBits)
{ template <typename CacheType>
std::vector<uint8_t> vBytes((vBits.size() + 7) / 8); void InitQuorumsCache(CacheType& cache);
for (const auto i : irange::range(vBits.size())) {
vBytes[i / 8] |= vBits[i] << (i % 8); } // namespace utils
}
return HexStr(vBytes);
}
template <typename CacheType>
static void InitQuorumsCache(CacheType& cache);
};
const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType); const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType);

View File

@ -138,7 +138,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
: pblock->GetBlockTime(); : pblock->GetBlockTime();
if (fDIP0003Active_context) { if (fDIP0003Active_context) {
for (const Consensus::LLMQParams& params : llmq::CLLMQUtils::GetEnabledQuorumParams(pindexPrev)) { for (const Consensus::LLMQParams& params : llmq::utils::GetEnabledQuorumParams(pindexPrev)) {
std::vector<CTransactionRef> vqcTx; std::vector<CTransactionRef> vqcTx;
if (llmq::quorumBlockProcessor->GetMineableCommitmentsTx(params, if (llmq::quorumBlockProcessor->GetMineableCommitmentsTx(params,
nHeight, nHeight,

View File

@ -2810,7 +2810,7 @@ bool ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRec
// Tell our peer that he should send us CoinJoin queue messages // Tell our peer that he should send us CoinJoin queue messages
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDDSQUEUE, true)); connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::SENDDSQUEUE, true));
// Tell our peer that he should send us intra-quorum messages // Tell our peer that he should send us intra-quorum messages
if (llmq::CLLMQUtils::IsWatchQuorumsEnabled() && connman->IsMasternodeQuorumNode(pfrom)) { if (llmq::utils::IsWatchQuorumsEnabled() && connman->IsMasternodeQuorumNode(pfrom)) {
connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::QWATCH)); connman->PushMessage(pfrom, msgMaker.Make(NetMsgType::QWATCH));
} }
} }

View File

@ -65,7 +65,7 @@ static UniValue quorum_list(const JSONRPCRequest& request)
CBlockIndex* pindexTip = WITH_LOCK(cs_main, return ::ChainActive().Tip()); CBlockIndex* pindexTip = WITH_LOCK(cs_main, return ::ChainActive().Tip());
for (auto& type : llmq::CLLMQUtils::GetEnabledQuorumTypes(pindexTip)) { for (auto& type : llmq::utils::GetEnabledQuorumTypes(pindexTip)) {
const auto& llmq_params = llmq::GetLLMQParams(type); const auto& llmq_params = llmq::GetLLMQParams(type);
UniValue v(UniValue::VARR); UniValue v(UniValue::VARR);
@ -194,9 +194,9 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request)
UniValue minableCommitments(UniValue::VARR); UniValue minableCommitments(UniValue::VARR);
UniValue quorumArrConnections(UniValue::VARR); UniValue quorumArrConnections(UniValue::VARR);
for (const auto& type : llmq::CLLMQUtils::GetEnabledQuorumTypes(pindexTip)) { for (const auto& type : llmq::utils::GetEnabledQuorumTypes(pindexTip)) {
const auto& llmq_params = llmq::GetLLMQParams(type); const auto& llmq_params = llmq::GetLLMQParams(type);
bool rotation_enabled = llmq::CLLMQUtils::IsQuorumRotationEnabled(type, pindexTip); bool rotation_enabled = llmq::utils::IsQuorumRotationEnabled(type, pindexTip);
size_t quorums_num = rotation_enabled ? llmq_params.signingActiveQuorumCount : 1; size_t quorums_num = rotation_enabled ? llmq_params.signingActiveQuorumCount : 1;
for (int quorumIndex = 0; quorumIndex < quorums_num; ++quorumIndex) { for (int quorumIndex = 0; quorumIndex < quorums_num; ++quorumIndex) {
@ -212,9 +212,9 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request)
obj.pushKV("quorumHash", pQuorumBaseBlockIndex->GetBlockHash().ToString()); obj.pushKV("quorumHash", pQuorumBaseBlockIndex->GetBlockHash().ToString());
obj.pushKV("pindexTip", pindexTip->nHeight); obj.pushKV("pindexTip", pindexTip->nHeight);
auto allConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex, auto allConnections = llmq::utils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex,
proTxHash, false); proTxHash, false);
auto outboundConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, auto outboundConnections = llmq::utils::GetQuorumConnections(llmq_params,
pQuorumBaseBlockIndex, proTxHash, pQuorumBaseBlockIndex, proTxHash,
true); true);
std::map<uint256, CAddress> foundConnections; std::map<uint256, CAddress> foundConnections;
@ -297,7 +297,7 @@ static UniValue quorum_memberof(const JSONRPCRequest& request)
UniValue result(UniValue::VARR); UniValue result(UniValue::VARR);
for (const auto& type : llmq::CLLMQUtils::GetEnabledQuorumTypes(pindexTip)) { for (const auto& type : llmq::utils::GetEnabledQuorumTypes(pindexTip)) {
const auto& llmq_params = llmq::GetLLMQParams(type); const auto& llmq_params = llmq::GetLLMQParams(type);
size_t count = llmq_params.signingActiveQuorumCount; size_t count = llmq_params.signingActiveQuorumCount;
if (scanQuorumsCount != -1) { if (scanQuorumsCount != -1) {
@ -490,7 +490,7 @@ static UniValue quorum_sigs_cmd(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "quorum not found"); throw JSONRPCError(RPC_INVALID_PARAMETER, "quorum not found");
} }
uint256 signHash = llmq::CLLMQUtils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash); uint256 signHash = llmq::utils::BuildSignHash(llmqType, quorum->qc->quorumHash, id, msgHash);
return sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash); return sig.VerifyInsecure(quorum->qc->quorumPublicKey, signHash);
} }
} else if (cmd == "quorumhasrecsig") { } else if (cmd == "quorumhasrecsig") {
@ -836,7 +836,7 @@ static UniValue verifyislock(const JSONRPCRequest& request)
pBlockIndex = ::ChainActive()[signHeight]; pBlockIndex = ::ChainActive()[signHeight];
} }
} }
auto llmqType = llmq::CLLMQUtils::GetInstantSendLLMQType(pBlockIndex); auto llmqType = llmq::utils::GetInstantSendLLMQType(pBlockIndex);
// First check against the current active set, if it fails check against the last active set // First check against the current active set, if it fails check against the last active set
int signOffset{llmq::GetLLMQParams(llmqType).dkgInterval}; int signOffset{llmq::GetLLMQParams(llmqType).dkgInterval};
return llmq::quorumSigningManager->VerifyRecoveredSig(llmqType, signHeight, id, txid, sig, 0) || return llmq::quorumSigningManager->VerifyRecoveredSig(llmqType, signHeight, id, txid, sig, 0) ||

View File

@ -18,23 +18,23 @@ BOOST_AUTO_TEST_SUITE(evo_utils_tests)
void Test() void Test()
{ {
using namespace llmq; using namespace llmq::utils;
const auto& consensus_params = Params().GetConsensus(); const auto& consensus_params = Params().GetConsensus();
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, false, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, true, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, true, true), false); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeInstantSend, nullptr, true, true), false);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, false, false), false); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, false, false), false);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, true, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeDIP0024InstantSend, nullptr, true, true), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, false, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, false, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, false, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeChainLocks, nullptr, true, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, false), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, false), Params().IsTestChain());
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, true), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, true), Params().IsTestChain());
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, true), Params().IsTestChain()); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypePlatform, nullptr, true, true), Params().IsTestChain());
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, false), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, false), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, true), true);
BOOST_CHECK_EQUAL(CLLMQUtils::IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, true), true); BOOST_CHECK_EQUAL(IsQuorumTypeEnabledInternal(consensus_params.llmqTypeMnhf, nullptr, true, true), true);
} }
BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup) BOOST_FIXTURE_TEST_CASE(utils_IsQuorumTypeEnabled_tests_regtest, RegTestingSetup)

View File

@ -83,8 +83,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"policy/fees -> txmempool -> validation -> policy/fees" "policy/fees -> txmempool -> validation -> policy/fees"
"policy/policy -> policy/settings -> policy/policy" "policy/policy -> policy/settings -> policy/policy"
"evo/specialtxman -> validation -> evo/specialtxman" "evo/specialtxman -> validation -> evo/specialtxman"
"bloom -> llmq/commitment -> llmq/utils -> net -> bloom"
"banman -> bloom -> llmq/commitment -> llmq/utils -> net -> banman"
"evo/simplifiedmns -> llmq/blockprocessor -> net_processing -> llmq/snapshot -> evo/simplifiedmns" "evo/simplifiedmns -> llmq/blockprocessor -> net_processing -> llmq/snapshot -> evo/simplifiedmns"
"llmq/blockprocessor -> net_processing -> llmq/snapshot -> llmq/blockprocessor" "llmq/blockprocessor -> net_processing -> llmq/snapshot -> llmq/blockprocessor"