67 static constexpr auto kBACKEND_COUNTERS_KEY =
"backend_counters";
69 std::shared_ptr<BackendInterface> backend_;
70 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
71 std::shared_ptr<etlng::LoadBalancerInterface> balancer_;
72 std::shared_ptr<etlng::ETLServiceInterface const> etl_;
73 std::reference_wrapper<CountersType const> counters_;
80 bool backendCounters =
false;
87 boost::json::object counters;
88 std::optional<boost::json::object> backendCounters;
89 boost::json::object subscriptions;
90 boost::json::object
etl;
99 ripple::LedgerIndex seq = {};
100 std::optional<ripple::Fees> fees = std::nullopt;
107 std::size_t size = 0;
108 bool isEnabled =
false;
110 ripple::LedgerIndex latestLedgerSeq = {};
111 float objectHitRate = 1.0;
112 float successorHitRate = 1.0;
119 std::optional<AdminSection> adminSection = std::nullopt;
120 std::string completeLedgers;
121 uint32_t loadFactor = 1u;
122 std::chrono::time_point<std::chrono::system_clock> time = std::chrono::system_clock::now();
123 std::chrono::seconds uptime = {};
124 std::string clioVersion = util::build::getClioVersionString();
125 std::string xrplVersion = ripple::BuildInfo::getVersionString();
126 std::optional<boost::json::object> rippledInfo = std::nullopt;
129 bool isAmendmentBlocked =
false;
130 bool isCorruptionDetected =
false;
140 bool validated =
true;
155 std::shared_ptr<BackendInterface>
const& backend,
156 std::shared_ptr<feed::SubscriptionManagerInterface>
const& subscriptions,
157 std::shared_ptr<etlng::LoadBalancerInterface>
const& balancer,
158 std::shared_ptr<etlng::ETLServiceInterface const>
const&
etl,
159 CountersType
const& counters
162 , subscriptions_(subscriptions)
163 , balancer_(balancer)
165 , counters_(std::cref(counters))
176 spec([[maybe_unused]] uint32_t apiVersion)
178 static RpcSpec const kRPC_SPEC = {};
193 using namespace std::chrono;
195 auto const range = backend_->fetchLedgerRange();
196 ASSERT(range.has_value(),
"ServerInfo's ledger range must be available");
198 auto const lgrInfo = backend_->fetchLedgerBySequence(range->maxSequence, ctx.yield);
199 if (not lgrInfo.has_value())
202 auto const fees = backend_->fetchFees(lgrInfo->seq, ctx.yield);
203 if (not fees.has_value())
207 auto const sinceEpoch = duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
208 auto const age =
static_cast<int32_t
>(sinceEpoch) -
209 static_cast<int32_t
>(lgrInfo->closeTime.time_since_epoch().count()) -
212 output.info.completeLedgers = fmt::format(
"{}-{}", range->minSequence, range->maxSequence);
215 output.info.adminSection = {
216 .counters = counters_.get().report(),
217 .backendCounters = input.backendCounters ? std::make_optional(backend_->stats()) : std::nullopt,
218 .subscriptions = subscriptions_->report(),
219 .etl = etl_->getInfo()
223 auto const serverInfoRippled =
224 balancer_->forwardToRippled({{
"command",
"server_info"}}, ctx.clientIp, ctx.isAdmin, ctx.yield);
226 if (serverInfoRippled && !serverInfoRippled->contains(JS(error))) {
227 if (serverInfoRippled->contains(JS(result)) &&
228 serverInfoRippled->at(JS(result)).as_object().contains(JS(info))) {
229 output.info.rippledInfo = serverInfoRippled->at(JS(result)).as_object().at(JS(info)).as_object();
233 output.info.validatedLedger.age = age < 0 ? 0 : age;
234 output.info.validatedLedger.hash = ripple::strHex(lgrInfo->hash);
235 output.info.validatedLedger.seq = lgrInfo->seq;
236 output.info.validatedLedger.fees = fees;
237 output.info.cache.size = backend_->cache().size();
238 output.info.cache.isFull = backend_->cache().isFull();
239 output.info.cache.latestLedgerSeq = backend_->cache().latestLedgerSequence();
240 output.info.cache.objectHitRate = backend_->cache().getObjectHitRate();
241 output.info.cache.successorHitRate = backend_->cache().getSuccessorHitRate();
242 output.info.cache.isEnabled = not backend_->cache().isDisabled();
243 output.info.uptime = counters_.get().uptime();
244 output.info.isAmendmentBlocked = etl_->isAmendmentBlocked();
245 output.info.isCorruptionDetected = etl_->isCorruptionDetected();
252 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output)
254 using boost::json::value_from;
257 {JS(info), value_from(output.info)},
258 {JS(validated), output.validated},
263 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, InfoSection
const& info)
265 using boost::json::value_from;
266 using ripple::to_string;
269 {JS(complete_ledgers), info.completeLedgers},
270 {JS(load_factor), info.loadFactor},
271 {JS(time), to_string(std::chrono::floor<std::chrono::microseconds>(info.time))},
272 {JS(uptime), info.uptime.count()},
273 {
"clio_version", info.clioVersion},
274 {
"libxrpl_version", info.xrplVersion},
275 {JS(validated_ledger), value_from(info.validatedLedger)},
276 {
"cache", value_from(info.cache)},
279 if (info.isAmendmentBlocked)
280 jv.as_object()[JS(amendment_blocked)] =
true;
282 if (info.isCorruptionDetected)
283 jv.as_object()[
"corruption_detected"] =
true;
285 if (info.rippledInfo) {
286 auto const& rippledInfo = info.rippledInfo.value();
288 if (rippledInfo.contains(JS(load_factor)))
289 jv.as_object()[JS(load_factor)] = rippledInfo.at(JS(load_factor));
290 if (rippledInfo.contains(JS(validation_quorum)))
291 jv.as_object()[JS(validation_quorum)] = rippledInfo.at(JS(validation_quorum));
292 if (rippledInfo.contains(JS(build_version)))
293 jv.as_object()[
"rippled_version"] = rippledInfo.at(JS(build_version));
294 if (rippledInfo.contains(JS(network_id)))
295 jv.as_object()[JS(network_id)] = rippledInfo.at(JS(network_id));
298 if (info.adminSection) {
299 jv.as_object()[
"etl"] = info.adminSection->etl;
300 jv.as_object()[JS(counters)] = info.adminSection->counters;
301 jv.as_object()[JS(counters)].as_object()[
"subscriptions"] = info.adminSection->subscriptions;
302 if (info.adminSection->backendCounters.has_value()) {
303 jv.as_object()[kBACKEND_COUNTERS_KEY] = *info.adminSection->backendCounters;
309 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, ValidatedLedgerSection
const& validated)
312 {JS(age), validated.age},
313 {JS(hash), validated.hash},
314 {JS(seq), validated.seq},
315 {JS(base_fee_xrp), validated.fees->base.decimalXRP()},
316 {JS(reserve_base_xrp), validated.fees->reserve.decimalXRP()},
317 {JS(reserve_inc_xrp), validated.fees->increment.decimalXRP()},
322 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, CacheSection
const& cache)
325 {
"size", cache.size},
326 {
"is_enabled", cache.isEnabled},
327 {
"is_full", cache.isFull},
328 {
"latest_ledger_seq", cache.latestLedgerSeq},
329 {
"object_hit_rate", cache.objectHitRate},
330 {
"successor_hit_rate", cache.successorHitRate},
335 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv)
338 auto const jsonObject = jv.as_object();
339 if (jsonObject.contains(kBACKEND_COUNTERS_KEY) && jsonObject.at(kBACKEND_COUNTERS_KEY).is_bool())
340 input.backendCounters = jv.at(kBACKEND_COUNTERS_KEY).as_bool();
BaseServerInfoHandler(std::shared_ptr< BackendInterface > const &backend, std::shared_ptr< feed::SubscriptionManagerInterface > const &subscriptions, std::shared_ptr< etlng::LoadBalancerInterface > const &balancer, std::shared_ptr< etlng::ETLServiceInterface const > const &etl, CountersType const &counters)
Construct a new BaseServerInfoHandler object.
Definition ServerInfo.hpp:154