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/Peer.h>
6#include <xrpld/overlay/PeerSet.h>
7
8#include <xrpl/basics/CountedObject.h>
9#include <xrpl/basics/base_uint.h>
10#include <xrpl/beast/clock/abstract_clock.h>
11#include <xrpl/json/json_value.h>
12#include <xrpl/ledger/Ledger.h>
13#include <xrpl/nodestore/Database.h>
14#include <xrpl/shamap/SHAMap.h>
15#include <xrpl/shamap/SHAMapAddNode.h>
16#include <xrpl/shamap/SHAMapNodeID.h>
17
18#include <xrpl.pb.h>
19
20#include <chrono>
21#include <cstddef>
22#include <cstdint>
23#include <memory>
24#include <mutex>
25#include <set>
26#include <string_view>
27#include <utility>
28#include <vector>
29
30namespace xrpl {
31
32// A ledger we are trying to acquire
33class InboundLedger final : public TimeoutCounter,
34 public std::enable_shared_from_this<InboundLedger>,
35 public CountedObject<InboundLedger>
36{
37public:
39
40 // These are the reasons we might acquire a ledger
41 enum class Reason {
42 HISTORY, // Acquiring past ledger
43 GENERIC, // Generic other reasons
44 CONSENSUS // We believe the consensus round requires this ledger
45 };
46
48 Application& app,
49 uint256 const& hash,
50 std::uint32_t seq,
51 Reason reason,
54
55 ~InboundLedger() override;
56
57 // Called when another attempt is made to fetch this same ledger
58 void
60
64 bool
65 isComplete() const
66 {
67 return complete_;
68 }
69
73 bool
74 isFailed() const
75 {
76 return failed_;
77 }
78
80 getLedger() const
81 {
82 return ledger_;
83 }
84
86 getSeq() const
87 {
88 return seq_;
89 }
90
91 bool
92 checkLocal();
93 void
94 init(ScopedLockType& collectionLock);
95
96 bool
98
100
105 getJson(int);
106
107 void
108 runData();
109
110 void
112 {
113 lastAction_ = clock_.now();
114 }
115
118 {
119 return lastAction_;
120 }
121
122private:
124
125 void
127
128 void
130
133
134 void
135 addPeers();
136
137 void
139
140 void
141 done();
142
143 void
144 onTimer(bool progress, ScopedLockType& peerSetLock) override;
145
147 getPeerCount() const;
148
150 pmDowncast() override;
151
152 int
153 processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData const& data);
154
155 bool
157
158 void
160 std::shared_ptr<Peer> const& peer,
161 protocol::TMLedgerData const& packet,
162 SHAMapAddNode& san);
163
164 bool
166
167 bool
169
171 neededTxHashes(int max, SHAMapSyncFilter const* filter) const;
172
174 neededStateHashes(int max, SHAMapSyncFilter const* filter) const;
175
178
180 bool haveHeader_{false};
181 bool haveState_{false};
182 bool haveTransactions_{false};
183 bool signaled_{false};
184 bool byHash_{true};
187
189
191
192 // Data we have received from peers
198};
199
200} // namespace xrpl
Abstract interface to a clock.
std::chrono::steady_clock::time_point time_point
Represents a JSON value.
Definition json_value.h:117
clock_type::time_point lastAction_
json::Value getJson(int)
Return a json::ValueType::Object.
void tryDB(node_store::Database &srcDB)
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.
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
void receiveNode(std::shared_ptr< Peer > const &peer, protocol::TMLedgerData const &packet, SHAMapAddNode &san)
Process node data received from a peer Call with a lock.
SHAMapAddNode stats_
int processData(std::shared_ptr< Peer > peer, protocol::TMLedgerData const &data)
Process one TMLedgerData Returns the number of useful nodes.
bool takeHeader(std::string_view data)
Take ledger header data Call with a lock.
bool takeAsRootNode(std::string_view data, SHAMapAddNode &san)
Process AS root node received from a peer Call with a lock.
void filterNodes(std::vector< std::pair< SHAMapNodeID, uint256 > > &nodes, TriggerReason reason)
std::shared_ptr< Ledger > ledger_
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_
std::pair< protocol::TMGetObjectByHash::ObjectType, uint256 > neededHash_t
std::uint32_t getSeq() const
std::mutex receivedDataLock_
std::unique_ptr< PeerSet > peerSet_
void addPeers()
Add more peers to the set, if possible.
bool takeTxRootNode(std::string_view data, SHAMapAddNode &san)
Process AS root node received from a peer Call with a lock.
beast::AbstractClock< std::chrono::steady_clock > clock_type
void init(ScopedLockType &collectionLock)
void update(std::uint32_t seq)
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()
TimeoutCounter(Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
std::unique_lock< std::recursive_mutex > ScopedLockType
Persistency layer for NodeObject.
Definition Database.h:45
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:580