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<etl::LoadBalancerInterface> balancer_;
72 std::shared_ptr<etl::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<etl::LoadBalancerInterface>
const& balancer,
158 std::shared_ptr<etl::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())
206 auto output = Output{};
207 auto const sinceEpoch =
208 duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
209 auto const age =
static_cast<int32_t
>(sinceEpoch) -
210 static_cast<int32_t
>(lgrInfo->closeTime.time_since_epoch().count()) -
213 output.info.completeLedgers = fmt::format(
"{}-{}", range->minSequence, range->maxSequence);
216 output.info.adminSection = {
217 .counters = counters_.get().report(),
219 input.backendCounters ? std::make_optional(backend_->stats()) : std::nullopt,
220 .subscriptions = subscriptions_->report(),
221 .etl = etl_->getInfo()
225 auto const serverInfoRippled = balancer_->forwardToRippled(
226 {{
"command",
"server_info"}}, ctx.clientIp, ctx.isAdmin, ctx.yield
229 if (serverInfoRippled && !serverInfoRippled->contains(JS(error))) {
230 if (serverInfoRippled->contains(JS(result)) &&
231 serverInfoRippled->at(JS(result)).as_object().contains(JS(info))) {
232 output.info.rippledInfo =
233 serverInfoRippled->at(JS(result)).as_object().at(JS(info)).as_object();
237 output.info.validatedLedger.age = age < 0 ? 0 : age;
238 output.info.validatedLedger.hash = ripple::strHex(lgrInfo->hash);
239 output.info.validatedLedger.seq = lgrInfo->seq;
240 output.info.validatedLedger.fees = fees;
241 output.info.cache.size = backend_->cache().size();
242 output.info.cache.isFull = backend_->cache().isFull();
243 output.info.cache.latestLedgerSeq = backend_->cache().latestLedgerSequence();
244 output.info.cache.objectHitRate = backend_->cache().getObjectHitRate();
245 output.info.cache.successorHitRate = backend_->cache().getSuccessorHitRate();
246 output.info.cache.isEnabled = not backend_->cache().isDisabled();
247 output.info.uptime = counters_.get().uptime();
248 output.info.isAmendmentBlocked = etl_->isAmendmentBlocked();
249 output.info.isCorruptionDetected = etl_->isCorruptionDetected();
256 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output)
258 using boost::json::value_from;
261 {JS(info), value_from(output.info)},
262 {JS(validated), output.validated},
267 tag_invoke(boost::json::value_from_tag, boost::json::value& jv,
InfoSection const& info)
269 using boost::json::value_from;
270 using ripple::to_string;
273 {JS(complete_ledgers), info.completeLedgers},
274 {JS(load_factor), info.loadFactor},
275 {JS(time), to_string(std::chrono::floor<std::chrono::microseconds>(info.time))},
276 {JS(uptime), info.uptime.count()},
277 {
"clio_version", info.clioVersion},
278 {
"libxrpl_version", info.xrplVersion},
279 {JS(validated_ledger), value_from(info.validatedLedger)},
280 {
"cache", value_from(info.cache)},
283 if (info.isAmendmentBlocked)
284 jv.as_object()[JS(amendment_blocked)] =
true;
286 if (info.isCorruptionDetected)
287 jv.as_object()[
"corruption_detected"] =
true;
289 if (info.rippledInfo) {
290 auto const& rippledInfo = info.rippledInfo.value();
292 if (rippledInfo.contains(JS(load_factor)))
293 jv.as_object()[JS(load_factor)] = rippledInfo.at(JS(load_factor));
294 if (rippledInfo.contains(JS(validation_quorum)))
295 jv.as_object()[JS(validation_quorum)] = rippledInfo.at(JS(validation_quorum));
296 if (rippledInfo.contains(JS(build_version)))
297 jv.as_object()[
"rippled_version"] = rippledInfo.at(JS(build_version));
298 if (rippledInfo.contains(JS(network_id)))
299 jv.as_object()[JS(network_id)] = rippledInfo.at(JS(network_id));
302 if (info.adminSection) {
303 jv.as_object()[
"etl"] = info.adminSection->etl;
304 jv.as_object()[JS(counters)] = info.adminSection->counters;
305 jv.as_object()[JS(counters)].as_object()[
"subscriptions"] =
306 info.adminSection->subscriptions;
307 if (info.adminSection->backendCounters.has_value()) {
308 jv.as_object()[kBACKEND_COUNTERS_KEY] = *info.adminSection->backendCounters;
315 boost::json::value_from_tag,
316 boost::json::value& jv,
321 {JS(age), validated.age},
322 {JS(hash), validated.hash},
323 {JS(seq), validated.seq},
324 {JS(base_fee_xrp), validated.fees->base.decimalXRP()},
325 {JS(reserve_base_xrp), validated.fees->reserve.decimalXRP()},
326 {JS(reserve_inc_xrp), validated.fees->increment.decimalXRP()},
331 tag_invoke(boost::json::value_from_tag, boost::json::value& jv,
CacheSection const& cache)
334 {
"size", cache.size},
335 {
"is_enabled", cache.isEnabled},
336 {
"is_full", cache.isFull},
337 {
"latest_ledger_seq", cache.latestLedgerSeq},
338 {
"object_hit_rate", cache.objectHitRate},
339 {
"successor_hit_rate", cache.successorHitRate},
344 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv)
346 auto input = BaseServerInfoHandler::Input{};
347 auto const jsonObject = jv.as_object();
348 if (jsonObject.contains(kBACKEND_COUNTERS_KEY) &&
349 jsonObject.at(kBACKEND_COUNTERS_KEY).is_bool())
350 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< etl::LoadBalancerInterface > const &balancer, std::shared_ptr< etl::ETLServiceInterface const > const &etl, CountersType const &counters)
Construct a new BaseServerInfoHandler object.
Definition ServerInfo.hpp:154