Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
NetworkValidatedLedgers.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2022, 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
23
24#include <boost/signals2/connection.hpp>
25#include <boost/signals2/signal.hpp>
26#include <boost/signals2/variadic_signal.hpp>
27
28#include <condition_variable>
29#include <cstdint>
30#include <memory>
31#include <mutex>
32#include <optional>
33
34namespace etl {
35
45 std::optional<uint32_t> latest_; // currently known latest sequence validated by network
46
47 mutable std::mutex mtx_;
48 std::condition_variable cv_;
49
50 SignalType notificationChannel_;
51
52public:
58 static std::shared_ptr<NetworkValidatedLedgers>
60
66 void
67 push(uint32_t idx) final;
68
76 std::optional<uint32_t>
77 getMostRecent() final;
78
87 bool
88 waitUntilValidatedByNetwork(uint32_t sequence, std::optional<uint32_t> maxWaitMs = {}) final;
89
90 boost::signals2::scoped_connection
91 subscribe(SignalType::slot_type const& subscriber) override;
92};
93
94} // namespace etl
An interface for NetworkValidatedLedgers.
Definition NetworkValidatedLedgersInterface.hpp:35
This datastructure is used to keep track of the sequence of the most recent ledger validated by the n...
Definition NetworkValidatedLedgers.hpp:44
void push(uint32_t idx) final
Notify the datastructure that idx has been validated by the network.
Definition NetworkValidatedLedgers.cpp:38
bool waitUntilValidatedByNetwork(uint32_t sequence, std::optional< uint32_t > maxWaitMs={}) final
Waits for the sequence to be validated by the network.
Definition NetworkValidatedLedgers.cpp:57
static std::shared_ptr< NetworkValidatedLedgers > makeValidatedLedgers()
A factory function for NetworkValidatedLedgers.
Definition NetworkValidatedLedgers.cpp:32
std::optional< uint32_t > getMostRecent() final
Get most recently validated sequence.
Definition NetworkValidatedLedgers.cpp:49
boost::signals2::scoped_connection subscribe(SignalType::slot_type const &subscriber) override
Allows clients to get notified when a new validated ledger becomes known to Clio.
Definition NetworkValidatedLedgers.cpp:70
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:37