mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-30 08:35:52 +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_->cache().update(diff, lgrInfo.seq);
|
||||||
backend_->updateRange(lgrInfo.seq);
|
backend_->updateRange(lgrInfo.seq);
|
||||||
}
|
}
|
||||||
auto now = std::chrono::duration_cast<std::chrono::seconds>(
|
|
||||||
std::chrono::system_clock::now().time_since_epoch())
|
setLastClose(lgrInfo.closeTime);
|
||||||
.count();
|
auto age = lastCloseAgeSeconds();
|
||||||
auto closeTime = lgrInfo.closeTime.time_since_epoch().count();
|
|
||||||
auto age = now - (rippleEpochStart + closeTime);
|
|
||||||
// if the ledger closed over 10 minutes ago, assume we are still
|
// if the ledger closed over 10 minutes ago, assume we are still
|
||||||
// catching up and don't publish
|
// catching up and don't publish
|
||||||
if (age < 600)
|
if (age < 600)
|
||||||
|
|||||||
@@ -139,6 +139,18 @@ private:
|
|||||||
lastPublish_ = std::chrono::system_clock::now();
|
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,
|
/// Download a ledger with specified sequence in full, via GetLedgerData,
|
||||||
/// and write the data to the databases. This takes several minutes or
|
/// and write the data to the databases. This takes several minutes or
|
||||||
/// longer.
|
/// longer.
|
||||||
@@ -334,6 +346,17 @@ public:
|
|||||||
std::chrono::system_clock::now() - getLastPublish())
|
std::chrono::system_clock::now() - getLastPublish())
|
||||||
.count();
|
.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
|
#endif
|
||||||
|
|||||||
@@ -422,8 +422,8 @@ handle_request(
|
|||||||
"This is a clio server. clio only serves validated data. If you "
|
"This is a clio server. clio only serves validated data. If you "
|
||||||
"want to talk to rippled, include 'ledger_index':'current' in your "
|
"want to talk to rippled, include 'ledger_index':'current' in your "
|
||||||
"request");
|
"request");
|
||||||
auto lastPublishAge = context->etl->lastPublishAgeSeconds();
|
auto lastCloseAge = context->etl->lastCloseAgeSeconds();
|
||||||
if (lastPublishAge >= 60)
|
if (lastCloseAge >= 60)
|
||||||
warnings.emplace_back("This server may be out of date");
|
warnings.emplace_back("This server may be out of date");
|
||||||
result["warnings"] = warnings;
|
result["warnings"] = warnings;
|
||||||
responseStr = boost::json::serialize(response);
|
responseStr = boost::json::serialize(response);
|
||||||
|
|||||||
@@ -351,10 +351,9 @@ public:
|
|||||||
"want to talk to rippled, include 'ledger_index':'current' in your "
|
"want to talk to rippled, include 'ledger_index':'current' in your "
|
||||||
"request");
|
"request");
|
||||||
|
|
||||||
auto lastPublishAge = etl_->lastPublishAgeSeconds();
|
auto lastCloseAge = etl_->lastCloseAgeSeconds();
|
||||||
if (lastPublishAge >= 60)
|
if (lastCloseAge >= 60)
|
||||||
warnings.emplace_back("This server may be out of date");
|
warnings.emplace_back("This server may be out of date");
|
||||||
|
|
||||||
response["warnings"] = warnings;
|
response["warnings"] = warnings;
|
||||||
std::string responseStr = boost::json::serialize(response);
|
std::string responseStr = boost::json::serialize(response);
|
||||||
if (!dosGuard_.add(*ip, responseStr.size()))
|
if (!dosGuard_.add(*ip, responseStr.size()))
|
||||||
|
|||||||
Reference in New Issue
Block a user