xrpld
Loading...
Searching...
No Matches
InboundLedger.h
1#pragma once
2
3#include <xrpld/app/ledger/detail/TimeoutCounter.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/overlay/PeerSet.h>
6
7#include <xrpl/basics/CountedObject.h>
8#include <xrpl/ledger/Ledger.h>
9
10#include <mutex>
11#include <set>
12#include <utility>
13
14namespace xrpl {
15
16// A ledger we are trying to acquire
17class InboundLedger final : public TimeoutCounter,
18 public std::enable_shared_from_this<InboundLedger>,
19 public CountedObject<InboundLedger>
20{
21public:
23
24 // These are the reasons we might acquire a ledger
25 enum class Reason {
26 HISTORY, // Acquiring past ledger
27 GENERIC, // Generic other reasons
28 CONSENSUS // We believe the consensus round requires this ledger
29 };
30
32 Application& app,
33 uint256 const& hash,
34 std::uint32_t seq,
35 Reason reason,
38
39 ~InboundLedger() override;
40
41 // Called when another attempt is made to fetch this same ledger
42 void
44
46 bool
47 isComplete() const
48 {
49 return complete_;
50 }
51
53 bool
54 isFailed() const
55 {
56 return failed_;
57 }
58
60 getLedger() const
61 {
62 return ledger_;
63 }
64
66 getSeq() const
67 {
68 return seq_;
69 }
70
71 bool
72 checkLocal();
73 void
74 init(ScopedLockType& collectionLock);
75
76 bool
78
80
83 getJson(int);
84
85 void
86 runData();
87
88 void
90 {
91 lastAction_ = clock_.now();
92 }
93
96 {
97 return lastAction_;
98 }
99
100private:
102
103 void
105
106 void
108
111
112 void
113 addPeers();
114
115 void
117
118 void
119 done();
120
121 void
122 onTimer(bool progress, ScopedLockType& peerSetLock) override;
123
125 getPeerCount() const;
126
128 pmDowncast() override;
129
130 int
131 processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData const& data);
132
133 bool
134 takeHeader(std::string const& data);
135
136 void
137 receiveNode(protocol::TMLedgerData const& packet, SHAMapAddNode&);
138
139 bool
140 takeTxRootNode(Slice const& data, SHAMapAddNode&);
141
142 bool
143 takeAsRootNode(Slice const& data, SHAMapAddNode&);
144
146 neededTxHashes(int max, SHAMapSyncFilter const* filter) const;
147
149 neededStateHashes(int max, SHAMapSyncFilter const* filter) const;
150
153
155 bool haveHeader_{false};
156 bool haveState_{false};
157 bool haveTransactions_{false};
158 bool signaled_{false};
159 bool byHash_{true};
162
164
166
167 // Data we have received from peers
173};
174
175} // namespace xrpl
Abstract interface to a clock.
std::chrono::steady_clock::time_point time_point
Represents a JSON value.
Definition json_value.h:130
clock_type::time_point lastAction_
json::Value getJson(int)
Return a json::ValueType::Object.
void trigger(std::shared_ptr< Peer > const &, TriggerReason)
Request more nodes, perhaps from a specific peer.
InboundLedger(Application &app, uint256 const &hash, std::uint32_t seq, Reason reason, clock_type &, std::unique_ptr< PeerSet > peerSet)
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
void runData()
Process pending TMLedgerData Query the a random sample of the 'best' peers.
void tryDB(NodeStore::Database &srcDB)
std::size_t getPeerCount() const
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 const *filter) const
SHAMapAddNode stats_
int processData(std::shared_ptr< Peer > peer, protocol::TMLedgerData const &data)
Process one TMLedgerData Returns the number of useful nodes.
void filterNodes(std::vector< std::pair< SHAMapNodeID, uint256 > > &nodes, TriggerReason reason)
std::shared_ptr< Ledger > ledger_
bool takeAsRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
bool isComplete() const
Returns true if we got all the data.
std::vector< std::pair< std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > > > receivedData_
bool takeHeader(std::string const &data)
Take ledger header data Call with a lock.
std::pair< protocol::TMGetObjectByHash::ObjectType, uint256 > neededHash_t
std::uint32_t getSeq() const
std::mutex receivedDataLock_
bool takeTxRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
std::unique_ptr< PeerSet > peerSet_
void addPeers()
Add more peers to the set, if possible.
beast::AbstractClock< std::chrono::steady_clock > clock_type
void init(ScopedLockType &collectionLock)
void update(std::uint32_t seq)
void receiveNode(protocol::TMLedgerData const &packet, SHAMapAddNode &)
Process node data received from a peer Call with a lock.
bool isFailed() const
Returns false if we failed to get the data.
std::vector< uint256 > neededTxHashes(int max, SHAMapSyncFilter const *filter) const
clock_type::time_point getLastAction() const
std::set< uint256 > recentNodes_
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::shared_ptr< Ledger const > getLedger() const
std::vector< neededHash_t > getNeededHashes()
Persistency layer for NodeObject.
Definition Database.h:32
An immutable linear range of bytes.
Definition Slice.h:26
TimeoutCounter(Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
std::unique_lock< std::recursive_mutex > ScopedLockType
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 256 > uint256
Definition base_uint.h:562