Skip to content

Commit

Permalink
Improve reporting of ledger age in server_info
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrippled authored and nbougalis committed Jun 26, 2020
1 parent df29e98 commit 00702f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/ripple/app/ledger/LedgerMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Transaction;
class LedgerMaster : public Stoppable, public AbstractFetchPackContainer
{
public:
// Age for last validated ledger if the process has yet to validate.
static constexpr std::chrono::seconds NO_VALIDATED_LEDGER_AGE =
std::chrono::hours{24 * 14};

explicit LedgerMaster(
Application& app,
Stopwatch& stopwatch,
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/ledger/impl/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ LedgerMaster::getValidatedLedgerAge()
if (valClose == 0s)
{
JLOG(m_journal.debug()) << "No validated ledger";
return weeks{2};
return NO_VALIDATED_LEDGER_AGE;
}

std::chrono::seconds ret = app_.timeKeeper().closeTime().time_since_epoch();
Expand Down
26 changes: 17 additions & 9 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2757,16 +2757,24 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters)
if (std::abs(closeOffset.count()) >= 60)
l[jss::close_time_offset] = closeOffset.count();

auto lCloseTime = lpClosed->info().closeTime;
auto closeTime = app_.timeKeeper().closeTime();
if (lCloseTime <= closeTime)
constexpr std::chrono::seconds HIGH_AGE_THRESHOLD{1000000};
if (m_ledgerMaster.haveValidated())
{
using namespace std::chrono_literals;
auto age = closeTime - lCloseTime;
if (age < 1000000s)
l[jss::age] = Json::UInt(age.count());
else
l[jss::age] = 0;
auto const age = m_ledgerMaster.getValidatedLedgerAge();
l[jss::age] =
Json::UInt(age < HIGH_AGE_THRESHOLD ? age.count() : 0);
}
else
{
auto lCloseTime = lpClosed->info().closeTime;
auto closeTime = app_.timeKeeper().closeTime();
if (lCloseTime <= closeTime)
{
using namespace std::chrono_literals;
auto age = closeTime - lCloseTime;
l[jss::age] =
Json::UInt(age < HIGH_AGE_THRESHOLD ? age.count() : 0);
}
}
}

Expand Down

0 comments on commit 00702f2

Please sign in to comment.