Skip to content

Commit c48c0e7

Browse files
committed
refactor: stop using ::ChainstateActive() in GetBlockHash
1 parent 6abf7f8 commit c48c0e7

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/llmq/blockprocessor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
222222
}
223223
const auto& llmq_params = llmq_params_opt.value();
224224

225-
uint256 quorumHash = GetQuorumBlockHash(llmq_params, nHeight, qc.quorumIndex);
225+
uint256 quorumHash = GetQuorumBlockHash(llmq_params, m_chainstate.m_chain, nHeight, qc.quorumIndex);
226226

227227
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__,
228228
nHeight, ToUnderlying(qc.llmqType), qc.quorumIndex, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString(), fJustCheck);
@@ -420,22 +420,22 @@ size_t CQuorumBlockProcessor::GetNumCommitmentsRequired(const Consensus::LLMQPar
420420
size_t ret{0};
421421

422422
for (const auto quorumIndex : irange::range(quorums_num)) {
423-
uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight, quorumIndex);
423+
uint256 quorumHash = GetQuorumBlockHash(llmqParams, m_chainstate.m_chain, nHeight, quorumIndex);
424424
if (!quorumHash.IsNull() && !HasMinedCommitment(llmqParams.type, quorumHash)) ++ret;
425425
}
426426

427427
return ret;
428428
}
429429

430430
// WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet)
431-
uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight, int quorumIndex)
431+
uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex)
432432
{
433433
AssertLockHeld(cs_main);
434434

435435
int quorumStartHeight = nHeight - (nHeight % llmqParams.dkgInterval) + quorumIndex;
436436

437437
uint256 quorumBlockHash;
438-
if (!GetBlockHash(quorumBlockHash, quorumStartHeight)) {
438+
if (!GetBlockHash(active_chain, quorumBlockHash, quorumStartHeight)) {
439439
LogPrint(BCLog::LLMQ, "[GetQuorumBlockHash] llmqType[%d] h[%d] qi[%d] quorumStartHeight[%d] quorumHash[EMPTY]\n", ToUnderlying(llmqParams.type), nHeight, quorumIndex, quorumStartHeight);
440440
return {};
441441
}
@@ -705,7 +705,7 @@ std::optional<std::vector<CFinalCommitment>> CQuorumBlockProcessor::GetMineableC
705705
for (const auto quorumIndex : irange::range(quorums_num)) {
706706
CFinalCommitment cf;
707707

708-
uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight, quorumIndex);
708+
uint256 quorumHash = GetQuorumBlockHash(llmqParams, m_chainstate.m_chain, nHeight, quorumIndex);
709709
if (quorumHash.IsNull()) {
710710
break;
711711
}

src/llmq/blockprocessor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <optional>
2020

2121
class BlockValidationState;
22+
class CChain;
2223
class CChainState;
2324
class CConnman;
2425
class CDataStream;
@@ -77,7 +78,7 @@ class CQuorumBlockProcessor
7778
bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
7879
static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
7980
size_t GetNumCommitmentsRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
80-
static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
81+
static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, const CChain& active_chain, int nHeight, int quorumIndex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
8182
};
8283
} // namespace llmq
8384

src/validation.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,13 +1970,15 @@ void StopScriptCheckWorkerThreads()
19701970
scriptcheckqueue.StopWorkerThreads();
19711971
}
19721972

1973-
bool GetBlockHash(uint256& hashRet, int nBlockHeight)
1973+
bool GetBlockHash(const CChain& active_chain, uint256& hashRet, int nBlockHeight)
19741974
{
19751975
LOCK(cs_main);
1976-
if(::ChainActive().Tip() == nullptr) return false;
1977-
if(nBlockHeight < -1 || nBlockHeight > ::ChainActive().Height()) return false;
1978-
if(nBlockHeight == -1) nBlockHeight = ::ChainActive().Height();
1979-
hashRet = ::ChainActive()[nBlockHeight]->GetBlockHash();
1976+
1977+
if (active_chain.Tip() == nullptr) return false;
1978+
if (nBlockHeight < -1 || nBlockHeight > active_chain.Height()) return false;
1979+
if (nBlockHeight == -1) nBlockHeight = active_chain.Height();
1980+
hashRet = active_chain[nBlockHeight]->GetBlockHash();
1981+
19801982
return true;
19811983
}
19821984

src/validation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,10 +1143,10 @@ extern std::unique_ptr<CBlockTreeDB> pblocktree;
11431143

11441144

11451145
/**
1146-
* Return true if hash can be found in ::ChainActive() at nBlockHeight height.
1147-
* Fills hashRet with found hash, if no nBlockHeight is specified - ::ChainActive().Height() is used.
1146+
* Return true if hash can be found in active_chain at nBlockHeight height.
1147+
* Fills hashRet with found hash, if no nBlockHeight is specified - active_chain.Height() is used.
11481148
*/
1149-
bool GetBlockHash(uint256& hashRet, int nBlockHeight = -1);
1149+
bool GetBlockHash(const CChain& active_chain, uint256& hashRet, int nBlockHeight = -1);
11501150

11511151
/** Get block file info entry for one block file */
11521152
CBlockFileInfo* GetBlockFileInfo(size_t n);

0 commit comments

Comments
 (0)