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 #include <ripple/core/Stoppable.h>
28 
29 #include <memory>
30 #include <mutex>
31 #include <vector>
32 
33 namespace ripple {
34 
35 namespace test {
36 class LedgerReplayClient;
37 } // namespace test
38 
39 namespace LedgerReplayParameters {
40 // timeout value for LedgerReplayTask
42 
43 // for LedgerReplayTask to calculate max allowed timeouts
44 // = max( TASK_MAX_TIMEOUTS_MINIMUM,
45 // (# of ledger to replay) * TASK_MAX_TIMEOUTS_MULTIPLIER)
48 
49 // timeout value for subtasks: LedgerDeltaAcquire and SkipListAcquire
51 // max of allowed subtask timeouts
53 
54 // max number of peers that do not support the ledger replay feature
55 // returned by the PeerSet before switch to fallback
56 auto constexpr MAX_NO_FEATURE_PEER_COUNT = 2;
57 // subtask timeout value after fallback
59 
60 // for LedgerReplayer to limit the number of LedgerReplayTask
61 std::uint32_t constexpr MAX_TASKS = 10;
62 
63 // for LedgerReplayer to limit the number of ledgers to replay in one task
64 std::uint32_t constexpr MAX_TASK_SIZE = 256;
65 
66 // to limit the number of LedgerReplay related jobs in JobQueue
68 } // namespace LedgerReplayParameters
69 
73 class LedgerReplayer final : public Stoppable
74 {
75 public:
77  Application& app,
78  InboundLedgers& inboundLedgers,
79  std::unique_ptr<PeerSetBuilder> peerSetBuilder,
80  Stoppable& parent);
81 
83 
91  void
92  replay(
94  uint256 const& finishLedgerHash,
95  std::uint32_t totalNumLedgers);
96 
98  void
100 
107  void
108  gotSkipList(
109  LedgerInfo const& info,
111 
118  void
120  LedgerInfo const& info,
122 
124  void
125  sweep();
126 
127  void
128  onStop() override;
129 
130 private:
131  mutable std::mutex mtx_;
135 
140 
142 };
143 
144 } // namespace ripple
145 
146 #endif
ripple::Application
Definition: Application.h:102
ripple::LedgerReplayer::skipLists_
hash_map< uint256, std::weak_ptr< SkipListAcquire > > skipLists_
Definition: LedgerReplayer.h:134
ripple::LedgerReplayParameters::SUB_TASK_MAX_TIMEOUTS
constexpr std::uint32_t SUB_TASK_MAX_TIMEOUTS
Definition: LedgerReplayer.h:52
std::shared_ptr
STL class.
ripple::LedgerReplayer::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: LedgerReplayer.cpp:259
ripple::LedgerReplayParameters::SUB_TASK_FALLBACK_TIMEOUT
constexpr auto SUB_TASK_FALLBACK_TIMEOUT
Definition: LedgerReplayer.h:58
ripple::LedgerReplayParameters::MAX_TASKS
constexpr std::uint32_t MAX_TASKS
Definition: LedgerReplayer.h:61
vector
std::chrono::milliseconds
ripple::LedgerReplayParameters::MAX_TASK_SIZE
constexpr std::uint32_t MAX_TASK_SIZE
Definition: LedgerReplayer.h:64
ripple::LedgerReplayer::deltas_
hash_map< uint256, std::weak_ptr< LedgerDeltaAcquire > > deltas_
Definition: LedgerReplayer.h:133
ripple::LedgerReplayParameters::MAX_QUEUED_TASKS
constexpr std::uint32_t MAX_QUEUED_TASKS
Definition: LedgerReplayer.h:67
ripple::LedgerReplayer::createDeltas
void createDeltas(std::shared_ptr< LedgerReplayTask > task)
Create LedgerDeltaAcquire subtasks for the LedgerReplayTask task.
Definition: LedgerReplayer.cpp:114
ripple::base_uint< 256 >
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::LedgerReplayer::inboundLedgers_
InboundLedgers & inboundLedgers_
Definition: LedgerReplayer.h:137
ripple::LedgerReplayParameters::SUB_TASK_TIMEOUT
constexpr auto SUB_TASK_TIMEOUT
Definition: LedgerReplayer.h:50
ripple::LedgerReplayer::~LedgerReplayer
~LedgerReplayer()
Definition: LedgerReplayer.cpp:40
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:198
ripple::LedgerReplayer::replay
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
Definition: LedgerReplayer.cpp:47
ripple::LedgerReplayParameters::TASK_MAX_TIMEOUTS_MULTIPLIER
constexpr std::uint32_t TASK_MAX_TIMEOUTS_MULTIPLIER
Definition: LedgerReplayer.h:46
std::map
STL class.
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::LedgerReplayer::LedgerReplayer
LedgerReplayer(Application &app, InboundLedgers &inboundLedgers, std::unique_ptr< PeerSetBuilder > peerSetBuilder, Stoppable &parent)
Definition: LedgerReplayer.cpp:27
ripple::LedgerReplayer::tasks_
std::vector< std::shared_ptr< LedgerReplayTask > > tasks_
Definition: LedgerReplayer.h:132
ripple::LedgerReplayParameters::TASK_TIMEOUT
constexpr auto TASK_TIMEOUT
Definition: LedgerReplayer.h:41
ripple::LedgerReplayer::sweep
void sweep()
Remove completed tasks.
Definition: LedgerReplayer.cpp:221
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerReplayParameters::TASK_MAX_TIMEOUTS_MINIMUM
constexpr std::uint32_t TASK_MAX_TIMEOUTS_MINIMUM
Definition: LedgerReplayer.h:47
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:73
ripple::LedgerReplayer::j_
beast::Journal j_
Definition: LedgerReplayer.h:139
mutex
ripple::LedgerReplayer::app_
Application & app_
Definition: LedgerReplayer.h:136
ripple::LedgerReplayParameters::MAX_NO_FEATURE_PEER_COUNT
constexpr auto MAX_NO_FEATURE_PEER_COUNT
Definition: LedgerReplayer.h:56
ripple::LedgerInfo
Information about the notional ledger backing the view.
Definition: ReadView.h:84
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:46
ripple::LedgerReplayer::peerSetBuilder_
std::unique_ptr< PeerSetBuilder > peerSetBuilder_
Definition: LedgerReplayer.h:138
std::unique_ptr
STL class.
std::unordered_map
STL class.
ripple::LedgerReplayer::gotSkipList
void gotSkipList(LedgerInfo const &info, std::shared_ptr< SHAMapItem const > const &data)
Process a skip list (extracted from a TMProofPathResponse message)
Definition: LedgerReplayer.cpp:175
ripple::LedgerReplayer::mtx_
std::mutex mtx_
Definition: LedgerReplayer.h:131