diff --git a/src/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index d1f8c690da..d9b94dddc6 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -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> CQuorumBlockProcessor::GetMineableC std::vector ret; - if (!IsCommitmentRequired(llmqParams, nHeight /*, 0*/)) { + if (GetNumCommitmentsRequired(llmqParams, nHeight) == 0) { // no commitment required return std::nullopt; } diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index 492334b6c2..4a5d82631c 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -70,7 +70,7 @@ private: static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::multimap& 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); };