-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathNetworkOPs.h
320 lines (261 loc) · 13.4 KB
/
NetworkOPs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_NETWORKOPS_H
#define RIPPLE_NETWORKOPS_H
namespace ripple {
// Operations that clients may wish to perform against the network
// Master operational handler, server sequencer, network tracker
class Peer;
class LedgerConsensus;
// This is the primary interface into the "client" portion of the program.
// Code that wants to do normal operations on the network such as
// creating and monitoring accounts, creating transactions, and so on
// should use this interface. The RPC code will primarily be a light wrapper
// over this code.
//
// Eventually, it will check the node's operating mode (synched, unsynched,
// etectera) and defer to the correct means of processing. The current
// code assumes this node is synched (and will continue to do so until
// there's a functional network.
//
/** Provides server functionality for clients.
Clients include backend applications, local commands, and connected
clients. This class acts as a proxy, fulfilling the command with local
data if possible, or asking the network and returning the results if
needed.
A backend application or local client can trust a local instance of
rippled / NetworkOPs. However, client software connecting to non-local
instances of rippled will need to be hardened to protect against hostile
or unreliable servers.
*/
class NetworkOPs
: public InfoSub::Source
{
protected:
explicit NetworkOPs (Stoppable& parent);
public:
typedef beast::abstract_clock <std::chrono::seconds> clock_type;
enum Fault
{
// exceptions these functions can throw
IO_ERROR = 1,
NO_NETWORK = 2,
};
enum OperatingMode
{
// how we process transactions or account balance requests
omDISCONNECTED = 0, // not ready to process requests
omCONNECTED = 1, // convinced we are talking to the network
omSYNCING = 2, // fallen slightly behind
omTRACKING = 3, // convinced we agree with the network
omFULL = 4 // we have the ledger and can even validate
};
// VFALCO TODO Fix OrderBookDB to not need this unrelated type.
//
typedef boost::unordered_map <std::uint64_t, InfoSub::wptr> SubMapType;
public:
// VFALCO TODO Make LedgerMaster a SharedPtr or a reference.
//
static NetworkOPs* New (clock_type& clock, LedgerMaster& ledgerMaster,
Stoppable& parent, beast::Journal journal);
virtual ~NetworkOPs () = 0;
//--------------------------------------------------------------------------
//
// Network information
//
// Our best estimate of wall time in seconds from 1/1/2000
virtual std::uint32_t getNetworkTimeNC () = 0;
// Our best estimate of current ledger close time
virtual std::uint32_t getCloseTimeNC () = 0;
// Use *only* to timestamp our own validation
virtual std::uint32_t getValidationTimeNC () = 0;
virtual void closeTimeOffset (int) = 0;
virtual boost::posix_time::ptime getNetworkTimePT () = 0;
virtual std::uint32_t getLedgerID (uint256 const& hash) = 0;
virtual std::uint32_t getCurrentLedgerID () = 0;
virtual OperatingMode getOperatingMode () = 0;
virtual std::string strOperatingMode () = 0;
virtual Ledger::pointer getClosedLedger () = 0;
virtual Ledger::pointer getValidatedLedger () = 0;
virtual Ledger::pointer getPublishedLedger () = 0;
virtual Ledger::pointer getCurrentLedger () = 0;
virtual Ledger::pointer getLedgerByHash (uint256 const& hash) = 0;
virtual Ledger::pointer getLedgerBySeq (const std::uint32_t seq) = 0;
virtual void missingNodeInLedger (const std::uint32_t seq) = 0;
virtual uint256 getClosedLedgerHash () = 0;
// Do we have this inclusive range of ledgers in our database
virtual bool haveLedgerRange (std::uint32_t from, std::uint32_t to) = 0;
virtual bool haveLedger (std::uint32_t seq) = 0;
virtual std::uint32_t getValidatedSeq () = 0;
virtual bool isValidated (std::uint32_t seq) = 0;
virtual bool isValidated (std::uint32_t seq, uint256 const& hash) = 0;
virtual bool isValidated (Ledger::ref l) = 0;
virtual bool getValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal) = 0;
virtual bool getFullValidatedRange (std::uint32_t& minVal, std::uint32_t& maxVal) = 0;
virtual SerializedValidation::ref getLastValidation () = 0;
virtual void setLastValidation (SerializedValidation::ref v) = 0;
virtual SLE::pointer getSLE (Ledger::pointer lpLedger, uint256 const& uHash) = 0;
virtual SLE::pointer getSLEi (Ledger::pointer lpLedger, uint256 const& uHash) = 0;
//--------------------------------------------------------------------------
//
// Transaction processing
//
// must complete immediately
// VFALCO TODO Make this a TxCallback structure
typedef std::function<void (Transaction::pointer, TER)> stCallback;
virtual void submitTransaction (Job&, SerializedTransaction::pointer,
stCallback callback = stCallback ()) = 0;
virtual Transaction::pointer submitTransactionSync (Transaction::ref tpTrans,
bool bAdmin, bool bLocal, bool bFailHard, bool bSubmit) = 0;
virtual void runTransactionQueue () = 0;
virtual Transaction::pointer processTransactionCb (Transaction::pointer,
bool bAdmin, bool bLocal, bool bFailHard, stCallback) = 0;
virtual Transaction::pointer processTransaction (Transaction::pointer transaction,
bool bAdmin, bool bLocal, bool bFailHard) = 0;
virtual Transaction::pointer findTransactionByID (uint256 const& transactionID) = 0;
virtual int findTransactionsByDestination (std::list<Transaction::pointer>&,
const RippleAddress& destinationAccount, std::uint32_t startLedgerSeq,
std::uint32_t endLedgerSeq, int maxTransactions) = 0;
//--------------------------------------------------------------------------
//
// Account functions
//
virtual AccountState::pointer getAccountState (Ledger::ref lrLedger,
const RippleAddress& accountID) = 0;
virtual SLE::pointer getGenerator (Ledger::ref lrLedger,
uint160 const& uGeneratorID) = 0;
//--------------------------------------------------------------------------
//
// Directory functions
//
virtual STVector256 getDirNodeInfo (Ledger::ref lrLedger,
uint256 const& uRootIndex, std::uint64_t& uNodePrevious,
std::uint64_t& uNodeNext) = 0;
//--------------------------------------------------------------------------
//
// Owner functions
//
virtual Json::Value getOwnerInfo (Ledger::pointer lpLedger,
const RippleAddress& naAccount) = 0;
//--------------------------------------------------------------------------
//
// Book functions
//
virtual void getBookPage (
Ledger::pointer lpLedger,
const uint160& uTakerPaysCurrencyID,
const uint160& uTakerPaysIssuerID,
const uint160& uTakerGetsCurrencyID,
const uint160& uTakerGetsIssuerID,
const uint160& uTakerID,
const bool bProof,
const unsigned int iLimit,
const Json::Value& jvMarker,
Json::Value& jvResult) = 0;
//--------------------------------------------------------------------------
// ledger proposal/close functions
virtual void processTrustedProposal (LedgerProposal::pointer proposal,
boost::shared_ptr<protocol::TMProposeSet> set, RippleAddress nodePublic,
uint256 checkLedger, bool sigGood) = 0;
virtual SHAMapAddNode gotTXData (const boost::shared_ptr<Peer>& peer,
uint256 const& hash, const std::list<SHAMapNode>& nodeIDs,
const std::list< Blob >& nodeData) = 0;
virtual bool recvValidation (SerializedValidation::ref val,
const std::string& source) = 0;
virtual void takePosition (int seq, SHAMap::ref position) = 0;
virtual SHAMap::pointer getTXMap (uint256 const& hash) = 0;
virtual bool hasTXSet (const boost::shared_ptr<Peer>& peer,
uint256 const& set, protocol::TxSetStatus status) = 0;
virtual void mapComplete (uint256 const& hash, SHAMap::ref map) = 0;
virtual bool stillNeedTXSet (uint256 const& hash) = 0;
// Fetch packs
virtual void makeFetchPack (Job&, boost::weak_ptr<Peer> peer,
boost::shared_ptr<protocol::TMGetObjectByHash> request,
Ledger::pointer wantLedger, Ledger::pointer haveLedger, std::uint32_t uUptime) = 0;
virtual bool shouldFetchPack (std::uint32_t seq) = 0;
virtual void gotFetchPack (bool progress, std::uint32_t seq) = 0;
virtual void addFetchPack (uint256 const& hash, boost::shared_ptr< Blob >& data) = 0;
virtual bool getFetchPack (uint256 const& hash, Blob& data) = 0;
virtual int getFetchSize () = 0;
virtual void sweepFetchPack () = 0;
// network state machine
virtual void endConsensus (bool correctLCL) = 0;
virtual void setStandAlone () = 0;
virtual void setStateTimer () = 0;
virtual void newLCL (int proposers, int convergeTime, uint256 const& ledgerHash) = 0;
// VFALCO TODO rename to setNeedNetworkLedger
virtual void needNetworkLedger () = 0;
virtual void clearNeedNetworkLedger () = 0;
virtual bool isNeedNetworkLedger () = 0;
virtual bool isFull () = 0;
virtual void setProposing (bool isProposing, bool isValidating) = 0;
virtual bool isProposing () = 0;
virtual bool isValidating () = 0;
virtual bool isFeatureBlocked () = 0;
virtual void setFeatureBlocked () = 0;
virtual void consensusViewChange () = 0;
virtual int getPreviousProposers () = 0;
virtual int getPreviousConvergeTime () = 0;
virtual std::uint32_t getLastCloseTime () = 0;
virtual void setLastCloseTime (std::uint32_t t) = 0;
virtual Json::Value getConsensusInfo () = 0;
virtual Json::Value getServerInfo (bool human, bool admin) = 0;
virtual void clearLedgerFetch () = 0;
virtual Json::Value getLedgerFetchInfo () = 0;
virtual std::uint32_t acceptLedger () = 0;
typedef boost::unordered_map <uint160, std::list<LedgerProposal::pointer> > Proposals;
virtual Proposals& peekStoredProposals () = 0;
virtual void storeProposal (LedgerProposal::ref proposal,
const RippleAddress& peerPublic) = 0;
virtual uint256 getConsensusLCL () = 0;
virtual void reportFeeChange () = 0;
virtual void updateLocalTx (Ledger::ref newValidLedger) = 0;
virtual void addLocalTx (Ledger::ref openLedger, SerializedTransaction::ref txn) = 0;
virtual std::size_t getLocalTxCount () = 0;
//Helper function to generate SQL query to get transactions
virtual std::string transactionsSQL (std::string selection,
const RippleAddress& account, std::int32_t minLedger, std::int32_t maxLedger,
bool descending, std::uint32_t offset, int limit, bool binary,
bool count, bool bAdmin) = 0;
// client information retrieval functions
typedef std::vector< std::pair<Transaction::pointer, TransactionMetaSet::pointer> > AccountTxs;
virtual AccountTxs getAccountTxs (const RippleAddress& account,
std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset,
int limit, bool bAdmin) = 0;
typedef std::vector< std::pair<Transaction::pointer, TransactionMetaSet::pointer> > TxsAccount;
virtual TxsAccount getTxsAccount (const RippleAddress& account,
std::int32_t minLedger, std::int32_t maxLedger, bool forward, Json::Value& token,
int limit, bool bAdmin) = 0;
typedef boost::tuple<std::string, std::string, std::uint32_t> txnMetaLedgerType;
typedef std::vector<txnMetaLedgerType> MetaTxsList;
virtual MetaTxsList getAccountTxsB (const RippleAddress& account,
std::int32_t minLedger, std::int32_t maxLedger, bool descending,
std::uint32_t offset, int limit, bool bAdmin) = 0;
virtual MetaTxsList getTxsAccountB (const RippleAddress& account,
std::int32_t minLedger, std::int32_t maxLedger, bool forward,
Json::Value& token, int limit, bool bAdmin) = 0;
virtual std::vector<RippleAddress> getLedgerAffectedAccounts (std::uint32_t ledgerSeq) = 0;
//--------------------------------------------------------------------------
//
// Monitoring: publisher side
//
virtual void pubLedger (Ledger::ref lpAccepted) = 0;
virtual void pubProposedTransaction (Ledger::ref lpCurrent,
SerializedTransaction::ref stTxn, TER terResult) = 0;
};
} // ripple
#endif