Add ServiceRegistry to help migration.

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
This commit is contained in:
JCW
2026-01-06 10:22:58 +00:00
parent edade08e61
commit 79ad174ac4
5 changed files with 628 additions and 0 deletions

View File

@@ -0,0 +1,207 @@
#ifndef XRPL_CORE_SERVICEREGISTRY_H_INCLUDED
#define XRPL_CORE_SERVICEREGISTRY_H_INCLUDED
#include <xrpl/basics/Blob.h>
#include <xrpl/basics/SHAMapHash.h>
#include <xrpl/basics/TaggedCache.h>
#include <xrpl/ledger/CachedSLEs.h>
#include <xrpl/protocol/Protocol.h>
#include <cstdint>
#include <memory>
namespace xrpl {
// Forward declarations
namespace NodeStore {
class Database;
}
namespace Resource {
class Manager;
}
namespace perf {
class PerfLog;
}
class AcceptedLedger;
class AmendmentTable;
class Cluster;
class CollectorManager;
class DatabaseCon;
class Family;
class HashRouter;
class InboundLedgers;
class InboundTransactions;
class JobQueue;
class LedgerCleaner;
class LedgerMaster;
class LedgerReplayer;
class LoadFeeTrack;
class LoadManager;
class ManifestCache;
class NetworkOPs;
class OpenLedger;
class OrderBookDB;
class Overlay;
class PathRequests;
class PeerReservationTable;
class PendingSaves;
class RelationalDatabase;
class ServerHandler;
class SHAMapStore;
class TimeKeeper;
class TransactionMaster;
class TxQ;
class ValidatorList;
class ValidatorSite;
template <class Adaptor>
class Validations;
class RCLValidationsAdaptor;
using RCLValidations = Validations<RCLValidationsAdaptor>;
using NodeCache = TaggedCache<SHAMapHash, Blob>;
/** Service registry for dependency injection.
This abstract interface provides access to various services and components
used throughout the application. It separates the service locator pattern
from the Application lifecycle management.
Components that need access to services can hold a reference to
ServiceRegistry rather than Application when they only need service
access and not lifecycle management.
The implementation (ServiceRegistryImpl) is provided in xrpld.
*/
class ServiceRegistry
{
public:
ServiceRegistry() = default;
virtual ~ServiceRegistry() = default;
// Core infrastructure services
virtual CollectorManager&
getCollectorManager() = 0;
virtual Family&
getNodeFamily() = 0;
virtual TimeKeeper&
timeKeeper() = 0;
virtual JobQueue&
getJobQueue() = 0;
virtual NodeCache&
getTempNodeCache() = 0;
virtual CachedSLEs&
cachedSLEs() = 0;
// Protocol and validation services
virtual AmendmentTable&
getAmendmentTable() = 0;
virtual HashRouter&
getHashRouter() = 0;
virtual LoadFeeTrack&
getFeeTrack() = 0;
virtual LoadManager&
getLoadManager() = 0;
virtual RCLValidations&
getValidations() = 0;
virtual ValidatorList&
validators() = 0;
virtual ValidatorSite&
validatorSites() = 0;
virtual ManifestCache&
validatorManifests() = 0;
virtual ManifestCache&
publisherManifests() = 0;
// Network services
virtual Overlay&
overlay() = 0;
virtual Cluster&
cluster() = 0;
virtual PeerReservationTable&
peerReservations() = 0;
virtual Resource::Manager&
getResourceManager() = 0;
// Storage services
virtual NodeStore::Database&
getNodeStore() = 0;
virtual SHAMapStore&
getSHAMapStore() = 0;
virtual RelationalDatabase&
getRelationalDatabase() = 0;
// Ledger services
virtual InboundLedgers&
getInboundLedgers() = 0;
virtual InboundTransactions&
getInboundTransactions() = 0;
virtual TaggedCache<uint256, AcceptedLedger>&
getAcceptedLedgerCache() = 0;
virtual LedgerMaster&
getLedgerMaster() = 0;
virtual LedgerCleaner&
getLedgerCleaner() = 0;
virtual LedgerReplayer&
getLedgerReplayer() = 0;
virtual PendingSaves&
pendingSaves() = 0;
virtual OpenLedger&
openLedger() = 0;
virtual OpenLedger const&
openLedger() const = 0;
// Transaction and operation services
virtual NetworkOPs&
getOPs() = 0;
virtual OrderBookDB&
getOrderBookDB() = 0;
virtual TransactionMaster&
getMasterTransaction() = 0;
virtual TxQ&
getTxQ() = 0;
virtual PathRequests&
getPathRequests() = 0;
// Server services
virtual ServerHandler&
getServerHandler() = 0;
virtual perf::PerfLog&
getPerfLog() = 0;
};
} // namespace xrpl
#endif

