rippled
LedgerDeltaAcquire.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_LEDGERDELTAACQUIRE_H_INCLUDED
21 #define RIPPLE_APP_LEDGER_LEDGERDELTAACQUIRE_H_INCLUDED
22 
23 #include <ripple/app/ledger/InboundLedger.h>
24 #include <ripple/app/ledger/Ledger.h>
25 #include <ripple/app/ledger/impl/TimeoutCounter.h>
26 #include <ripple/basics/CountedObject.h>
27 #include <ripple/basics/base_uint.h>
28 
29 #include <list>
30 #include <map>
31 
32 namespace ripple {
33 class InboundLedgers;
34 class PeerSet;
35 namespace test {
36 class LedgerReplayClient;
37 } // namespace test
38 
44 class LedgerDeltaAcquire final
45  : public TimeoutCounter,
46  public std::enable_shared_from_this<LedgerDeltaAcquire>,
47  public CountedObject<LedgerDeltaAcquire>
48 {
49 public:
55  using OnDeltaDataCB =
56  std::function<void(bool successful, uint256 const& hash)>;
57 
67  Application& app,
68  InboundLedgers& inboundLedgers,
69  uint256 const& ledgerHash,
70  std::uint32_t ledgerSeq,
71  std::unique_ptr<PeerSet> peerSet);
72 
73  ~LedgerDeltaAcquire() override;
74 
79  void
80  init(int numPeers);
81 
89  void
91  LedgerInfo const& info,
93 
103 
111  void
113 
114 private:
115  void
116  onTimer(bool progress, ScopedLockType& peerSetLock) override;
117 
119  pmDowncast() override;
120 
126  void
127  trigger(std::size_t limit, ScopedLockType& sl);
128 
137  void
139  ScopedLockType& sl,
141 
146  void
147  notify(ScopedLockType& sl);
148 
158  bool fallBack_ = false;
159 
160  friend class LedgerReplayTask; // for asserts only
162 };
163 
164 } // namespace ripple
165 
166 #endif
ripple::LedgerDeltaAcquire::dataReadyCallbacks_
std::vector< OnDeltaDataCB > dataReadyCallbacks_
Definition: LedgerDeltaAcquire.h:155
ripple::Application
Definition: Application.h:115
ripple::LedgerDeltaAcquire::notify
void notify(ScopedLockType &sl)
Call the OnDeltaDataCB callbacks.
Definition: LedgerDeltaAcquire.cpp:263
ripple::TimeoutCounter::ScopedLockType
std::unique_lock< std::recursive_mutex > ScopedLockType
Definition: TimeoutCounter.h:81
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::LedgerDeltaAcquire::ledgerSeq_
const std::uint32_t ledgerSeq_
Definition: LedgerDeltaAcquire.h:150
std::shared_ptr
STL class.
ripple::LedgerDeltaAcquire::orderedTxns_
std::map< std::uint32_t, std::shared_ptr< STTx const > > orderedTxns_
Definition: LedgerDeltaAcquire.h:154
ripple::LedgerDeltaAcquire::processData
void processData(LedgerInfo const &info, std::map< std::uint32_t, std::shared_ptr< STTx const >> &&orderedTxns)
Process the data extracted from a peer's reply.
Definition: LedgerDeltaAcquire.cpp:139
list
ripple::LedgerDeltaAcquire::~LedgerDeltaAcquire
~LedgerDeltaAcquire() override
Definition: LedgerDeltaAcquire.cpp:52
ripple::LedgerDeltaAcquire::peerSet_
std::unique_ptr< PeerSet > peerSet_
Definition: LedgerDeltaAcquire.h:151
std::vector
STL class.
ripple::LedgerDeltaAcquire::init
void init(int numPeers)
Start the LedgerDeltaAcquire task.
Definition: LedgerDeltaAcquire.cpp:58
ripple::LedgerDeltaAcquire::fullLedger_
std::shared_ptr< Ledger const > fullLedger_
Definition: LedgerDeltaAcquire.h:153
ripple::LedgerDeltaAcquire::inboundLedgers_
InboundLedgers & inboundLedgers_
Definition: LedgerDeltaAcquire.h:149
std::function
ripple::TimeoutCounter
This class is an "active" object.
Definition: TimeoutCounter.h:66
ripple::LedgerDeltaAcquire
Manage the retrieval of a ledger delta (header and transactions) from the network.
Definition: LedgerDeltaAcquire.h:44
ripple::base_uint< 256 >
ripple::LedgerDeltaAcquire::replayTemp_
std::shared_ptr< Ledger const > replayTemp_
Definition: LedgerDeltaAcquire.h:152
ripple::LedgerDeltaAcquire::reasons_
std::set< InboundLedger::Reason > reasons_
Definition: LedgerDeltaAcquire.h:156
std::unique_lock< std::recursive_mutex >
ripple::LedgerDeltaAcquire::trigger
void trigger(std::size_t limit, ScopedLockType &sl)
Trigger another round.
Definition: LedgerDeltaAcquire.cpp:69
std::enable_shared_from_this
std::uint32_t
map
ripple::test::LedgerReplayClient
Ledger replay client side.
Definition: LedgerReplay_test.cpp:561
ripple::LedgerDeltaAcquire::addDataCallback
void addDataCallback(InboundLedger::Reason reason, OnDeltaDataCB &&cb)
Add a reason and a callback to the LedgerDeltaAcquire subtask.
Definition: LedgerDeltaAcquire.cpp:170
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:33
ripple::LedgerDeltaAcquire::pmDowncast
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
Definition: LedgerDeltaAcquire.cpp:133
std::weak_ptr
STL class.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerDeltaAcquire::noFeaturePeerCount
std::uint32_t noFeaturePeerCount
Definition: LedgerDeltaAcquire.h:157
ripple::LedgerDeltaAcquire::fallBack_
bool fallBack_
Definition: LedgerDeltaAcquire.h:158
ripple::LedgerDeltaAcquire::tryBuild
std::shared_ptr< Ledger const > tryBuild(std::shared_ptr< Ledger const > const &parent)
Try to build the ledger if not already.
Definition: LedgerDeltaAcquire.cpp:192
std::optional
std::size_t
ripple::LedgerInfo
Information about the notional ledger backing the view.
Definition: ReadView.h:75
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:43
ripple::LedgerReplayTask
Definition: LedgerReplayTask.h:40
std::unique_ptr
STL class.
ripple::LedgerDeltaAcquire::LedgerDeltaAcquire
LedgerDeltaAcquire(Application &app, InboundLedgers &inboundLedgers, uint256 const &ledgerHash, std::uint32_t ledgerSeq, std::unique_ptr< PeerSet > peerSet)
Constructor.
Definition: LedgerDeltaAcquire.cpp:31
std::set< InboundLedger::Reason >
ripple::LedgerDeltaAcquire::onTimer
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Hook called from invokeOnTimer().
Definition: LedgerDeltaAcquire.cpp:117
ripple::LedgerDeltaAcquire::onLedgerBuilt
void onLedgerBuilt(ScopedLockType &sl, std::optional< InboundLedger::Reason > reason={})
Process a newly built ledger, such as store it.
Definition: LedgerDeltaAcquire.cpp:224