rippled
LedgerReplayer.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_LEDGERREPLAYER_H_INCLUDED
21 #define RIPPLE_APP_LEDGER_LEDGERREPLAYER_H_INCLUDED
22 
23 #include <ripple/app/ledger/LedgerMaster.h>
24 #include <ripple/app/ledger/LedgerReplayTask.h>
25 #include <ripple/app/main/Application.h>
26 #include <ripple/beast/utility/Journal.h>
27 
28 #include <memory>
29 #include <mutex>
30 #include <vector>
31 
32 namespace ripple {
33 
34 namespace test {
35 class LedgerReplayClient;
36 } // namespace test
37 
38 namespace LedgerReplayParameters {
39 // timeout value for LedgerReplayTask
41 
42 // for LedgerReplayTask to calculate max allowed timeouts
43 // = max( TASK_MAX_TIMEOUTS_MINIMUM,
44 // (# of ledger to replay) * TASK_MAX_TIMEOUTS_MULTIPLIER)
47 
48 // timeout value for subtasks: LedgerDeltaAcquire and SkipListAcquire
50 // max of allowed subtask timeouts
52 
53 // max number of peers that do not support the ledger replay feature
54 // returned by the PeerSet before switch to fallback
55 auto constexpr MAX_NO_FEATURE_PEER_COUNT = 2;
56 // subtask timeout value after fallback
58 
59 // for LedgerReplayer to limit the number of LedgerReplayTask
60 std::uint32_t constexpr MAX_TASKS = 10;
61 
62 // for LedgerReplayer to limit the number of ledgers to replay in one task
63 std::uint32_t constexpr MAX_TASK_SIZE = 256;
64 
65 // to limit the number of LedgerReplay related jobs in JobQueue
67 } // namespace LedgerReplayParameters
68 
72 class LedgerReplayer final
73 {
74 public:
76  Application& app,
77  InboundLedgers& inboundLedgers,
78  std::unique_ptr<PeerSetBuilder> peerSetBuilder);
79 
81 
89  void
90  replay(
92  uint256 const& finishLedgerHash,
93  std::uint32_t totalNumLedgers);
94 
96  void
98 
105  void
106  gotSkipList(
107  LedgerInfo const& info,
108  boost::intrusive_ptr<SHAMapItem const> const& data);
109 
116  void
118  LedgerInfo const& info,
120 
122  void
123  sweep();
124 
125  void
126  stop();
127 
129  tasksSize() const
130  {
132  return tasks_.size();
133  }
134 
136  deltasSize() const
137  {
139  return deltas_.size();
140  }
141 
144  {
146  return skipLists_.size();
147  }
148 
149 private:
150  mutable std::mutex mtx_;
154 
159 
161 };
162 
163 } // namespace ripple
164 
165 #endif
ripple::Application
Definition: Application.h:116
ripple::LedgerReplayer::skipLists_
hash_map< uint256, std::weak_ptr< SkipListAcquire > > skipLists_
Definition: LedgerReplayer.h:153
ripple::LedgerReplayParameters::SUB_TASK_MAX_TIMEOUTS
constexpr std::uint32_t SUB_TASK_MAX_TIMEOUTS
Definition: LedgerReplayer.h:51
std::shared_ptr
STL class.
ripple::LedgerReplayParameters::SUB_TASK_FALLBACK_TIMEOUT
constexpr auto SUB_TASK_FALLBACK_TIMEOUT
Definition: LedgerReplayer.h:57
ripple::LedgerReplayer::stop
void stop()
Definition: LedgerReplayer.cpp:265
ripple::LedgerReplayParameters::MAX_TASKS
constexpr std::uint32_t MAX_TASKS
Definition: LedgerReplayer.h:60
vector
std::chrono::milliseconds
std::lock_guard
STL class.
ripple::LedgerReplayParameters::MAX_TASK_SIZE
constexpr std::uint32_t MAX_TASK_SIZE
Definition: LedgerReplayer.h:63
ripple::LedgerReplayer::deltas_
hash_map< uint256, std::weak_ptr< LedgerDeltaAcquire > > deltas_
Definition: LedgerReplayer.h:152
ripple::LedgerReplayer::gotSkipList
void gotSkipList(LedgerInfo const &info, boost::intrusive_ptr< SHAMapItem const > const &data)
Process a skip list (extracted from a TMProofPathResponse message)
Definition: LedgerReplayer.cpp:173
ripple::LedgerReplayParameters::MAX_QUEUED_TASKS
constexpr std::uint32_t MAX_QUEUED_TASKS
Definition: LedgerReplayer.h:66
ripple::LedgerReplayer::createDeltas
void createDeltas(std::shared_ptr< LedgerReplayTask > task)
Create LedgerDeltaAcquire subtasks for the LedgerReplayTask task.
Definition: LedgerReplayer.cpp:112
ripple::base_uint< 256 >
ripple::LedgerReplayer::tasksSize
std::size_t tasksSize() const
Definition: LedgerReplayer.h:129
ripple::LedgerReplayer::inboundLedgers_
InboundLedgers & inboundLedgers_
Definition: LedgerReplayer.h:156
ripple::LedgerReplayParameters::SUB_TASK_TIMEOUT
constexpr auto SUB_TASK_TIMEOUT
Definition: LedgerReplayer.h:49
ripple::LedgerReplayer::~LedgerReplayer
~LedgerReplayer()
Definition: LedgerReplayer.cpp:38
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::LedgerReplayer::gotReplayDelta
void gotReplayDelta(LedgerInfo const &info, std::map< std::uint32_t, std::shared_ptr< STTx const >> &&txns)
Process a ledger delta (extracted from a TMReplayDeltaResponse message)
Definition: LedgerReplayer.cpp:196
ripple::LedgerReplayer::replay
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
Definition: LedgerReplayer.cpp:45
ripple::LedgerReplayParameters::TASK_MAX_TIMEOUTS_MULTIPLIER
constexpr std::uint32_t TASK_MAX_TIMEOUTS_MULTIPLIER
Definition: LedgerReplayer.h:45
std::map
STL class.
ripple::test::LedgerReplayClient
Ledger replay client side.
Definition: LedgerReplay_test.cpp:567
memory
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:33
ripple::LedgerHeader
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:33
ripple::LedgerReplayer::tasks_
std::vector< std::shared_ptr< LedgerReplayTask > > tasks_
Definition: LedgerReplayer.h:151
ripple::LedgerReplayParameters::TASK_TIMEOUT
constexpr auto TASK_TIMEOUT
Definition: LedgerReplayer.h:40
ripple::LedgerReplayer::sweep
void sweep()
Remove completed tasks.
Definition: LedgerReplayer.cpp:219
ripple::LedgerReplayer::deltasSize
std::size_t deltasSize() const
Definition: LedgerReplayer.h:136
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerReplayer::LedgerReplayer
LedgerReplayer(Application &app, InboundLedgers &inboundLedgers, std::unique_ptr< PeerSetBuilder > peerSetBuilder)
Definition: LedgerReplayer.cpp:27
ripple::LedgerReplayParameters::TASK_MAX_TIMEOUTS_MINIMUM
constexpr std::uint32_t TASK_MAX_TIMEOUTS_MINIMUM
Definition: LedgerReplayer.h:46
ripple::LedgerReplayer::skipListsSize
std::size_t skipListsSize() const
Definition: LedgerReplayer.h:143
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:72
ripple::LedgerReplayer::j_
beast::Journal j_
Definition: LedgerReplayer.h:158
mutex
std::size_t
ripple::LedgerReplayer::app_
Application & app_
Definition: LedgerReplayer.h:155
ripple::LedgerReplayParameters::MAX_NO_FEATURE_PEER_COUNT
constexpr auto MAX_NO_FEATURE_PEER_COUNT
Definition: LedgerReplayer.h:55
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:43
ripple::LedgerReplayer::peerSetBuilder_
std::unique_ptr< PeerSetBuilder > peerSetBuilder_
Definition: LedgerReplayer.h:157
std::unique_ptr
STL class.
std::unordered_map
STL class.
ripple::LedgerReplayer::mtx_
std::mutex mtx_
Definition: LedgerReplayer.h:150