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 efa57e872b
commit b2f4e23abd
6 changed files with 628 additions and 0 deletions

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