@@ -558,8 +558,8 @@ class ResearcherTally
558
558
{
559
559
const SnapshotCalculator calc (superblock.m_timestamp , m_current_superblock);
560
560
561
- LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: m_researchers.size() = %u" ,
562
- __func__, m_researchers.size ());
561
+ LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: superblock height = %u, m_researchers.size() = %u" ,
562
+ __func__, superblock. m_height , m_researchers.size ());
563
563
564
564
for (auto & account_pair : m_researchers) {
565
565
const Cpid cpid = account_pair.first ;
@@ -594,7 +594,7 @@ class ResearcherTally
594
594
ResearchAccount& account = m_researchers[iter.Cpid()];
595
595
account.m_accrual = calc.AccrualDelta(iter.Cpid(), account);
596
596
597
- LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: accrual account not found"
597
+ LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: accrual account not found "
598
598
"for CPID %s. Creating account with accrual %" PRId64" from "
599
599
"AccrualDelta() = %" PRId64 ". m_researchers.size() now %u",
600
600
__func__,
@@ -626,15 +626,16 @@ class ResearcherTally
626
626
627
627
account.m_accrual = accrual_correction + accrual_delta;
628
628
629
- LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: accrual account not found"
629
+ LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: accrual account not found "
630
630
" for CPID %s. Creating account with accrual %" PRId64" from "
631
- " Accrual Correction = %" PRId64 " , Accrual Delta = %" PRId64
632
- " , m_researchers.size() now %u." ,
631
+ " Accrual Correction = %" PRId64 " , Accrual Delta = %" PRId64 " , "
632
+ " superblock height = % " PRId64 " , m_researchers.size() = %u." ,
633
633
__func__,
634
634
iter.Cpid ().ToString (),
635
635
account.m_accrual ,
636
636
accrual_correction,
637
637
accrual_delta,
638
+ superblock.m_height ,
638
639
m_researchers.size ());
639
640
}
640
641
}
@@ -644,7 +645,7 @@ class ResearcherTally
644
645
// !
645
646
// ! \brief Compute "catch-up" accrual to correct for newbie accrual bug.
646
647
// !
647
- // ! \param superblock Incoming superblock to calculate rewards at .
648
+ // ! \param cpid for which to calculate the accrual correction .
648
649
// !
649
650
CAmount GetNewbieSuperblockAccrualCorrection (Cpid cpid)
650
651
{
@@ -658,22 +659,7 @@ class ResearcherTally
658
659
// similar to the calculation in the auditsnapshotaccrual RPC function.
659
660
CAmount accrual = 0 ;
660
661
661
- const GRC::BeaconRegistry& beacons = GRC::GetBeaconRegistry ();
662
-
663
- // This had better succeed, because it is coming from the incoming superblock cpids! If not just
664
- // return 0 accrual, because the beacon is not actually active.
665
- const GRC::BeaconOption beacon = beacons.Try (cpid);
666
-
667
- if (!beacon) return accrual;
668
-
669
- // Start at the tip.
670
- const CBlockIndex* pindex = mapBlockIndex[hashBestChain];
671
-
672
- // In the loop below we will be going BACKWARDS through the chain, so this will be at a HIGHER
673
- // height.
674
- const CBlockIndex* pindex_prev;
675
-
676
- SuperblockPtr superblock;
662
+ // const GRC::BeaconRegistry& beacons = GRC::GetBeaconRegistry();
677
663
678
664
// This lambda is almost a straight lift from the auditsnapshotaccrual RPC function. It is simplifed,
679
665
// because since the accrual account doesn't exist, there has been no staking for this CPID and no payout,
@@ -685,10 +671,18 @@ class ResearcherTally
685
671
{
686
672
int64_t time_interval = high_time - low_time;
687
673
674
+ int64_t abs_time_interval = time_interval;
675
+
676
+ int sign = (time_interval >= 0 ) ? 1 : -1 ;
677
+
678
+ if (sign < 0 ) {
679
+ abs_time_interval = -time_interval;
680
+ }
681
+
688
682
// This is the same way that AccrualDelta calculates accruals in the snapshot calculator. Here
689
683
// we use the absolute value of the time interval to ensure negative values are carried through
690
684
// correctly in the bignumber calculations.
691
- const uint64_t base_accrual = time_interval
685
+ const uint64_t base_accrual = abs_time_interval
692
686
* magnitude.Scaled ()
693
687
* MAG_UNIT_NUMERATOR;
694
688
@@ -701,11 +695,11 @@ class ResearcherTally
701
695
accrual_bn /= Magnitude::SCALE_FACTOR;
702
696
accrual_bn /= MAG_UNIT_DENOMINATOR;
703
697
704
- period = accrual_bn.GetLow64 ();
698
+ period = accrual_bn.GetLow64 () * ( int64_t ) sign ;
705
699
}
706
700
else
707
701
{
708
- period = base_accrual
702
+ period = base_accrual * ( int64_t ) sign
709
703
* COIN
710
704
/ 86400
711
705
/ Magnitude::SCALE_FACTOR
@@ -729,27 +723,63 @@ class ResearcherTally
729
723
return period;
730
724
};
731
725
726
+
727
+ // This had better succeed, because it is coming from the incoming superblock cpids! If not just
728
+ // return 0 accrual, because the beacon is not actually active.
729
+ // const GRC::BeaconOption beacon = beacons.Try(cpid);
730
+
731
+ // if (!beacon) return accrual;
732
+
733
+ const CBlockIndex* pindex_baseline = GRC::Tally::GetBaseline ();
734
+
735
+ // Start at the tip.
736
+ const CBlockIndex* pindex_high = mapBlockIndex[hashBestChain];
737
+
738
+ // Rewind pindex_high to the current superblock.
739
+ while (pindex_high->nHeight > m_current_superblock.m_height )
740
+ {
741
+ pindex_high = pindex_high->pprev ;
742
+ }
743
+
744
+ // Set pindex to the block before: (pindex_high->pprev).
745
+ const CBlockIndex* pindex = pindex_high->pprev ;
746
+
747
+ SuperblockPtr superblock;
732
748
unsigned int period_num = 0 ;
733
- while (pindex->nHeight < m_current_superblock.m_height )
749
+
750
+ while (pindex->nHeight >= pindex_baseline->nHeight )
734
751
{
735
- // This ensures we move to the next (lower height) superblock as the first period to
736
- // accrue.
737
- if (period_num && pindex->IsSuperblock ())
752
+ if (pindex->IsSuperblock ())
738
753
{
739
754
superblock = SuperblockPtr::ReadFromDisk (pindex);
740
755
741
756
const GRC::Magnitude magnitude = superblock->m_cpids .MagnitudeOf (cpid);
742
757
743
- tally_accrual_period (pindex->nTime , pindex_prev->nTime , magnitude);
758
+ CAmount period = tally_accrual_period (pindex->nTime , pindex_high->nTime , magnitude);
759
+
760
+ LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: period_num = %u, "
761
+ " low height = %i, high height = %u, magnitude at low height SB = %f, "
762
+ " low time = %u, high time = %u, "
763
+ " accrual for period = %" PRId64 " , accrual = %" PRId64 " ." ,
764
+ __func__,
765
+ period_num,
766
+ pindex->nHeight ,
767
+ pindex_high->nHeight ,
768
+ magnitude.Floating (),
769
+ pindex->nTime ,
770
+ pindex_high->nTime ,
771
+ period,
772
+ accrual);
744
773
745
774
// Stop the accrual when we get to a superblock that is before the beacon advertisement.
746
- if (pindex->nTime < beacon->m_timestamp ) break ;
775
+ // if (pindex->nTime < beacon->m_timestamp) break;
776
+
777
+ // We are going backwards through the chain.
778
+ pindex_high = pindex;
779
+ ++period_num;
747
780
}
748
781
749
- // We are going backwards through the chain.
750
- pindex_prev = pindex;
751
782
pindex = pindex->pprev ;
752
- ++period_num;
753
783
}
754
784
755
785
return accrual;
0 commit comments