@@ -183,6 +183,15 @@ class ResearcherTally
183
183
return iter->second ;
184
184
}
185
185
186
+ // !
187
+ // ! \brief Set the index of the first block that the tally tracks research
188
+ // ! rewards for.
189
+ // !
190
+ void SetStartIndex (const CBlockIndex* pindex)
191
+ {
192
+ m_start_pindex = pindex;
193
+ }
194
+
186
195
// !
187
196
// ! \brief Record a block's research reward data in the tally.
188
197
// !
@@ -376,6 +385,12 @@ class ResearcherTally
376
385
// !
377
386
AccrualSnapshotRepository m_snapshots;
378
387
388
+ // !
389
+ // ! \brief Index of the first block that the tally tracks research rewards
390
+ // ! for.
391
+ // !
392
+ const CBlockIndex* m_start_pindex = nullptr ;
393
+
379
394
// !
380
395
// ! \brief Points to the index of the block when snapshot accrual activates
381
396
// ! (the block just before protocol enforces snapshot accrual).
@@ -480,6 +495,38 @@ class ResearcherTally
480
495
{
481
496
assert (m_snapshot_baseline_pindex != nullptr );
482
497
498
+ // If we're not building the initial baseline at the threshold, reset
499
+ // the research accounts and rescan these up to the threshold height.
500
+ // We need to make sure that the accounts contain the blocks with the
501
+ // last rewards before the baseline:
502
+ //
503
+ if (pindexBest != m_snapshot_baseline_pindex) {
504
+ LogPrintf (" %s: Rebuilding research reward tally..." , __func__);
505
+
506
+ m_researchers.clear ();
507
+
508
+ const CBlockIndex* pindex = m_start_pindex;
509
+
510
+ for (;
511
+ pindex && pindex != m_snapshot_baseline_pindex;
512
+ pindex = pindex->pnext )
513
+ {
514
+ if (pindex->nResearchSubsidy <= 0 ) {
515
+ continue ;
516
+ }
517
+
518
+ if (const CpidOption cpid = pindex->GetMiningId ().TryCpid ()) {
519
+ RecordRewardBlock (*cpid, pindex);
520
+ }
521
+ }
522
+
523
+ if (pindex && pindex->nResearchSubsidy > 0 ) {
524
+ if (const CpidOption cpid = pindex->GetMiningId ().TryCpid ()) {
525
+ RecordRewardBlock (*cpid, pindex);
526
+ }
527
+ }
528
+ }
529
+
483
530
LogPrintf (" %s: rebuilding from %" PRId64 " to %" PRId64 " ..." ,
484
531
__func__,
485
532
m_snapshot_baseline_pindex->nHeight ,
@@ -497,22 +544,28 @@ class ResearcherTally
497
544
498
545
// Scan forward to the chain tip and reapply snapshot accrual for each
499
546
// account while writing snapshot files for every superblock along the
500
- // way:
547
+ // way. Finish rescanning the research accounts :
501
548
//
502
549
for (const CBlockIndex* pindex = m_snapshot_baseline_pindex->pnext ;
503
550
pindex;
504
551
pindex = pindex->pnext )
505
552
{
506
- if (pindex->nIsSuperBlock != 1 ) {
553
+ if (pindex->nResearchSubsidy <= 0 && pindex-> nIsSuperBlock != 1 ) {
507
554
continue ;
508
555
}
509
556
510
- if (!block.ReadFromDisk (pindex)) {
511
- return false ;
557
+ if (pindex->nIsSuperBlock == 1 ) {
558
+ if (!block.ReadFromDisk (pindex)) {
559
+ return false ;
560
+ }
561
+
562
+ if (!ApplySuperblock (block.GetSuperblock (pindex))) {
563
+ return false ;
564
+ }
512
565
}
513
566
514
- if (! ApplySuperblock (block. GetSuperblock (pindex) )) {
515
- return false ;
567
+ if (const CpidOption cpid = pindex-> GetMiningId (). TryCpid ( )) {
568
+ RecordRewardBlock (*cpid, pindex) ;
516
569
}
517
570
}
518
571
@@ -539,6 +592,7 @@ bool Tally::Initialize(CBlockIndex* pindex)
539
592
LogPrintf (" Initializing research reward tally..." );
540
593
541
594
const int64_t start_time = GetTimeMillis ();
595
+ g_researcher_tally.SetStartIndex (pindex);
542
596
543
597
for (; pindex; pindex = pindex->pnext ) {
544
598
if (pindex->nHeight + 1 == GetV11Threshold ()) {
0 commit comments