diff --git a/src/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index ac4ca6eb43..7e8473288f 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -222,7 +222,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH } const auto& llmq_params = llmq_params_opt.value(); - uint256 quorumHash = GetQuorumBlockHash(llmq_params, nHeight, qc.quorumIndex); + uint256 quorumHash = GetQuorumBlockHash(llmq_params, m_chainstate.m_chain, nHeight, qc.quorumIndex); LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s height=%d, type=%d, quorumIndex=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s fJustCheck[%d] processing commitment from block.\n", __func__, nHeight, ToUnderlying(qc.llmqType), qc.quorumIndex, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString(), fJustCheck); @@ -420,7 +420,7 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar size_t ret{0}; for (const auto quorumIndex : irange::range(quorums_num)) { - uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight, quorumIndex); + uint256 quorumHash = GetQuorumBlockHash(llmqParams, m_chainstate.m_chain, nHeight, quorumIndex); if (!quorumHash.IsNull() && !HasMinedCommitment(llmqParams.type, quorumHash)) ++ret; } @@ -428,14 +428,14 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar } // WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet) -uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight, int quorumIndex) +uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) { AssertLockHeld(cs_main); int quorumStartHeight = nHeight - (nHeight % llmqParams.dkgInterval) + quorumIndex; uint256 quorumBlockHash; - if (!GetBlockHash(quorumBlockHash, quorumStartHeight)) { + if (!GetBlockHash(active_chain, quorumBlockHash, quorumStartHeight)) { LogPrint(BCLog::LLMQ, "[GetQuorumBlockHash] llmqType[%d] h[%d] qi[%d] quorumStartHeight[%d] quorumHash[EMPTY]\n", ToUnderlying(llmqParams.type), nHeight, quorumIndex, quorumStartHeight); return {}; } @@ -705,7 +705,7 @@ std::optional> CQuorumBlockProcessor::GetMineableC for (const auto quorumIndex : irange::range(quorums_num)) { CFinalCommitment cf; - uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight, quorumIndex); + uint256 quorumHash = GetQuorumBlockHash(llmqParams, m_chainstate.m_chain, nHeight, quorumIndex); if (quorumHash.IsNull()) { break; } diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index a1131a9a19..f308be6b66 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -19,6 +19,7 @@ #include class BlockValidationState; +class CChain; class CChainState; class CConnman; class CDataStream; @@ -77,7 +78,7 @@ private: bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main); static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight) 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); + static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); }; } // namespace llmq diff --git a/src/validation.cpp b/src/validation.cpp index 532bbfd1c1..d261c35157 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1970,13 +1970,15 @@ void StopScriptCheckWorkerThreads() scriptcheckqueue.StopWorkerThreads(); } -bool GetBlockHash(uint256& hashRet, int nBlockHeight) +bool GetBlockHash(const CChain& active_chain, uint256& hashRet, int nBlockHeight) { LOCK(cs_main); - if(::ChainActive().Tip() == nullptr) return false; - if(nBlockHeight < -1 || nBlockHeight > ::ChainActive().Height()) return false; - if(nBlockHeight == -1) nBlockHeight = ::ChainActive().Height(); - hashRet = ::ChainActive()[nBlockHeight]->GetBlockHash(); + + if (active_chain.Tip() == nullptr) return false; + if (nBlockHeight < -1 || nBlockHeight > active_chain.Height()) return false; + if (nBlockHeight == -1) nBlockHeight = active_chain.Height(); + hashRet = active_chain[nBlockHeight]->GetBlockHash(); + return true; } diff --git a/src/validation.h b/src/validation.h index 39ba3e2e1a..5718121301 100644 --- a/src/validation.h +++ b/src/validation.h @@ -1143,10 +1143,10 @@ extern std::unique_ptr pblocktree; /** - * Return true if hash can be found in ::ChainActive() at nBlockHeight height. - * Fills hashRet with found hash, if no nBlockHeight is specified - ::ChainActive().Height() is used. + * Return true if hash can be found in active_chain at nBlockHeight height. + * Fills hashRet with found hash, if no nBlockHeight is specified - active_chain.Height() is used. */ -bool GetBlockHash(uint256& hashRet, int nBlockHeight = -1); +bool GetBlockHash(const CChain& active_chain, uint256& hashRet, int nBlockHeight = -1); /** Get block file info entry for one block file */ CBlockFileInfo* GetBlockFileInfo(size_t n);