From 44a3b9c90fe132379b8108c32fb2fbb49f032612 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 4 Apr 2019 11:36:49 +0200 Subject: [PATCH] Don't use pindex->GetBlockHash() in ProcessCommitment The block hash is not necessarily set at this point, for example when coming from TestBlockValidity(). --- src/llmq/quorums_blockprocessor.cpp | 12 ++++++------ src/llmq/quorums_blockprocessor.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index af4f1dec7..d9aee40ee 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -153,7 +153,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* for (auto& p : qcs) { auto& qc = p.second; - if (!ProcessCommitment(pindex, qc, state)) { + if (!ProcessCommitment(pindex->nHeight, block.GetHash(), qc, state)) { return false; } } @@ -167,11 +167,11 @@ static std::tuple BuildInversedHeightKey(Consensus::L return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, (uint8_t)llmqType, std::numeric_limits::max() - nMinedHeight); } -bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state) +bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state) { auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qc.llmqType); - uint256 quorumHash = GetQuorumBlockHash((Consensus::LLMQType)qc.llmqType, pindex->nHeight); + uint256 quorumHash = GetQuorumBlockHash((Consensus::LLMQType)qc.llmqType, nHeight); if (quorumHash.IsNull()) { return state.DoS(100, false, REJECT_INVALID, "bad-qc-block"); } @@ -191,7 +191,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const C return state.DoS(100, false, REJECT_INVALID, "bad-qc-dup"); } - if (!IsMiningPhase(params.type, pindex->nHeight)) { + if (!IsMiningPhase(params.type, nHeight)) { // should not happen as it's already handled in ProcessBlock return state.DoS(100, false, REJECT_INVALID, "bad-qc-height"); } @@ -204,8 +204,8 @@ bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const C // Store commitment in DB auto quorumIndex = mapBlockIndex.at(qc.quorumHash); - evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)params.type, quorumHash)), std::make_pair(qc, pindex->GetBlockHash())); - evoDb.Write(BuildInversedHeightKey(params.type, pindex->nHeight), quorumIndex->nHeight); + evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)params.type, quorumHash)), std::make_pair(qc, blockHash)); + evoDb.Write(BuildInversedHeightKey(params.type, nHeight), quorumIndex->nHeight); { LOCK(minableCommitmentsCs); diff --git a/src/llmq/quorums_blockprocessor.h b/src/llmq/quorums_blockprocessor.h index ad10d4e30..94984c533 100644 --- a/src/llmq/quorums_blockprocessor.h +++ b/src/llmq/quorums_blockprocessor.h @@ -58,7 +58,7 @@ public: private: bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, std::map& ret, CValidationState& state); - bool ProcessCommitment(const CBlockIndex* pindex, const CFinalCommitment& qc, CValidationState& state); + bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state); bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight); bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight); uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight);