mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: minimize passing around llmqType just to search for LLMQParams (#4551)
* minimize passing around llmqType just to search for LLMQParams * more Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
c20eccab44
commit
a0b68ca856
@ -922,7 +922,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
|
||||
|
||||
auto members = llmq::CLLMQUtils::GetAllQuorumMembers(qc.llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = llmq::CLLMQUtils::GetAllQuorumMembers(llmq::GetLLMQParams(qc.llmqType), pQuorumBaseBlockIndex);
|
||||
|
||||
for (size_t i = 0; i < members.size(); i++) {
|
||||
if (!mnList.HasMN(members[i]->proTxHash)) {
|
||||
|
@ -141,15 +141,15 @@ 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
|
||||
// allowed, including null commitments.
|
||||
// Note: must only check quorums that were enabled at the _previous_ block height to match mining logic
|
||||
for (const auto& type : CLLMQUtils::GetEnabledQuorumTypes(pindex->pprev)) {
|
||||
for (const Consensus::LLMQParams& params : CLLMQUtils::GetEnabledQuorumParams(pindex->pprev)) {
|
||||
// skip these checks when replaying blocks after the crash
|
||||
if (!::ChainActive().Tip()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// does the currently processed block contain a (possibly null) commitment for the current session?
|
||||
bool hasCommitmentInNewBlock = qcs.count(type) != 0;
|
||||
bool isCommitmentRequired = IsCommitmentRequired(type, pindex->nHeight);
|
||||
bool hasCommitmentInNewBlock = qcs.count(params.type) != 0;
|
||||
bool isCommitmentRequired = IsCommitmentRequired(params, pindex->nHeight);
|
||||
|
||||
if (hasCommitmentInNewBlock && !isCommitmentRequired) {
|
||||
// If we're either not in the mining phase or a non-null commitment was mined already, reject the block
|
||||
@ -191,7 +191,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
|
||||
|
||||
const auto& llmq_params = GetLLMQParams(qc.llmqType);
|
||||
|
||||
uint256 quorumHash = GetQuorumBlockHash(qc.llmqType, nHeight);
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmq_params, nHeight);
|
||||
|
||||
// skip `bad-qc-block` checks below when replaying blocks after the crash
|
||||
if (!::ChainActive().Tip()) {
|
||||
@ -217,7 +217,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-qc-dup");
|
||||
}
|
||||
|
||||
if (!IsMiningPhase(llmq_params.type, nHeight)) {
|
||||
if (!IsMiningPhase(llmq_params, nHeight)) {
|
||||
// should not happen as it's already handled in ProcessBlock
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-qc-height");
|
||||
}
|
||||
@ -367,38 +367,37 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const C
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CQuorumBlockProcessor::IsMiningPhase(Consensus::LLMQType llmqType, int nHeight)
|
||||
bool CQuorumBlockProcessor::IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight)
|
||||
{
|
||||
const auto& llmq_params = GetLLMQParams(llmqType);
|
||||
int phaseIndex = nHeight % llmq_params.dkgInterval;
|
||||
if (phaseIndex >= llmq_params.dkgMiningWindowStart && phaseIndex <= llmq_params.dkgMiningWindowEnd) {
|
||||
int phaseIndex = nHeight % llmqParams.dkgInterval;
|
||||
if (phaseIndex >= llmqParams.dkgMiningWindowStart && phaseIndex <= llmqParams.dkgMiningWindowEnd) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CQuorumBlockProcessor::IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight) const
|
||||
bool CQuorumBlockProcessor::IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmqType, nHeight);
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight);
|
||||
|
||||
// perform extra check for quorumHash.IsNull as the quorum hash is unknown for the first block of a session
|
||||
// this is because the currently processed block's hash will be the quorumHash of this session
|
||||
bool isMiningPhase = !quorumHash.IsNull() && IsMiningPhase(llmqType, nHeight);
|
||||
bool isMiningPhase = !quorumHash.IsNull() && IsMiningPhase(llmqParams, nHeight);
|
||||
|
||||
// did we already mine a non-null commitment for this session?
|
||||
bool hasMinedCommitment = !quorumHash.IsNull() && HasMinedCommitment(llmqType, quorumHash);
|
||||
bool hasMinedCommitment = !quorumHash.IsNull() && HasMinedCommitment(llmqParams.type, quorumHash);
|
||||
|
||||
return isMiningPhase && !hasMinedCommitment;
|
||||
}
|
||||
|
||||
// WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet)
|
||||
uint256 CQuorumBlockProcessor::GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight)
|
||||
uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
int quorumStartHeight = nHeight - (nHeight % GetLLMQParams(llmqType).dkgInterval);
|
||||
int quorumStartHeight = nHeight - (nHeight % llmqParams.dkgInterval);
|
||||
uint256 quorumBlockHash;
|
||||
if (!GetBlockHash(quorumBlockHash, quorumStartHeight)) {
|
||||
return {};
|
||||
@ -545,27 +544,27 @@ bool CQuorumBlockProcessor::GetMineableCommitmentByHash(const uint256& commitmen
|
||||
|
||||
// Will return false if no commitment should be mined
|
||||
// Will return true and a null commitment if no mineable commitment is known and none was mined yet
|
||||
bool CQuorumBlockProcessor::GetMineableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret) const
|
||||
bool CQuorumBlockProcessor::GetMineableCommitment(const Consensus::LLMQParams& llmqParams, int nHeight, CFinalCommitment& ret) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
if (!IsCommitmentRequired(llmqType, nHeight)) {
|
||||
if (!IsCommitmentRequired(llmqParams, nHeight)) {
|
||||
// no commitment required
|
||||
return false;
|
||||
}
|
||||
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmqType, nHeight);
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight);
|
||||
if (quorumHash.IsNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LOCK(minableCommitmentsCs);
|
||||
|
||||
auto k = std::make_pair(llmqType, quorumHash);
|
||||
auto k = std::make_pair(llmqParams.type, quorumHash);
|
||||
auto it = minableCommitmentsByQuorum.find(k);
|
||||
if (it == minableCommitmentsByQuorum.end()) {
|
||||
// null commitment required
|
||||
ret = CFinalCommitment(GetLLMQParams(llmqType), quorumHash);
|
||||
ret = CFinalCommitment(llmqParams, quorumHash);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -574,12 +573,12 @@ bool CQuorumBlockProcessor::GetMineableCommitment(Consensus::LLMQType llmqType,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CQuorumBlockProcessor::GetMineableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret) const
|
||||
bool CQuorumBlockProcessor::GetMineableCommitmentTx(const Consensus::LLMQParams& llmqParams, int nHeight, CTransactionRef& ret) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
CFinalCommitmentTxPayload qc;
|
||||
if (!GetMineableCommitment(llmqType, nHeight, qc.commitment)) {
|
||||
if (!GetMineableCommitment(llmqParams, nHeight, qc.commitment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ public:
|
||||
void AddMineableCommitment(const CFinalCommitment& fqc);
|
||||
bool HasMineableCommitment(const uint256& hash) const;
|
||||
bool GetMineableCommitmentByHash(const uint256& commitmentHash, CFinalCommitment& ret) const;
|
||||
bool GetMineableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool GetMineableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool GetMineableCommitment(const Consensus::LLMQParams& llmqParams, int nHeight, CFinalCommitment& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool GetMineableCommitmentTx(const Consensus::LLMQParams& llmqParams, int nHeight, CTransactionRef& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
|
||||
CFinalCommitmentPtr GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, uint256& retMinedBlockHash) const;
|
||||
@ -66,9 +66,9 @@ public:
|
||||
private:
|
||||
static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
static bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight);
|
||||
bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
static uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight);
|
||||
bool IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
};
|
||||
|
||||
extern CQuorumBlockProcessor* quorumBlockProcessor;
|
||||
|
@ -68,7 +68,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool che
|
||||
return false;
|
||||
}
|
||||
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(llmq_params, pQuorumBaseBlockIndex);
|
||||
for (size_t i = members.size(); i < llmq_params.size; i++) {
|
||||
if (validMembers[i]) {
|
||||
LogPrintfFinalCommitment("invalid validMembers bitset. bit %d should not be set\n", i);
|
||||
|
@ -27,7 +27,7 @@ UniValue CDKGDebugSessionStatus::ToJson(int detailLevel) const
|
||||
if (detailLevel == 2) {
|
||||
const CBlockIndex* pindex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash));
|
||||
if (pindex != nullptr) {
|
||||
dmnMembers = CLLMQUtils::GetAllQuorumMembers( llmqType, pindex);
|
||||
dmnMembers = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pindex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,23 +147,23 @@ void CDKGDebugManager::ResetLocalSessionStatus(Consensus::LLMQType llmqType)
|
||||
localStatus.nTime = GetAdjustedTime();
|
||||
}
|
||||
|
||||
void CDKGDebugManager::InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight)
|
||||
void CDKGDebugManager::InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, const uint256& quorumHash, int quorumHeight)
|
||||
{
|
||||
LOCK(cs);
|
||||
|
||||
auto it = localStatus.sessions.find(llmqType);
|
||||
auto it = localStatus.sessions.find(llmqParams.type);
|
||||
if (it == localStatus.sessions.end()) {
|
||||
it = localStatus.sessions.emplace(llmqType, CDKGDebugSessionStatus()).first;
|
||||
it = localStatus.sessions.emplace(llmqParams.type, CDKGDebugSessionStatus()).first;
|
||||
}
|
||||
|
||||
auto& session = it->second;
|
||||
session.llmqType = llmqType;
|
||||
session.llmqType = llmqParams.type;
|
||||
session.quorumHash = quorumHash;
|
||||
session.quorumHeight = (uint32_t)quorumHeight;
|
||||
session.phase = 0;
|
||||
session.statusBitset = 0;
|
||||
session.members.clear();
|
||||
session.members.resize((size_t)GetLLMQParams(llmqType).size);
|
||||
session.members.resize((size_t)llmqParams.size);
|
||||
}
|
||||
|
||||
void CDKGDebugManager::UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function<bool(CDKGDebugSessionStatus& status)>&& func)
|
||||
|
@ -98,7 +98,7 @@ public:
|
||||
void GetLocalDebugStatus(CDKGDebugStatus& ret) const;
|
||||
|
||||
void ResetLocalSessionStatus(Consensus::LLMQType llmqType);
|
||||
void InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight);
|
||||
void InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, const uint256& quorumHash, int quorumHeight);
|
||||
|
||||
void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function<bool(CDKGDebugSessionStatus& status)>&& func);
|
||||
void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function<bool(CDKGDebugMemberStatus& status)>&& func);
|
||||
|
@ -126,8 +126,8 @@ bool CDKGSession::Init(const CBlockIndex* _pQuorumBaseBlockIndex, const std::vec
|
||||
}
|
||||
|
||||
if (!myProTxHash.IsNull()) {
|
||||
quorumDKGDebugManager->InitLocalSessionStatus(params.type, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight);
|
||||
relayMembers = CLLMQUtils::GetQuorumRelayMembers(params.type, m_quorum_base_block_index, myProTxHash, true);
|
||||
quorumDKGDebugManager->InitLocalSessionStatus(params, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight);
|
||||
relayMembers = CLLMQUtils::GetQuorumRelayMembers(params, m_quorum_base_block_index, myProTxHash, true);
|
||||
}
|
||||
|
||||
if (myProTxHash.IsNull()) {
|
||||
|
@ -164,7 +164,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex)
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mns = CLLMQUtils::GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex);
|
||||
auto mns = CLLMQUtils::GetAllQuorumMembers(params, pQuorumBaseBlockIndex);
|
||||
|
||||
if (!curSession->Init(pQuorumBaseBlockIndex, mns, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
|
||||
LogPrintf("CDKGSessionManager::%s -- quorum initialization failed for %s\n", __func__, curSession->params.name);
|
||||
@ -518,9 +518,9 @@ void CDKGSessionHandler::HandleDKGRound()
|
||||
return changed;
|
||||
});
|
||||
|
||||
CLLMQUtils::EnsureQuorumConnections(params.type, pQuorumBaseBlockIndex, curSession->myProTxHash);
|
||||
CLLMQUtils::EnsureQuorumConnections(params, pQuorumBaseBlockIndex, curSession->myProTxHash);
|
||||
if (curSession->AreWeMember()) {
|
||||
CLLMQUtils::AddQuorumProbeConnections(params.type, pQuorumBaseBlockIndex, curSession->myProTxHash);
|
||||
CLLMQUtils::AddQuorumProbeConnections(params, pQuorumBaseBlockIndex, curSession->myProTxHash);
|
||||
}
|
||||
|
||||
WaitForNextPhase(QuorumPhase_Initialized, QuorumPhase_Contribute, curQuorumHash, []{return false;});
|
||||
|
@ -310,7 +310,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
|
||||
{
|
||||
LOCK(contributionsCacheCs);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pQuorumBaseBlockIndex);
|
||||
|
||||
memberIndexesRet.clear();
|
||||
vvecsRet.clear();
|
||||
@ -344,7 +344,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
|
||||
{
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pQuorumBaseBlockIndex);
|
||||
|
||||
vecRet.clear();
|
||||
vecRet.reserve(members.size());
|
||||
|
@ -257,7 +257,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
|
||||
}
|
||||
|
||||
for (auto& p : Params().GetConsensus().llmqs) {
|
||||
EnsureQuorumConnections(p.first, pindexNew);
|
||||
EnsureQuorumConnections(p.second, pindexNew);
|
||||
}
|
||||
|
||||
{
|
||||
@ -276,26 +276,24 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
|
||||
TriggerQuorumDataRecoveryThreads(pindexNew);
|
||||
}
|
||||
|
||||
void CQuorumManager::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexNew) const
|
||||
void CQuorumManager::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
|
||||
{
|
||||
const auto& llmq_params = GetLLMQParams(llmqType);
|
||||
auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);
|
||||
|
||||
auto lastQuorums = ScanQuorums(llmqType, pindexNew, (size_t)llmq_params.keepOldConnections);
|
||||
|
||||
auto connmanQuorumsToDelete = g_connman->GetMasternodeQuorums(llmqType);
|
||||
auto connmanQuorumsToDelete = g_connman->GetMasternodeQuorums(llmqParams.type);
|
||||
|
||||
// don't remove connections for the currently in-progress DKG round
|
||||
int curDkgHeight = pindexNew->nHeight - (pindexNew->nHeight % llmq_params.dkgInterval);
|
||||
int curDkgHeight = pindexNew->nHeight - (pindexNew->nHeight % llmqParams.dkgInterval);
|
||||
auto curDkgBlock = pindexNew->GetAncestor(curDkgHeight)->GetBlockHash();
|
||||
connmanQuorumsToDelete.erase(curDkgBlock);
|
||||
|
||||
for (const auto& quorum : lastQuorums) {
|
||||
if (CLLMQUtils::EnsureQuorumConnections(llmqType, quorum->m_quorum_base_block_index, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
|
||||
if (CLLMQUtils::EnsureQuorumConnections(llmqParams, quorum->m_quorum_base_block_index, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) {
|
||||
continue;
|
||||
}
|
||||
if (connmanQuorumsToDelete.count(quorum->qc->quorumHash) > 0) {
|
||||
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorum->qc->quorumHash.ToString());
|
||||
g_connman->RemoveMasternodeQuorumNodes(llmqType, quorum->qc->quorumHash);
|
||||
g_connman->RemoveMasternodeQuorumNodes(llmqParams.type, quorum->qc->quorumHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,8 +311,9 @@ CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType l
|
||||
}
|
||||
assert(qc->quorumHash == pQuorumBaseBlockIndex->GetBlockHash());
|
||||
|
||||
auto quorum = std::make_shared<CQuorum>(llmq::GetLLMQParams(llmqType), blsWorker);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers((Consensus::LLMQType)qc->llmqType, pQuorumBaseBlockIndex);
|
||||
const auto& llmqParams = llmq::GetLLMQParams(llmqType);
|
||||
auto quorum = std::make_shared<CQuorum>(llmqParams, blsWorker);
|
||||
auto members = CLLMQUtils::GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex);
|
||||
|
||||
quorum->Init(qc, pQuorumBaseBlockIndex, minedBlockHash, members);
|
||||
|
||||
|
@ -235,7 +235,7 @@ public:
|
||||
|
||||
private:
|
||||
// all private methods here are cs_main-free
|
||||
void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexNew) const;
|
||||
void EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pindexNew) const;
|
||||
|
||||
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) const EXCLUSIVE_LOCKS_REQUIRED(quorumsCacheCs);
|
||||
bool BuildQuorumContributions(const CFinalCommitmentPtr& fqc, const std::shared_ptr<CQuorum>& quorum) const;
|
||||
|
@ -25,12 +25,12 @@ namespace llmq
|
||||
CCriticalSection cs_llmq_vbc;
|
||||
VersionBitsCache llmq_versionbitscache;
|
||||
|
||||
std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex)
|
||||
std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex)
|
||||
{
|
||||
static CCriticalSection cs_members;
|
||||
static std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CDeterministicMNCPtr>, StaticSaltedHasher>> mapQuorumMembers;
|
||||
|
||||
if (!IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) {
|
||||
if (!IsQuorumTypeEnabled(llmqParams.type, pQuorumBaseBlockIndex->pprev)) {
|
||||
return {};
|
||||
}
|
||||
std::vector<CDeterministicMNCPtr> quorumMembers;
|
||||
@ -39,16 +39,16 @@ std::vector<CDeterministicMNCPtr> CLLMQUtils::GetAllQuorumMembers(Consensus::LLM
|
||||
if (mapQuorumMembers.empty()) {
|
||||
InitQuorumsCache(mapQuorumMembers);
|
||||
}
|
||||
if (mapQuorumMembers[llmqType].get(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers)) {
|
||||
if (mapQuorumMembers[llmqParams.type].get(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers)) {
|
||||
return quorumMembers;
|
||||
}
|
||||
}
|
||||
|
||||
auto allMns = deterministicMNManager->GetListForBlock(pQuorumBaseBlockIndex);
|
||||
auto modifier = ::SerializeHash(std::make_pair(llmqType, pQuorumBaseBlockIndex->GetBlockHash()));
|
||||
quorumMembers = allMns.CalculateQuorum(GetLLMQParams(llmqType).size, modifier);
|
||||
auto modifier = ::SerializeHash(std::make_pair(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()));
|
||||
quorumMembers = allMns.CalculateQuorum(llmqParams.size, modifier);
|
||||
LOCK(cs_members);
|
||||
mapQuorumMembers[llmqType].insert(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers);
|
||||
mapQuorumMembers[llmqParams.type].insert(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers);
|
||||
return quorumMembers;
|
||||
}
|
||||
|
||||
@ -116,10 +116,10 @@ uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, c
|
||||
return proTxHash2;
|
||||
}
|
||||
|
||||
std::set<uint256> CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound)
|
||||
std::set<uint256> CLLMQUtils::GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound)
|
||||
{
|
||||
if (IsAllMembersConnectedEnabled(llmqType)) {
|
||||
auto mns = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
if (IsAllMembersConnectedEnabled(llmqParams.type)) {
|
||||
auto mns = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex);
|
||||
std::set<uint256> result;
|
||||
|
||||
for (const auto& dmn : mns) {
|
||||
@ -136,13 +136,13 @@ std::set<uint256> CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType,
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return GetQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex, forMember, onlyOutbound);
|
||||
return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound);
|
||||
}
|
||||
}
|
||||
|
||||
std::set<uint256> CLLMQUtils::GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &forMember, bool onlyOutbound)
|
||||
std::set<uint256> CLLMQUtils::GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &forMember, bool onlyOutbound)
|
||||
{
|
||||
auto mns = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto mns = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex);
|
||||
std::set<uint256> result;
|
||||
|
||||
auto calcOutbound = [&](size_t i, const uint256& proTxHash) {
|
||||
@ -202,9 +202,9 @@ std::set<size_t> CLLMQUtils::CalcDeterministicWatchConnections(Consensus::LLMQTy
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash)
|
||||
bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash)
|
||||
{
|
||||
auto members = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex);
|
||||
bool isMember = std::find_if(members.begin(), members.end(), [&](const CDeterministicMNCPtr& dmn) { return dmn->proTxHash == myProTxHash; }) != members.end();
|
||||
|
||||
if (!isMember && !CLLMQUtils::IsWatchQuorumsEnabled()) {
|
||||
@ -214,17 +214,17 @@ bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBl
|
||||
std::set<uint256> connections;
|
||||
std::set<uint256> relayMembers;
|
||||
if (isMember) {
|
||||
connections = CLLMQUtils::GetQuorumConnections(llmqType, pQuorumBaseBlockIndex, myProTxHash, true);
|
||||
relayMembers = CLLMQUtils::GetQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex, myProTxHash, true);
|
||||
connections = CLLMQUtils::GetQuorumConnections(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true);
|
||||
relayMembers = CLLMQUtils::GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true);
|
||||
} else {
|
||||
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqType, pQuorumBaseBlockIndex, members.size(), 1);
|
||||
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqParams.type, pQuorumBaseBlockIndex, members.size(), 1);
|
||||
for (auto idx : cindexes) {
|
||||
connections.emplace(members[idx]->proTxHash);
|
||||
}
|
||||
relayMembers = connections;
|
||||
}
|
||||
if (!connections.empty()) {
|
||||
if (!g_connman->HasMasternodeQuorumNodes(llmqType, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) {
|
||||
if (!g_connman->HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) {
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString());
|
||||
for (auto& c : connections) {
|
||||
@ -237,21 +237,21 @@ bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBl
|
||||
}
|
||||
LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */
|
||||
}
|
||||
g_connman->SetMasternodeQuorumNodes(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), connections);
|
||||
g_connman->SetMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), connections);
|
||||
}
|
||||
if (!relayMembers.empty()) {
|
||||
g_connman->SetMasternodeQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers);
|
||||
g_connman->SetMasternodeQuorumRelayMembers(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CLLMQUtils::AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &myProTxHash)
|
||||
void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &myProTxHash)
|
||||
{
|
||||
if (!CLLMQUtils::IsQuorumPoseEnabled(llmqType)) {
|
||||
if (!CLLMQUtils::IsQuorumPoseEnabled(llmqParams.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto members = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex);
|
||||
auto members = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex);
|
||||
auto curTime = GetAdjustedTime();
|
||||
|
||||
std::set<uint256> probeConnections;
|
||||
@ -331,9 +331,22 @@ bool CLLMQUtils::IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockI
|
||||
std::vector<Consensus::LLMQType> CLLMQUtils::GetEnabledQuorumTypes(const CBlockIndex* pindex)
|
||||
{
|
||||
std::vector<Consensus::LLMQType> ret;
|
||||
for (const auto& p : Params().GetConsensus().llmqs) {
|
||||
if (IsQuorumTypeEnabled(p.first, pindex)) {
|
||||
ret.push_back(p.first);
|
||||
ret.reserve(Params().GetConsensus().llmqs.size());
|
||||
for (const auto& [type, _] : Params().GetConsensus().llmqs) {
|
||||
if (IsQuorumTypeEnabled(type, pindex)) {
|
||||
ret.push_back(type);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> CLLMQUtils::GetEnabledQuorumParams(const CBlockIndex* pindex)
|
||||
{
|
||||
std::vector<std::reference_wrapper<const Consensus::LLMQParams>> ret;
|
||||
ret.reserve(Params().GetConsensus().llmqs.size());
|
||||
for (const auto& [type, params] : Params().GetConsensus().llmqs) {
|
||||
if (IsQuorumTypeEnabled(type, pindex)) {
|
||||
ret.emplace_back(params);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -39,7 +39,7 @@ class CLLMQUtils
|
||||
{
|
||||
public:
|
||||
// includes members which failed DKG
|
||||
static std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex);
|
||||
static std::vector<CDeterministicMNCPtr> GetAllQuorumMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexQuorum);
|
||||
|
||||
static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector<bool>& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash);
|
||||
static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
|
||||
@ -54,16 +54,17 @@ public:
|
||||
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType);
|
||||
static bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType);
|
||||
static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
|
||||
static std::set<uint256> GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
|
||||
static std::set<uint256> GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound);
|
||||
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(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash);
|
||||
static void AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash);
|
||||
static bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash);
|
||||
static void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash);
|
||||
|
||||
static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash);
|
||||
static bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
|
||||
static std::vector<Consensus::LLMQType> GetEnabledQuorumTypes(const CBlockIndex* pindex);
|
||||
static std::vector<std::reference_wrapper<const Consensus::LLMQParams>> GetEnabledQuorumParams(const CBlockIndex* pindex);
|
||||
|
||||
/// Returns the state of `-llmq-data-recovery`
|
||||
static bool QuorumDataRecoveryEnabled();
|
||||
@ -115,7 +116,7 @@ public:
|
||||
static void InitQuorumsCache(CacheType& cache);
|
||||
};
|
||||
|
||||
const Consensus::LLMQParams& GetLLMQParams(const Consensus::LLMQType llmqType);
|
||||
const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType);
|
||||
|
||||
} // namespace llmq
|
||||
|
||||
|
@ -148,9 +148,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
: pblock->GetBlockTime();
|
||||
|
||||
if (fDIP0003Active_context) {
|
||||
for (const Consensus::LLMQType& type : llmq::CLLMQUtils::GetEnabledQuorumTypes(pindexPrev)) {
|
||||
for (const Consensus::LLMQParams& params : llmq::CLLMQUtils::GetEnabledQuorumParams(pindexPrev)) {
|
||||
CTransactionRef qcTx;
|
||||
if (llmq::quorumBlockProcessor->GetMineableCommitmentTx(type,
|
||||
if (llmq::quorumBlockProcessor->GetMineableCommitmentTx(params,
|
||||
nHeight,
|
||||
qcTx)) {
|
||||
pblock->vtx.emplace_back(qcTx);
|
||||
|
@ -196,8 +196,8 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request)
|
||||
|
||||
if (fMasternodeMode) {
|
||||
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return ::ChainActive()[tipHeight - (tipHeight % llmq_params.dkgInterval)]);
|
||||
auto allConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params.type, pQuorumBaseBlockIndex, proTxHash, false);
|
||||
auto outboundConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params.type, pQuorumBaseBlockIndex, proTxHash, true);
|
||||
auto allConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex, proTxHash, false);
|
||||
auto outboundConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex, proTxHash, true);
|
||||
std::map<uint256, CAddress> foundConnections;
|
||||
g_connman->ForEachNode([&](const CNode* pnode) {
|
||||
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
|
||||
@ -223,8 +223,7 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request)
|
||||
|
||||
LOCK(cs_main);
|
||||
llmq::CFinalCommitment fqc;
|
||||
if (llmq::quorumBlockProcessor->GetMineableCommitment(llmq_params.type,
|
||||
tipHeight, fqc)) {
|
||||
if (llmq::quorumBlockProcessor->GetMineableCommitment(llmq_params, tipHeight, fqc)) {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
fqc.ToJson(obj);
|
||||
minableCommitments.pushKV(std::string(llmq_params.name), obj);
|
||||
|
Loading…
Reference in New Issue
Block a user