rippled
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 <ripple/app/ledger/InboundLedger.h>
24 #include <ripple/app/ledger/impl/TimeoutCounter.h>
25 #include <ripple/app/main/Application.h>
26 
27 #include <memory>
28 #include <vector>
29 
30 namespace ripple {
31 class InboundLedgers;
32 class Ledger;
33 class LedgerDeltaAcquire;
34 class LedgerReplayer;
35 class SkipListAcquire;
36 namespace test {
37 class LedgerReplayClient;
38 } // namespace test
39 
40 class LedgerReplayTask final
41  : public TimeoutCounter,
42  public std::enable_shared_from_this<LedgerReplayTask>,
43  public CountedObject<LedgerReplayTask>
44 {
45 public:
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 
132  static char const*
134  {
135  return "LedgerReplayTask";
136  }
137 
138 private:
139  void
140  onTimer(bool progress, ScopedLockType& sl) override;
141 
143  pmDowncast() override;
144 
151  void
153  uint256 const& hash,
154  std::uint32_t seq,
155  std::vector<uint256> const& sList);
156 
161  void
162  deltaReady(uint256 const& deltaHash);
163 
168  void
169  trigger(ScopedLockType& sl);
170 
175  void
177 
181  uint32_t maxTimeouts_;
184  uint32_t deltaToBuild_ = 0; // should not build until have parent
186 
188 };
189 
190 } // namespace ripple
191 
192 #endif
ripple::Application
Definition: Application.h:102
ripple::LedgerReplayTask::deltas_
std::vector< std::shared_ptr< LedgerDeltaAcquire > > deltas_
Definition: LedgerReplayTask.h:185
ripple::TimeoutCounter::ScopedLockType
std::unique_lock< std::recursive_mutex > ScopedLockType
Definition: TimeoutCounter.h:81
ripple::LedgerReplayTask::onTimer
void onTimer(bool progress, ScopedLockType &sl) override
Hook called from invokeOnTimer().
Definition: LedgerReplayTask.cpp:250
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::LedgerReplayTask::TaskParameter::reason_
InboundLedger::Reason reason_
Definition: LedgerReplayTask.h:50
std::shared_ptr
STL class.
ripple::LedgerReplayTask::TaskParameter::finishSeq_
std::uint32_t finishSeq_
Definition: LedgerReplayTask.h:55
ripple::LedgerReplayTask::getCountedObjectName
static char const * getCountedObjectName()
Definition: LedgerReplayTask.h:133
ripple::LedgerReplayTask::TaskParameter::startHash_
uint256 startHash_
Definition: LedgerReplayTask.h:57
ripple::LedgerReplayTask::replayer_
LedgerReplayer & replayer_
Definition: LedgerReplayTask.h:179
vector
ripple::LedgerReplayTask::getTaskParameter
TaskParameter const & getTaskParameter() const
Definition: LedgerReplayTask.h:123
ripple::LedgerReplayTask::deltaReady
void deltaReady(uint256 const &deltaHash)
Notify this task (by a LedgerDeltaAcquire subtask) that a delta is ready.
Definition: LedgerReplayTask.cpp:174
ripple::LedgerReplayTask::TaskParameter::full_
bool full_
Definition: LedgerReplayTask.h:59
ripple::LedgerReplayTask::LedgerReplayTask
LedgerReplayTask(Application &app, InboundLedgers &inboundLedgers, LedgerReplayer &replayer, std::shared_ptr< SkipListAcquire > &skipListAcquirer, TaskParameter &&parameter)
Constructor.
Definition: LedgerReplayTask.cpp:84
ripple::LedgerReplayTask::pmDowncast
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
Definition: LedgerReplayTask.cpp:266
ripple::LedgerReplayTask::trigger
void trigger(ScopedLockType &sl)
Trigger another round.
Definition: LedgerReplayTask.cpp:146
ripple::TimeoutCounter
This class is an "active" object.
Definition: TimeoutCounter.h:66
ripple::LedgerReplayTask::updateSkipList
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.
Definition: LedgerReplayTask.cpp:226
ripple::LedgerReplayTask::tryAdvance
void tryAdvance(ScopedLockType &sl)
Try to build more ledgers.
Definition: LedgerReplayTask.cpp:184
ripple::LedgerReplayTask::TaskParameter::update
bool update(uint256 const &hash, std::uint32_t seq, std::vector< uint256 > const &sList)
fill all the fields that was not filled during construction
Definition: LedgerReplayTask.cpp:39
ripple::LedgerReplayTask::parameter_
TaskParameter parameter_
Definition: LedgerReplayTask.h:180
ripple::LedgerReplayTask::addDelta
void addDelta(std::shared_ptr< LedgerDeltaAcquire > const &delta)
add a new LedgerDeltaAcquire subtask
Definition: LedgerReplayTask.cpp:272
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:73
ripple::LedgerReplayTask::parent_
std::shared_ptr< Ledger const > parent_
Definition: LedgerReplayTask.h:183
ripple::LedgerReplayTask::TaskParameter::TaskParameter
TaskParameter(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
constructor
Definition: LedgerReplayTask.cpp:29
ripple::LedgerReplayTask::inboundLedgers_
InboundLedgers & inboundLedgers_
Definition: LedgerReplayTask.h:178
ripple::LedgerReplayTask::finished
bool finished() const
return if the task is finished
Definition: LedgerReplayTask.cpp:300
ripple::LedgerReplayTask::maxTimeouts_
uint32_t maxTimeouts_
Definition: LedgerReplayTask.h:181
std::enable_shared_from_this
std::uint32_t
ripple::LedgerReplayTask::~LedgerReplayTask
~LedgerReplayTask()
Definition: LedgerReplayTask.cpp:110
ripple::test::LedgerReplayClient
Ledger replay client side.
Definition: LedgerReplay_test.cpp:548
memory
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:34
ripple::LedgerReplayTask::init
void init()
Start the task.
Definition: LedgerReplayTask.cpp:116
ripple::LedgerReplayTask::TaskParameter
Definition: LedgerReplayTask.h:46
std::weak_ptr
STL class.
ripple::LedgerReplayTask::TaskParameter::skipList_
std::vector< uint256 > skipList_
Definition: LedgerReplayTask.h:56
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerReplayTask::skipListAcquirer_
std::shared_ptr< SkipListAcquire > skipListAcquirer_
Definition: LedgerReplayTask.h:182
ripple::LedgerReplayTask::TaskParameter::startSeq_
std::uint32_t startSeq_
Definition: LedgerReplayTask.h:58
ripple::LedgerReplayTask::deltaToBuild_
uint32_t deltaToBuild_
Definition: LedgerReplayTask.h:184
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:73
ripple::LedgerReplayTask::TaskParameter::finishHash_
uint256 finishHash_
Definition: LedgerReplayTask.h:51
ripple::LedgerReplayTask::TaskParameter::totalLedgers_
std::uint32_t totalLedgers_
Definition: LedgerReplayTask.h:52
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:46
ripple::LedgerReplayTask
Definition: LedgerReplayTask.h:40
ripple::LedgerReplayTask::TaskParameter::canMergeInto
bool canMergeInto(TaskParameter const &existingTask) const
check if this task can be merged into an existing task
Definition: LedgerReplayTask.cpp:58