Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verifiedbeaconreport and pendingbeaconreport #1696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 121 additions & 4 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ extern UniValue SuperblockReport(int lookback = 14, bool displaycontract = false
extern bool ScraperSynchronizeDPOR();
std::string ExplainMagnitude(std::string sCPID);

extern ScraperPendingBeaconMap GetPendingBeaconsForReport();
extern ScraperPendingBeaconMap GetVerifiedBeaconsForReport(bool from_global = false);


extern UniValue GetJSONVersionReport(const int64_t lookback, const bool full_version);

bool GetEarliestStakeTime(std::string grcaddress, std::string cpid);
Expand Down Expand Up @@ -735,18 +739,29 @@ UniValue revokebeacon(const UniValue& params, bool fHelp)

UniValue beaconreport(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
if (fHelp || params.size() > 0)
throw runtime_error(
"beaconreport\n"
"\n"
"Displays list of valid beacons in the network\n");

LOCK(cs_main);

UniValue results(UniValue::VARR);

for (const auto& beacon_pair : NN::GetBeaconRegistry().Beacons())
std::vector<std::pair<NN::Cpid, NN::Beacon>> active_beacons;

// Minimize the lock on cs_main.
{
LOCK(cs_main);

const auto& beacon_map = NN::GetBeaconRegistry().Beacons();

active_beacons.reserve(beacon_map.size());
active_beacons.assign(beacon_map.begin(), beacon_map.end());
}

for (const auto& beacon_pair : active_beacons)
{

UniValue entry(UniValue::VOBJ);

entry.pushKV("cpid", beacon_pair.first.ToString());
Expand All @@ -759,6 +774,108 @@ UniValue beaconreport(const UniValue& params, bool fHelp)
return results;
}

UniValue beaconconvergence(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw runtime_error(
"verifiedbeaconreport\n"
"\n"
"Displays verified and pending beacons from the scraper viewpoint.\n");

UniValue results(UniValue::VOBJ);

std::vector<std::pair<NN::Cpid, NN::Beacon>> active_beacons;

UniValue verified_from_global(UniValue::VARR);

ScraperPendingBeaconMap verified_beacons_from_global = GetVerifiedBeaconsForReport(true);

for (const auto&verified_beacon_pair : verified_beacons_from_global)
{
UniValue entry(UniValue::VOBJ);

entry.pushKV("cpid", verified_beacon_pair.first);
entry.pushKV("timestamp", verified_beacon_pair.second.timestamp);

verified_from_global.push_back(entry);
}

results.pushKV("verified beacons from scraper global", verified_from_global);


UniValue verified_from_convergence(UniValue::VARR);

ScraperPendingBeaconMap verified_beacons_from_convergence = GetVerifiedBeaconsForReport(false);

for (const auto&verified_beacon_pair : verified_beacons_from_convergence)
{
UniValue entry(UniValue::VOBJ);

entry.pushKV("cpid", verified_beacon_pair.first);
entry.pushKV("timestamp", verified_beacon_pair.second.timestamp);

verified_from_convergence.push_back(entry);
}

results.pushKV("verified beacons from latest convergence", verified_from_convergence);

UniValue pending(UniValue::VARR);

ScraperPendingBeaconMap pending_beacons = GetPendingBeaconsForReport();

for (const auto& beacon_pair : pending_beacons)
{
UniValue entry(UniValue::VOBJ);

entry.pushKV("cpid", beacon_pair.second.cpid);
entry.pushKV("address", beacon_pair.first);
entry.pushKV("timestamp", beacon_pair.second.timestamp);

pending.push_back(entry);
}

results.pushKV("pending beacons from GetConsensusBeaconList", pending);

return results;
}

UniValue pendingbeaconreport(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 0)
throw runtime_error(
"pendingbeaconreport\n"
"\n"
"Displays pending beacons directly from the beacon registry.\n");

UniValue results(UniValue::VARR);

std::vector<std::pair<CKeyID, NN::PendingBeacon>> pending_beacons;

// Minimize the lock on cs_main.
{
LOCK(cs_main);

const auto& pending_beacon_map = NN::GetBeaconRegistry().PendingBeacons();

pending_beacons.reserve(pending_beacon_map.size());
pending_beacons.assign(pending_beacon_map.begin(), pending_beacon_map.end());
}

for (const auto& pending_beacon_pair : pending_beacons)
{

UniValue entry(UniValue::VOBJ);

entry.pushKV("cpid", pending_beacon_pair.second.m_cpid.ToString());
entry.pushKV("address", pending_beacon_pair.first.ToString());
entry.pushKV("timestamp", pending_beacon_pair.second.m_timestamp);

results.push_back(entry);
}

return results;
}

