Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ETLService.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/BackendInterface.hpp"
23#include "data/Types.hpp"
24#include "etl/ETLState.hpp"
26#include "etl/SystemState.hpp"
27#include "etl/impl/AmendmentBlockHandler.hpp"
28#include "etl/impl/LedgerFetcher.hpp"
29#include "etlng/CacheLoaderInterface.hpp"
30#include "etlng/CacheUpdaterInterface.hpp"
31#include "etlng/ETLServiceInterface.hpp"
32#include "etlng/ExtractorInterface.hpp"
33#include "etlng/InitialLoadObserverInterface.hpp"
34#include "etlng/LedgerPublisherInterface.hpp"
36#include "etlng/LoaderInterface.hpp"
37#include "etlng/MonitorInterface.hpp"
38#include "etlng/TaskManagerInterface.hpp"
39#include "etlng/TaskManagerProviderInterface.hpp"
40#include "etlng/impl/AmendmentBlockHandler.hpp"
41#include "etlng/impl/CacheUpdater.hpp"
42#include "etlng/impl/Extraction.hpp"
43#include "etlng/impl/LedgerPublisher.hpp"
44#include "etlng/impl/Loading.hpp"
45#include "etlng/impl/Monitor.hpp"
46#include "etlng/impl/Registry.hpp"
47#include "etlng/impl/Scheduling.hpp"
48#include "etlng/impl/TaskManager.hpp"
49#include "etlng/impl/ext/Cache.hpp"
50#include "etlng/impl/ext/Core.hpp"
51#include "etlng/impl/ext/NFT.hpp"
52#include "etlng/impl/ext/Successor.hpp"
53#include "util/async/AnyExecutionContext.hpp"
54#include "util/async/AnyOperation.hpp"
55#include "util/config/ConfigDefinition.hpp"
56#include "util/log/Logger.hpp"
57
58#include <boost/asio/io_context.hpp>
59#include <boost/json/object.hpp>
60#include <boost/signals2/connection.hpp>
61#include <fmt/core.h>
62#include <xrpl/basics/Blob.h>
63#include <xrpl/basics/base_uint.h>
64#include <xrpl/basics/strHex.h>
65#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
66#include <xrpl/proto/org/xrpl/rpc/v1/ledger.pb.h>
67#include <xrpl/protocol/LedgerHeader.h>
68#include <xrpl/protocol/STTx.h>
69#include <xrpl/protocol/TxFormats.h>
70#include <xrpl/protocol/TxMeta.h>
71
72#include <cstddef>
73#include <cstdint>
74#include <functional>
75#include <memory>
76#include <optional>
77#include <string>
78
79namespace etlng {
80
95 util::Logger log_{"ETL"};
96
98 std::reference_wrapper<util::config::ClioConfigDefinition const> config_;
99 std::shared_ptr<BackendInterface> backend_;
100 std::shared_ptr<LoadBalancerInterface> balancer_;
101 std::shared_ptr<etl::NetworkValidatedLedgersInterface> ledgers_;
102 std::shared_ptr<LedgerPublisherInterface> publisher_;
103 std::shared_ptr<CacheLoaderInterface> cacheLoader_;
104 std::shared_ptr<CacheUpdaterInterface> cacheUpdater_;
105 std::shared_ptr<ExtractorInterface> extractor_;
106 std::shared_ptr<LoaderInterface> loader_;
107 std::shared_ptr<InitialLoadObserverInterface> initialLoadObserver_;
108 std::shared_ptr<etlng::TaskManagerProviderInterface> taskManagerProvider_;
109 std::shared_ptr<etl::SystemState> state_;
110
111 std::unique_ptr<MonitorInterface> monitor_;
112 std::unique_ptr<TaskManagerInterface> taskMan_;
113
114 boost::signals2::scoped_connection monitorSubscription_;
115
116 std::optional<util::async::AnyOperation<void>> mainLoop_;
117
118public:
138 std::reference_wrapper<util::config::ClioConfigDefinition const> config,
139 std::shared_ptr<data::BackendInterface> backend,
140 std::shared_ptr<LoadBalancerInterface> balancer,
141 std::shared_ptr<etl::NetworkValidatedLedgersInterface> ledgers,
142 std::shared_ptr<LedgerPublisherInterface> publisher,
143 std::shared_ptr<CacheLoaderInterface> cacheLoader,
144 std::shared_ptr<CacheUpdaterInterface> cacheUpdater,
145 std::shared_ptr<ExtractorInterface> extractor,
146 std::shared_ptr<LoaderInterface> loader,
147 std::shared_ptr<InitialLoadObserverInterface> initialLoadObserver,
148 std::shared_ptr<etlng::TaskManagerProviderInterface> taskManagerProvider,
149 std::shared_ptr<etl::SystemState> state
150 );
151
152 ~ETLService() override;
153
154 void
155 run() override;
156
157 void
158 stop() override;
159
160 boost::json::object
161 getInfo() const override;
162
163 bool
164 isAmendmentBlocked() const override;
165
166 bool
167 isCorruptionDetected() const override;
168
169 std::optional<etl::ETLState>
170 getETLState() const override;
171
172 std::uint32_t
173 lastCloseAgeSeconds() const override;
174
175private:
176 // TODO: this better be std::expected
177 std::optional<data::LedgerRange>
178 loadInitialLedgerIfNeeded();
179
180 void
181 startMonitor(uint32_t seq);
182
183 void
184 startLoading(uint32_t seq);
185};
186
187} // namespace etlng
This class is responsible for continuously extracting data from a p2p node, and writing that data to ...
Definition ETLService.hpp:94
void stop() override
Stop the ETL service.
Definition ETLService.cpp:156
void run() override
Start all components to run ETL service.
Definition ETLService.cpp:121
bool isCorruptionDetected() const override
Check whether Clio detected DB corruptions.
Definition ETLService.cpp:187
std::uint32_t lastCloseAgeSeconds() const override
Get time passed since last ledger close, in seconds.
Definition ETLService.cpp:199
std::optional< etl::ETLState > getETLState() const override
Get the etl nodes' state.
Definition ETLService.cpp:193
boost::json::object getInfo() const override
Get state of ETL as a JSON object.
Definition ETLService.cpp:167
bool isAmendmentBlocked() const override
Check for the amendment blocked state.
Definition ETLService.cpp:181
ETLService(util::async::AnyExecutionContext ctx, std::reference_wrapper< util::config::ClioConfigDefinition const > config, std::shared_ptr< data::BackendInterface > backend, std::shared_ptr< LoadBalancerInterface > balancer, std::shared_ptr< etl::NetworkValidatedLedgersInterface > ledgers, std::shared_ptr< LedgerPublisherInterface > publisher, std::shared_ptr< CacheLoaderInterface > cacheLoader, std::shared_ptr< CacheUpdaterInterface > cacheUpdater, std::shared_ptr< ExtractorInterface > extractor, std::shared_ptr< LoaderInterface > loader, std::shared_ptr< InitialLoadObserverInterface > initialLoadObserver, std::shared_ptr< etlng::TaskManagerProviderInterface > taskManagerProvider, std::shared_ptr< etl::SystemState > state)
Create an instance of ETLService.
Definition ETLService.cpp:82
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
This is a base class for any ETL service implementations.
Definition ETLServiceInterface.hpp:36