51 static constexpr auto kBackendCountersKey =
"backend_counters";
53 std::shared_ptr<BackendInterface> backend_;
54 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
55 std::shared_ptr<etl::LoadBalancerInterface> balancer_;
56 std::shared_ptr<etl::ETLServiceInterface const> etl_;
57 std::reference_wrapper<CountersType const> counters_;
64 boost::json::object counters;
65 std::optional<boost::json::object> backendCounters;
66 boost::json::object subscriptions;
67 boost::json::object etl;
76 xrpl::LedgerIndex seq = {};
77 std::optional<xrpl::Fees> fees = std::nullopt;
85 bool isEnabled =
false;
87 xrpl::LedgerIndex latestLedgerSeq = {};
88 float objectHitRate = 1.0;
89 float successorHitRate = 1.0;
96 std::optional<AdminSection> adminSection = std::nullopt;
97 std::string completeLedgers;
98 uint32_t loadFactor = 1u;
99 std::chrono::time_point<std::chrono::system_clock> time = ClockType::now();
100 std::chrono::seconds uptime = {};
101 std::string clioVersion = util::build::getClioVersionString();
102 std::string xrplVersion = xrpl::build_info::getVersionString();
103 std::optional<boost::json::object> rippledInfo = std::nullopt;
106 bool isAmendmentBlocked =
false;
107 bool isCorruptionDetected =
false;
117 bool validated =
true;
132 std::shared_ptr<BackendInterface> backend,
133 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
134 std::shared_ptr<etl::LoadBalancerInterface> balancer,
135 std::shared_ptr<etl::ETLServiceInterface const> etl,
136 CountersType
const& counters
138 : backend_(std::move(backend))
139 , subscriptions_(std::move(subscriptions))
140 , balancer_(std::move(balancer))
141 , etl_(std::move(etl))
142 , counters_(std::cref(counters))
157 using namespace std::chrono;
159 auto const range = backend_->fetchLedgerRange();
160 ASSERT(range.has_value(),
"ServerInfo's ledger range must be available");
162 auto const lgrInfo = backend_->fetchLedgerBySequence(
167 if (not lgrInfo.has_value())
168 return Error{Status{XrpldError::RpcInternal}};
170 auto const fees = backend_->fetchFees(lgrInfo->seq, ctx.yield);
171 if (not fees.has_value())
172 return Error{Status{XrpldError::RpcInternal}};
174 auto output = Output{};
175 auto const sinceEpoch = duration_cast<seconds>(output.info.time.time_since_epoch()).count();
176 auto const age =
static_cast<int32_t
>(sinceEpoch) -
177 static_cast<int32_t
>(lgrInfo->closeTime.time_since_epoch().count()) -
181 output.info.completeLedgers = fmt::format(
"{}-{}", range->minSequence, range->maxSequence);
185 output.info.adminSection = {
186 .counters = counters_.get().report(),
188 input.backendCounters ? std::make_optional(backend_->stats()) : std::nullopt,
189 .subscriptions = subscriptions_->report(),
190 .etl = etl_->getInfo()
194 auto const serverInfoRippled = balancer_->forwardToRippled(
195 {{
"command",
"server_info"}}, ctx.clientIp, ctx.isAdmin, ctx.yield
198 if (serverInfoRippled && !serverInfoRippled->contains(JS(error))) {
199 if (serverInfoRippled->contains(JS(result)) &&
200 serverInfoRippled->at(JS(result)).as_object().contains(JS(info))) {
201 output.info.rippledInfo =
202 serverInfoRippled->at(JS(result)).as_object().at(JS(info)).as_object();
206 output.info.validatedLedger.age = age < 0 ? 0 : age;
207 output.info.validatedLedger.hash = xrpl::strHex(lgrInfo->hash);
208 output.info.validatedLedger.seq = lgrInfo->seq;
209 output.info.validatedLedger.fees = fees;
210 output.info.cache.size = backend_->cache().size();
211 output.info.cache.isFull = backend_->cache().isFull();
212 output.info.cache.latestLedgerSeq = backend_->cache().latestLedgerSequence();
213 output.info.cache.objectHitRate = backend_->cache().getObjectHitRate();
214 output.info.cache.successorHitRate = backend_->cache().getSuccessorHitRate();
215 output.info.cache.isEnabled = not backend_->cache().isDisabled();
216 output.info.uptime = counters_.get().uptime();
217 output.info.isAmendmentBlocked = etl_->isAmendmentBlocked();
218 output.info.isCorruptionDetected = etl_->isCorruptionDetected();
225 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output)
227 using boost::json::value_from;
230 {JS(info), value_from(output.info)},
231 {JS(validated), output.validated},
236 tag_invoke(boost::json::value_from_tag, boost::json::value& jv,
InfoSection const& info)
238 using boost::json::value_from;
240 {JS(complete_ledgers), info.completeLedgers},
241 {JS(load_factor), info.loadFactor},
242 {JS(time), xrpl::to_string(std::chrono::floor<std::chrono::microseconds>(info.time))},
243 {JS(uptime), info.uptime.count()},
244 {
"clio_version", info.clioVersion},
245 {
"libxrpl_version", info.xrplVersion},
246 {JS(validated_ledger), value_from(info.validatedLedger)},
247 {
"cache", value_from(info.cache)},
250 if (info.isAmendmentBlocked)
251 jv.as_object()[JS(amendment_blocked)] =
true;
253 if (info.isCorruptionDetected)
254 jv.as_object()[
"corruption_detected"] =
true;
256 if (info.rippledInfo) {
257 auto const& rippledInfo = *info.rippledInfo;
259 if (rippledInfo.contains(JS(load_factor)))
260 jv.as_object()[JS(load_factor)] = rippledInfo.at(JS(load_factor));
261 if (rippledInfo.contains(JS(validation_quorum)))
262 jv.as_object()[JS(validation_quorum)] = rippledInfo.at(JS(validation_quorum));
263 if (rippledInfo.contains(JS(build_version)))
264 jv.as_object()[
"rippled_version"] = rippledInfo.at(JS(build_version));
265 if (rippledInfo.contains(JS(network_id)))
266 jv.as_object()[JS(network_id)] = rippledInfo.at(JS(network_id));
269 if (info.adminSection) {
270 jv.as_object()[
"etl"] = info.adminSection->etl;
271 jv.as_object()[JS(counters)] = info.adminSection->counters;
272 jv.as_object()[JS(counters)].as_object()[
"subscriptions"] =
273 info.adminSection->subscriptions;
274 if (info.adminSection->backendCounters.has_value()) {
275 jv.as_object()[kBackendCountersKey] = *info.adminSection->backendCounters;
282 boost::json::value_from_tag,
283 boost::json::value& jv,
289 {JS(age), validated.age},
290 {JS(hash), validated.hash},
291 {JS(seq), validated.seq},
292 {JS(base_fee_xrp), validated.fees->base.decimalXRP()},
293 {JS(reserve_base_xrp), validated.fees->reserve.decimalXRP()},
294 {JS(reserve_inc_xrp), validated.fees->increment.decimalXRP()},
300 tag_invoke(boost::json::value_from_tag, boost::json::value& jv,
CacheSection const& cache)
303 {
"size", cache.size},
304 {
"is_enabled", cache.isEnabled},
305 {
"is_full", cache.isFull},
306 {
"latest_ledger_seq", cache.latestLedgerSeq},
307 {
"object_hit_rate", cache.objectHitRate},
308 {
"successor_hit_rate", cache.successorHitRate},
BaseServerInfoHandler(std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< etl::LoadBalancerInterface > balancer, std::shared_ptr< etl::ETLServiceInterface const > etl, CountersType const &counters)
Construct a new BaseServerInfoHandler object.
Definition ServerInfo.hpp:131