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/ledger/ReadView.h>
27 #include <ripple/net/InfoSub.h>
28 #include <ripple/protocol/STValidation.h>
29 #include <ripple/protocol/messages.h>
30 #include <boost/asio.hpp>
31 #include <deque>
32 #include <memory>
33 #include <tuple>
34 
35 namespace ripple {
36 
37 // Operations that clients may wish to perform against the network
38 // Master operational handler, server sequencer, network tracker
39 
40 class Peer;
41 class LedgerMaster;
42 class Transaction;
43 class ValidatorKeys;
44 
45 // This is the primary interface into the "client" portion of the program.
46 // Code that wants to do normal operations on the network such as
47 // creating and monitoring accounts, creating transactions, and so on
48 // should use this interface. The RPC code will primarily be a light wrapper
49 // over this code.
50 //
51 // Eventually, it will check the node's operating mode (synched, unsynched,
52 // etectera) and defer to the correct means of processing. The current
53 // code assumes this node is synched (and will continue to do so until
54 // there's a functional network.
55 //
56 
66 enum class OperatingMode {
67  DISCONNECTED = 0,
68  CONNECTED = 1,
69  SYNCING = 2,
70  TRACKING = 3,
71  FULL = 4
72 };
73 
74 namespace RPC {
75 enum class SubmitSync;
76 }
77 
91 {
92 public:
94 
95  enum class FailHard : unsigned char { no, yes };
96  static inline FailHard
97  doFailHard(bool noMeansDont)
98  {
99  return noMeansDont ? FailHard::yes : FailHard::no;
100  }
101 
102 public:
103  ~NetworkOPs() override = default;
104 
105  virtual void
106  stop() = 0;
107 
108  //--------------------------------------------------------------------------
109  //
110  // Network information
111  //
112 
113  virtual OperatingMode
114  getOperatingMode() const = 0;
115  virtual std::string
116  strOperatingMode(OperatingMode const mode, bool const admin = false)
117  const = 0;
118  virtual std::string
119  strOperatingMode(bool const admin = false) const = 0;
120 
121  //--------------------------------------------------------------------------
122  //
123  // Transaction processing
124  //
125 
126  // must complete immediately
127  virtual void
129 
147  virtual void
149  std::shared_ptr<Transaction>& transaction,
150  bool bUnlimited,
151  RPC::SubmitSync sync,
152  bool bLocal,
153  FailHard failType) = 0;
154 
168  virtual bool
169  transactionBatch(bool drain) = 0;
170 
171  //--------------------------------------------------------------------------
172  //
173  // Owner functions
174  //
175 
176  virtual Json::Value
177  getOwnerInfo(
179  AccountID const& account) = 0;
180 
181  //--------------------------------------------------------------------------
182  //
183  // Book functions
184  //
185 
186  virtual void
187  getBookPage(
189  Book const& book,
190  AccountID const& uTakerID,
191  bool const bProof,
192  unsigned int iLimit,
193  Json::Value const& jvMarker,
194  Json::Value& jvResult) = 0;
195 
196  //--------------------------------------------------------------------------
197 
198  // ledger proposal/close functions
199  virtual bool
201 
202  virtual bool
205  std::string const& source) = 0;
206 
207  virtual void
208  mapComplete(std::shared_ptr<SHAMap> const& map, bool fromAcquire) = 0;
209 
210  // network state machine
211  virtual bool
212  beginConsensus(uint256 const& netLCL) = 0;
213  virtual void
214  endConsensus() = 0;
215  virtual void
216  setStandAlone() = 0;
217  virtual void
218  setStateTimer() = 0;
219  virtual void
220  setBatchApplyTimer() = 0;
221 
222  virtual void
223  setNeedNetworkLedger() = 0;
224  virtual void
226  virtual bool
227  isNeedNetworkLedger() = 0;
228  virtual bool
229  isFull() = 0;
230  virtual void
231  setMode(OperatingMode om) = 0;
232  virtual bool
233  isBlocked() = 0;
234  virtual bool
235  isAmendmentBlocked() = 0;
236  virtual void
237  setAmendmentBlocked() = 0;
238  virtual bool
239  isAmendmentWarned() = 0;
240  virtual void
241  setAmendmentWarned() = 0;
242  virtual void
243  clearAmendmentWarned() = 0;
244  virtual bool
245  isUNLBlocked() = 0;
246  virtual void
247  setUNLBlocked() = 0;
248  virtual void
249  clearUNLBlocked() = 0;
250  virtual void
251  consensusViewChange() = 0;
252 
253  virtual Json::Value
254  getConsensusInfo() = 0;
255  virtual Json::Value
256  getServerInfo(bool human, bool admin, bool counters) = 0;
257  virtual void
258  clearLedgerFetch() = 0;
259  virtual Json::Value
260  getLedgerFetchInfo() = 0;
261 
268  virtual std::uint32_t
269  acceptLedger(
271  std::nullopt) = 0;
272 
273  virtual void
274  reportFeeChange() = 0;
275 
276  virtual void
277  updateLocalTx(ReadView const& newValidLedger) = 0;
278  virtual std::size_t
279  getLocalTxCount() = 0;
280 
281  //--------------------------------------------------------------------------
282  //
283  // Monitoring: publisher side
284  //
285  virtual void
286  pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) = 0;
287  virtual void
289  std::shared_ptr<ReadView const> const& ledger,
290  std::shared_ptr<STTx const> const& transaction,
291  TER result) = 0;
292  virtual void
294 
295  virtual void
296  forwardValidation(Json::Value const& jvObj) = 0;
297  virtual void
298  forwardManifest(Json::Value const& jvObj) = 0;
299  virtual void
300  forwardProposedTransaction(Json::Value const& jvObj) = 0;
301  virtual void
303 
304  virtual void
305  stateAccounting(Json::Value& obj) = 0;
306 };
307 
308 //------------------------------------------------------------------------------
309 
312  Application& app,
313  NetworkOPs::clock_type& clock,
314  bool standalone,
315  std::size_t minPeerCount,
316  bool start_valid,
317  JobQueue& job_queue,
318  LedgerMaster& ledgerMaster,
319  ValidatorKeys const& validatorKeys,
320  boost::asio::io_service& io_svc,
321  beast::Journal journal,
322  beast::insight::Collector::ptr const& collector);
323 
324 } // namespace ripple
325 
326 #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:90
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:44
ripple::NetworkOPs::recvValidation
virtual bool recvValidation(std::shared_ptr< STValidation > const &val, std::string const &source)=0
ripple::RPC::SubmitSync
SubmitSync
Possible values for defining synchronous behavior of the transaction submission API.
Definition: SubmitSync.h:36
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::forwardManifest
virtual void forwardManifest(Json::Value const &jvObj)=0
ripple::NetworkOPs::FailHard::no
@ no
ripple::NetworkOPs::consensusViewChange
virtual void consensusViewChange()=0
ripple::NetworkOPs::setAmendmentBlocked
virtual void setAmendmentBlocked()=0
ripple::NetworkOPs::isAmendmentWarned
virtual bool isAmendmentWarned()=0
ripple::NetworkOPs::processTransaction
virtual void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, RPC::SubmitSync sync, bool bLocal, FailHard failType)=0
Process a transaction.
ripple::NetworkOPs::getOperatingMode
virtual OperatingMode getOperatingMode() const =0
tuple
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, ValidatorKeys const &validatorKeys, boost::asio::io_service &io_svc, beast::Journal journal, beast::insight::Collector::ptr const &collector)
Definition: NetworkOPs.cpp:4719
ripple::NetworkOPs::~NetworkOPs
~NetworkOPs() override=default
ripple::NetworkOPs::isAmendmentBlocked
virtual bool isAmendmentBlocked()=0
ripple::NetworkOPs::pubProposedTransaction
virtual void pubProposedTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result)=0
ripple::NetworkOPs::mapComplete
virtual void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire)=0
ripple::NetworkOPs::stateAccounting
virtual void stateAccounting(Json::Value &obj)=0
ripple::NetworkOPs::setBatchApplyTimer
virtual void setBatchApplyTimer()=0
ripple::NetworkOPs::clearLedgerFetch
virtual void clearLedgerFetch()=0
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::NetworkOPs::setStandAlone
virtual void setStandAlone()=0
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::NetworkOPs::clearUNLBlocked
virtual void clearUNLBlocked()=0
ripple::OperatingMode::DISCONNECTED
@ DISCONNECTED
not ready to process requests
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::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::InfoSub::Source
Abstracts the source of subscription data.
Definition: InfoSub.h:67
ripple::NetworkOPs::setStateTimer
virtual void setStateTimer()=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::FailHard
FailHard
Definition: NetworkOPs.h:95
ripple::NetworkOPs::clock_type
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition: NetworkOPs.h:93
ripple::NetworkOPs::transactionBatch
virtual bool transactionBatch(bool drain)=0
Apply transactions in batches.
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::NetworkOPs::processTrustedProposal
virtual bool processTrustedProposal(RCLCxPeerPos peerPos)=0
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:54
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::acceptLedger
virtual std::uint32_t acceptLedger(std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)=0
Accepts the current transaction tree, return the new ledger's sequence.
ripple::NetworkOPs::stop
virtual void stop()=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:66
ripple::NetworkOPs::setNeedNetworkLedger
virtual void setNeedNetworkLedger()=0
ripple::NetworkOPs::setMode
virtual void setMode(OperatingMode om)=0
std::optional< std::chrono::milliseconds >
ripple::NetworkOPs::FailHard::yes
@ yes
std::size_t
ripple::Book
Specifies an order book.
Definition: Book.h:33
ripple::NetworkOPs::doFailHard
static FailHard doFailHard(bool noMeansDont)
Definition: NetworkOPs.h:97
ripple::NetworkOPs::beginConsensus
virtual bool beginConsensus(uint256 const &netLCL)=0
ripple::NetworkOPs::forwardProposedTransaction
virtual void forwardProposedTransaction(Json::Value const &jvObj)=0
std::unique_ptr
STL class.
ripple::NetworkOPs::getLedgerFetchInfo
virtual Json::Value getLedgerFetchInfo()=0
ripple::NetworkOPs::endConsensus
virtual void endConsensus()=0
ripple::NetworkOPs::forwardValidation
virtual void forwardValidation(Json::Value const &jvObj)=0
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate