Skip to content

Commit

Permalink
Speed up ScanQuorums
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Sep 8, 2023
1 parent 6dad072 commit 0d320e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,16 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp

std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t maxCount)
{
std::vector<CQuorumCPtr> result;
result.reserve(maxCount);
// TODO: speed up even more by using a cache
auto& params = Params().GetConsensus().llmqs.at(llmqType);
auto pindex = pindexStart->GetAncestor(pindexStart->nHeight - (pindexStart->nHeight % params.dkgInterval));

while (pindex != NULL && result.size() < maxCount && deterministicMNManager->IsDIP3Enforced(pindex->nHeight)) {
if (HasQuorum(llmqType, pindex->GetBlockHash())) {
auto quorum = GetQuorum(llmqType, pindex);
if (quorum) {
result.emplace_back(quorum);
}
}

// TODO speedup (skip blocks where no quorums could have been mined)
pindex = pindex->pprev;
auto quorumIndexes = quorumBlockProcessor->GetMinedCommitmentsUntilBlock(params.type, pindexStart, maxCount);
std::vector<CQuorumCPtr> result;
result.reserve(quorumIndexes.size());
for (auto& quorumIndex : quorumIndexes) {
assert(quorumIndex);
auto quorum = GetQuorum(params.type, quorumIndex);
assert(quorum != nullptr);
result.emplace_back(quorum);
}

return result;
Expand Down
5 changes: 5 additions & 0 deletions test/functional/tiertwo_chainlocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def run_test(self):
(qfc, badmembers) = self.mine_quorum()
assert_equal(171, miner.getblockcount())

# in order to avoid sync issues signing sessions quorum selection looks for quorums mined at most at chaintip - 8 blocks.
# let's round it and mine 10 blocks
miner.generate(10)
self.sync_all()

# mine single block, wait for chainlock
self.nodes[0].generate(1)
self.wait_for_chainlock_tip_all_nodes()
Expand Down
6 changes: 6 additions & 0 deletions test/functional/tiertwo_signing_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def run_test(self):
self.log.info("----------------------------------")
(qfc, badmembers) = self.mine_quorum()
assert_equal(171, miner.getblockcount())

# in order to avoid sync issues signing sessions quorum selection looks for quorums mined at most at chaintip - 8 blocks.
# let's round it and mine 10 blocks
miner.generate(10)
self.sync_all()

# Quorum members
members = self.get_quorum_members(qfc['quorumHash'])

Expand Down

0 comments on commit 0d320e5

Please sign in to comment.