rippled
Loading...
Searching...
No Matches
InboundLedger.h
1#pragma once
2
3#include <xrpld/app/ledger/Ledger.h>
4#include <xrpld/app/ledger/detail/TimeoutCounter.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/overlay/PeerSet.h>
7
8#include <xrpl/basics/CountedObject.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
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 mLedger;
63 }
64
66 getSeq() const
67 {
68 return mSeq;
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 {
92 }
93
96 {
97 return mLastAction;
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& data);
132
133 bool
134 takeHeader(std::string const& data);
135
136 void
137 receiveNode(protocol::TMLedgerData& 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* filter) const;
147
149 neededStateHashes(int max, SHAMapSyncFilter* filter) const;
150
153
162
164
166
167 // Data we have received from peers
172};
173
174} // namespace xrpl
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.
void receiveNode(protocol::TMLedgerData &packet, SHAMapAddNode &)
Process node data received from a peer Call with a lock.
std::vector< uint256 > neededTxHashes(int max, SHAMapSyncFilter *filter) const
void trigger(std::shared_ptr< Peer > const &, TriggerReason)
Request more nodes, perhaps from a specific peer.
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
Json::Value getJson(int)
Return a Json::objectValue.
void runData()
Process pending TMLedgerData Query the a random sample of the 'best' peers.
void tryDB(NodeStore::Database &srcDB)
std::size_t getPeerCount() const
std::vector< uint256 > neededStateHashes(int max, SHAMapSyncFilter *filter) const
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Called with a lock by the PeerSet when the timer expires.
clock_type::time_point mLastAction
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.
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.
SHAMapAddNode mStats
int processData(std::shared_ptr< Peer > peer, protocol::TMLedgerData &data)
Process one TMLedgerData Returns the number of useful nodes.
std::uint32_t getSeq() const
bool takeTxRootNode(Slice const &data, SHAMapAddNode &)
Process AS root node received from a peer Call with a lock.
void addPeers()
Add more peers to the set, if possible.
std::shared_ptr< Ledger > mLedger
std::set< uint256 > mRecentNodes
void init(ScopedLockType &collectionLock)
void update(std::uint32_t seq)
std::vector< std::pair< std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > > > mReceivedData
std::mutex mReceivedDataLock
bool isFailed() const
Returns false if we failed to get the data.
clock_type::time_point getLastAction() const
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()
beast::abstract_clock< std::chrono::steady_clock > clock_type
std::unique_ptr< PeerSet > mPeerSet
Persistency layer for NodeObject.
Definition Database.h:31
An immutable linear range of bytes.
Definition Slice.h:26
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:5