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 void
174  RCLCxPeerPos peerPos,
176 
177  virtual bool
178  recvValidation(STValidation::ref val, 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  isAmendmentBlocked() = 0;
205  virtual void
206  setAmendmentBlocked() = 0;
207  virtual bool
208  isAmendmentWarned() = 0;
209  virtual void
210  setAmendmentWarned() = 0;
211  virtual void
212  clearAmendmentWarned() = 0;
213  virtual void
214  consensusViewChange() = 0;
215 
216  virtual Json::Value
217  getConsensusInfo() = 0;
218  virtual Json::Value
219  getServerInfo(bool human, bool admin, bool counters) = 0;
220  virtual void
221  clearLedgerFetch() = 0;
222  virtual Json::Value
223  getLedgerFetchInfo() = 0;
224 
231  virtual std::uint32_t
232  acceptLedger(
233  boost::optional<std::chrono::milliseconds> consensusDelay =
234  boost::none) = 0;
235 
236  virtual uint256
237  getConsensusLCL() = 0;
238 
239  virtual void
240  reportFeeChange() = 0;
241 
242  virtual void
243  updateLocalTx(ReadView const& newValidLedger) = 0;
244  virtual std::size_t
245  getLocalTxCount() = 0;
246 
248  {
249  uint32_t ledgerSeq = 0;
250  uint32_t txnSeq = 0;
251  };
252 
253  // client information retrieval functions
256 
257  virtual AccountTxs
259  AccountID const& account,
260  std::int32_t minLedger,
261  std::int32_t maxLedger,
262  bool descending,
263  std::uint32_t offset,
264  int limit,
265  bool bUnlimited) = 0;
266 
267  virtual AccountTxs
269  AccountID const& account,
270  std::int32_t minLedger,
271  std::int32_t maxLedger,
272  bool forward,
274  int limit,
275  bool bUnlimited) = 0;
276 
279 
280  virtual MetaTxsList
282  AccountID const& account,
283  std::int32_t minLedger,
284  std::int32_t maxLedger,
285  bool descending,
286  std::uint32_t offset,
287  int limit,
288  bool bUnlimited) = 0;
289 
290  virtual MetaTxsList
292  AccountID const& account,
293  std::int32_t minLedger,
294  std::int32_t maxLedger,
295  bool forward,
297  int limit,
298  bool bUnlimited) = 0;
299 
300  //--------------------------------------------------------------------------
301  //
302  // Monitoring: publisher side
303  //
304  virtual void
305  pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) = 0;
306  virtual void
308  std::shared_ptr<ReadView const> const& lpCurrent,
309  std::shared_ptr<STTx const> const& stTxn,
310  TER terResult) = 0;
311  virtual void
313 };
314 
315 //------------------------------------------------------------------------------
316 
319  Application& app,
320  NetworkOPs::clock_type& clock,
321  bool standalone,
322  std::size_t minPeerCount,
323  bool start_valid,
324  JobQueue& job_queue,
325  LedgerMaster& ledgerMaster,
326  Stoppable& parent,
327  ValidatorKeys const& validatorKeys,
328  boost::asio::io_service& io_svc,
329  beast::Journal journal,
330  beast::insight::Collector::ptr const& collector);
331 
332 } // namespace ripple
333 
334 #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:94
ripple::NetworkOPs::AccountTxMarker::ledgerSeq
uint32_t ledgerSeq
Definition: NetworkOPs.h:249
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:42
ripple::NetworkOPs::getServerInfo
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
std::string
STL class.
std::shared_ptr
STL class.
ripple::NetworkOPs::recvValidation
virtual bool recvValidation(STValidation::ref val, std::string const &source)=0
ripple::NetworkOPs::FailHard::no
@ no
std::pair
ripple::NetworkOPs::consensusViewChange
virtual void consensusViewChange()=0
ripple::LedgerMaster
Definition: LedgerMaster.h:58
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
Definition: base_uint.h:63
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:3893
ripple::OperatingMode::DISCONNECTED
@ DISCONNECTED
not ready to process requests
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
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::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:62
ripple::set
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
Definition: BasicConfig.h:276
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::clearNeedNetworkLedger
virtual void clearNeedNetworkLedger()=0
ripple::NetworkOPs::getLocalTxCount
virtual std::size_t getLocalTxCount()=0
ripple::NetworkOPs::NetworkOPs
NetworkOPs(Stoppable &parent)
Definition: NetworkOPs.cpp:3846
ripple::NetworkOPs::FailHard
FailHard
Definition: NetworkOPs.h:96
ripple::NetworkOPs::AccountTxMarker
Definition: NetworkOPs.h:247
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
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:188
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
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::AccountTxMarker::txnSeq
uint32_t txnSeq
Definition: NetworkOPs.h:250
std::unique_ptr
STL class.
ripple::NetworkOPs::processTrustedProposal
virtual void processTrustedProposal(RCLCxPeerPos peerPos, std::shared_ptr< protocol::TMProposeSet > set)=0
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::pubValidation
virtual void pubValidation(STValidation::ref val)=0
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