Skip to content

Commit

Permalink
Don't use pindex->GetBlockHash() in ProcessCommitment
Browse files Browse the repository at this point in the history
The block hash is not necessarily set at this point, for example when
coming from TestBlockValidity().
  • Loading branch information
codablock committed Apr 4, 2019
1 parent f9dbe3e commit 44a3b9c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -167,11 +167,11 @@ static std::tuple<std::string, uint8_t, int> BuildInversedHeightKey(Consensus::L
return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, (uint8_t)llmqType, std::numeric_limits<int>::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");
}
Expand All @@ -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");
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CQuorumBlockProcessor

private:
bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, std::map<Consensus::LLMQType, CFinalCommitment>& 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);
Expand Down

0 comments on commit 44a3b9c

Please sign in to comment.