rippled
NetworkOPs.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_APP_MISC_NETWORKOPS_H_INCLUDED
21 #define RIPPLE_APP_MISC_NETWORKOPS_H_INCLUDED
22 
23 #include <ripple/app/consensus/RCLCxPeerPos.h>
24 #include <ripple/app/ledger/Ledger.h>
25 #include <ripple/core/JobQueue.h>
26 #include <ripple/core/Stoppable.h>
27 #include <ripple/ledger/ReadView.h>
28 #include <ripple/net/InfoSub.h>
29 #include <ripple/protocol/STValidation.h>
30 #include <boost/asio.hpp>
31 #include <deque>
32 #include <memory>
33 #include <tuple>
34 
35 #include <ripple/protocol/messages.h>
36 
37 namespace ripple {
38 
39 // Operations that clients may wish to perform against the network
40 // Master operational handler, server sequencer, network tracker
41 
42 class Peer;
43 class LedgerMaster;
44 class Transaction;
45 class ValidatorKeys;
46 
47 // This is the primary interface into the "client" portion of the program.
48 // Code that wants to do normal operations on the network such as
49 // creating and monitoring accounts, creating transactions, and so on
50 // should use this interface. The RPC code will primarily be a light wrapper
51 // over this code.
52 //
53 // Eventually, it will check the node's operating mode (synched, unsynched,
54 // etectera) and defer to the correct means of processing. The current
55 // code assumes this node is synched (and will continue to do so until
56 // there's a functional network.
57 //
58 
68 enum class OperatingMode {
69  DISCONNECTED = 0,
70  CONNECTED = 1,
71  SYNCING = 2,
72  TRACKING = 3,
73  FULL = 4
74 };
75 
89 {
90 protected:
91  explicit NetworkOPs(Stoppable& parent);
92 
93 public:
95 
96  enum class FailHard : unsigned char { no, yes };
97  static inline FailHard
98  doFailHard(bool noMeansDont)
99  {
100  return noMeansDont ? FailHard::yes : FailHard::no;
101  }
102 
103 public:
104  ~NetworkOPs() override = default;
105 
106  //--------------------------------------------------------------------------
107  //
108  // Network information
109  //
110 
111  virtual OperatingMode
112  getOperatingMode() const = 0;
113  virtual std::string
114  strOperatingMode(OperatingMode const mode, bool const admin = false)
115  const = 0;
116  virtual std::string
117  strOperatingMode(bool const admin = false) const = 0;
118 
119  //--------------------------------------------------------------------------
120  //
121  // Transaction processing
122  //
123 
124  // must complete immediately
125  virtual void
127 
137  virtual void
139  std::shared_ptr<Transaction>& transaction,
140  bool bUnlimited,
141  bool bLocal,
142  FailHard failType) = 0;
143 
144  //--------------------------------------------------------------------------
145  //
146  // Owner functions
147  //
148 
149  virtual Json::Value
150  getOwnerInfo(
152  AccountID const& account) = 0;
153 
154  //--------------------------------------------------------------------------
155  //
156  // Book functions
157  //
158 
159  virtual void
160  getBookPage(
162  Book const& book,
163  AccountID const& uTakerID,
164  bool const bProof,
165  unsigned int iLimit,
166  Json::Value const& jvMarker,
167  Json::Value& jvResult) = 0;
168 
169  //--------------------------------------------------------------------------
170 
171  // ledger proposal/close functions
172  virtual bool
174 
175  virtual bool
178  std::string const& source) = 0;
179 
180  virtual void
181  mapComplete(std::shared_ptr<SHAMap> const& map, bool fromAcquire) = 0;
182 
183  // network state machine
184  virtual bool
185  beginConsensus(uint256 const& netLCL) = 0;
186  virtual void
187  endConsensus() = 0;
188  virtual void
189  setStandAlone() = 0;
190  virtual void
191  setStateTimer() = 0;
192 
193  virtual void
194  setNeedNetworkLedger() = 0;
195  virtual void
197  virtual bool
198  isNeedNetworkLedger() = 0;
199  virtual bool
200  isFull() = 0;
201  virtual void
202  setMode(OperatingMode om) = 0;
203  virtual bool
204  isBlocked() = 0;
205  virtual bool
206  isAmendmentBlocked() = 0;
207  virtual void
208  setAmendmentBlocked() = 0;
209  virtual bool
210  isAmendmentWarned() = 0;
211  virtual void
212  setAmendmentWarned() = 0;
213  virtual void
214  clearAmendmentWarned() = 0;
215  virtual bool
216  isUNLBlocked() = 0;
217  virtual void
218  setUNLBlocked() = 0;
219  virtual void
220  clearUNLBlocked() = 0;
221  virtual void
222  consensusViewChange() = 0;
223 
224  virtual Json::Value
225  getConsensusInfo() = 0;
226  virtual Json::Value
227  getServerInfo(bool human, bool admin, bool counters) = 0;
228  virtual void
229  clearLedgerFetch() = 0;
230  virtual Json::Value
231  getLedgerFetchInfo() = 0;
232 
239  virtual std::uint32_t
240  acceptLedger(
241  boost::optional<std::chrono::milliseconds> consensusDelay =
242  boost::none) = 0;
243 
244  virtual uint256
245  getConsensusLCL() = 0;
246 
247  virtual void
248  reportFeeChange() = 0;
249 
250  virtual void
251  updateLocalTx(ReadView const& newValidLedger) = 0;
252  virtual std::size_t
253  getLocalTxCount() = 0;
254 
256  {
257  uint32_t ledgerSeq = 0;
258  uint32_t txnSeq = 0;
259  };
260 
261  // client information retrieval functions
262  using AccountTx =
265 
266  virtual AccountTxs
268  AccountID const& account,
269  std::int32_t minLedger,
270  std::int32_t maxLedger,
271  bool descending,
272  std::uint32_t offset,
273  int limit,
274  bool bUnlimited) = 0;
275 
276  virtual AccountTxs
278  AccountID const& account,
279  std::int32_t minLedger,
280  std::int32_t maxLedger,
281  bool forward,
283  int limit,
284  bool bUnlimited) = 0;
285 
288 
289  virtual MetaTxsList
291  AccountID const& account,
292  std::int32_t minLedger,
293  std::int32_t maxLedger,
294  bool descending,
295  std::uint32_t offset,
296  int limit,
297  bool bUnlimited) = 0;
298 
299  virtual MetaTxsList
301  AccountID const& account,
302  std::int32_t minLedger,
303  std::int32_t maxLedger,
304  bool forward,
306  int limit,
307  bool bUnlimited) = 0;
308 
309  //--------------------------------------------------------------------------
310  //
311  // Monitoring: publisher side
312  //
313  virtual void
314  pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) = 0;
315  virtual void
317  std::shared_ptr<ReadView const> const& lpCurrent,
318  std::shared_ptr<STTx const> const& stTxn,
319  TER terResult) = 0;
320  virtual void
322 
323  virtual void
324  forwardProposedTransaction(Json::Value const& jvObj) = 0;
325  virtual void
327 };
328 
329 //------------------------------------------------------------------------------
330 
333  Application& app,
334  NetworkOPs::clock_type& clock,
335  bool standalone,
336  std::size_t minPeerCount,
337  bool start_valid,
338  JobQueue& job_queue,
339  LedgerMaster& ledgerMaster,
340  Stoppable& parent,
341  ValidatorKeys const& validatorKeys,
342  boost::asio::io_service& io_svc,
343  beast::Journal journal,
344  beast::insight::Collector::ptr const& collector);
345 
346 } // namespace ripple
347 
348 #endif
ripple::NetworkOPs::pubLedger
virtual void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted)=0
ripple::NetworkOPs
Provides server functionality for clients.
Definition: NetworkOPs.h:88
ripple::Application
Definition: Application.h:101
ripple::NetworkOPs::AccountTxMarker::ledgerSeq
uint32_t ledgerSeq
Definition: NetworkOPs.h:257
ripple::NetworkOPs::forwardProposedAccountTransaction
virtual void forwardProposedAccountTransaction(Json::Value const &jvObj)=0
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:42
ripple::NetworkOPs::recvValidation
virtual bool recvValidation(std::shared_ptr< STValidation > const &val, std::string const &source)=0
ripple::NetworkOPs::getServerInfo
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
ripple::NetworkOPs::isUNLBlocked
virtual bool isUNLBlocked()=0
std::string
STL class.
std::shared_ptr
STL class.
ripple::NetworkOPs::FailHard::no
@ no
std::pair
ripple::NetworkOPs::consensusViewChange
virtual void consensusViewChange()=0
ripple::LedgerMaster
Definition: LedgerMaster.h:72
std::vector
STL class.
ripple::NetworkOPs::pubProposedTransaction
virtual void pubProposedTransaction(std::shared_ptr< ReadView const > const &lpCurrent, std::shared_ptr< STTx const > const &stTxn, TER terResult)=0
ripple::NetworkOPs::setAmendmentBlocked
virtual void setAmendmentBlocked()=0
ripple::NetworkOPs::isAmendmentWarned
virtual bool isAmendmentWarned()=0
ripple::NetworkOPs::getOperatingMode
virtual OperatingMode getOperatingMode() const =0
tuple
ripple::NetworkOPs::~NetworkOPs
~NetworkOPs() override=default
ripple::NetworkOPs::isAmendmentBlocked
virtual bool isAmendmentBlocked()=0
ripple::NetworkOPs::mapComplete
virtual void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire)=0
ripple::ValidatorKeys
Validator keys and manifest as set in configuration file.
Definition: ValidatorKeys.h:36
ripple::NetworkOPs::clearLedgerFetch
virtual void clearLedgerFetch()=0
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::NetworkOPs::setStandAlone
virtual void setStandAlone()=0
ripple::base_uint< 160, detail::AccountIDTag >
ripple::make_NetworkOPs
std::unique_ptr< NetworkOPs > make_NetworkOPs(Application &app, NetworkOPs::clock_type &clock, bool standalone, std::size_t minPeerCount, bool startvalid, JobQueue &job_queue, LedgerMaster &ledgerMaster, Stoppable &parent, ValidatorKeys const &validatorKeys, boost::asio::io_service &io_svc, beast::Journal journal, beast::insight::Collector::ptr const &collector)
Definition: NetworkOPs.cpp:4145
ripple::NetworkOPs::clearUNLBlocked
virtual void clearUNLBlocked()=0
ripple::OperatingMode::DISCONNECTED
@ DISCONNECTED
not ready to process requests
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::NetworkOPs::isNeedNetworkLedger
virtual bool isNeedNetworkLedger()=0
ripple::NetworkOPs::submitTransaction
virtual void submitTransaction(std::shared_ptr< STTx const > const &)=0
ripple::OperatingMode::CONNECTED
@ CONNECTED
convinced we are talking to the network
ripple::NetworkOPs::getOwnerInfo
virtual Json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account)=0
ripple::NetworkOPs::setAmendmentWarned
virtual void setAmendmentWarned()=0
ripple::NetworkOPs::getConsensusLCL
virtual uint256 getConsensusLCL()=0
ripple::OperatingMode::TRACKING
@ TRACKING
convinced we agree with the network
ripple::NetworkOPs::updateLocalTx
virtual void updateLocalTx(ReadView const &newValidLedger)=0
ripple::NetworkOPs::getBookPage
virtual void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &book, AccountID const &uTakerID, bool const bProof, unsigned int iLimit, Json::Value const &jvMarker, Json::Value &jvResult)=0
ripple::TERSubset< CanCvtToTER >
ripple::NetworkOPs::reportFeeChange
virtual void reportFeeChange()=0
ripple::NetworkOPs::pubValidation
virtual void pubValidation(std::shared_ptr< STValidation > const &val)=0
ripple::NetworkOPs::processTransaction
virtual void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, FailHard failType)=0
Process transactions as they arrive from the network or which are submitted by clients.
ripple::InfoSub::Source
Abstracts the source of subscription data.
Definition: InfoSub.h:56
ripple::NetworkOPs::setStateTimer
virtual void setStateTimer()=0
ripple::NetworkOPs::getTxsAccount
virtual AccountTxs getTxsAccount(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool forward, std::optional< AccountTxMarker > &marker, int limit, bool bUnlimited)=0
ripple::NetworkOPs::getConsensusInfo
virtual Json::Value getConsensusInfo()=0
deque
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::NetworkOPs::setUNLBlocked
virtual void setUNLBlocked()=0
ripple::NetworkOPs::clearNeedNetworkLedger
virtual void clearNeedNetworkLedger()=0
ripple::NetworkOPs::getLocalTxCount
virtual std::size_t getLocalTxCount()=0
ripple::NetworkOPs::NetworkOPs
NetworkOPs(Stoppable &parent)
Definition: NetworkOPs.cpp:4098
ripple::NetworkOPs::FailHard
FailHard
Definition: NetworkOPs.h:96
ripple::NetworkOPs::AccountTxMarker
Definition: NetworkOPs.h:255
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::NetworkOPs::processTrustedProposal
virtual bool processTrustedProposal(RCLCxPeerPos peerPos)=0
ripple::NetworkOPs::getAccountTxs
virtual AccountTxs getAccountTxs(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset, int limit, bool bUnlimited)=0
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NetworkOPs::isBlocked
virtual bool isBlocked()=0
ripple::NetworkOPs::clearAmendmentWarned
virtual void clearAmendmentWarned()=0
ripple::NetworkOPs::isFull
virtual bool isFull()=0
ripple::NetworkOPs::strOperatingMode
virtual std::string strOperatingMode(OperatingMode const mode, bool const admin=false) const =0
ripple::OperatingMode
OperatingMode
Specifies the mode under which the server believes it's operating.
Definition: NetworkOPs.h:68
ripple::NetworkOPs::setNeedNetworkLedger
virtual void setNeedNetworkLedger()=0
ripple::NetworkOPs::setMode
virtual void setMode(OperatingMode om)=0
std::optional
ripple::NetworkOPs::FailHard::yes
@ yes
std::size_t
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::NetworkOPs::doFailHard
static FailHard doFailHard(bool noMeansDont)
Definition: NetworkOPs.h:98
ripple::NetworkOPs::acceptLedger
virtual std::uint32_t acceptLedger(boost::optional< std::chrono::milliseconds > consensusDelay=boost::none)=0
Accepts the current transaction tree, return the new ledger's sequence.
ripple::NetworkOPs::beginConsensus
virtual bool beginConsensus(uint256 const &netLCL)=0
ripple::NetworkOPs::forwardProposedTransaction
virtual void forwardProposedTransaction(Json::Value const &jvObj)=0
ripple::NetworkOPs::AccountTxMarker::txnSeq
uint32_t txnSeq
Definition: NetworkOPs.h:258
std::unique_ptr
STL class.
ripple::NetworkOPs::getTxsAccountB
virtual MetaTxsList getTxsAccountB(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool forward, std::optional< AccountTxMarker > &marker, int limit, bool bUnlimited)=0
ripple::NetworkOPs::getLedgerFetchInfo
virtual Json::Value getLedgerFetchInfo()=0
ripple::NetworkOPs::endConsensus
virtual void endConsensus()=0
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::NetworkOPs::getAccountTxsB
virtual MetaTxsList getAccountTxsB(AccountID const &account, std::int32_t minLedger, std::int32_t maxLedger, bool descending, std::uint32_t offset, int limit, bool bUnlimited)=0
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate