rippled
Loading...
Searching...
No Matches
LedgerReplayTask.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2020 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or 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#ifndef RIPPLE_APP_LEDGER_LEDGERREPLAYTASK_H_INCLUDED
21#define RIPPLE_APP_LEDGER_LEDGERREPLAYTASK_H_INCLUDED
22
23#include <xrpld/app/ledger/InboundLedger.h>
24#include <xrpld/app/ledger/detail/TimeoutCounter.h>
25#include <xrpld/app/main/Application.h>
26
27#include <vector>
28
29namespace ripple {
30class InboundLedgers;
31class Ledger;
32class LedgerDeltaAcquire;
33class LedgerReplayer;
34class SkipListAcquire;
35namespace test {
36class LedgerReplayClient;
37} // namespace test
38
40 : public TimeoutCounter,
41 public std::enable_shared_from_this<LedgerReplayTask>,
42 public CountedObject<LedgerReplayTask>
43{
44public:
46 {
47 public:
48 // set on construct
51 std::uint32_t totalLedgers_; // including the start and the finish
52
53 // to be updated
55 std::vector<uint256> skipList_ = {}; // including the finishHash
58 bool full_ = false;
59
68 uint256 const& finishLedgerHash,
69 std::uint32_t totalNumLedgers);
70
80 bool
81 update(
82 uint256 const& hash,
83 std::uint32_t seq,
84 std::vector<uint256> const& sList);
85
87 bool
88 canMergeInto(TaskParameter const& existingTask) const;
89 };
90
101 Application& app,
102 InboundLedgers& inboundLedgers,
103 LedgerReplayer& replayer,
104 std::shared_ptr<SkipListAcquire>& skipListAcquirer,
105 TaskParameter&& parameter);
106
108
110 void
111 init();
112
118 void
120
121 TaskParameter const&
123 {
124 return parameter_;
125 }
126
128 bool
129 finished() const;
130
131private:
132 void
133 onTimer(bool progress, ScopedLockType& sl) override;
134
136 pmDowncast() override;
137
144 void
146 uint256 const& hash,
147 std::uint32_t seq,
148 std::vector<uint256> const& sList);
149
154 void
155 deltaReady(uint256 const& deltaHash);
156
161 void
163
168 void
170
174 uint32_t maxTimeouts_;
177 uint32_t deltaToBuild_ = 0; // should not build until have parent
179
181};
182
183} // namespace ripple
184
185#endif
Tracks the number of instances of an object.
Manages the lifetime of inbound ledgers.
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.
bool finished() const
return if the task is finished
std::vector< std::shared_ptr< LedgerDeltaAcquire > > deltas_
void addDelta(std::shared_ptr< LedgerDeltaAcquire > const &delta)
add a new LedgerDeltaAcquire subtask
void deltaReady(uint256 const &deltaHash)
Notify this task (by a LedgerDeltaAcquire subtask) that a delta is ready.
LedgerReplayer & replayer_
void init()
Start the task.
InboundLedgers & inboundLedgers_
std::shared_ptr< SkipListAcquire > skipListAcquirer_
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.
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
TaskParameter const & getTaskParameter() const
void tryAdvance(ScopedLockType &sl)
Try to build more ledgers.
std::shared_ptr< Ledger const > parent_
void onTimer(bool progress, ScopedLockType &sl) override
Hook called from invokeOnTimer().
Manages the lifetime of ledger replay tasks.
This class is an "active" object.
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:26