@@ -23,7 +23,6 @@ namespace llmq
23
23
CQuorumBlockProcessor* quorumBlockProcessor;
24
24
25
25
static const std::string DB_MINED_COMMITMENT = " q_mc" ;
26
- static const std::string DB_FIRST_MINED_COMMITMENT = " q_fmc" ;
27
26
static const std::string DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT = " q_mcih" ;
28
27
29
28
static const std::string DB_UPGRADED = " q_dbupgraded" ;
@@ -244,11 +243,6 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
244
243
245
244
// if a reorg happened, we should allow to mine this commitment later
246
245
AddMinableCommitment (qc);
247
-
248
- uint256 fmq = GetFirstMinedQuorumHash (p.first );
249
- if (fmq == qc.quorumHash ) {
250
- evoDb.Erase (std::make_pair (DB_FIRST_MINED_COMMITMENT, (uint8_t )p.first ));
251
- }
252
246
}
253
247
254
248
return true ;
@@ -392,14 +386,61 @@ bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, con
392
386
return evoDb.Read (key, ret);
393
387
}
394
388
395
- uint256 CQuorumBlockProcessor::GetFirstMinedQuorumHash (Consensus::LLMQType llmqType)
389
+ std::vector< const CBlockIndex*> CQuorumBlockProcessor::GetMinedCommitmentsUntilBlock (Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t maxCount )
396
390
{
397
- auto key = std::make_pair (DB_FIRST_MINED_COMMITMENT, (uint8_t )llmqType);
398
- uint256 quorumHash;
399
- if (!evoDb.Read (key, quorumHash)) {
400
- return uint256 ();
391
+ auto dbIt = evoDb.GetCurTransaction ().NewIteratorUniquePtr ();
392
+
393
+ auto firstKey = BuildInversedHeightKey (llmqType, pindex->nHeight );
394
+ auto lastKey = BuildInversedHeightKey (llmqType, 0 );
395
+
396
+ dbIt->Seek (firstKey);
397
+
398
+ std::vector<const CBlockIndex*> ret;
399
+ ret.reserve (maxCount);
400
+
401
+ while (dbIt->Valid () && ret.size () < maxCount) {
402
+ decltype (firstKey) curKey;
403
+ int quorumHeight;
404
+ if (!dbIt->GetKey (curKey) || curKey >= lastKey) {
405
+ break ;
406
+ }
407
+ if (std::get<0 >(curKey) != DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT || std::get<1 >(curKey) != (uint8_t )llmqType) {
408
+ break ;
409
+ }
410
+
411
+ int nMinedHeight = std::numeric_limits<int >::max () - std::get<2 >(curKey);
412
+ if (nMinedHeight > pindex->nHeight ) {
413
+ break ;
414
+ }
415
+
416
+ if (!dbIt->GetValue (quorumHeight)) {
417
+ break ;
418
+ }
419
+
420
+ auto quorumIndex = pindex->GetAncestor (quorumHeight);
421
+ assert (quorumIndex);
422
+ ret.emplace_back (pindex->GetAncestor (quorumHeight));
423
+
424
+ dbIt->Next ();
401
425
}
402
- return quorumHash;
426
+
427
+ return ret;
428
+ }
429
+
430
+ std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> CQuorumBlockProcessor::GetMinedAndActiveCommitmentsUntilBlock (const CBlockIndex* pindex)
431
+ {
432
+ std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> ret;
433
+
434
+ for (const auto & p : Params ().GetConsensus ().llmqs ) {
435
+ auto & v = ret[p.second .type ];
436
+ v.reserve (p.second .signingActiveQuorumCount );
437
+ auto commitments = GetMinedCommitmentsUntilBlock (p.second .type , pindex, p.second .signingActiveQuorumCount );
438
+ for (auto & c : commitments) {
439
+ v.emplace_back (c);
440
+ }
441
+ }
442
+
443
+ return ret;
403
444
}
404
445
405
446
bool CQuorumBlockProcessor::HasMinableCommitment (const uint256& hash)
0 commit comments