Skip to content

Commit

Permalink
Merge pull request #1643 from jamescowens/convergencereport
Browse files Browse the repository at this point in the history
adds an rpc call convergencereport
  • Loading branch information
jamescowens committed Feb 22, 2020
2 parents a0070d8 + 6054c5c commit f107dfc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rpcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ static const CRPCCommand vRPCCommands[] =
{ "deletecscrapermanifest", &deletecscrapermanifest, cat_developer },
{ "archivelog", &archivelog, cat_developer },
{ "testnewsb", &testnewsb, cat_developer },
{ "convergencereport", &convergencereport, cat_developer },

// Network commands
{ "addnode", &addnode, cat_network },
Expand Down
1 change: 1 addition & 0 deletions src/rpcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ extern UniValue savescraperfilemanifest(const UniValue& params, bool fHelp);
extern UniValue deletecscrapermanifest(const UniValue& params, bool fHelp);
extern UniValue archivelog(const UniValue& params, bool fHelp);
extern UniValue testnewsb(const UniValue& params, bool fHelp);
extern UniValue convergencereport(const UniValue& params, bool fHelp);

// Network
extern UniValue addnode(const UniValue& params, bool fHelp);
Expand Down
81 changes: 81 additions & 0 deletions src/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5434,7 +5434,88 @@ UniValue archivelog(const UniValue& params, bool fHelp)
return UniValue(ret);
}

UniValue convergencereport(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 0 )
throw std::runtime_error(
"convergencereport\n"
"Display local node report of scraper convergence.\n"
);

// See if converged stats/contract update needed...
bool bConvergenceUpdateNeeded = true;
{
LOCK(cs_ConvergedScraperStatsCache);

if (GetAdjustedTime() - ConvergedScraperStatsCache.nTime < (nScraperSleep / 1000) || ConvergedScraperStatsCache.bClean)
{
bConvergenceUpdateNeeded = false;
}
}

if (bConvergenceUpdateNeeded)
{
// Don't need the output but will use the global cache, which will be updated.
ScraperGetSuperblockContract(false, false);
}

UniValue result(UniValue::VOBJ);

{
LOCK(cs_ConvergedScraperStatsCache);

if (!ConvergedScraperStatsCache.NewFormatSuperblock.WellFormed())
{
throw JSONRPCError(RPC_MISC_ERROR, "Error: A convergence cannot be formed at this time. Please review the scraper.log for details.");
}

int64_t nConvergenceTime = ConvergedScraperStatsCache.nTime;

result.pushKV("convergence_timestamp", nConvergenceTime);
result.pushKV("convergence_datetime", DateTimeStrFormat("%x %H:%M:%S UTC", nConvergenceTime));

UniValue ExcludedProjects(UniValue::VARR);

for (const auto& entry : ConvergedScraperStatsCache.Convergence.vExcludedProjects)
{
ExcludedProjects.push_back(entry);
}

result.pushKV("excluded_projects", ExcludedProjects);


UniValue IncludedScrapers(UniValue::VARR);

for (const auto& entry : ConvergedScraperStatsCache.Convergence.vIncludedScrapers)
{
IncludedScrapers.push_back(entry);
}

result.pushKV("included_scrapers", IncludedScrapers);


UniValue ExcludedScrapers(UniValue::VARR);

for (const auto& entry : ConvergedScraperStatsCache.Convergence.vExcludedScrapers)
{
ExcludedScrapers.push_back(entry);
}

result.pushKV("excluded_scrapers", ExcludedScrapers);


UniValue ScrapersNotPublishing(UniValue::VARR);

for (const auto& entry : ConvergedScraperStatsCache.Convergence.vScrapersNotPublishing)
{
ScrapersNotPublishing.push_back(entry);
}

result.pushKV("scrapers_not_publishing", ScrapersNotPublishing);
}

return result;
}

UniValue testnewsb(const UniValue& params, bool fHelp)
{
Expand Down

0 comments on commit f107dfc

Please sign in to comment.