mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-21 14:20:56 +00:00
beast::insight instruments are created during ApplicationImp's member-init list, and opentelemetry-cpp 1.28 never rebinds an already-vended Meter, so an instrument created before the MeterProvider is published records nothing for the rest of the process. Observable instruments carry the opposite constraint: registering one arms the SDK reader thread, and its callbacks run hook handlers that read services which do not exist that early. Publish the provider in Telemetry's constructor, ahead of every producer, and defer only the observables. Collector gains onCollectionReady() and onCollectionStopping(); OTelCollector arms and disarms its gauges in response. StatsDCollector starts its polling thread in its own constructor and had the same hazard, so it uses the pair to gate that thread. The metrics resource carries service.instance.id and is immutable once built, so the node public key is resolved in Main.cpp, where a config error can still be reported, and passed to makeApplication(). getNodeIdentity() remains authoritative; both paths now share readNodeIdentity(), so telemetry cannot report a key the node has abandoned. An explicit ~ApplicationImp stops observing and stops telemetry, covering the setup() failure paths that never reach run(). Telemetry::stop() is once-only and no longer clears another instance's global pointer. The histogram view's meter selector now matches the meter actually in use, so its bucket boundaries apply for the first time.
190 lines
5.8 KiB
C++
190 lines
5.8 KiB
C++
#pragma once
|
|
|
|
#include <xrpl/basics/UnorderedContainers.h>
|
|
#include <xrpl/basics/base_uint.h>
|
|
#include <xrpl/beast/hash/uhash.h>
|
|
#include <xrpl/beast/utility/Journal.h>
|
|
#include <xrpl/core/PeerReservationTable.h>
|
|
#include <xrpl/protocol/PublicKey.h>
|
|
#include <xrpl/protocol/SecretKey.h>
|
|
#include <xrpl/rdb/DatabaseCon.h>
|
|
#include <xrpl/server/Manifest.h>
|
|
|
|
// boost::optional (not std::optional) appears in the declarations below,
|
|
// because SOCI's into()/use() bindings only support boost::optional.
|
|
#include <boost/optional/optional.hpp>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <utility>
|
|
|
|
namespace xrpl {
|
|
|
|
/**
|
|
* @brief makeWalletDB Opens the wallet database and returns it.
|
|
* @param setup Path to the database and other opening parameters.
|
|
* @param j Journal.
|
|
* @return Unique pointer to the database descriptor.
|
|
*/
|
|
std::unique_ptr<DatabaseCon>
|
|
makeWalletDB(DatabaseCon::Setup const& setup, beast::Journal j);
|
|
|
|
/**
|
|
* @brief makeTestWalletDB Opens a test wallet database with an arbitrary name.
|
|
* @param setup Path to the database and other opening parameters.
|
|
* @param dbname Name of the database.
|
|
* @param j Journal.
|
|
* @return Unique pointer to the database descriptor.
|
|
*/
|
|
std::unique_ptr<DatabaseCon>
|
|
makeTestWalletDB(DatabaseCon::Setup const& setup, std::string const& dbname, beast::Journal j);
|
|
|
|
/**
|
|
* @brief getManifests Loads a manifest from the wallet database and stores it
|
|
* in the cache.
|
|
* @param session Session with the database.
|
|
* @param dbTable Name of the database table from which the manifest will be
|
|
* extracted.
|
|
* @param cache_ Cache for storing the manifest.
|
|
* @param j Journal.
|
|
*/
|
|
void
|
|
getManifests(
|
|
soci::session& session,
|
|
std::string const& dbTable,
|
|
ManifestCache& cache,
|
|
beast::Journal j);
|
|
|
|
/**
|
|
* @brief saveManifests Saves all given manifests to the database.
|
|
* @param session Session with the database.
|
|
* @param dbTable Name of the database table that will store the manifest.
|
|
* @param isTrusted Callback that returns true if the key is trusted.
|
|
* @param map Maps public keys to manifests.
|
|
* @param j Journal.
|
|
*/
|
|
void
|
|
saveManifests(
|
|
soci::session& session,
|
|
std::string const& dbTable,
|
|
std::function<bool(PublicKey const&)> const& isTrusted,
|
|
hash_map<PublicKey, Manifest> const& map,
|
|
beast::Journal j);
|
|
|
|
/**
|
|
* @brief addValidatorManifest Saves the manifest of a validator to the
|
|
* database.
|
|
* @param session Session with the database.
|
|
* @param serialized Manifest of the validator in raw format.
|
|
*/
|
|
void
|
|
addValidatorManifest(soci::session& session, std::string const& serialized);
|
|
|
|
/**
|
|
* Delete any saved public/private key associated with this node.
|
|
*/
|
|
void
|
|
clearNodeIdentity(soci::session& session);
|
|
|
|
/**
|
|
* Returns this node's stored keypair, if the database holds a valid one.
|
|
*
|
|
* Read-only: unlike getNodeIdentity(), never generates or persists a key. A row
|
|
* counts only when its public and secret keys are a pair.
|
|
*
|
|
* @param session Session with the database.
|
|
*
|
|
* @return The stored keypair, or std::nullopt.
|
|
*/
|
|
std::optional<std::pair<PublicKey, SecretKey>>
|
|
readNodeIdentity(soci::session& session);
|
|
|
|
/**
|
|
* Returns a stable public and private key for this node.
|
|
*
|
|
* The node's public identity is defined by a secp256k1 keypair
|
|
* that is (normally) randomly generated. This function will
|
|
* return such a keypair, securely generating one if needed.
|
|
*
|
|
* @param session Session with the database.
|
|
*
|
|
* @return Pair of public and private secp256k1 keys.
|
|
*/
|
|
std::pair<PublicKey, SecretKey>
|
|
getNodeIdentity(soci::session& session);
|
|
|
|
/**
|
|
* @brief getPeerReservationTable Returns the peer reservation table.
|
|
* @param session Session with the database.
|
|
* @param j Journal.
|
|
* @return Peer reservation hash table.
|
|
*/
|
|
std::unordered_set<PeerReservation, beast::Uhash<>, KeyEqual>
|
|
getPeerReservationTable(soci::session& session, beast::Journal j);
|
|
|
|
/**
|
|
* @brief insertPeerReservation Adds an entry to the peer reservation table.
|
|
* @param session Session with the database.
|
|
* @param nodeId Public key of the node.
|
|
* @param description Description of the node.
|
|
*/
|
|
void
|
|
insertPeerReservation(
|
|
soci::session& session,
|
|
PublicKey const& nodeId,
|
|
std::string const& description);
|
|
|
|
/**
|
|
* @brief deletePeerReservation Deletes an entry from the peer reservation
|
|
* table.
|
|
* @param session Session with the database.
|
|
* @param nodeId Public key of the node to remove.
|
|
*/
|
|
void
|
|
deletePeerReservation(soci::session& session, PublicKey const& nodeId);
|
|
|
|
/**
|
|
* @brief createFeatureVotes Creates the FeatureVote table if it does not exist.
|
|
* @param session Session with the wallet database.
|
|
* @return true if the table already exists
|
|
*/
|
|
bool
|
|
createFeatureVotes(soci::session& session);
|
|
|
|
// For historical reasons the up-vote and down-vote integer representations
|
|
// are unintuitive.
|
|
enum class AmendmentVote : int { Obsolete = -1, Up = 0, Down = 1 };
|
|
|
|
/**
|
|
* @brief readAmendments Reads all amendments from the FeatureVotes table.
|
|
* @param session Session with the wallet database.
|
|
* @param callback Callback called for each amendment with its hash, name and
|
|
* optionally a flag denoting whether the amendment should be vetoed.
|
|
*/
|
|
void
|
|
readAmendments(
|
|
soci::session& session,
|
|
std::function<void(
|
|
boost::optional<std::string> amendmentHash,
|
|
boost::optional<std::string> amendmentName,
|
|
boost::optional<AmendmentVote> vote)> const& callback);
|
|
|
|
/**
|
|
* @brief voteAmendment Set the veto value for a particular amendment.
|
|
* @param session Session with the wallet database.
|
|
* @param amendment Hash of the amendment.
|
|
* @param name Name of the amendment.
|
|
* @param vote Whether to vote in favor of this amendment.
|
|
*/
|
|
void
|
|
voteAmendment(
|
|
soci::session& session,
|
|
uint256 const& amendment,
|
|
std::string const& name,
|
|
AmendmentVote vote);
|
|
|
|
} // namespace xrpl
|