mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
fix(llmq): Fix quorum commitments requirement conditions (#4899)
Wasn't really requiring other commitments for rotation quorums once a single commitment was mined
This commit is contained in:
parent
24205ccce9
commit
a999023cbd
@ -152,18 +152,18 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*
|
||||
break;
|
||||
}
|
||||
|
||||
bool isCommitmentRequired = IsCommitmentRequired(params, pindex->nHeight);
|
||||
const size_t numCommitmentsRequired = GetNumCommitmentsRequired(params, pindex->nHeight);
|
||||
const auto numCommitmentsInNewBlock = qcs.count(params.type);
|
||||
|
||||
if (!isCommitmentRequired && numCommitmentsInNewBlock > 0) {
|
||||
if (numCommitmentsRequired < numCommitmentsInNewBlock) {
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-qc-not-allowed");
|
||||
}
|
||||
|
||||
if (isCommitmentRequired && numCommitmentsInNewBlock == 0) {
|
||||
if (numCommitmentsRequired > numCommitmentsInNewBlock) {
|
||||
return state.DoS(100, false, REJECT_INVALID, "bad-qc-missing");
|
||||
}
|
||||
if (llmq::CLLMQUtils::IsQuorumRotationEnabled(params.type, pindex)) {
|
||||
LogPrintf("[ProcessBlock] h[%d] isCommitmentRequired[%d] numCommitmentsInNewBlock[%d]\n", pindex->nHeight, isCommitmentRequired, numCommitmentsInNewBlock);
|
||||
LogPrintf("[ProcessBlock] h[%d] numCommitmentsRequired[%d] numCommitmentsInNewBlock[%d]\n", pindex->nHeight, numCommitmentsRequired, numCommitmentsInNewBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@ -431,11 +431,11 @@ bool CQuorumBlockProcessor::IsMiningPhase(const Consensus::LLMQParams& llmqParam
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CQuorumBlockProcessor::IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const
|
||||
size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
if (!IsMiningPhase(llmqParams, nHeight)) return false;
|
||||
if (!IsMiningPhase(llmqParams, nHeight)) return 0;
|
||||
|
||||
// Note: This function can be called for new blocks
|
||||
assert(nHeight <= ::ChainActive().Height() + 1);
|
||||
@ -443,14 +443,14 @@ bool CQuorumBlockProcessor::IsCommitmentRequired(const Consensus::LLMQParams& ll
|
||||
|
||||
bool rotation_enabled = CLLMQUtils::IsQuorumRotationEnabled(llmqParams.type, pindex);
|
||||
size_t quorums_num = rotation_enabled ? llmqParams.signingActiveQuorumCount : 1;
|
||||
size_t ret{0};
|
||||
|
||||
for (int quorumIndex = 0; quorumIndex < quorums_num; ++quorumIndex) {
|
||||
uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight, quorumIndex);
|
||||
if (quorumHash.IsNull()) return false;
|
||||
if (HasMinedCommitment(llmqParams.type, quorumHash)) return false;
|
||||
if (!quorumHash.IsNull() && !HasMinedCommitment(llmqParams.type, quorumHash)) ++ret;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet)
|
||||
@ -711,7 +711,7 @@ std::optional<std::vector<CFinalCommitment>> CQuorumBlockProcessor::GetMineableC
|
||||
|
||||
std::vector<CFinalCommitment> ret;
|
||||
|
||||
if (!IsCommitmentRequired(llmqParams, nHeight /*, 0*/)) {
|
||||
if (GetNumCommitmentsRequired(llmqParams, nHeight) == 0) {
|
||||
// no commitment required
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ private:
|
||||
static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::multimap<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, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
size_t GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user