From 2e13d1305c0a702349ad9dae92c0eab902070b9c Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Tue, 18 Jun 2019 13:34:16 +0200 Subject: [PATCH] Add some comments to make quorum merkle root calculation more clear+ (#2984) This should avoid future confusion. --- src/evo/cbtx.cpp | 4 ++++ src/llmq/quorums_blockprocessor.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/evo/cbtx.cpp b/src/evo/cbtx.cpp index 1778e171c..ed180627a 100644 --- a/src/evo/cbtx.cpp +++ b/src/evo/cbtx.cpp @@ -155,6 +155,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre static std::map> quorumsCached; static std::map> qcHashesCached; + // The returned quorums are in reversed order, so the most recent one is at index 0 auto quorums = llmq::quorumBlockProcessor->GetMinedAndActiveCommitmentsUntilBlock(pindexPrev); std::map> qcHashes; size_t hashCount = 0; @@ -201,6 +202,9 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qc.commitment.llmqType); auto& v = qcHashes[params.type]; if (v.size() == params.signingActiveQuorumCount) { + // we pop the last entry, which is actually the oldest quorum as GetMinedAndActiveCommitmentsUntilBlock + // returned quorums in reversed order. This pop and later push can only work ONCE, but we rely on the + // fact that a block can only contain a single commitment for one LLMQ type v.pop_back(); } v.emplace_back(qcHash); diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index e7ddde295..d44616cbd 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -405,6 +405,7 @@ bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, con return true; } +// The returned quorums are in reversed order, so the most recent one is at index 0 std::vector CQuorumBlockProcessor::GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t maxCount) { auto dbIt = evoDb.GetCurTransaction().NewIteratorUniquePtr(); @@ -446,6 +447,7 @@ std::vector CQuorumBlockProcessor::GetMinedCommitmentsUntilB return ret; } +// The returned quorums are in reversed order, so the most recent one is at index 0 std::map> CQuorumBlockProcessor::GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex* pindex) { std::map> ret;