Skip to content

Commit

Permalink
Fix suspected bug in AutoGreylist::Reset()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jan 21, 2025
1 parent 44211b5 commit e9c0e11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/gridcoin/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ void AutoGreylist::Reset()
{
if (m_greylist_ptr != nullptr) {
m_greylist_ptr->clear();
} else {
m_greylist_ptr = std::make_shared<Greylist>();
}

m_superblock_hash = Superblock().GetHash(true);
Expand All @@ -585,7 +587,7 @@ WhitelistSnapshot Whitelist::Snapshot(const ProjectEntry::ProjectFilterFlag& fil
return WhitelistSnapshot(std::make_shared<ProjectList>(projects), filter);
}

if (refresh_greylist) {
if (refresh_greylist && m_auto_greylist != nullptr) {
m_auto_greylist->Refresh();
}

Expand All @@ -609,7 +611,7 @@ WhitelistSnapshot Whitelist::Snapshot(const ProjectEntry::ProjectFilterFlag& fil
// applies the current state of the greylist at the time of the construction of the whitelist snapshot, without
// disturbing the underlying projects registry.

bool in_greylist = m_auto_greylist->Contains(iter.first);
bool in_greylist = m_auto_greylist != nullptr ? m_auto_greylist->Contains(iter.first) : false;

// If the project does NOT have a status of auto greylist override, and it is either active or already manually
// greylisted, then if it is in the greylist, mark with the status auto greylisted.
Expand Down
2 changes: 0 additions & 2 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,6 @@ class AutoGreylist
//!
void Reset();

//static std::shared_ptr<AutoGreylist> GetAutoGreylistCache();

private:
mutable CCriticalSection autogreylist_lock;

Expand Down
30 changes: 15 additions & 15 deletions src/test/gridcoin/project_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,19 @@ BOOST_AUTO_TEST_CASE(it_adds_whitelisted_projects_from_contract_data)
int height = 0;
int64_t time = 0;

BOOST_CHECK(whitelist.Snapshot().size() == 0);
BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == false);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).size() == 0);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == false);

AddProjectEntry(1, "Enigma", "http://enigma.test", false, height, time, false);

BOOST_CHECK(whitelist.Snapshot().size() == 1);
BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == true);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).size() == 1);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == true);

AddProjectEntry(2, "Foo", "http://foo.test", false, height++, time++, false);

BOOST_CHECK(whitelist.Snapshot().size() == 2);
BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == true);
BOOST_CHECK(whitelist.Snapshot().Contains("Foo") == true);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).size() == 2);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == true);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Foo") == true);
}

BOOST_AUTO_TEST_CASE(it_removes_whitelisted_projects_from_contract_data)
Expand All @@ -503,13 +503,13 @@ BOOST_AUTO_TEST_CASE(it_removes_whitelisted_projects_from_contract_data)

AddProjectEntry(1, "Enigma", "http://enigma.test", false, height, time, true);

BOOST_CHECK(whitelist.Snapshot().size() == 1);
BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == true);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).size() == 1);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == true);

DeleteProjectEntry(1, "Enigma", height++, time++, false);

BOOST_CHECK(whitelist.Snapshot().size() == 0);
BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == false);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).size() == 0);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == false);
}

BOOST_AUTO_TEST_CASE(it_does_not_mutate_existing_snapshots)
Expand All @@ -522,14 +522,14 @@ BOOST_AUTO_TEST_CASE(it_does_not_mutate_existing_snapshots)
AddProjectEntry(1, "Enigma", "http://enigma.test", false, height, time, true);
AddProjectEntry(2, "Foo", "http://foo.test", true, height++, time++, false);

auto snapshot = whitelist.Snapshot();
auto snapshot = whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false);

DeleteProjectEntry(1, "Enigma", height, time, false);

BOOST_CHECK(snapshot.Contains("Enigma") == true);

BOOST_CHECK(whitelist.Snapshot().Contains("Enigma") == false);
BOOST_CHECK(whitelist.Snapshot().Contains("Foo") == true);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Enigma") == false);
BOOST_CHECK(whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false).Contains("Foo") == true);
}

BOOST_AUTO_TEST_CASE(it_overwrites_projects_with_the_same_name)
Expand All @@ -542,7 +542,7 @@ BOOST_AUTO_TEST_CASE(it_overwrites_projects_with_the_same_name)
AddProjectEntry(1, "Enigma", "http://enigma.test", false, height, time, true);
AddProjectEntry(2, "Enigma", "http://new.enigma.test", true, height++, time++, false);

auto snapshot = whitelist.Snapshot();
auto snapshot = whitelist.Snapshot(GRC::ProjectEntry::ProjectFilterFlag::ACTIVE, false, false);
BOOST_CHECK(snapshot.size() == 1);

for (const auto& project : snapshot) {
Expand Down

0 comments on commit e9c0e11

Please sign in to comment.