xrpld
Loading...
Searching...
No Matches
LedgerReplayTask.h
1#pragma once
2
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/detail/TimeoutCounter.h>
5#include <xrpld/app/main/Application.h>
6
7#include <xrpl/basics/CountedObject.h>
8#include <xrpl/basics/base_uint.h>
9
10#include <cstdint>
11#include <memory>
12#include <vector>
13
14namespace xrpl {
15class InboundLedgers;
16class Ledger;
18class LedgerReplayer;
19class SkipListAcquire;
20namespace test {
22} // namespace test
23
24class LedgerReplayTask final : public TimeoutCounter,
25 public std::enable_shared_from_this<LedgerReplayTask>,
26 public CountedObject<LedgerReplayTask>
27{
28public:
30 {
31 public:
32 // set on construct
35 std::uint32_t totalLedgers; // including the start and the finish
36
37 // to be updated
39 std::vector<uint256> skipList; // including the finishHash
42 bool full = false;
43
52 uint256 const& finishLedgerHash,
53 std::uint32_t totalNumLedgers);
54
64 bool
65 update(uint256 const& hash, std::uint32_t seq, std::vector<uint256> const& sList);
66
70 [[nodiscard]] bool
71 canMergeInto(TaskParameter const& existingTask) const;
72 };
73
84 Application& app,
85 InboundLedgers& inboundLedgers,
86 LedgerReplayer& replayer,
87 std::shared_ptr<SkipListAcquire>& skipListAcquirer,
88 TaskParameter const& parameter);
89
90 ~LedgerReplayTask() override;
91
95 void
96 init();
97
103 void
105
106 TaskParameter const&
108 {
109 return parameter_;
110 }
111
115 bool
116 finished() const;
117
118private:
119 void
120 onTimer(bool progress, ScopedLockType& sl) override;
121
123 pmDowncast() override;
124
131 void
132 updateSkipList(uint256 const& hash, std::uint32_t seq, std::vector<uint256> const& sList);
133
138 void
139 deltaReady(uint256 const& deltaHash);
140
145 void
147
152 void
154
158 uint32_t maxTimeouts_;
161 uint32_t deltaToBuild_ = 0; // should not build until have parent
163
165};
166
167} // namespace xrpl
Manages the lifetime of inbound ledgers.
Manage the retrieval of a ledger delta (header and transactions) from the network.
TaskParameter(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
constructor
bool update(uint256 const &hash, std::uint32_t seq, std::vector< uint256 > const &sList)
fill all the fields that was not filled during construction
bool canMergeInto(TaskParameter const &existingTask) const
check if this task can be merged into an existing task
void trigger(ScopedLockType &sl)
Trigger another round.
void onTimer(bool progress, ScopedLockType &sl) override
Hook called from invokeOnTimer().
LedgerReplayer & replayer_
LedgerReplayTask(Application &app, InboundLedgers &inboundLedgers, LedgerReplayer &replayer, std::shared_ptr< SkipListAcquire > &skipListAcquirer, TaskParameter const &parameter)
Constructor.
InboundLedgers & inboundLedgers_
void updateSkipList(uint256 const &hash, std::uint32_t seq, std::vector< uint256 > const &sList)
Update this task (by a SkipListAcquire subtask) when skip list is ready.
void tryAdvance(ScopedLockType &sl)
Try to build more ledgers.
void deltaReady(uint256 const &deltaHash)
Notify this task (by a LedgerDeltaAcquire subtask) that a delta is ready.
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
TaskParameter const & getTaskParameter() const
std::vector< std::shared_ptr< LedgerDeltaAcquire > > deltas_
bool finished() const
return if the task is finished
void addDelta(std::shared_ptr< LedgerDeltaAcquire > const &delta)
add a new LedgerDeltaAcquire subtask
std::shared_ptr< Ledger const > parent_
std::shared_ptr< SkipListAcquire > skipListAcquirer_
void init()
Start the task.
Manages the lifetime of ledger replay tasks.
Manage the retrieval of a skip list in a ledger from the network.
TimeoutCounter(Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
std::unique_lock< std::recursive_mutex > ScopedLockType
Ledger replay client side.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 256 > uint256
Definition base_uint.h:580