Skip to content

Commit

Permalink
Fix bug in UpdateGreylistCandidateEntry (tbs)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jan 20, 2025
1 parent 5a086c3 commit 9c15cee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "node/ui_interface.h"

#include <algorithm>
#include <atomic>

using namespace GRC;
using LogFlags = BCLog::LogFlags;
Expand Down
70 changes: 36 additions & 34 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,45 +641,47 @@ class AutoGreylist
{
uint8_t sbs_from_baseline_no_update = sb_from_baseline - m_sb_from_baseline_processed - 1;

m_sb_from_baseline_processed = sb_from_baseline;

// ZCD part. Remember we are going backwards, so if total_credit is greater than or equal to
// the bookmark, then we have zero or even negative project total credit between superblocks, so
// this qualifies as a ZCD.
if (m_sb_from_baseline_processed <= 20) {
// Skipped updates count as ZCDs. We stop counting at 20 superblocks (back) from
// the initial SB baseline. The skipped updates may actually not be used in practice, because we are
// iterating over the entire whitelist for each SB and inserting std::nullopt TC updates for each project.
m_zcd_20_SB_count += sbs_from_baseline_no_update;

// If total credit is greater than the bookmark, this means that (going forward in time) credit actually
// declined, so in addition to the zero credit days recorded for the skipped updates, we must add an
// additional day for the credit decline (going forward in time). If total credit is std::nullopt, then
// this means no statistics available, which also is a ZCD.
if ((total_credit && total_credit >= m_TC_bookmark) || !total_credit){
++m_zcd_20_SB_count;
if (sb_from_baseline > 0) {
// ZCD part. Remember we are going backwards, so if total_credit is greater than or equal to
// the bookmark, then we have zero or even negative project total credit between superblocks, so
// this qualifies as a ZCD.
if (sb_from_baseline <= 20) {
// Skipped updates count as ZCDs. We stop counting at 20 superblocks (back) from
// the initial SB baseline. The skipped updates may actually not be used in practice, because we are
// iterating over the entire whitelist for each SB and inserting std::nullopt TC updates for each project.
m_zcd_20_SB_count += sbs_from_baseline_no_update;

// If total credit is greater than the bookmark, this means that (going forward in time) credit actually
// declined, so in addition to the zero credit days recorded for the skipped updates, we must add an
// additional day for the credit decline (going forward in time). If total credit is std::nullopt, then
// this means no statistics available, which also is a ZCD.
if ((total_credit && total_credit >= m_TC_bookmark) || !total_credit){
++m_zcd_20_SB_count;
}
}
}

// WAS part. Here we deal with two numbers, the 40 SB from baseline, and the 7 SB from baseline. We use
// the initial bookmark, and compute the difference, which is the same as adding up the deltas between
// the TC's in each superblock. For updates with no total credit entry (i.e. std::optional is nullopt),
// do not change the sums.
//
// If the initial bookmark TC is not available (i.e. the current SB did not have stats for this project),
// but this update does, then update the initial bookmark to this total credit.
if (!m_TC_initial_bookmark && total_credit) {
m_TC_initial_bookmark = total_credit;
}

if (total_credit && m_TC_initial_bookmark && m_TC_initial_bookmark > total_credit) {
if (m_sb_from_baseline_processed <= 7) {
m_TC_7_SB_sum = *m_TC_initial_bookmark - *total_credit;
// WAS part. Here we deal with two numbers, the 40 SB from baseline, and the 7 SB from baseline. We use
// the initial bookmark, and compute the difference, which is the same as adding up the deltas between
// the TC's in each superblock. For updates with no total credit entry (i.e. std::optional is nullopt),
// do not change the sums.
//
// If the initial bookmark TC is not available (i.e. the current SB did not have stats for this project),
// but this update does, then update the initial bookmark to this total credit.
if (!m_TC_initial_bookmark && total_credit) {
m_TC_initial_bookmark = total_credit;
}

if (m_sb_from_baseline_processed <= 40) {
m_TC_40_SB_sum = *m_TC_initial_bookmark - *total_credit;
if (total_credit && m_TC_initial_bookmark && m_TC_initial_bookmark > total_credit) {
if (sb_from_baseline <= 7) {
m_TC_7_SB_sum = *m_TC_initial_bookmark - *total_credit;
}

if (sb_from_baseline <= 40) {
m_TC_40_SB_sum = *m_TC_initial_bookmark - *total_credit;
}
}

m_sb_from_baseline_processed = sb_from_baseline;
}

// Update bookmark.
Expand Down

0 comments on commit 9c15cee

Please sign in to comment.