mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: stop using ::ChainstateActive()
in GetBlockHash
This commit is contained in:
parent
6abf7f8b63
commit
c48c0e79f3
@ -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<std::vector<CFinalCommitment>> 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;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <optional>
|
||||
|
||||
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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1143,10 +1143,10 @@ extern std::unique_ptr<CBlockTreeDB> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user