Skip to content

Commit

Permalink
Wire in greylist history to getautogreylist
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Jan 19, 2025
1 parent 14ea9dc commit f9a3392
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/gridcoin/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ class AutoGreylist
std::optional<bool> m_meets_greylisting_crit;
};

const std::vector<UpdateHistoryEntry> GetUpdateHistory() const
{
return m_update_history;
}

const std::string m_project_name;

uint8_t m_zcd_20_SB_count;
Expand Down
49 changes: 47 additions & 2 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2680,21 +2680,28 @@ UniValue listprojects(const UniValue& params, bool fHelp)

UniValue getautogreylist(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 1) {
if (fHelp || params.size() > 2) {
throw runtime_error(
"getautogreylist <bool> \n"
"getautogreylist <bool> <bool> \n"
"\n"
"<bool> -> true to show all projects, including those that do not meet greylisting criteria. Defaults to false. \n"
"\n"
"<bool> -> true to show greylist history for each project. Defaults to false. \n"
"\n"
"Displays information about projects that meet auto greylisting criteria.");
}

bool show_all_projects = false;
bool show_history = false;

if (params.size()) {
show_all_projects = params[0].get_bool();
}

if (params.size() >= 2) {
show_history = params[1].get_bool();
}

UniValue res(UniValue::VOBJ);

std::shared_ptr<GRC::AutoGreylist> greylist_ptr = GRC::AutoGreylist::GetAutoGreylistCache();
Expand All @@ -2715,6 +2722,44 @@ UniValue getautogreylist(const UniValue& params, bool fHelp)
entry.pushKV("was", iter.second.GetWAS().ToDouble());
entry.pushKV("meets_greylist_criteria", iter.second.m_meets_greylisting_crit);

if (show_history) {
UniValue entry_history(UniValue::VARR);

for (const auto& hist_entry : iter.second.GetUpdateHistory()) {
UniValue historical_entry(UniValue::VOBJ);

historical_entry.pushKV("superblocks_from_baseline", hist_entry.m_sb_from_baseline_processed);

if (hist_entry.m_total_credit) {
historical_entry.pushKV("total_credit", *hist_entry.m_total_credit);
} else {
historical_entry.pushKV("total_credit", "NA");
}

if (hist_entry.m_zcd) {
historical_entry.pushKV("zcd", *hist_entry.m_zcd);
} else {
historical_entry.pushKV("zcd", "NA");
}

if (hist_entry.m_was) {
historical_entry.pushKV("was", hist_entry.m_was->ToDouble());
} else {
historical_entry.pushKV("was", "NA");
}

if (hist_entry.m_meets_greylisting_crit) {
historical_entry.pushKV("meets_greylisting_criteria", *hist_entry.m_meets_greylisting_crit);
} else {
historical_entry.pushKV("meets_greylisting_criteria", "NA");
}

entry_history.push_back(historical_entry);
}

entry.pushKV("history", entry_history);
}

autogreylist.push_back(entry);
}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listmanifests" , 0 },
{ "listprojects" , 0 },
{ "getautogreylist" , 0 },
{ "getautogreylist" , 1 },
{ "sendalert" , 2 },
{ "sendalert" , 3 },
{ "sendalert" , 4 },
Expand Down

0 comments on commit f9a3392

Please sign in to comment.