xrpld
Loading...
Searching...
No Matches
LedgerReplayer.h
1#pragma once
2
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/LedgerReplayTask.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/overlay/PeerSet.h>
7
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/protocol/LedgerHeader.h>
11#include <xrpl/protocol/STTx.h>
12#include <xrpl/shamap/SHAMapItem.h>
13
14#include <cstddef>
15#include <cstdint>
16#include <map>
17#include <memory>
18#include <mutex>
19#include <vector>
20
21namespace xrpl {
22
23namespace test {
25} // namespace test
26
28// timeout value for LedgerReplayTask
30
31// for LedgerReplayTask to calculate max allowed timeouts
32// = max( kTaskMaxTimeoutsMinimum,
33// (# of ledger to replay) * kTaskMaxTimeoutsMultiplier)
36
37// timeout value for subtasks: LedgerDeltaAcquire and SkipListAcquire
39// max of allowed subtask timeouts
41
42// max number of peers that do not support the ledger replay feature
43// returned by the PeerSet before switch to fallback
44constexpr auto kMaxNoFeaturePeerCount = 2;
45// subtask timeout value after fallback
47
48// for LedgerReplayer to limit the number of LedgerReplayTask
49constexpr std::uint32_t kMaxTasks = 10;
50
51// for LedgerReplayer to limit the number of ledgers to replay in one task
53
54// to limit the number of LedgerReplay related jobs in JobQueue
56} // namespace ledger_replay_parameters
57
61class LedgerReplayer final
62{
63public:
65 Application& app,
66 InboundLedgers& inboundLedgers,
67 std::unique_ptr<PeerSetBuilder> peerSetBuilder);
68
70
78 void
79 replay(InboundLedger::Reason r, uint256 const& finishLedgerHash, std::uint32_t totalNumLedgers);
80
84 void
86
93 void
94 gotSkipList(LedgerHeader const& info, boost::intrusive_ptr<SHAMapItem const> const& data);
95
102 void
104 LedgerHeader const& info,
106
110 void
111 sweep();
112
113 void
114 stop();
115
117 tasksSize() const
118 {
119 std::scoped_lock const lock(mtx_);
120 return tasks_.size();
121 }
122
125 {
126 std::scoped_lock const lock(mtx_);
127 return deltas_.size();
128 }
129
132 {
133 std::scoped_lock const lock(mtx_);
134 return skipLists_.size();
135 }
136
137private:
142
147
149};
150
151} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Manages the lifetime of inbound ledgers.
hash_map< uint256, std::weak_ptr< SkipListAcquire > > skipLists_
InboundLedgers & inboundLedgers_
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
void gotReplayDelta(LedgerHeader const &info, std::map< std::uint32_t, std::shared_ptr< STTx const > > &&txns)
Process a ledger delta (extracted from a TMReplayDeltaResponse message).
std::size_t skipListsSize() const
std::size_t tasksSize() const
void gotSkipList(LedgerHeader const &info, boost::intrusive_ptr< SHAMapItem const > const &data)
Process a skip list (extracted from a TMProofPathResponse message).
std::unique_ptr< PeerSetBuilder > peerSetBuilder_
std::vector< std::shared_ptr< LedgerReplayTask > > tasks_
void sweep()
Remove completed tasks.
void createDeltas(std::shared_ptr< LedgerReplayTask > task)
Create LedgerDeltaAcquire subtasks for the LedgerReplayTask task.
LedgerReplayer(Application &app, InboundLedgers &inboundLedgers, std::unique_ptr< PeerSetBuilder > peerSetBuilder)
hash_map< uint256, std::weak_ptr< LedgerDeltaAcquire > > deltas_
std::size_t deltasSize() const
Ledger replay client side.
constexpr std::uint32_t kMaxTasks
constexpr std::uint32_t kTaskMaxTimeoutsMultiplier
constexpr std::uint32_t kSubTaskMaxTimeouts
constexpr std::uint32_t kMaxTaskSize
constexpr std::uint32_t kMaxQueuedTasks
constexpr std::uint32_t kTaskMaxTimeoutsMinimum
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
BaseUInt< 256 > uint256
Definition base_uint.h:580
Information about the notional ledger backing the view.