mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-27 15:28:03 +00:00
fix(telemetry): resolve the node identity before the Application is built
resolveNodePublicKey() returned std::nullopt in three real cases: a first boot with no wallet database, a standalone run (its wallet is a private temporary database), and --newnodeid. Telemetry's resources are built during ApplicationImp's member-init list and are immutable, so on those runs the node reported an empty service.instance.id and no xrpl.node.id for the whole run, while setup() minted a key moments later and patched only the tracer. Replace it with resolveNodeIdentity(), which always returns a keypair: derived from a configured seed, else read from an existing wallet database, else minted. Main.cpp passes that pair to makeApplication(), ApplicationImp stores it in nodeIdentity_ -- now declared before telemetry_ and no longer an optional, because it is always set -- and builds the telemetry resource from it. setup() calls getNodeIdentity(), which now persists rather than mints: it stores the resolved pair when the wallet holds no identity, adopts the stored one when it does, and clears first for --newnodeid. The write stays in setup() because that is where the database exists; a standalone run has no persistent wallet to write to, which is why the pair has to be decided before construction rather than read back afterwards. Wallet gains storeNodeIdentity() for that write, and getNodeIdentity(session) now uses it instead of repeating the insert. The three-argument makeApplication() mints a keypair, so jtx::Env and any other test Application behave as a standalone run always did. Also fold the three hand-rolled "meter from a NoopMeterProvider" copies into telemetry::noopMeter(): the base-pointer call and the kMeterVersion argument are both easy to get wrong alone, and the meter identity has to match the one the histogram views select on. The new gtest covers the wallet half: store-then-read, store not replacing an existing identity, clear-then-store, and that the mint path persists. It adds the tests.libxrpl > xrpl.rdb levelization edge, regenerated here.
This commit is contained in:
@@ -102,6 +102,22 @@ clearNodeIdentity(soci::session& session);
|
||||
std::optional<std::pair<PublicKey, SecretKey>>
|
||||
readNodeIdentity(soci::session& session);
|
||||
|
||||
/**
|
||||
* Persist a keypair as this node's identity.
|
||||
*
|
||||
* Write-only counterpart of readNodeIdentity(). The caller must have found the
|
||||
* table empty: this inserts a row without clearing, so storing twice leaves two
|
||||
* and readNodeIdentity() then returns whichever the query yields first.
|
||||
*
|
||||
* Exists because xrpld resolves its identity before the Application, and so
|
||||
* before any database, is built; setup() persists that keypair here.
|
||||
*
|
||||
* @param session Session with the database.
|
||||
* @param keys The keypair to store.
|
||||
*/
|
||||
void
|
||||
storeNodeIdentity(soci::session& session, std::pair<PublicKey, SecretKey> const& keys);
|
||||
|
||||
/**
|
||||
* Returns a stable public and private key for this node.
|
||||
*
|
||||
|
||||
@@ -133,6 +133,25 @@ inline constexpr std::string_view kMeterName{"xrpld"};
|
||||
* OTel instrumentation scope version reported for the meter.
|
||||
*/
|
||||
inline constexpr std::string_view kMeterVersion{"1.0.0"};
|
||||
|
||||
/**
|
||||
* A meter whose instruments record nothing.
|
||||
*
|
||||
* For every path that must hand out a usable meter without a pipeline behind
|
||||
* it: telemetry disabled, or an exporter that failed to build. Callers then
|
||||
* need no null check, because an instrument always comes back.
|
||||
*
|
||||
* Two details are easy to get wrong alone, which is why this is shared: the
|
||||
* provider must be reached through a base `MeterProvider` pointer, because
|
||||
* `NoopMeterProvider`'s override hides the base class's defaulted overload;
|
||||
* and the version must be @ref kMeterVersion, or the meter identity differs
|
||||
* from the one the histogram views select on.
|
||||
*
|
||||
* @param name Instrumentation scope name to report.
|
||||
* @return An inert meter. Never empty.
|
||||
*/
|
||||
[[nodiscard]] opentelemetry::nostd::shared_ptr<opentelemetry::metrics::Meter>
|
||||
noopMeter(std::string_view name = kMeterName);
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user