@@ -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,9 +645,9 @@ 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
- CAmount GetNewbieSuperblockAccrualCorrection (Cpid cpid)
650
+ CAmount GetNewbieSuperblockAccrualCorrection (const Cpid& cpid)
650
651
{
651
652
// This function is ONLY called if there is no accounting record for the CPID.
652
653
// For there to be no accounting record also means there is no recorded accrual for
@@ -658,23 +659,6 @@ 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;
677
-
678
662
// This lambda is almost a straight lift from the auditsnapshotaccrual RPC function. It is simplifed,
679
663
// because since the accrual account doesn't exist, there has been no staking for this CPID and no payout,
680
664
// so only superblock to superblock periods need to be considered.
@@ -685,10 +669,18 @@ class ResearcherTally
685
669
{
686
670
int64_t time_interval = high_time - low_time;
687
671
672
+ int64_t abs_time_interval = time_interval;
673
+
674
+ int sign = (time_interval >= 0 ) ? 1 : -1 ;
675
+
676
+ if (sign < 0 ) {
677
+ abs_time_interval = -time_interval;
678
+ }
679
+
688
680
// This is the same way that AccrualDelta calculates accruals in the snapshot calculator. Here
689
681
// we use the absolute value of the time interval to ensure negative values are carried through
690
682
// correctly in the bignumber calculations.
691
- const uint64_t base_accrual = time_interval
683
+ const uint64_t base_accrual = abs_time_interval
692
684
* magnitude.Scaled ()
693
685
* MAG_UNIT_NUMERATOR;
694
686
@@ -701,11 +693,11 @@ class ResearcherTally
701
693
accrual_bn /= Magnitude::SCALE_FACTOR;
702
694
accrual_bn /= MAG_UNIT_DENOMINATOR;
703
695
704
- period = accrual_bn.GetLow64 ();
696
+ period = accrual_bn.GetLow64 () * ( int64_t ) sign ;
705
697
}
706
698
else
707
699
{
708
- period = base_accrual
700
+ period = base_accrual * ( int64_t ) sign
709
701
* COIN
710
702
/ 86400
711
703
/ Magnitude::SCALE_FACTOR
@@ -729,33 +721,87 @@ class ResearcherTally
729
721
return period;
730
722
};
731
723
724
+ const GRC::BeaconRegistry& beacons = GRC::GetBeaconRegistry ();
725
+ GRC::BeaconOption beacon = beacons.Try (cpid);
726
+
727
+ LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: beacon registry size = %u" , __func__, beacons.Beacons ().size ());
728
+
729
+ if (beacon)
730
+ {
731
+ // Walk back the entries in the historical beacon map linked by renewal prev tx hash until the first
732
+ // beacon in the renewal chain is found (the original advertisement). The accrual starts no earlier
733
+ // than here.
734
+ while (beacon->Renewed ())
735
+ {
736
+ beacon = &beacons.HistoricalBeacons ().find (beacon->m_prev_beacon_txn_hash )->second ;
737
+ }
738
+ }
739
+ else
740
+ {
741
+
742
+ LogPrint (BCLog::LogFlags::ACCRUAL, " ERROR: %s: No active beacon for cpid %s." ,
743
+ __func__, cpid.ToString ());
744
+
745
+ return accrual;
746
+ }
747
+
748
+
749
+
750
+ const CBlockIndex* pindex_baseline = GRC::Tally::GetBaseline ();
751
+
752
+ // Start at the tip.
753
+ const CBlockIndex* pindex_high = mapBlockIndex[hashBestChain];
754
+
755
+ // Rewind pindex_high to the current superblock.
756
+ while (pindex_high->nHeight > m_current_superblock.m_height )
757
+ {
758
+ pindex_high = pindex_high->pprev ;
759
+ }
760
+
761
+ // Set pindex to the block before: (pindex_high->pprev).
762
+ const CBlockIndex* pindex = pindex_high->pprev ;
763
+
764
+ SuperblockPtr superblock;
732
765
unsigned int period_num = 0 ;
733
- while (pindex->nHeight < m_current_superblock.m_height )
766
+
767
+ while (pindex->nHeight >= pindex_baseline->nHeight )
734
768
{
735
- // This ensures we move to the next (lower height) superblock as the first period to
736
- // accrue.
737
- if (period_num && pindex->IsSuperblock ())
769
+ if (pindex->IsSuperblock ())
738
770
{
739
771
superblock = SuperblockPtr::ReadFromDisk (pindex);
740
772
741
773
const GRC::Magnitude magnitude = superblock->m_cpids .MagnitudeOf (cpid);
742
774
743
- tally_accrual_period (pindex->nTime , pindex_prev->nTime , magnitude);
775
+ CAmount period = tally_accrual_period (pindex->nTime , pindex_high->nTime , magnitude);
776
+
777
+ LogPrint (BCLog::LogFlags::ACCRUAL, " INFO %s: period_num = %u, "
778
+ " low height = %i, high height = %u, magnitude at low height SB = %f, "
779
+ " low time = %u, high time = %u, "
780
+ " accrual for period = %" PRId64 " , accrual = %" PRId64 " ." ,
781
+ __func__,
782
+ period_num,
783
+ pindex->nHeight ,
784
+ pindex_high->nHeight ,
785
+ magnitude.Floating (),
786
+ pindex->nTime ,
787
+ pindex_high->nTime ,
788
+ period,
789
+ accrual);
744
790
745
791
// Stop the accrual when we get to a superblock that is before the beacon advertisement.
746
- if (pindex->nTime < beacon->m_timestamp ) break ;
792
+ // if (pindex->nTime < beacon->m_timestamp) break;
793
+
794
+ // We are going backwards through the chain.
795
+ pindex_high = pindex;
796
+ ++period_num;
747
797
}
748
798
749
- // We are going backwards through the chain.
750
- pindex_prev = pindex;
751
799
pindex = pindex->pprev ;
752
- ++period_num;
753
800
}
754
801
755
802
return accrual;
756
803
}
757
804
758
-
759
805
// !
760
806
// ! \brief Locate the block index entry of the superblock before the
761
807
// ! snapshot accrual threshold.
0 commit comments