UniValue beaconstatus(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 1)
Expand Down
2 changes: 2 additions & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ static const CRPCCommand vRPCCommands[] =

// Mining commands
{ "advertisebeacon", &advertisebeacon, cat_mining },
{ "beaconconvergence", &beaconconvergence, cat_mining },
{ "beaconreport", &beaconreport, cat_mining },
{ "beaconstatus", &beaconstatus, cat_mining },
{ "explainmagnitude", &explainmagnitude, cat_mining },
Expand All @@ -348,6 +349,7 @@ static const CRPCCommand vRPCCommands[] =
{ "magnitude", &magnitude, cat_mining },
{ "myneuralhash", &myneuralhash, cat_mining },
{ "neuralhash", &neuralhash, cat_mining },
{ "pendingbeaconreport", &pendingbeaconreport, cat_mining },
{ "resetcpids", &resetcpids, cat_mining },
{ "revokebeacon", &revokebeacon, cat_mining },
{ "staketime", &staketime, cat_mining },
Expand Down
2 changes: 2 additions & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp);
//Mining
extern UniValue advertisebeacon(const UniValue& params, bool fHelp);
extern UniValue beaconreport(const UniValue& params, bool fHelp);
extern UniValue beaconconvergence(const UniValue& params, bool fHelp);
extern UniValue beaconstatus(const UniValue& params, bool fHelp);
extern UniValue explainmagnitude(const UniValue& params, bool fHelp);
extern UniValue getmininginfo(const UniValue& params, bool fHelp);
extern UniValue lifetime(const UniValue& params, bool fHelp);
extern UniValue magnitude(const UniValue& params, bool fHelp);
extern UniValue myneuralhash(const UniValue& params, bool fHelp);
extern UniValue neuralhash(const UniValue& params, bool fHelp);
extern UniValue pendingbeaconreport(const UniValue& params, bool fHelp);
extern UniValue resetcpids(const UniValue& params, bool fHelp);
extern UniValue revokebeacon(const UniValue& params, bool fHelp);
extern UniValue staketime(const UniValue& params, bool fHelp);
Expand Down
35 changes: 35 additions & 0 deletions src/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4925,6 +4925,41 @@ ScraperStatsAndVerifiedBeacons GetScraperStatsAndVerifiedBeacons(const Converged
return stats_and_verified_beacons;
}

// This is for rpc report functions.
ScraperPendingBeaconMap GetPendingBeaconsForReport()
{
return GetConsensusBeaconList().mPendingMap;
jamescowens marked this conversation as resolved.
Show resolved Hide resolved
}

ScraperPendingBeaconMap GetVerifiedBeaconsForReport(bool from_global)
{
ScraperPendingBeaconMap VerifiedBeacons;

if (from_global)
{
LOCK(cs_VerifiedBeacons);
_log(logattribute::INFO, "LOCK", "cs_VerifiedBeacons");

// An intentional copy.
VerifiedBeacons = GetVerifiedBeacons().mVerifiedMap;

_log(logattribute::INFO, "ENDLOCK", "cs_VerifiedBeacons");

}
else
{
LOCK(cs_ConvergedScraperStatsCache);
_log(logattribute::INFO, "LOCK", "cs_ConvergedScraperStatsCache");

// An intentional copy.
VerifiedBeacons = GetScraperStatsAndVerifiedBeacons(ConvergedScraperStatsCache).mVerifiedMap;

_log(logattribute::INFO, "ENDLOCK", "cs_ConvergedScraperStatsCache");
}

return VerifiedBeacons;
}


/***********************
* Neural Network *
Expand Down
2 changes: 2 additions & 0 deletions src/scraper/scraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ scraperSBvalidationtype ValidateSuperblock(const NN::Superblock& NewFormatSuperb
std::vector<uint160> GetVerifiedBeaconIDs(const ConvergedManifest& StructConvergedManifest);
std::vector<uint160> GetVerifiedBeaconIDs(const ScraperPendingBeaconMap& VerifiedBeaconMap);
ScraperStatsAndVerifiedBeacons GetScraperStatsAndVerifiedBeacons(const ConvergedScraperStats &stats);
ScraperPendingBeaconMap GetPendingBeaconsForReport();
ScraperPendingBeaconMap GetVerifiedBeaconsForReport(bool from_global = false);

static std::vector<std::string> vstatsobjecttypestrings = { "NetWorkWide", "byCPID", "byProject", "byCPIDbyProject" };

Expand Down