22#include "data/BackendInterface.hpp"
23#include "etl/ETLState.hpp"
25#include "etlng/InitialLoadObserverInterface.hpp"
27#include "etlng/Source.hpp"
28#include "feed/SubscriptionManagerInterface.hpp"
30#include "util/Assert.hpp"
31#include "util/Mutex.hpp"
32#include "util/ResponseExpirationCache.hpp"
33#include "util/log/Logger.hpp"
34#include "util/newconfig/ConfigDefinition.hpp"
36#include <boost/asio.hpp>
37#include <boost/asio/io_context.hpp>
38#include <boost/asio/spawn.hpp>
39#include <boost/json/object.hpp>
40#include <boost/json/value.hpp>
41#include <grpcpp/grpcpp.h>
42#include <org/xrpl/rpc/v1/get_ledger.pb.h>
43#include <org/xrpl/rpc/v1/ledger.pb.h>
44#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
78 using RawLedgerObjectType = org::xrpl::rpc::v1::RawLedgerObject;
79 using GetLedgerResponseType = org::xrpl::rpc::v1::GetLedgerResponse;
80 using OptionalGetLedgerResponseType = std::optional<GetLedgerResponseType>;
83 static constexpr std::uint32_t kDEFAULT_DOWNLOAD_RANGES = 16;
87 std::optional<util::ResponseExpirationCache> forwardingCache_;
88 std::optional<std::string> forwardingXUserValue_;
90 std::vector<SourcePtr> sources_;
91 std::optional<etl::ETLState> etlState_;
92 std::uint32_t downloadRanges_ =
93 kDEFAULT_DOWNLOAD_RANGES;
122 boost::asio::io_context& ioc,
123 std::shared_ptr<BackendInterface> backend,
124 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
125 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers,
126 SourceFactory sourceFactory = makeSource
140 static std::shared_ptr<LoadBalancerInterface>
143 boost::asio::io_context& ioc,
144 std::shared_ptr<BackendInterface> backend,
145 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
146 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers,
147 SourceFactory sourceFactory = makeSource
160 std::vector<std::string>
162 [[maybe_unused]] uint32_t sequence,
163 [[maybe_unused]] std::chrono::steady_clock::duration retryAfter
166 ASSERT(
false,
"Not available for new ETL");
179 std::vector<std::string>
183 std::chrono::steady_clock::duration retryAfter
199 OptionalGetLedgerResponseType
201 uint32_t ledgerSequence,
203 bool getObjectNeighbors,
204 std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2}
224 std::expected<boost::json::object, rpc::CombinedError>
226 boost::json::object
const& request,
227 std::optional<std::string>
const& clientIp,
229 boost::asio::yield_context yield
236 std::optional<etl::ETLState>
246 stop(boost::asio::yield_context yield) override;
261 template <typename Func>
263 execute(Func f, uint32_t ledgerSequence, std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2});
269 chooseForwardingSource();
271 std::expected<boost::json::object, rpc::CombinedError>
272 forwardToRippledImpl(
273 boost::json::object
const& request,
274 std::optional<std::string>
const& clientIp,
276 boost::asio::yield_context yield
An interface for LoadBalancer.
Definition LoadBalancerInterface.hpp:45
This class is used to manage connections to transaction processing processes.
Definition LoadBalancer.hpp:76
void stop(boost::asio::yield_context yield) override
Stop the load balancer. This will stop all subscription sources.
Definition LoadBalancer.cpp:343
std::optional< etl::ETLState > getETLState() noexcept override
Return state of ETL nodes.
Definition LoadBalancer.cpp:333
LoadBalancer(util::config::ClioConfigDefinition const &config, boost::asio::io_context &ioc, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< etl::NetworkValidatedLedgersInterface > validatedLedgers, SourceFactory sourceFactory=makeSource)
Create an instance of the load balancer.
Definition LoadBalancer.cpp:80
std::vector< std::string > loadInitialLedger(uint32_t sequence, std::chrono::steady_clock::duration retryAfter) override
Load the initial ledger, writing data to the queue.
Definition LoadBalancer.hpp:161
static std::shared_ptr< LoadBalancerInterface > makeLoadBalancer(util::config::ClioConfigDefinition const &config, boost::asio::io_context &ioc, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< etl::NetworkValidatedLedgersInterface > validatedLedgers, SourceFactory sourceFactory=makeSource)
A factory function for the load balancer.
Definition LoadBalancer.cpp:66
std::expected< boost::json::object, rpc::CombinedError > forwardToRippled(boost::json::object const &request, std::optional< std::string > const &clientIp, bool isAdmin, boost::asio::yield_context yield) override
Forward a JSON RPC request to a randomly selected rippled node.
Definition LoadBalancer.cpp:236
OptionalGetLedgerResponseType fetchLedger(uint32_t ledgerSequence, bool getObjects, bool getObjectNeighbors, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2}) override
Fetch data for a specific ledger.
Definition LoadBalancer.cpp:206
static constexpr std::string_view kUSER_FORWARDING_X_USER_VALUE
Value for the X-User header when forwarding user requests.
Definition LoadBalancer.hpp:108
boost::json::value toJson() const override
Represent the state of this load balancer as a JSON object.
Definition LoadBalancer.cpp:281
static constexpr std::string_view kADMIN_FORWARDING_X_USER_VALUE
Value for the X-User header when forwarding admin requests.
Definition LoadBalancer.hpp:103
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
A container for data that is protected by a mutex. Inspired by Mutex in Rust.
Definition Mutex.hpp:96
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
Definition LoadBalancer.hpp:67
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36
A tag class to help identify LoadBalancer in templated code.
Definition LoadBalancer.hpp:62