View File

@@ -29,6 +29,7 @@
#include <xrpld/app/rdb/Wallet.h>
#include <xrpld/app/tx/apply.h>
#include <xrpld/core/DatabaseCon.h>
#include <xrpld/core/ServiceRegistryImpl.h>
#include <xrpld/overlay/Cluster.h>
#include <xrpld/overlay/PeerReservationTable.h>
#include <xrpld/overlay/PeerSet.h>
@@ -217,6 +218,9 @@ public:
std::unique_ptr<GRPCServer> grpcServer_;
// ServiceRegistry implementation that delegates to this Application
std::unique_ptr<ServiceRegistryImpl> serviceRegistry_;
//--------------------------------------------------------------------------
static std::size_t
@@ -453,6 +457,7 @@ public:
std::chrono::milliseconds(100),
get_io_context())
, grpcServer_(std::make_unique<GRPCServer>(*this))
, serviceRegistry_(std::make_unique<ServiceRegistryImpl>(*this))
{
initAccountIdCache(config_->getValueFor(SizedItem::accountIdCacheSize));
@@ -808,6 +813,16 @@ public:
return *mWalletDB;
}
ServiceRegistry&
getServiceRegistry() override
{
XRPL_ASSERT(
serviceRegistry_,
"xrpl::ApplicationImp::getServiceRegistry : non-null service "
"registry");
return *serviceRegistry_;
}
bool
serverOkay(std::string& reason) override;

View File

@@ -6,6 +6,7 @@
#include <xrpl/basics/TaggedCache.h>
#include <xrpl/beast/utility/PropertyStream.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/shamap/TreeNodeCache.h>
@@ -256,6 +257,9 @@ public:
virtual std::optional<uint256> const&
trapTxID() const = 0;
virtual ServiceRegistry&
getServiceRegistry() = 0;
};
std::unique_ptr<Application>

View File

@@ -0,0 +1,157 @@
#ifndef XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED
#define XRPLD_CORE_SERVICEREGISTRYIMPL_H_INCLUDED
#include <xrpl/core/ServiceRegistry.h>
namespace xrpl {
// Forward declaration
class Application;
/** Implementation of ServiceRegistry that delegates to Application.
This class provides a ServiceRegistry interface that wraps an Application
reference. It allows components to depend on ServiceRegistry instead of
Application, enabling gradual migration and better separation of concerns.
Usage:
Application& app = ...;
ServiceRegistry& registry = app.getServiceRegistry();
// or
ServiceRegistryImpl registry(app);
*/
class ServiceRegistryImpl : public ServiceRegistry
{
public:
explicit ServiceRegistryImpl(Application& app);
~ServiceRegistryImpl() override = default;
// Core infrastructure services
CollectorManager&
getCollectorManager() override;
Family&
getNodeFamily() override;
TimeKeeper&
timeKeeper() override;
JobQueue&
getJobQueue() override;
NodeCache&
getTempNodeCache() override;
CachedSLEs&
cachedSLEs() override;
// Protocol and validation services
AmendmentTable&
getAmendmentTable() override;
HashRouter&
getHashRouter() override;
LoadFeeTrack&
getFeeTrack() override;
LoadManager&
getLoadManager() override;
RCLValidations&
getValidations() override;
ValidatorList&
validators() override;
ValidatorSite&
validatorSites() override;
ManifestCache&
validatorManifests() override;
ManifestCache&
publisherManifests() override;
// Network services
Overlay&
overlay() override;
Cluster&
cluster() override;
PeerReservationTable&
peerReservations() override;
Resource::Manager&
getResourceManager() override;
// Storage services
NodeStore::Database&
getNodeStore() override;
SHAMapStore&
getSHAMapStore() override;
RelationalDatabase&
getRelationalDatabase() override;
// Ledger services
InboundLedgers&
getInboundLedgers() override;
InboundTransactions&
getInboundTransactions() override;
TaggedCache<uint256, AcceptedLedger>&
getAcceptedLedgerCache() override;
LedgerMaster&
getLedgerMaster() override;
LedgerCleaner&
getLedgerCleaner() override;
LedgerReplayer&
getLedgerReplayer() override;
PendingSaves&
pendingSaves() override;
OpenLedger&
openLedger() override;
OpenLedger const&
openLedger() const override;
// Transaction and operation services
NetworkOPs&
getOPs() override;
OrderBookDB&
getOrderBookDB() override;
TransactionMaster&
getMasterTransaction() override;
TxQ&
getTxQ() override;
PathRequests&
getPathRequests() override;
// Server services
ServerHandler&
getServerHandler() override;
perf::PerfLog&
getPerfLog() override;
private:
Application& app_;
};
} // namespace xrpl
#endif

View File

