mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-19 03:05:51 +00:00
Use ledger close times for stale data warning (#194)
This commit is contained in:
@@ -147,11 +147,9 @@ ReportingETL::publishLedger(ripple::LedgerInfo const& lgrInfo)
|
||||
backend_->cache().update(diff, lgrInfo.seq);
|
||||
backend_->updateRange(lgrInfo.seq);
|
||||
}
|
||||
auto now = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
auto closeTime = lgrInfo.closeTime.time_since_epoch().count();
|
||||
auto age = now - (rippleEpochStart + closeTime);
|
||||
|
||||
setLastClose(lgrInfo.closeTime);
|
||||
auto age = lastCloseAgeSeconds();
|
||||
// if the ledger closed over 10 minutes ago, assume we are still
|
||||
// catching up and don't publish
|
||||
if (age < 600)
|
||||
|
||||
@@ -139,6 +139,18 @@ private:
|
||||
lastPublish_ = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
/// The time that the most recently published ledger was closed.
|
||||
std::chrono::time_point<ripple::NetClock> lastCloseTime_;
|
||||
|
||||
mutable std::shared_mutex closeTimeMtx_;
|
||||
|
||||
void
|
||||
setLastClose(std::chrono::time_point<ripple::NetClock> lastCloseTime)
|
||||
{
|
||||
std::unique_lock lck(closeTimeMtx_);
|
||||
lastCloseTime_ = lastCloseTime;
|
||||
}
|
||||
|
||||
/// Download a ledger with specified sequence in full, via GetLedgerData,
|
||||
/// and write the data to the databases. This takes several minutes or
|
||||
/// longer.
|
||||
@@ -334,6 +346,17 @@ public:
|
||||
std::chrono::system_clock::now() - getLastPublish())
|
||||
.count();
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
lastCloseAgeSeconds() const
|
||||
{
|
||||
std::shared_lock lck(closeTimeMtx_);
|
||||
auto now = std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
auto closeTime = lastCloseTime_.time_since_epoch().count();
|
||||
return now - (rippleEpochStart + closeTime);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -422,8 +422,8 @@ handle_request(
|
||||
"This is a clio server. clio only serves validated data. If you "
|
||||
"want to talk to rippled, include 'ledger_index':'current' in your "
|
||||
"request");
|
||||
auto lastPublishAge = context->etl->lastPublishAgeSeconds();
|
||||
if (lastPublishAge >= 60)
|
||||
auto lastCloseAge = context->etl->lastCloseAgeSeconds();
|
||||
if (lastCloseAge >= 60)
|
||||
warnings.emplace_back("This server may be out of date");
|
||||
result["warnings"] = warnings;
|
||||
responseStr = boost::json::serialize(response);
|
||||
|
||||
@@ -351,10 +351,9 @@ public:
|
||||
"want to talk to rippled, include 'ledger_index':'current' in your "
|
||||
"request");
|
||||
|
||||
auto lastPublishAge = etl_->lastPublishAgeSeconds();
|
||||
if (lastPublishAge >= 60)
|
||||
auto lastCloseAge = etl_->lastCloseAgeSeconds();
|
||||
if (lastCloseAge >= 60)
|
||||
warnings.emplace_back("This server may be out of date");
|
||||
|
||||
response["warnings"] = warnings;
|
||||
std::string responseStr = boost::json::serialize(response);
|
||||
if (!dosGuard_.add(*ip, responseStr.size()))
|
||||
|
||||
Reference in New Issue
Block a user