Skip to content

Commit 2e13d13

Browse files
codablockUdjinM6
authored andcommitted
Add some comments to make quorum merkle root calculation more clear+ (#2984)
This should avoid future confusion.
1 parent 6677a61 commit 2e13d13

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/evo/cbtx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
155155
static std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> quorumsCached;
156156
static std::map<Consensus::LLMQType, std::vector<uint256>> qcHashesCached;
157157

158+
// The returned quorums are in reversed order, so the most recent one is at index 0
158159
auto quorums = llmq::quorumBlockProcessor->GetMinedAndActiveCommitmentsUntilBlock(pindexPrev);
159160
std::map<Consensus::LLMQType, std::vector<uint256>> qcHashes;
160161
size_t hashCount = 0;
@@ -201,6 +202,9 @@ bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPre
201202
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qc.commitment.llmqType);
202203
auto& v = qcHashes[params.type];
203204
if (v.size() == params.signingActiveQuorumCount) {
205+
// we pop the last entry, which is actually the oldest quorum as GetMinedAndActiveCommitmentsUntilBlock
206+
// returned quorums in reversed order. This pop and later push can only work ONCE, but we rely on the
207+
// fact that a block can only contain a single commitment for one LLMQ type
204208
v.pop_back();
205209
}
206210
v.emplace_back(qcHash);

src/llmq/quorums_blockprocessor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, con
405405
return true;
406406
}
407407

408+
// The returned quorums are in reversed order, so the most recent one is at index 0
408409
std::vector<const CBlockIndex*> CQuorumBlockProcessor::GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t maxCount)
409410
{
410411
auto dbIt = evoDb.GetCurTransaction().NewIteratorUniquePtr();
@@ -446,6 +447,7 @@ std::vector<const CBlockIndex*> CQuorumBlockProcessor::GetMinedCommitmentsUntilB
446447
return ret;
447448
}
448449

450+
// The returned quorums are in reversed order, so the most recent one is at index 0
449451
std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> CQuorumBlockProcessor::GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex* pindex)
450452
{
451453
std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> ret;

0 commit comments

Comments
 (0)