@@ -0,0 +1,245 @@
#include <xrpld/app/main/Application.h>
#include <xrpld/core/ServiceRegistryImpl.h>
namespace xrpl {
ServiceRegistryImpl::ServiceRegistryImpl(Application& app) : app_(app)
{
}
// Core infrastructure services
CollectorManager&
ServiceRegistryImpl::getCollectorManager()
{
return app_.getCollectorManager();
}
Family&
ServiceRegistryImpl::getNodeFamily()
{
return app_.getNodeFamily();
}
TimeKeeper&
ServiceRegistryImpl::timeKeeper()
{
return app_.timeKeeper();
}
JobQueue&
ServiceRegistryImpl::getJobQueue()
{
return app_.getJobQueue();
}
NodeCache&
ServiceRegistryImpl::getTempNodeCache()
{
return app_.getTempNodeCache();
}
CachedSLEs&
ServiceRegistryImpl::cachedSLEs()
{
return app_.cachedSLEs();
}
// Protocol and validation services
AmendmentTable&
ServiceRegistryImpl::getAmendmentTable()
{
return app_.getAmendmentTable();
}
HashRouter&
ServiceRegistryImpl::getHashRouter()
{
return app_.getHashRouter();
}
LoadFeeTrack&
ServiceRegistryImpl::getFeeTrack()
{
return app_.getFeeTrack();
}
LoadManager&
ServiceRegistryImpl::getLoadManager()
{
return app_.getLoadManager();
}
RCLValidations&
ServiceRegistryImpl::getValidations()
{
return app_.getValidations();
}
ValidatorList&
ServiceRegistryImpl::validators()
{
return app_.validators();
}
ValidatorSite&
ServiceRegistryImpl::validatorSites()
{
return app_.validatorSites();
}
ManifestCache&
ServiceRegistryImpl::validatorManifests()
{
return app_.validatorManifests();
}
ManifestCache&
ServiceRegistryImpl::publisherManifests()
{
return app_.publisherManifests();
}
// Network services
Overlay&
ServiceRegistryImpl::overlay()
{
return app_.overlay();
}
Cluster&
ServiceRegistryImpl::cluster()
{
return app_.cluster();
}
PeerReservationTable&
ServiceRegistryImpl::peerReservations()
{
return app_.peerReservations();
}
Resource::Manager&
ServiceRegistryImpl::getResourceManager()
{
return app_.getResourceManager();
}
// Storage services
NodeStore::Database&
ServiceRegistryImpl::getNodeStore()
{
return app_.getNodeStore();
}
SHAMapStore&
ServiceRegistryImpl::getSHAMapStore()
{
return app_.getSHAMapStore();
}
RelationalDatabase&
ServiceRegistryImpl::getRelationalDatabase()
{
return app_.getRelationalDatabase();
}
// Ledger services
InboundLedgers&
ServiceRegistryImpl::getInboundLedgers()
{
return app_.getInboundLedgers();
}
InboundTransactions&
ServiceRegistryImpl::getInboundTransactions()
{
return app_.getInboundTransactions();
}
TaggedCache<uint256, AcceptedLedger>&
ServiceRegistryImpl::getAcceptedLedgerCache()
{
return app_.getAcceptedLedgerCache();
}
LedgerMaster&
ServiceRegistryImpl::getLedgerMaster()
{
return app_.getLedgerMaster();
}
LedgerCleaner&
ServiceRegistryImpl::getLedgerCleaner()
{
return app_.getLedgerCleaner();
}
LedgerReplayer&
ServiceRegistryImpl::getLedgerReplayer()
{
return app_.getLedgerReplayer();
}
PendingSaves&
ServiceRegistryImpl::pendingSaves()
{
return app_.pendingSaves();
}
OpenLedger&
ServiceRegistryImpl::openLedger()
{
return app_.openLedger();
}
OpenLedger const&
ServiceRegistryImpl::openLedger() const
{
return app_.openLedger();
}
// Transaction and operation services
NetworkOPs&
ServiceRegistryImpl::getOPs()
{
return app_.getOPs();
}
OrderBookDB&
ServiceRegistryImpl::getOrderBookDB()
{
return app_.getOrderBookDB();
}
TransactionMaster&
ServiceRegistryImpl::getMasterTransaction()
{
return app_.getMasterTransaction();
}
TxQ&
ServiceRegistryImpl::getTxQ()
{
return app_.getTxQ();
}
PathRequests&
ServiceRegistryImpl::getPathRequests()
{
return app_.getPathRequests();
}
// Server services
ServerHandler&
ServiceRegistryImpl::getServerHandler()
{
return app_.getServerHandler();
}
perf::PerfLog&
ServiceRegistryImpl::getPerfLog()
{
return app_.getPerfLog();
}
} // namespace xrpl