rippled
Loading...
Searching...
No Matches
InboundLedger.h
1#ifndef XRPL_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
2#define XRPL_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
3
4#include <xrpld/app/ledger/Ledger.h>
5#include <xrpld/app/ledger/detail/TimeoutCounter.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/overlay/PeerSet.h>
8
9#include <xrpl/basics/CountedObject.h>
10
11#include <mutex>
12#include <set>
13#include <utility>
14
15namespace ripple {
16
17// A ledger we are trying to acquire
18class InboundLedger final : public TimeoutCounter,
19 public std::enable_shared_from_this<InboundLedger>,
20 public CountedObject<InboundLedger>
21{
22public:
24
25 // These are the reasons we might acquire a ledger
26 enum class Reason {
27 HISTORY, // Acquiring past ledger
28 GENERIC, // Generic other reasons
29 CONSENSUS // We believe the consensus round requires this ledger
30 };
31
33 Application& app,
34 uint256 const& hash,
35 std::uint32_t seq,
36 Reason reason,
39
41
42 // Called when another attempt is made to fetch this same ledger
43 void
45
47 bool
48 isComplete() const
49 {
50 return complete_;
51 }
52
54 bool
55 isFailed() const
56 {
57 return failed_;
58 }
59
61 getLedger() const
62 {
63 return mLedger;
64 }
65
67 getSeq() const
68 {
69 return mSeq;
70 }
71
72 bool
73 checkLocal();
74 void
75 init(ScopedLockType& collectionLock);
76
77 bool
78 gotData(
81
84
87 getJson(int);
88
89 void
90 runData();
91
92 void
94 {
96 }
97
100 {
101 return mLastAction;
102 }
103
104private:
106
107 void
110 TriggerReason reason);
111
112 void
114
117
118 void
119 addPeers();
120
121 void
123
124 void
125 done();
126
127 void
128 onTimer(bool progress, ScopedLockType& peerSetLock) override;
129
131 getPeerCount() const;
132
134 pmDowncast() override;
135
136 int
137 processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
138
139 bool
140 takeHeader(std::string const& data);
141
142 void
143 receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode&);
144
145 bool
146 takeTxRootNode(Slice const& data, SHAMapAddNode&);
147
148 bool
149 takeAsRootNode(Slice const& data, SHAMapAddNode&);
150
152 neededTxHashes(int max, SHAMapSyncFilter* filter) const;
153
155 neededStateHashes(int max, SHAMapSyncFilter* filter) const;
156
159
168
170
172
173 // Data we have received from peers
180};
181
182} // namespace ripple
183
184#endif
Represents a JSON value.
Definition json_value.h:130
virtual time_point now() const =0
Returns the current time.
Tracks the number of instances of an object.
Json::Value getJson(int)
Return a Json::objectValue.
void runData()
Process pending TMLedgerData Query the a random sample of the 'best' peers.
std::size_t getPeerCount() const
void trigger(std::shared_ptr< Peer > const &, TriggerReason)
Request more nodes, perhaps from a specific peer.
void init(ScopedLockType &collectionLock)
clock_type::time_point mLastAction
std::set< uint256 > mRecentNodes
void receiveNode(protocol::TMLedgerData &packet, SHAMapAddNode &)
Process node data received from a peer Call with a lock.
bool isComplete() const
Returns true if we got all the data.
bool takeHeader(std::string const &data)
Take ledger header data Call with a lock.
void addPeers()
Add more peers to the set, if possible.
std::shared_ptr< Ledger const > getLedger() const
int processData(std::shared_ptr< Peer > peer, protocol::TMLedgerData &data)
Process one TMLedgerData Returns the number of useful nodes.
beast::abstract_clock< std::chrono::steady_clock > clock_type
std::uint32_t getSeq() const
clock_type::time_point getLastAction() const
std::shared_ptr< Ledger > mLedger
std::vector< uint256 > neededTxHashes(int max, SHAMapSyncFilter *filter) const
void tryDB(NodeStore::Database &srcDB)
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Called with a lock by the PeerSet when the timer expires.
std::vector< uint256 > neededStateHashes(int max, SHAMapSyncFilter *filter) const
bool isFailed() const
Returns false if we failed to get the data.
void filterNodes(std::vector< std::pair< SHAMapNodeID, uint256 > > &nodes, TriggerReason reason)
bool takeAsRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
bool takeTxRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
std::vector< std::pair< std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > > > mReceivedData
bool gotData(std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > const &)
Stash a TMLedgerData received from a peer for later processing Returns 'true' if we need to dispatch.
std::vector< neededHash_t > getNeededHashes()
void update(std::uint32_t seq)
std::unique_ptr< PeerSet > mPeerSet
Persistency layer for NodeObject.
Definition Database.h:32
An immutable linear range of bytes.
Definition Slice.h:27
This class is an "active" object.
std::unique_lock< std::recursive_mutex > ScopedLockType
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6