diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 85309f0bd3..67b2890b57 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -469,8 +469,7 @@ bool CQuorumManager::HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockP return quorum_block_processor.HasMinedCommitment(llmqType, quorumHash); } -bool CQuorumManager::RequestQuorumData(CNode* pfrom, CConnman& connman, Consensus::LLMQType llmqType, - const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, +bool CQuorumManager::RequestQuorumData(CNode* pfrom, CConnman& connman, CQuorumCPtr pQuorum, uint16_t nDataMask, const uint256& proTxHash) const { if (pfrom == nullptr) { @@ -485,22 +484,20 @@ bool CQuorumManager::RequestQuorumData(CNode* pfrom, CConnman& connman, Consensu LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- pfrom is not a verified masternode\n", __func__); return false; } + const Consensus::LLMQType llmqType = pQuorum->qc->llmqType; if (!Params().GetLLMQ(llmqType).has_value()) { LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid llmqType: %d\n", __func__, ToUnderlying(llmqType)); return false; } - if (pQuorumBaseBlockIndex == nullptr) { - LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid pQuorumBaseBlockIndex: nullptr\n", __func__); - return false; - } - if (GetQuorum(llmqType, pQuorumBaseBlockIndex) == nullptr) { - LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Quorum not found: %s, %d\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString(), ToUnderlying(llmqType)); + const CBlockIndex* pindex{pQuorum->m_quorum_base_block_index}; + if (pindex == nullptr) { + LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- Invalid m_quorum_base_block_index : nullptr\n", __func__); return false; } LOCK(cs_data_requests); - const CQuorumDataRequestKey key(pfrom->GetVerifiedProRegTxHash(), true, pQuorumBaseBlockIndex->GetBlockHash(), llmqType); - const CQuorumDataRequest request(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), nDataMask, proTxHash); + const CQuorumDataRequestKey key(pfrom->GetVerifiedProRegTxHash(), true, pindex->GetBlockHash(), llmqType); + const CQuorumDataRequest request(llmqType, pindex->GetBlockHash(), nDataMask, proTxHash); auto [old_pair, inserted] = mapQuorumDataRequests.emplace(key, request); if (!inserted) { if (old_pair->second.IsExpired(/*add_bias=*/true)) { @@ -1006,8 +1003,7 @@ void CQuorumManager::StartQuorumDataRecoveryThread(CConnman& connman, const CQuo return; } - if (RequestQuorumData(pNode, connman, pQuorum->qc->llmqType, pQuorum->m_quorum_base_block_index, - nDataMask, proTxHash)) { + if (RequestQuorumData(pNode, connman, pQuorum, nDataMask, proTxHash)) { nTimeLastSuccess = GetTime().count(); printLog("Requested"); } else { diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 6e8db117db..645802efa6 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -277,8 +277,7 @@ public: static bool HasQuorum(Consensus::LLMQType llmqType, const CQuorumBlockProcessor& quorum_block_processor, const uint256& quorumHash); - bool RequestQuorumData(CNode* pfrom, CConnman& connman, Consensus::LLMQType llmqType, - const CBlockIndex* pQuorumBaseBlockIndex, uint16_t nDataMask, + bool RequestQuorumData(CNode* pfrom, CConnman& connman, const CQuorumCPtr pQuorum, uint16_t nDataMask, const uint256& proTxHash = uint256()) const; // all these methods will lock cs_main for a short period of time diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index 5289d027a2..e7da6e4a03 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -793,7 +793,6 @@ static RPCHelpMan quorum_getdata() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const NodeContext& node = EnsureAnyNodeContext(request.context); - const ChainstateManager& chainman = EnsureChainman(node); const LLMQContext& llmq_ctx = EnsureLLMQContext(node); CConnman& connman = EnsureConnman(node); @@ -815,10 +814,12 @@ static RPCHelpMan quorum_getdata() } } - const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(quorumHash)); - + const auto quorum = llmq_ctx.qman->GetQuorum(llmqType, quorumHash); + if (!quorum) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "quorum not found"); + } return connman.ForNode(nodeId, [&](CNode* pNode) { - return llmq_ctx.qman->RequestQuorumData(pNode, connman, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash); + return llmq_ctx.qman->RequestQuorumData(pNode, connman, quorum, nDataMask, proTxHash); }); }, };