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 <memory>
28#include <vector>
29
30namespace ripple {
31class InboundLedgers;
32class Ledger;
33class LedgerDeltaAcquire;
34class LedgerReplayer;
35class SkipListAcquire;
36namespace test {
37class LedgerReplayClient;
38} // namespace test
39
41 : public TimeoutCounter,
42 public std::enable_shared_from_this<LedgerReplayTask>,
43 public CountedObject<LedgerReplayTask>
44{
45public:
47 {
48 public:
49 // set on construct
52 std::uint32_t totalLedgers_; // including the start and the finish
53
54 // to be updated
56 std::vector<uint256> skipList_ = {}; // including the finishHash
59 bool full_ = false;
60
69 uint256 const& finishLedgerHash,
70 std::uint32_t totalNumLedgers);
71
81 bool
82 update(
83 uint256 const& hash,
84 std::uint32_t seq,
85 std::vector<uint256> const& sList);
86
88 bool
89 canMergeInto(TaskParameter const& existingTask) const;
90 };
91
102 Application& app,
103 InboundLedgers& inboundLedgers,
104 LedgerReplayer& replayer,
105 std::shared_ptr<SkipListAcquire>& skipListAcquirer,
106 TaskParameter&& parameter);
107
109
111 void
112 init();
113
119 void
121
122 TaskParameter const&
124 {
125 return parameter_;
126 }
127
129 bool
130 finished() const;
131
132private:
133 void
134 onTimer(bool progress, ScopedLockType& sl) override;
135
137 pmDowncast() override;
138
145 void
147 uint256 const& hash,
148 std::uint32_t seq,
149 std::vector<uint256> const& sList);
150
155 void
156 deltaReady(uint256 const& deltaHash);
157
162 void
164
169 void
171
175 uint32_t maxTimeouts_;
178 uint32_t deltaToBuild_ = 0; // should not build until have parent
180
182};
183
184} // namespace ripple
185
186#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