rippled
Application.cpp
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 #include <ripple/app/consensus/RCLValidations.h>
21 #include <ripple/app/ledger/InboundLedgers.h>
22 #include <ripple/app/ledger/InboundTransactions.h>
23 #include <ripple/app/ledger/LedgerCleaner.h>
24 #include <ripple/app/ledger/LedgerMaster.h>
25 #include <ripple/app/ledger/LedgerReplayer.h>
26 #include <ripple/app/ledger/LedgerToJson.h>
27 #include <ripple/app/ledger/OpenLedger.h>
28 #include <ripple/app/ledger/OrderBookDB.h>
29 #include <ripple/app/ledger/PendingSaves.h>
30 #include <ripple/app/ledger/TransactionMaster.h>
31 #include <ripple/app/main/Application.h>
32 #include <ripple/app/main/BasicApp.h>
33 #include <ripple/app/main/DBInit.h>
34 #include <ripple/app/main/GRPCServer.h>
35 #include <ripple/app/main/LoadManager.h>
36 #include <ripple/app/main/NodeIdentity.h>
37 #include <ripple/app/main/NodeStoreScheduler.h>
38 #include <ripple/app/main/Tuning.h>
39 #include <ripple/app/misc/AmendmentTable.h>
40 #include <ripple/app/misc/HashRouter.h>
41 #include <ripple/app/misc/LoadFeeTrack.h>
42 #include <ripple/app/misc/NetworkOPs.h>
43 #include <ripple/app/misc/SHAMapStore.h>
44 #include <ripple/app/misc/TxQ.h>
45 #include <ripple/app/misc/ValidatorKeys.h>
46 #include <ripple/app/misc/ValidatorSite.h>
47 #include <ripple/app/paths/PathRequests.h>
48 #include <ripple/app/rdb/RelationalDBInterface_global.h>
49 #include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
50 #include <ripple/app/reporting/ReportingETL.h>
51 #include <ripple/app/tx/apply.h>
52 #include <ripple/basics/ByteUtilities.h>
53 #include <ripple/basics/PerfLog.h>
54 #include <ripple/basics/ResolverAsio.h>
55 #include <ripple/basics/safe_cast.h>
56 #include <ripple/beast/asio/io_latency_probe.h>
57 #include <ripple/beast/core/LexicalCast.h>
58 #include <ripple/core/DatabaseCon.h>
59 #include <ripple/json/json_reader.h>
60 #include <ripple/nodestore/DatabaseShard.h>
61 #include <ripple/nodestore/DummyScheduler.h>
62 #include <ripple/overlay/Cluster.h>
63 #include <ripple/overlay/PeerReservationTable.h>
64 #include <ripple/overlay/PeerSet.h>
65 #include <ripple/overlay/make_Overlay.h>
66 #include <ripple/protocol/BuildInfo.h>
67 #include <ripple/protocol/Feature.h>
68 #include <ripple/protocol/Protocol.h>
69 #include <ripple/protocol/STParsedJSON.h>
70 #include <ripple/resource/Fees.h>
71 #include <ripple/rpc/ShardArchiveHandler.h>
72 #include <ripple/rpc/impl/RPCHelpers.h>
73 #include <ripple/shamap/NodeFamily.h>
74 #include <ripple/shamap/ShardFamily.h>
75 
76 #include <boost/algorithm/string/predicate.hpp>
77 #include <boost/asio/steady_timer.hpp>
78 #include <boost/system/error_code.hpp>
79 
80 #include <date/date.h>
81 
82 #include <condition_variable>
83 #include <cstring>
84 #include <iostream>
85 #include <limits>
86 #include <mutex>
87 #include <optional>
88 #include <utility>
89 #include <variant>
90 
91 namespace ripple {
92 
93 // VFALCO TODO Move the function definitions into the class declaration
94 class ApplicationImp : public Application, public BasicApp
95 {
96 private:
98  {
99  private:
104 
105  public:
109  std::chrono::milliseconds interval,
110  boost::asio::io_service& ios)
111  : m_event(ev)
112  , m_journal(journal)
113  , m_probe(interval, ios)
114  , lastSample_{}
115  {
116  }
117 
118  void
120  {
121  m_probe.sample(std::ref(*this));
122  }
123 
124  template <class Duration>
125  void
126  operator()(Duration const& elapsed)
127  {
128  using namespace std::chrono;
129  auto const lastSample = ceil<milliseconds>(elapsed);
130 
131  lastSample_ = lastSample;
132 
133  if (lastSample >= 10ms)
134  m_event.notify(lastSample);
135  if (lastSample >= 500ms)
136  {
137  JLOG(m_journal.warn())
138  << "io_service latency = " << lastSample.count();
139  }
140  }
141 
143  get() const
144  {
145  return lastSample_.load();
146  }
147 
148  void
150  {
151  m_probe.cancel();
152  }
153 
154  void
156  {
158  }
159  };
160 
161 public:
165 
169 
170  // Required by the SHAMapStore
172 
180 
185 
187 
193  // VFALCO TODO Make OrderBookDB abstract
217  boost::asio::steady_timer sweepTimer_;
218  boost::asio::steady_timer entropyTimer_;
219 
223 
224  boost::asio::signal_set m_signals;
225 
227  mutable std::mutex mut_;
228  bool isTimeToStop = false;
229 
231 
233 
235 
238 
239  //--------------------------------------------------------------------------
240 
241  static std::size_t
243  {
244 #if RIPPLE_SINGLE_IO_SERVICE_THREAD
245  return 1;
246 #else
247  auto const cores = std::thread::hardware_concurrency();
248 
249  // Use a single thread when running on under-provisioned systems
250  // or if we are configured to use minimal resources.
251  if ((cores == 1) || ((config.NODE_SIZE == 0) && (cores == 2)))
252  return 1;
253 
254  // Otherwise, prefer two threads.
255  return 2;
256 #endif
257  }
258 
259  //--------------------------------------------------------------------------
260 
266  , config_(std::move(config))
267  , logs_(std::move(logs))
268  , timeKeeper_(std::move(timeKeeper))
269  , m_journal(logs_->journal("Application"))
270 
271  // PerfLog must be started before any other threads are launched.
272  , perfLog_(perf::make_PerfLog(
273  perf::setup_PerfLog(
274  config_->section("perf"),
275  config_->CONFIG_DIR),
276  logs_->journal("PerfLog"),
277  [this] { signalStop(); }))
278 
279  , m_txMaster(*this)
280 
282  config_->section(SECTION_INSIGHT),
283  logs_->journal("Collector")))
284 
285  , m_jobQueue(std::make_unique<JobQueue>(
286  m_collectorManager->group("jobq"),
287  logs_->journal("JobQueue"),
288  *logs_,
289  *perfLog_))
290 
292 
294  *this,
296  logs_->journal("SHAMapStore")))
297 
298  , accountIDCache_(128000)
299 
300  , m_tempNodeCache(
301  "NodeCache",
302  16384,
304  stopwatch(),
305  logs_->journal("TaggedCache"))
306 
309 
311  m_collectorManager->collector(),
312  logs_->journal("Resource")))
313 
314  , m_nodeStore(m_shaMapStore->makeNodeStore(4))
315 
317 
318  // The shard store is optional and make_ShardStore can return null.
319  , shardStore_(make_ShardStore(
320  *this,
322  4,
323  logs_->journal("ShardStore")))
324 
325  , m_orderBookDB(*this)
326 
327  , m_pathRequests(std::make_unique<PathRequests>(
328  *this,
329  logs_->journal("PathRequest"),
330  m_collectorManager->collector()))
331 
332  , m_ledgerMaster(std::make_unique<LedgerMaster>(
333  *this,
334  stopwatch(),
335  m_collectorManager->collector(),
336  logs_->journal("LedgerMaster")))
337 
338  , ledgerCleaner_(
339  make_LedgerCleaner(*this, logs_->journal("LedgerCleaner")))
340 
341  // VFALCO NOTE must come before NetworkOPs to prevent a crash due
342  // to dependencies in the destructor.
343  //
345  *this,
346  stopwatch(),
347  m_collectorManager->collector()))
348 
350  *this,
351  m_collectorManager->collector(),
352  [this](std::shared_ptr<SHAMap> const& set, bool fromAcquire) {
353  gotTXSet(set, fromAcquire);
354  }))
355 
356  , m_ledgerReplayer(std::make_unique<LedgerReplayer>(
357  *this,
359  make_PeerSetBuilder(*this)))
360 
362  "AcceptedLedger",
363  4,
365  stopwatch(),
366  logs_->journal("TaggedCache"))
367 
369  *this,
370  stopwatch(),
371  config_->standalone(),
372  config_->NETWORK_QUORUM,
373  config_->START_VALID,
374  *m_jobQueue,
377  get_io_service(),
378  logs_->journal("NetworkOPs"),
379  m_collectorManager->collector()))
380 
381  , cluster_(std::make_unique<Cluster>(logs_->journal("Overlay")))
382 
383  , peerReservations_(std::make_unique<PeerReservationTable>(
384  logs_->journal("PeerReservationTable")))
385 
387  std::make_unique<ManifestCache>(logs_->journal("ManifestCache")))
388 
390  std::make_unique<ManifestCache>(logs_->journal("ManifestCache")))
391 
392  , validators_(std::make_unique<ValidatorList>(
395  *timeKeeper_,
396  config_->legacy("database_path"),
397  logs_->journal("ValidatorList"),
398  config_->VALIDATION_QUORUM))
399 
400  , validatorSites_(std::make_unique<ValidatorSite>(*this))
401 
403  *this,
404  get_io_service(),
405  *m_jobQueue,
406  *m_networkOPs,
409 
410  , mFeeTrack(
411  std::make_unique<LoadFeeTrack>(logs_->journal("LoadManager")))
412 
413  , hashRouter_(std::make_unique<HashRouter>(
414  stopwatch(),
417 
418  , mValidations(
419  ValidationParms(),
420  stopwatch(),
421  *this,
422  logs_->journal("Validations"))
423 
424  , m_loadManager(make_LoadManager(*this, logs_->journal("LoadManager")))
425 
426  , txQ_(
427  std::make_unique<TxQ>(setup_TxQ(*config_), logs_->journal("TxQ")))
428 
430 
432 
434 
435  , checkSigs_(true)
436 
437  , m_resolver(
438  ResolverAsio::New(get_io_service(), logs_->journal("Resolver")))
439 
441  m_collectorManager->collector()->make_event("ios_latency"),
442  logs_->journal("Application"),
444  get_io_service())
445  , grpcServer_(std::make_unique<GRPCServer>(*this))
446  , reportingETL_(
447  config_->reporting() ? std::make_unique<ReportingETL>(*this)
448  : nullptr)
449  {
450  add(m_resourceManager.get());
451 
452  //
453  // VFALCO - READ THIS!
454  //
455  // Do not start threads, open sockets, or do any sort of "real work"
456  // inside the constructor. Put it in start instead. Or if you must,
457  // put it in setup (but everything in setup should be moved to start
458  // anyway.
459  //
460  // The reason is that the unit tests require an Application object to
461  // be created. But we don't actually start all the threads, sockets,
462  // and services when running the unit tests. Therefore anything which
463  // needs to be stopped will not get stopped correctly if it is
464  // started in this constructor.
465  //
466 
467  add(ledgerCleaner_.get());
468  }
469 
470  //--------------------------------------------------------------------------
471 
472  bool
473  setup() override;
474  void
475  start(bool withTimers) override;
476  void
477  run() override;
478  void
479  signalStop() override;
480  bool
481  checkSigs() const override;
482  void
483  checkSigs(bool) override;
484  bool
485  isStopping() const override;
486  int
487  fdRequired() const override;
488 
489  //--------------------------------------------------------------------------
490 
491  Logs&
492  logs() override
493  {
494  return *logs_;
495  }
496 
497  Config&
498  config() override
499  {
500  return *config_;
501  }
502 
505  {
506  return *m_collectorManager;
507  }
508 
509  Family&
510  getNodeFamily() override
511  {
512  return nodeFamily_;
513  }
514 
515  // The shard store is an optional feature. If the sever is configured for
516  // shards, this function will return a valid pointer, otherwise a nullptr.
517  Family*
518  getShardFamily() override
519  {
520  return shardFamily_.get();
521  }
522 
523  TimeKeeper&
524  timeKeeper() override
525  {
526  return *timeKeeper_;
527  }
528 
529  JobQueue&
530  getJobQueue() override
531  {
532  return *m_jobQueue;
533  }
534 
536  nodeIdentity() override
537  {
538  return nodeIdentity_;
539  }
540 
541  PublicKey const&
542  getValidationPublicKey() const override
543  {
544  return validatorKeys_.publicKey;
545  }
546 
547  NetworkOPs&
548  getOPs() override
549  {
550  return *m_networkOPs;
551  }
552 
553  boost::asio::io_service&
554  getIOService() override
555  {
556  return get_io_service();
557  }
558 
560  getIOLatency() override
561  {
562  return m_io_latency_sampler.get();
563  }
564 
565  LedgerMaster&
566  getLedgerMaster() override
567  {
568  return *m_ledgerMaster;
569  }
570 
572  getLedgerCleaner() override
573  {
574  return *ledgerCleaner_;
575  }
576 
578  getLedgerReplayer() override
579  {
580  return *m_ledgerReplayer;
581  }
582 
584  getInboundLedgers() override
585  {
586  return *m_inboundLedgers;
587  }
588 
591  {
592  return *m_inboundTransactions;
593  }
594 
597  {
598  return m_acceptedLedgerCache;
599  }
600 
601  void
602  gotTXSet(std::shared_ptr<SHAMap> const& set, bool fromAcquire)
603  {
604  if (set)
605  m_networkOPs->mapComplete(set, fromAcquire);
606  }
607 
610  {
611  return m_txMaster;
612  }
613 
615  getPerfLog() override
616  {
617  return *perfLog_;
618  }
619 
620  NodeCache&
621  getTempNodeCache() override
622  {
623  return m_tempNodeCache;
624  }
625 
627  getNodeStore() override
628  {
629  return *m_nodeStore;
630  }
631 
632  // The shard store is an optional feature. If the sever is configured for
633  // shards, this function will return a valid pointer, otherwise a nullptr.
635  getShardStore() override
636  {
637  return shardStore_.get();
638  }
639 
641  getShardArchiveHandler(bool tryRecovery) override
642  {
643  static std::mutex handlerMutex;
644  std::lock_guard lock(handlerMutex);
645 
646  // After constructing the handler, try to
647  // initialize it. Log on error; set the
648  // member variable on success.
649  auto initAndSet =
651  if (!handler)
652  return false;
653 
654  if (!handler->init())
655  {
656  JLOG(m_journal.error())
657  << "Failed to initialize ShardArchiveHandler.";
658 
659  return false;
660  }
661 
662  shardArchiveHandler_ = std::move(handler);
663  return true;
664  };
665 
666  // Need to resume based on state from a previous
667  // run.
668  if (tryRecovery)
669  {
670  if (shardArchiveHandler_ != nullptr)
671  {
672  JLOG(m_journal.error())
673  << "ShardArchiveHandler already created at startup.";
674 
675  return nullptr;
676  }
677 
678  auto handler =
680 
681  if (!initAndSet(std::move(handler)))
682  return nullptr;
683  }
684 
685  // Construct the ShardArchiveHandler
686  if (shardArchiveHandler_ == nullptr)
687  {
688  auto handler =
690 
691  if (!initAndSet(std::move(handler)))
692  return nullptr;
693  }
694 
695  return shardArchiveHandler_.get();
696  }
697 
699  getMasterMutex() override
700  {
701  return m_masterMutex;
702  }
703 
704  LoadManager&
705  getLoadManager() override
706  {
707  return *m_loadManager;
708  }
709 
712  {
713  return *m_resourceManager;
714  }
715 
716  OrderBookDB&
717  getOrderBookDB() override
718  {
719  return m_orderBookDB;
720  }
721 
722  PathRequests&
723  getPathRequests() override
724  {
725  return *m_pathRequests;
726  }
727 
728  CachedSLEs&
729  cachedSLEs() override
730  {
731  return cachedSLEs_;
732  }
733 
735  getAmendmentTable() override
736  {
737  return *m_amendmentTable;
738  }
739 
740  LoadFeeTrack&
741  getFeeTrack() override
742  {
743  return *mFeeTrack;
744  }
745 
746  HashRouter&
747  getHashRouter() override
748  {
749  return *hashRouter_;
750  }
751 
753  getValidations() override
754  {
755  return mValidations;
756  }
757 
759  validators() override
760  {
761  return *validators_;
762  }
763 
765  validatorSites() override
766  {
767  return *validatorSites_;
768  }
769 
772  {
773  return *validatorManifests_;
774  }
775 
778  {
779  return *publisherManifests_;
780  }
781 
782  Cluster&
783  cluster() override
784  {
785  return *cluster_;
786  }
787 
789  peerReservations() override
790  {
791  return *peerReservations_;
792  }
793 
794  SHAMapStore&
795  getSHAMapStore() override
796  {
797  return *m_shaMapStore;
798  }
799 
800  PendingSaves&
801  pendingSaves() override
802  {
803  return pendingSaves_;
804  }
805 
806  AccountIDCache const&
807  accountIDCache() const override
808  {
809  return accountIDCache_;
810  }
811 
812  OpenLedger&
813  openLedger() override
814  {
815  if (config_->reporting())
816  Throw<ReportingShouldProxy>();
817  return *openLedger_;
818  }
819 
820  OpenLedger const&
821  openLedger() const override
822  {
823  if (config_->reporting())
824  Throw<ReportingShouldProxy>();
825  return *openLedger_;
826  }
827 
828  Overlay&
829  overlay() override
830  {
831  assert(overlay_);
832  return *overlay_;
833  }
834 
835  TxQ&
836  getTxQ() override
837  {
838  assert(txQ_.get() != nullptr);
839  return *txQ_;
840  }
841 
844  {
845  assert(mRelationalDBInterface.get() != nullptr);
846  return *mRelationalDBInterface;
847  }
848 
849  DatabaseCon&
850  getWalletDB() override
851  {
852  assert(mWalletDB.get() != nullptr);
853  return *mWalletDB;
854  }
855 
856  ReportingETL&
857  getReportingETL() override
858  {
859  assert(reportingETL_.get() != nullptr);
860  return *reportingETL_;
861  }
862 
863  bool
864  serverOkay(std::string& reason) override;
865 
867  journal(std::string const& name) override;
868 
869  //--------------------------------------------------------------------------
870 
871  bool
873  {
874  assert(mWalletDB.get() == nullptr);
875 
876  try
877  {
880 
881  // wallet database
883  setup.useGlobalPragma = false;
884 
886  }
887  catch (std::exception const& e)
888  {
889  JLOG(m_journal.fatal())
890  << "Failed to initialize SQL databases: " << e.what();
891  return false;
892  }
893 
894  return true;
895  }
896 
897  bool
899  {
900  if (config_->doImport)
901  {
902  auto j = logs_->journal("NodeObject");
903  NodeStore::DummyScheduler dummyScheduler;
906  megabytes(config_->getValueFor(
907  SizedItem::burstSize, std::nullopt)),
908  dummyScheduler,
909  0,
911  j);
912 
913  JLOG(j.warn()) << "Starting node import from '" << source->getName()
914  << "' to '" << m_nodeStore->getName() << "'.";
915 
916  using namespace std::chrono;
917  auto const start = steady_clock::now();
918 
919  m_nodeStore->importDatabase(*source);
920 
921  auto const elapsed =
922  duration_cast<seconds>(steady_clock::now() - start);
923  JLOG(j.warn()) << "Node import from '" << source->getName()
924  << "' took " << elapsed.count() << " seconds.";
925  }
926 
927  // tune caches
928  using namespace std::chrono;
929 
930  m_ledgerMaster->tune(
931  config_->getValueFor(SizedItem::ledgerSize),
932  seconds{config_->getValueFor(SizedItem::ledgerAge)});
933 
934  return true;
935  }
936 
937  //--------------------------------------------------------------------------
938 
939  // Called to indicate shutdown.
940  void
942  {
943  JLOG(m_journal.debug()) << "Application stopping";
944 
946 
947  // VFALCO Enormous hack, we have to force the probe to cancel
948  // before we stop the io_service queue or else it never
949  // unblocks in its destructor. The fix is to make all
950  // io_objects gracefully handle exit so that we can
951  // naturally return from io_service::run() instead of
952  // forcing a call to io_service::stop()
954 
955  m_resolver->stop_async();
956 
957  // NIKB This is a hack - we need to wait for the resolver to
958  // stop. before we stop the io_server_queue or weird
959  // things will happen.
960  m_resolver->stop();
961 
962  {
963  boost::system::error_code ec;
964  sweepTimer_.cancel(ec);
965  if (ec)
966  {
967  JLOG(m_journal.error())
968  << "Application: sweepTimer cancel error: " << ec.message();
969  }
970 
971  ec.clear();
972  entropyTimer_.cancel(ec);
973  if (ec)
974  {
975  JLOG(m_journal.error())
976  << "Application: entropyTimer cancel error: "
977  << ec.message();
978  }
979  }
980  // Make sure that any waitHandlers pending in our timers are done
981  // before we declare ourselves stopped.
982  using namespace std::chrono_literals;
983  waitHandlerCounter_.join("Application", 1s, m_journal);
984 
986 
987  validatorSites_->stop();
988 
989  // TODO Store manifests in manifests.sqlite instead of wallet.db
990  validatorManifests_->save(
991  getWalletDB(),
992  "ValidatorManifests",
993  [this](PublicKey const& pubKey) {
994  return validators().listed(pubKey);
995  });
996 
997  publisherManifests_->save(
998  getWalletDB(),
999  "PublisherManifests",
1000  [this](PublicKey const& pubKey) {
1001  return validators().trustedPublisher(pubKey);
1002  });
1003 
1004  // The order of these stop calls is delicate.
1005  // Re-ordering them risks undefined behavior.
1006  m_loadManager->stop();
1007  m_shaMapStore->stop();
1008  m_jobQueue->stop();
1010  shardArchiveHandler_->stop();
1011  if (overlay_)
1012  overlay_->stop();
1013  if (shardStore_)
1014  shardStore_->stop();
1015  grpcServer_->stop();
1016  m_networkOPs->stop();
1017  serverHandler_->stop();
1018  m_ledgerReplayer->stop();
1019  m_inboundTransactions->stop();
1020  m_inboundLedgers->stop();
1021  ledgerCleaner_->stop();
1022  if (reportingETL_)
1023  reportingETL_->stop();
1024  if (auto pg = dynamic_cast<RelationalDBInterfacePostgres*>(
1026  pg->stop();
1027  m_nodeStore->stop();
1028  perfLog_->stop();
1029  }
1030 
1031  //--------------------------------------------------------------------------
1032  //
1033  // PropertyStream
1034  //
1035 
1036  void
1038  {
1039  }
1040 
1041  //--------------------------------------------------------------------------
1042 
1043  void
1045  {
1046  // Only start the timer if waitHandlerCounter_ is not yet joined.
1047  if (auto optionalCountedHandler = waitHandlerCounter_.wrap(
1048  [this](boost::system::error_code const& e) {
1049  if (e.value() == boost::system::errc::success)
1050  {
1051  m_jobQueue->addJob(
1052  jtSWEEP, "sweep", [this](Job&) { doSweep(); });
1053  }
1054  // Recover as best we can if an unexpected error occurs.
1055  if (e.value() != boost::system::errc::success &&
1056  e.value() != boost::asio::error::operation_aborted)
1057  {
1058  // Try again later and hope for the best.
1059  JLOG(m_journal.error())
1060  << "Sweep timer got error '" << e.message()
1061  << "'. Restarting timer.";
1062  setSweepTimer();
1063  }
1064  }))
1065  {
1066  using namespace std::chrono;
1067  sweepTimer_.expires_from_now(
1068  seconds{config_->getValueFor(SizedItem::sweepInterval)});
1069  sweepTimer_.async_wait(std::move(*optionalCountedHandler));
1070  }
1071  }
1072 
1073  void
1075  {
1076  // Only start the timer if waitHandlerCounter_ is not yet joined.
1077  if (auto optionalCountedHandler = waitHandlerCounter_.wrap(
1078  [this](boost::system::error_code const& e) {
1079  if (e.value() == boost::system::errc::success)
1080  {
1081  crypto_prng().mix_entropy();
1082  setEntropyTimer();
1083  }
1084  // Recover as best we can if an unexpected error occurs.
1085  if (e.value() != boost::system::errc::success &&
1086  e.value() != boost::asio::error::operation_aborted)
1087  {
1088  // Try again later and hope for the best.
1089  JLOG(m_journal.error())
1090  << "Entropy timer got error '" << e.message()
1091  << "'. Restarting timer.";
1092  setEntropyTimer();
1093  }
1094  }))
1095  {
1096  using namespace std::chrono_literals;
1097  entropyTimer_.expires_from_now(5min);
1098  entropyTimer_.async_wait(std::move(*optionalCountedHandler));
1099  }
1100  }
1101 
1102  void
1104  {
1105  if (!config_->standalone() &&
1106  !getRelationalDBInterface().transactionDbHasSpace(*config_))
1107  {
1108  signalStop();
1109  }
1110 
1111  // VFALCO NOTE Does the order of calls matter?
1112  // VFALCO TODO fix the dependency inversion using an observer,
1113  // have listeners register for "onSweep ()" notification.
1114 
1115  nodeFamily_.sweep();
1116  if (shardFamily_)
1117  shardFamily_->sweep();
1119  getNodeStore().sweep();
1120  if (shardStore_)
1121  shardStore_->sweep();
1122  getLedgerMaster().sweep();
1123  getTempNodeCache().sweep();
1124  getValidations().expire();
1127  m_acceptedLedgerCache.sweep();
1128  cachedSLEs_.expire();
1129 
1130 #ifdef RIPPLED_REPORTING
1131  if (auto pg = dynamic_cast<RelationalDBInterfacePostgres*>(
1133  pg->sweep();
1134 #endif
1135 
1136  // Set timer to do another sweep later.
1137  setSweepTimer();
1138  }
1139 
1140  LedgerIndex
1142  {
1143  return maxDisallowedLedger_;
1144  }
1145 
1146 private:
1147  // For a newly-started validator, this is the greatest persisted ledger
1148  // and new validations must be greater than this.
1150 
1151  bool
1152  nodeToShards();
1153 
1154  void
1156 
1159 
1161  loadLedgerFromFile(std::string const& ledgerID);
1162 
1163  bool
1164  loadOldLedger(std::string const& ledgerID, bool replay, bool isFilename);
1165 
1166  void
1168 };
1169 
1170 //------------------------------------------------------------------------------
1171 
1172 // TODO Break this up into smaller, more digestible initialization segments.
1173 bool
1175 {
1176  // We want to intercept CTRL-C and the standard termination signal SIGTERM
1177  // and terminate the process. This handler will NEVER be invoked twice.
1178  //
1179  // Note that async_wait is "one-shot": for each call, the handler will be
1180  // invoked exactly once, either when one of the registered signals in the
1181  // signal set occurs or the signal set is cancelled. Subsequent signals are
1182  // effectively ignored (technically, they are queued up, waiting for a call
1183  // to async_wait).
1184  m_signals.add(SIGINT);
1185  m_signals.add(SIGTERM);
1186  m_signals.async_wait(
1187  [this](boost::system::error_code const& ec, int signum) {
1188  // Indicates the signal handler has been aborted; do nothing
1189  if (ec == boost::asio::error::operation_aborted)
1190  return;
1191 
1192  JLOG(m_journal.info()) << "Received signal " << signum;
1193 
1194  if (signum == SIGTERM || signum == SIGINT)
1195  signalStop();
1196  });
1197 
1198  auto debug_log = config_->getDebugLogFile();
1199 
1200  if (!debug_log.empty())
1201  {
1202  // Let debug messages go to the file but only WARNING or higher to
1203  // regular output (unless verbose)
1204 
1205  if (!logs_->open(debug_log))
1206  std::cerr << "Can't open log file " << debug_log << '\n';
1207 
1208  using namespace beast::severities;
1209  if (logs_->threshold() > kDebug)
1210  logs_->threshold(kDebug);
1211  }
1212  JLOG(m_journal.info()) << "process starting: "
1214 
1215  if (numberOfThreads(*config_) < 2)
1216  {
1217  JLOG(m_journal.warn()) << "Limited to a single I/O service thread by "
1218  "system configuration.";
1219  }
1220 
1221  // Optionally turn off logging to console.
1222  logs_->silent(config_->silent());
1223 
1224  m_jobQueue->setThreadCount(
1225  config_->WORKERS, config_->standalone() && !config_->reporting());
1226 
1227  if (!config_->standalone())
1228  timeKeeper_->run(config_->SNTP_SERVERS);
1229 
1230  if (!initRDBMS() || !initNodeStore())
1231  return false;
1232 
1233  if (shardStore_)
1234  {
1235  shardFamily_ =
1236  std::make_unique<ShardFamily>(*this, *m_collectorManager);
1237 
1238  if (!shardStore_->init())
1239  return false;
1240  }
1241 
1242  if (!peerReservations_->load(getWalletDB()))
1243  {
1244  JLOG(m_journal.fatal()) << "Cannot find peer reservations!";
1245  return false;
1246  }
1247 
1250 
1251  // Configure the amendments the server supports
1252  {
1253  auto const supported = []() {
1254  auto const& amendments = detail::supportedAmendments();
1256  supported.reserve(amendments.size());
1257  for (auto const& [a, vote] : amendments)
1258  {
1259  auto const f = ripple::getRegisteredFeature(a);
1260  assert(f);
1261  if (f)
1262  supported.emplace_back(a, *f, vote);
1263  }
1264  return supported;
1265  }();
1266  Section const& downVoted = config_->section(SECTION_VETO_AMENDMENTS);
1267 
1268  Section const& upVoted = config_->section(SECTION_AMENDMENTS);
1269 
1271  *this,
1272  config().AMENDMENT_MAJORITY_TIME,
1273  supported,
1274  upVoted,
1275  downVoted,
1276  logs_->journal("Amendments"));
1277  }
1278 
1280 
1281  auto const startUp = config_->START_UP;
1282  if (!config_->reporting())
1283  {
1284  if (startUp == Config::FRESH)
1285  {
1286  JLOG(m_journal.info()) << "Starting new Ledger";
1287 
1289  }
1290  else if (
1291  startUp == Config::LOAD || startUp == Config::LOAD_FILE ||
1292  startUp == Config::REPLAY)
1293  {
1294  JLOG(m_journal.info()) << "Loading specified Ledger";
1295 
1296  if (!loadOldLedger(
1297  config_->START_LEDGER,
1298  startUp == Config::REPLAY,
1299  startUp == Config::LOAD_FILE))
1300  {
1301  JLOG(m_journal.error())
1302  << "The specified ledger could not be loaded.";
1303  return false;
1304  }
1305  }
1306  else if (startUp == Config::NETWORK)
1307  {
1308  // This should probably become the default once we have a stable
1309  // network.
1310  if (!config_->standalone())
1311  m_networkOPs->setNeedNetworkLedger();
1312 
1314  }
1315  else
1316  {
1318  }
1319  }
1320 
1321  if (!config().reporting())
1322  m_orderBookDB.setup(getLedgerMaster().getCurrentLedger());
1323 
1324  nodeIdentity_ = getNodeIdentity(*this);
1325 
1326  if (!cluster_->load(config().section(SECTION_CLUSTER_NODES)))
1327  {
1328  JLOG(m_journal.fatal()) << "Invalid entry in cluster configuration.";
1329  return false;
1330  }
1331 
1332  if (!config().reporting())
1333  {
1334  {
1336  return false;
1337 
1338  if (!validatorManifests_->load(
1339  getWalletDB(),
1340  "ValidatorManifests",
1342  config()
1343  .section(SECTION_VALIDATOR_KEY_REVOCATION)
1344  .values()))
1345  {
1346  JLOG(m_journal.fatal())
1347  << "Invalid configured validator manifest.";
1348  return false;
1349  }
1350 
1351  publisherManifests_->load(getWalletDB(), "PublisherManifests");
1352 
1353  // Setup trusted validators
1354  if (!validators_->load(
1356  config().section(SECTION_VALIDATORS).values(),
1357  config().section(SECTION_VALIDATOR_LIST_KEYS).values()))
1358  {
1359  JLOG(m_journal.fatal())
1360  << "Invalid entry in validator configuration.";
1361  return false;
1362  }
1363  }
1364 
1365  if (!validatorSites_->load(
1366  config().section(SECTION_VALIDATOR_LIST_SITES).values()))
1367  {
1368  JLOG(m_journal.fatal())
1369  << "Invalid entry in [" << SECTION_VALIDATOR_LIST_SITES << "]";
1370  return false;
1371  }
1372  }
1373  //----------------------------------------------------------------------
1374  //
1375  // Server
1376  //
1377  //----------------------------------------------------------------------
1378 
1379  // VFALCO NOTE Unfortunately, in stand-alone mode some code still
1380  // foolishly calls overlay(). When this is fixed we can
1381  // move the instantiation inside a conditional:
1382  //
1383  // if (!config_.standalone())
1384  if (!config_->reporting())
1385  {
1387  *this,
1389  *serverHandler_,
1391  *m_resolver,
1392  get_io_service(),
1393  *config_,
1394  m_collectorManager->collector());
1395  add(*overlay_); // add to PropertyStream
1396  }
1397 
1398  if (!config_->standalone())
1399  {
1400  // NodeStore import into the ShardStore requires the SQLite database
1401  if (config_->nodeToShard && !nodeToShards())
1402  return false;
1403  }
1404 
1405  // start first consensus round
1406  if (!config_->reporting() &&
1407  !m_networkOPs->beginConsensus(
1408  m_ledgerMaster->getClosedLedger()->info().hash))
1409  {
1410  JLOG(m_journal.fatal()) << "Unable to start consensus";
1411  return false;
1412  }
1413 
1414  {
1415  try
1416  {
1417  auto setup = setup_ServerHandler(
1419  setup.makeContexts();
1420  serverHandler_->setup(setup, m_journal);
1421  }
1422  catch (std::exception const& e)
1423  {
1424  if (auto stream = m_journal.fatal())
1425  {
1426  stream << "Unable to setup server handler";
1427  if (std::strlen(e.what()) > 0)
1428  stream << ": " << e.what();
1429  }
1430  return false;
1431  }
1432  }
1433 
1434  // Begin connecting to network.
1435  if (!config_->standalone())
1436  {
1437  // Should this message be here, conceptually? In theory this sort
1438  // of message, if displayed, should be displayed from PeerFinder.
1439  if (config_->PEER_PRIVATE && config_->IPS_FIXED.empty())
1440  {
1441  JLOG(m_journal.warn())
1442  << "No outbound peer connections will be made";
1443  }
1444 
1445  // VFALCO NOTE the state timer resets the deadlock detector.
1446  //
1447  m_networkOPs->setStateTimer();
1448  }
1449  else
1450  {
1451  JLOG(m_journal.warn()) << "Running in standalone mode";
1452 
1453  m_networkOPs->setStandAlone();
1454  }
1455 
1456  if (config_->canSign())
1457  {
1458  JLOG(m_journal.warn()) << "*** The server is configured to allow the "
1459  "'sign' and 'sign_for'";
1460  JLOG(m_journal.warn()) << "*** commands. These commands have security "
1461  "implications and have";
1462  JLOG(m_journal.warn()) << "*** been deprecated. They will be removed "
1463  "in a future release of";
1464  JLOG(m_journal.warn()) << "*** rippled.";
1465  JLOG(m_journal.warn()) << "*** If you do not use them to sign "
1466  "transactions please edit your";
1467  JLOG(m_journal.warn())
1468  << "*** configuration file and remove the [enable_signing] stanza.";
1469  JLOG(m_journal.warn()) << "*** If you do use them to sign transactions "
1470  "please migrate to a";
1471  JLOG(m_journal.warn())
1472  << "*** standalone signing solution as soon as possible.";
1473  }
1474 
1475  //
1476  // Execute start up rpc commands.
1477  //
1478  for (auto cmd : config_->section(SECTION_RPC_STARTUP).lines())
1479  {
1480  Json::Reader jrReader;
1481  Json::Value jvCommand;
1482 
1483  if (!jrReader.parse(cmd, jvCommand))
1484  {
1485  JLOG(m_journal.fatal()) << "Couldn't parse entry in ["
1486  << SECTION_RPC_STARTUP << "]: '" << cmd;
1487  }
1488 
1489  if (!config_->quiet())
1490  {
1491  JLOG(m_journal.fatal())
1492  << "Startup RPC: " << jvCommand << std::endl;
1493  }
1494 
1497  RPC::JsonContext context{
1498  {journal("RPCHandler"),
1499  *this,
1500  loadType,
1501  getOPs(),
1502  getLedgerMaster(),
1503  c,
1504  Role::ADMIN,
1505  {},
1506  {},
1508  jvCommand};
1509 
1510  Json::Value jvResult;
1511  RPC::doCommand(context, jvResult);
1512 
1513  if (!config_->quiet())
1514  {
1515  JLOG(m_journal.fatal()) << "Result: " << jvResult << std::endl;
1516  }
1517  }
1518 
1519  RPC::ShardArchiveHandler* shardArchiveHandler = nullptr;
1520  if (shardStore_)
1521  {
1522  try
1523  {
1524  // Create a ShardArchiveHandler if recovery
1525  // is needed (there's a state database left
1526  // over from a previous run).
1527  auto handler = getShardArchiveHandler(true);
1528 
1529  // Recovery is needed.
1530  if (handler)
1531  shardArchiveHandler = handler;
1532  }
1533  catch (std::exception const& e)
1534  {
1535  JLOG(m_journal.fatal())
1536  << "Exception when starting ShardArchiveHandler from "
1537  "state database: "
1538  << e.what();
1539 
1540  return false;
1541  }
1542  }
1543 
1544  if (shardArchiveHandler && !shardArchiveHandler->start())
1545  {
1546  JLOG(m_journal.fatal()) << "Failed to start ShardArchiveHandler.";
1547 
1548  return false;
1549  }
1550 
1551  validatorSites_->start();
1552 
1553  if (reportingETL_)
1554  reportingETL_->start();
1555 
1556  return true;
1557 }
1558 
1559 void
1560 ApplicationImp::start(bool withTimers)
1561 {
1562  JLOG(m_journal.info()) << "Application starting. Version is "
1564 
1565  if (withTimers)
1566  {
1567  setSweepTimer();
1568  setEntropyTimer();
1569  }
1570 
1572  m_resolver->start();
1573  m_loadManager->start();
1574  m_shaMapStore->start();
1575  if (overlay_)
1576  overlay_->start();
1577  grpcServer_->start();
1578  ledgerCleaner_->start();
1579  perfLog_->start();
1580 }
1581 
1582 void
1584 {
1585  if (!config_->standalone())
1586  {
1587  // VFALCO NOTE This seems unnecessary. If we properly refactor the load
1588  // manager then the deadlock detector can just always be
1589  // "armed"
1590  //
1592  }
1593 
1594  {
1596  cv_.wait(lk, [this] { return isTimeToStop; });
1597  }
1598 
1599  JLOG(m_journal.info()) << "Received shutdown request";
1600  stop();
1601  JLOG(m_journal.info()) << "Done.";
1602 }
1603 
1604 void
1606 {
1607  // Unblock the main thread (which is sitting in run()).
1608  // When we get C++20 this can use std::latch.
1609  std::lock_guard lk{mut_};
1610 
1611  if (!isTimeToStop)
1612  {
1613  isTimeToStop = true;
1614  cv_.notify_all();
1615  }
1616 }
1617 
1618 bool
1620 {
1621  return checkSigs_;
1622 }
1623 
1624 void
1626 {
1627  checkSigs_ = check;
1628 }
1629 
1630 bool
1632 {
1633  std::lock_guard lk{mut_};
1634  return isTimeToStop;
1635 }
1636 
1637 int
1639 {
1640  // Standard handles, config file, misc I/O etc:
1641  int needed = 128;
1642 
1643  // 2x the configured peer limit for peer connections:
1644  if (overlay_)
1645  needed += 2 * overlay_->limit();
1646 
1647  // the number of fds needed by the backend (internally
1648  // doubled if online delete is enabled).
1649  needed += std::max(5, m_shaMapStore->fdRequired());
1650 
1651  if (shardStore_)
1652  needed += shardStore_->fdRequired();
1653 
1654  // One fd per incoming connection a port can accept, or
1655  // if no limit is set, assume it'll handle 256 clients.
1656  for (auto const& p : serverHandler_->setup().ports)
1657  needed += std::max(256, p.limit);
1658 
1659  // The minimum number of file descriptors we need is 1024:
1660  return std::max(1024, needed);
1661 }
1662 
1663 //------------------------------------------------------------------------------
1664 
1665 void
1667 {
1668  std::vector<uint256> initialAmendments =
1669  (config_->START_UP == Config::FRESH) ? m_amendmentTable->getDesired()
1671 
1672  std::shared_ptr<Ledger> const genesis = std::make_shared<Ledger>(
1673  create_genesis, *config_, initialAmendments, nodeFamily_);
1674  m_ledgerMaster->storeLedger(genesis);
1675 
1676  auto const next =
1677  std::make_shared<Ledger>(*genesis, timeKeeper().closeTime());
1678  next->updateSkipList();
1679  next->setImmutable(*config_);
1680  openLedger_.emplace(next, cachedSLEs_, logs_->journal("OpenLedger"));
1681  m_ledgerMaster->storeLedger(next);
1682  m_ledgerMaster->switchLCL(next);
1683 }
1684 
1687 {
1688  auto j = journal("Ledger");
1689 
1690  try
1691  {
1692  auto const [ledger, seq, hash] = getLatestLedger(*this);
1693 
1694  if (!ledger)
1695  return ledger;
1696 
1697  ledger->setImmutable(*config_);
1698 
1699  if (getLedgerMaster().haveLedger(seq))
1700  ledger->setValidated();
1701 
1702  if (ledger->info().hash == hash)
1703  {
1704  JLOG(j.trace()) << "Loaded ledger: " << hash;
1705  return ledger;
1706  }
1707 
1708  if (auto stream = j.error())
1709  {
1710  stream << "Failed on ledger";
1711  Json::Value p;
1712  addJson(p, {*ledger, nullptr, LedgerFill::full});
1713  stream << p;
1714  }
1715 
1716  return {};
1717  }
1718  catch (SHAMapMissingNode const& mn)
1719  {
1720  JLOG(j.warn()) << "Ledger in database: " << mn.what();
1721  return {};
1722  }
1723 }
1724 
1727 {
1728  try
1729  {
1730  std::ifstream ledgerFile(name, std::ios::in);
1731 
1732  if (!ledgerFile)
1733  {
1734  JLOG(m_journal.fatal()) << "Unable to open file '" << name << "'";
1735  return nullptr;
1736  }
1737 
1738  Json::Reader reader;
1739  Json::Value jLedger;
1740 
1741  if (!reader.parse(ledgerFile, jLedger))
1742  {
1743  JLOG(m_journal.fatal()) << "Unable to parse ledger JSON";
1744  return nullptr;
1745  }
1746 
1747  std::reference_wrapper<Json::Value> ledger(jLedger);
1748 
1749  // accept a wrapped ledger
1750  if (ledger.get().isMember("result"))
1751  ledger = ledger.get()["result"];
1752 
1753  if (ledger.get().isMember("ledger"))
1754  ledger = ledger.get()["ledger"];
1755 
1756  std::uint32_t seq = 1;
1757  auto closeTime = timeKeeper().closeTime();
1758  using namespace std::chrono_literals;
1759  auto closeTimeResolution = 30s;
1760  bool closeTimeEstimated = false;
1761  std::uint64_t totalDrops = 0;
1762 
1763  if (ledger.get().isMember("accountState"))
1764  {
1765  if (ledger.get().isMember(jss::ledger_index))
1766  {
1767  seq = ledger.get()[jss::ledger_index].asUInt();
1768  }
1769 
1770  if (ledger.get().isMember("close_time"))
1771  {
1772  using tp = NetClock::time_point;
1773  using d = tp::duration;
1774  closeTime = tp{d{ledger.get()["close_time"].asUInt()}};
1775  }
1776  if (ledger.get().isMember("close_time_resolution"))
1777  {
1778  using namespace std::chrono;
1779  closeTimeResolution =
1780  seconds{ledger.get()["close_time_resolution"].asUInt()};
1781  }
1782  if (ledger.get().isMember("close_time_estimated"))
1783  {
1784  closeTimeEstimated =
1785  ledger.get()["close_time_estimated"].asBool();
1786  }
1787  if (ledger.get().isMember("total_coins"))
1788  {
1789  totalDrops = beast::lexicalCastThrow<std::uint64_t>(
1790  ledger.get()["total_coins"].asString());
1791  }
1792 
1793  ledger = ledger.get()["accountState"];
1794  }
1795 
1796  if (!ledger.get().isArrayOrNull())
1797  {
1798  JLOG(m_journal.fatal()) << "State nodes must be an array";
1799  return nullptr;
1800  }
1801 
1802  auto loadLedger =
1803  std::make_shared<Ledger>(seq, closeTime, *config_, nodeFamily_);
1804  loadLedger->setTotalDrops(totalDrops);
1805 
1806  for (Json::UInt index = 0; index < ledger.get().size(); ++index)
1807  {
1808  Json::Value& entry = ledger.get()[index];
1809 
1810  if (!entry.isObjectOrNull())
1811  {
1812  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1813  return nullptr;
1814  }
1815 
1816  uint256 uIndex;
1817 
1818  if (!uIndex.parseHex(entry[jss::index].asString()))
1819  {
1820  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1821  return nullptr;
1822  }
1823 
1824  entry.removeMember(jss::index);
1825 
1826  STParsedJSONObject stp("sle", ledger.get()[index]);
1827 
1828  if (!stp.object || uIndex.isZero())
1829  {
1830  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1831  return nullptr;
1832  }
1833 
1834  // VFALCO TODO This is the only place that
1835  // constructor is used, try to remove it
1836  STLedgerEntry sle(*stp.object, uIndex);
1837 
1838  if (!loadLedger->addSLE(sle))
1839  {
1840  JLOG(m_journal.fatal())
1841  << "Couldn't add serialized ledger: " << uIndex;
1842  return nullptr;
1843  }
1844  }
1845 
1846  loadLedger->stateMap().flushDirty(hotACCOUNT_NODE);
1847 
1848  loadLedger->setAccepted(
1849  closeTime, closeTimeResolution, !closeTimeEstimated, *config_);
1850 
1851  return loadLedger;
1852  }
1853  catch (std::exception const& x)
1854  {
1855  JLOG(m_journal.fatal()) << "Ledger contains invalid data: " << x.what();
1856  return nullptr;
1857  }
1858 }
1859 
1860 bool
1862  std::string const& ledgerID,
1863  bool replay,
1864  bool isFileName)
1865 {
1866  try
1867  {
1868  std::shared_ptr<Ledger const> loadLedger, replayLedger;
1869 
1870  if (isFileName)
1871  {
1872  if (!ledgerID.empty())
1873  loadLedger = loadLedgerFromFile(ledgerID);
1874  }
1875  else if (ledgerID.length() == 64)
1876  {
1877  uint256 hash;
1878 
1879  if (hash.parseHex(ledgerID))
1880  {
1881  loadLedger = loadByHash(hash, *this);
1882 
1883  if (!loadLedger)
1884  {
1885  // Try to build the ledger from the back end
1886  auto il = std::make_shared<InboundLedger>(
1887  *this,
1888  hash,
1889  0,
1891  stopwatch(),
1892  make_DummyPeerSet(*this));
1893  if (il->checkLocal())
1894  loadLedger = il->getLedger();
1895  }
1896  }
1897  }
1898  else if (ledgerID.empty() || boost::iequals(ledgerID, "latest"))
1899  {
1900  loadLedger = getLastFullLedger();
1901  }
1902  else
1903  {
1904  // assume by sequence
1905  std::uint32_t index;
1906 
1907  if (beast::lexicalCastChecked(index, ledgerID))
1908  loadLedger = loadByIndex(index, *this);
1909  }
1910 
1911  if (!loadLedger)
1912  return false;
1913 
1914  if (replay)
1915  {
1916  // Replay a ledger close with same prior ledger and transactions
1917 
1918  // this ledger holds the transactions we want to replay
1919  replayLedger = loadLedger;
1920 
1921  JLOG(m_journal.info()) << "Loading parent ledger";
1922 
1923  loadLedger = loadByHash(replayLedger->info().parentHash, *this);
1924  if (!loadLedger)
1925  {
1926  JLOG(m_journal.info())
1927  << "Loading parent ledger from node store";
1928 
1929  // Try to build the ledger from the back end
1930  auto il = std::make_shared<InboundLedger>(
1931  *this,
1932  replayLedger->info().parentHash,
1933  0,
1935  stopwatch(),
1936  make_DummyPeerSet(*this));
1937 
1938  if (il->checkLocal())
1939  loadLedger = il->getLedger();
1940 
1941  if (!loadLedger)
1942  {
1943  JLOG(m_journal.fatal()) << "Replay ledger missing/damaged";
1944  assert(false);
1945  return false;
1946  }
1947  }
1948  }
1949  using namespace std::chrono_literals;
1950  using namespace date;
1951  static constexpr NetClock::time_point ledgerWarnTimePoint{
1952  sys_days{January / 1 / 2018} - sys_days{January / 1 / 2000}};
1953  if (loadLedger->info().closeTime < ledgerWarnTimePoint)
1954  {
1955  JLOG(m_journal.fatal())
1956  << "\n\n*** WARNING ***\n"
1957  "You are replaying a ledger from before "
1958  << to_string(ledgerWarnTimePoint)
1959  << " UTC.\n"
1960  "This replay will not handle your ledger as it was "
1961  "originally "
1962  "handled.\nConsider running an earlier version of rippled "
1963  "to "
1964  "get the older rules.\n*** CONTINUING ***\n";
1965  }
1966 
1967  JLOG(m_journal.info()) << "Loading ledger " << loadLedger->info().hash
1968  << " seq:" << loadLedger->info().seq;
1969 
1970  if (loadLedger->info().accountHash.isZero())
1971  {
1972  JLOG(m_journal.fatal()) << "Ledger is empty.";
1973  assert(false);
1974  return false;
1975  }
1976 
1977  if (!loadLedger->walkLedger(journal("Ledger")))
1978  {
1979  JLOG(m_journal.fatal()) << "Ledger is missing nodes.";
1980  assert(false);
1981  return false;
1982  }
1983 
1984  if (!loadLedger->assertSensible(journal("Ledger")))
1985  {
1986  JLOG(m_journal.fatal()) << "Ledger is not sensible.";
1987  assert(false);
1988  return false;
1989  }
1990 
1991  m_ledgerMaster->setLedgerRangePresent(
1992  loadLedger->info().seq, loadLedger->info().seq);
1993 
1994  m_ledgerMaster->switchLCL(loadLedger);
1995  loadLedger->setValidated();
1996  m_ledgerMaster->setFullLedger(loadLedger, true, false);
1997  openLedger_.emplace(
1998  loadLedger, cachedSLEs_, logs_->journal("OpenLedger"));
1999 
2000  if (replay)
2001  {
2002  // inject transaction(s) from the replayLedger into our open ledger
2003  // and build replay structure
2004  auto replayData =
2005  std::make_unique<LedgerReplay>(loadLedger, replayLedger);
2006 
2007  for (auto const& [_, tx] : replayData->orderedTxns())
2008  {
2009  (void)_;
2010  auto txID = tx->getTransactionID();
2011 
2012  auto s = std::make_shared<Serializer>();
2013  tx->add(*s);
2014 
2016 
2017  openLedger_->modify(
2018  [&txID, &s](OpenView& view, beast::Journal j) {
2019  view.rawTxInsert(txID, std::move(s), nullptr);
2020  return true;
2021  });
2022  }
2023 
2024  m_ledgerMaster->takeReplay(std::move(replayData));
2025  }
2026  }
2027  catch (SHAMapMissingNode const& mn)
2028  {
2029  JLOG(m_journal.fatal())
2030  << "While loading specified ledger: " << mn.what();
2031  return false;
2032  }
2033  catch (boost::bad_lexical_cast&)
2034  {
2035  JLOG(m_journal.fatal())
2036  << "Ledger specified '" << ledgerID << "' is not valid";
2037  return false;
2038  }
2039 
2040  return true;
2041 }
2042 
2043 bool
2045 {
2046  if (!config().ELB_SUPPORT)
2047  return true;
2048 
2049  if (isStopping())
2050  {
2051  reason = "Server is shutting down";
2052  return false;
2053  }
2054 
2055  if (getOPs().isNeedNetworkLedger())
2056  {
2057  reason = "Not synchronized with network yet";
2058  return false;
2059  }
2060 
2061  if (getOPs().isAmendmentBlocked())
2062  {
2063  reason = "Server version too old";
2064  return false;
2065  }
2066 
2067  if (getOPs().isUNLBlocked())
2068  {
2069  reason = "No valid validator list available";
2070  return false;
2071  }
2072 
2073  if (getOPs().getOperatingMode() < OperatingMode::SYNCING)
2074  {
2075  reason = "Not synchronized with network";
2076  return false;
2077  }
2078 
2079  if (!getLedgerMaster().isCaughtUp(reason))
2080  return false;
2081 
2082  if (getFeeTrack().isLoadedLocal())
2083  {
2084  reason = "Too much load";
2085  return false;
2086  }
2087 
2088  return true;
2089 }
2090 
2093 {
2094  return logs_->journal(name);
2095 }
2096 
2097 bool
2099 {
2100  assert(overlay_);
2101  assert(!config_->standalone());
2102 
2103  if (config_->section(ConfigSection::shardDatabase()).empty())
2104  {
2105  JLOG(m_journal.fatal())
2106  << "The [shard_db] configuration setting must be set";
2107  return false;
2108  }
2109  if (!shardStore_)
2110  {
2111  JLOG(m_journal.fatal()) << "Invalid [shard_db] configuration";
2112  return false;
2113  }
2114  shardStore_->importDatabase(getNodeStore());
2115  return true;
2116 }
2117 
2118 void
2120 {
2122  if (seq)
2123  maxDisallowedLedger_ = *seq;
2124 
2125  JLOG(m_journal.trace())
2126  << "Max persisted ledger is " << maxDisallowedLedger_;
2127 }
2128 
2129 //------------------------------------------------------------------------------
2130 
2131 Application::Application() : beast::PropertyStream::Source("app")
2132 {
2133 }
2134 
2135 //------------------------------------------------------------------------------
2136 
2139  std::unique_ptr<Config> config,
2140  std::unique_ptr<Logs> logs,
2141  std::unique_ptr<TimeKeeper> timeKeeper)
2142 {
2143  return std::make_unique<ApplicationImp>(
2144  std::move(config), std::move(logs), std::move(timeKeeper));
2145 }
2146 
2147 } // namespace ripple
ripple::NodeStoreScheduler
A NodeStore::Scheduler which uses the JobQueue.
Definition: NodeStoreScheduler.h:30
ripple::Validations::expire
void expire()
Expire old validation sets.
Definition: Validations.h:725
beast::PropertyStream::Source::name
std::string const & name() const
Returns the name of this source.
Definition: beast_PropertyStream.cpp:190
ripple::ApplicationImp::m_resourceManager
std::unique_ptr< Resource::Manager > m_resourceManager
Definition: Application.cpp:186
ripple::ValidatorKeys::publicKey
PublicKey publicKey
Definition: ValidatorKeys.h:40
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:339
ripple::setup_TxQ
TxQ::Setup setup_TxQ(Config const &config)
Build a TxQ::Setup object from application configuration.
Definition: TxQ.cpp:1839
ripple::ApplicationImp::getReportingETL
ReportingETL & getReportingETL() override
Definition: Application.cpp:857
ripple::NodeStore::DummyScheduler
Simple NodeStore Scheduler that just peforms the tasks synchronously.
Definition: DummyScheduler.h:29
ripple::ApplicationImp::getValidationPublicKey
PublicKey const & getValidationPublicKey() const override
Definition: Application.cpp:542
ripple::ApplicationImp::m_tempNodeCache
NodeCache m_tempNodeCache
Definition: Application.cpp:181
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::NetworkOPs
Provides server functionality for clients.
Definition: NetworkOPs.h:86
ripple::ApplicationImp::openLedger_
std::optional< OpenLedger > openLedger_
Definition: Application.cpp:179
ripple::getNodeIdentity
std::pair< PublicKey, SecretKey > getNodeIdentity(Application &app)
The cryptographic credentials identifying this server instance.
Definition: NodeIdentity.cpp:32
ripple::ApplicationImp::m_ledgerReplayer
std::unique_ptr< LedgerReplayer > m_ledgerReplayer
Definition: Application.cpp:200
ripple::ApplicationImp::shardStore_
std::unique_ptr< NodeStore::DatabaseShard > shardStore_
Definition: Application.cpp:190
ripple::make_DummyPeerSet
std::unique_ptr< PeerSet > make_DummyPeerSet(Application &app)
Make a dummy PeerSet that does not do anything.
Definition: PeerSet.cpp:187
ripple::Application
Definition: Application.h:103
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::ApplicationImp::ledgerCleaner_
std::unique_ptr< LedgerCleaner > ledgerCleaner_
Definition: Application.cpp:197
ripple::LoadManager::activateDeadlockDetector
void activateDeadlockDetector()
Turn on deadlock detection.
Definition: LoadManager.cpp:55
ripple::ApplicationImp::m_inboundTransactions
std::unique_ptr< InboundTransactions > m_inboundTransactions
Definition: Application.cpp:199
ripple::NodeFamily::sweep
void sweep() override
Definition: NodeFamily.cpp:48
ripple::ApplicationImp::getShardFamily
Family * getShardFamily() override
Definition: Application.cpp:518
ripple::LoadManager
Manages load sources.
Definition: LoadManager.h:45
ripple::ApplicationImp::validators
ValidatorList & validators() override
Definition: Application.cpp:759
std::strlen
T strlen(T... args)
ripple::STLedgerEntry
Definition: STLedgerEntry.h:30
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:52
ripple::RPC::ShardArchiveHandler::makeShardArchiveHandler
static std::unique_ptr< ShardArchiveHandler > makeShardArchiveHandler(Application &app)
Definition: ShardArchiveHandler.cpp:49
std::string
STL class.
ripple::ApplicationImp::cachedSLEs
CachedSLEs & cachedSLEs() override
Definition: Application.cpp:729
std::shared_ptr
STL class.
ripple::ApplicationImp::getNodeStore
NodeStore::Database & getNodeStore() override
Definition: Application.cpp:627
ripple::RPC::ShardArchiveHandler::start
bool start()
Starts downloading and importing archives.
Definition: ShardArchiveHandler.cpp:235
ripple::TaggedCache< SHAMapHash, Blob >
ripple::ApplicationImp::serverOkay
bool serverOkay(std::string &reason) override
Definition: Application.cpp:2044
ripple::loadByIndex
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
Definition: Ledger.cpp:1061
utility
ripple::LedgerMaster::sweep
void sweep()
Definition: LedgerMaster.cpp:1829
ripple::ApplicationImp::mValidations
RCLValidations mValidations
Definition: Application.cpp:213
ripple::TransactionMaster::sweep
void sweep(void)
Definition: TransactionMaster.cpp:156
std::exception
STL class.
ripple::ApplicationImp::getAcceptedLedgerCache
TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache() override
Definition: Application.cpp:596
ripple::make_Overlay
std::unique_ptr< Overlay > make_Overlay(Application &app, Overlay::Setup const &setup, ServerHandler &serverHandler, Resource::Manager &resourceManager, Resolver &resolver, boost::asio::io_service &io_service, BasicConfig const &config, beast::insight::Collector::ptr const &collector)
Creates the implementation of Overlay.
Definition: OverlayImpl.cpp:1642
cstring
ripple::ApplicationImp::getHashRouter
HashRouter & getHashRouter() override
Definition: Application.cpp:747
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
beast::PropertyStream::Map
Definition: PropertyStream.h:236
ripple::ApplicationImp::validatorSites_
std::unique_ptr< ValidatorSite > validatorSites_
Definition: Application.cpp:208
ripple::ApplicationImp::mWalletDB
std::unique_ptr< DatabaseCon > mWalletDB
Definition: Application.cpp:221
ripple::ApplicationImp::getPathRequests
PathRequests & getPathRequests() override
Definition: Application.cpp:723
ripple::TaggedCache::sweep
void sweep()
Definition: TaggedCache.h:169
ripple::ApplicationImp::m_orderBookDB
OrderBookDB m_orderBookDB
Definition: Application.cpp:194
ripple::ApplicationImp::stop
void stop()
Definition: Application.cpp:941
ripple::make_LoadManager
std::unique_ptr< LoadManager > make_LoadManager(Application &app, beast::Journal journal)
Definition: LoadManager.cpp:197
ripple::TransactionMaster
Definition: TransactionMaster.h:36
ripple::ValidatorSite
Definition: ValidatorSite.h:69
std::pair
ripple::ApplicationImp::onWrite
void onWrite(beast::PropertyStream::Map &stream) override
Subclass override.
Definition: Application.cpp:1037
ripple::LedgerMaster
Definition: LedgerMaster.h:70
ripple::ApplicationImp::mRelationalDBInterface
std::unique_ptr< RelationalDBInterface > mRelationalDBInterface
Definition: Application.cpp:220
ripple::ApplicationImp::getInboundLedgers
InboundLedgers & getInboundLedgers() override
Definition: Application.cpp:584
ripple::ApplicationImp::accountIDCache
AccountIDCache const & accountIDCache() const override
Definition: Application.cpp:807
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::ApplicationImp::io_latency_sampler::cancel_async
void cancel_async()
Definition: Application.cpp:155
Json::UInt
unsigned int UInt
Definition: json_forwards.h:27
ripple::hotACCOUNT_NODE
@ hotACCOUNT_NODE
Definition: NodeObject.h:35
ripple::setup_DatabaseCon
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
Definition: DatabaseCon.cpp:106
ripple::ApplicationImp::getLedgerReplayer
LedgerReplayer & getLedgerReplayer() override
Definition: Application.cpp:578
ripple::InboundLedger::Reason::GENERIC
@ GENERIC
std::vector
STL class.
ripple::ConfigSection::shardDatabase
static std::string shardDatabase()
Definition: ConfigSections.h:38
std::string::length
T length(T... args)
ripple::ValidatorList::trustedPublisher
bool trustedPublisher(PublicKey const &identity) const
Returns true if public key is a trusted publisher.
Definition: ValidatorList.cpp:1404
ripple::ApplicationImp::waitHandlerCounter_
ClosureCounter< void, boost::system::error_code const & > waitHandlerCounter_
Definition: Application.cpp:216
ripple::ApplicationImp::getOPs
NetworkOPs & getOPs() override
Definition: Application.cpp:548
ripple::ApplicationImp::run
void run() override
Definition: Application.cpp:1583
ripple::make_InboundLedgers
std::unique_ptr< InboundLedgers > make_InboundLedgers(Application &app, InboundLedgers::clock_type &clock, beast::insight::Collector::ptr const &collector)
Definition: InboundLedgers.cpp:419
ripple::CollectorManager
Provides the beast::insight::Collector service.
Definition: CollectorManager.h:29
ripple::ConfigSection::importNodeDatabase
static std::string importNodeDatabase()
Definition: ConfigSections.h:43
std::chrono::milliseconds
ripple::Config::NODE_SIZE
std::size_t NODE_SIZE
Definition: Config.h:184
ripple::ApplicationImp::m_acceptedLedgerCache
TaggedCache< uint256, AcceptedLedger > m_acceptedLedgerCache
Definition: Application.cpp:201
ripple::ApplicationImp::setup
bool setup() override
Definition: Application.cpp:1174
ripple::SHAMapStore
class to create database, launch online delete thread, and related SQLite database
Definition: SHAMapStore.h:36
ripple::ApplicationImp::validatorManifests
ManifestCache & validatorManifests() override
Definition: Application.cpp:771
ripple::ApplicationImp::getWalletDB
DatabaseCon & getWalletDB() override
Retrieve the "wallet database".
Definition: Application.cpp:850
ripple::getLatestLedger
std::tuple< std::shared_ptr< Ledger >, std::uint32_t, uint256 > getLatestLedger(Application &app)
Definition: Ledger.cpp:1051
ripple::ApplicationImp::getCollectorManager
CollectorManager & getCollectorManager() override
Definition: Application.cpp:504
ripple::ApplicationImp::sweepTimer_
boost::asio::steady_timer sweepTimer_
Definition: Application.cpp:217
ripple::ApplicationImp::cluster_
std::unique_ptr< Cluster > cluster_
Definition: Application.cpp:203
ripple::ApplicationImp::getShardStore
NodeStore::DatabaseShard * getShardStore() override
Definition: Application.cpp:635
ripple::ApplicationImp::openLedger
OpenLedger const & openLedger() const override
Definition: Application.cpp:821
ripple::ApplicationImp::getIOLatency
std::chrono::milliseconds getIOLatency() override
Definition: Application.cpp:560
ripple::ApplicationImp::m_shaMapStore
std::unique_ptr< SHAMapStore > m_shaMapStore
Definition: Application.cpp:176
ripple::make_CollectorManager
std::unique_ptr< CollectorManager > make_CollectorManager(Section const &params, beast::Journal journal)
Definition: CollectorManager.cpp:72
ripple::Config::LOAD
@ LOAD
Definition: Config.h:132
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
std::recursive_mutex
STL class.
std::reference_wrapper::get
T get(T... args)
ripple::ApplicationImp::getIOService
boost::asio::io_service & getIOService() override
Definition: Application.cpp:554
ripple::ApplicationImp::shardArchiveHandler_
std::unique_ptr< RPC::ShardArchiveHandler > shardArchiveHandler_
Definition: Application.cpp:192
std::lock_guard
STL class.
beast::severities
A namespace for easy access to logging severity values.
Definition: Journal.h:29
ripple::perf::PerfLog
Singleton class that maintains performance counters and optionally writes Json-formatted data to a di...
Definition: PerfLog.h:47
ripple::STParsedJSONObject
Holds the serialized result of parsing an input JSON object.
Definition: STParsedJSON.h:31
ripple::PendingSaves
Keeps track of which ledgers haven't been fully saved.
Definition: PendingSaves.h:36
ripple::Resource::feeReferenceRPC
const Charge feeReferenceRPC
ripple::make_LedgerCleaner
std::unique_ptr< LedgerCleaner > make_LedgerCleaner(Application &app, beast::Journal journal)
Definition: LedgerCleaner.cpp:455
ripple::Pathfinder::initPathTable
static void initPathTable()
Definition: Pathfinder.cpp:1244
std::cerr
ripple::ApplicationImp::ApplicationImp
ApplicationImp(std::unique_ptr< Config > config, std::unique_ptr< Logs > logs, std::unique_ptr< TimeKeeper > timeKeeper)
Definition: Application.cpp:261
ripple::ApplicationImp::signalStop
void signalStop() override
Definition: Application.cpp:1605
ripple::ApplicationImp::cluster
Cluster & cluster() override
Definition: Application.cpp:783
ripple::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition: chrono.h:88
ripple::RelationalDBInterface
Definition: RelationalDBInterface.h:48
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:3807
ripple::make_InboundTransactions
std::unique_ptr< InboundTransactions > make_InboundTransactions(Application &app, beast::insight::Collector::ptr const &collector, std::function< void(std::shared_ptr< SHAMap > const &, bool)> gotSet)
Definition: InboundTransactions.cpp:272
ripple::RelationalDBInterface::init
static std::unique_ptr< RelationalDBInterface > init(Application &app, Config const &config, JobQueue &jobQueue)
init Creates and returns appropriate interface based on config.
Definition: RelationalDBInterface.cpp:40
ripple::ApplicationImp::getLedgerMaster
LedgerMaster & getLedgerMaster() override
Definition: Application.cpp:566
Json::Reader
Unserialize a JSON document into a Value.
Definition: json_reader.h:36
ripple::NodeFamily
Definition: NodeFamily.h:30
ripple::STParsedJSONObject::object
std::optional< STObject > object
The STObject if the parse was successful.
Definition: STParsedJSON.h:50
ripple::ResolverAsio::New
static std::unique_ptr< ResolverAsio > New(boost::asio::io_service &, beast::Journal)
Definition: ResolverAsio.cpp:406
iostream
ripple::ApplicationImp::m_nodeStore
std::unique_ptr< NodeStore::Database > m_nodeStore
Definition: Application.cpp:188
ripple::RelationalDBInterfacePostgres
Definition: RelationalDBInterfacePostgres.h:27
ripple::ApplicationImp::perfLog_
std::unique_ptr< perf::PerfLog > perfLog_
Definition: Application.cpp:167
ripple::AccountIDCache
Caches the base58 representations of AccountIDs.
Definition: AccountID.h:118
ripple::ApplicationImp::nodeIdentity_
std::pair< PublicKey, SecretKey > nodeIdentity_
Definition: Application.cpp:183
ripple::InboundLedgers::sweep
virtual void sweep()=0
ripple::ValidatorKeys
Validator keys and manifest as set in configuration file.
Definition: ValidatorKeys.h:36
ripple::HashRouter
Routing table for objects identified by hash.
Definition: HashRouter.h:53
ripple::forceValidity
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
Definition: apply.cpp:89
ripple::ApplicationImp::validatorKeys_
const ValidatorKeys validatorKeys_
Definition: Application.cpp:184
ripple::ApplicationImp::timeKeeper_
std::unique_ptr< TimeKeeper > timeKeeper_
Definition: Application.cpp:164
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::ApplicationImp::cv_
std::condition_variable cv_
Definition: Application.cpp:226
ripple::SHAMapMissingNode
Definition: SHAMapMissingNode.h:55
ripple::Validity::SigGoodOnly
@ SigGoodOnly
Signature is good, but local checks fail.
ripple::ApplicationImp::getShardArchiveHandler
RPC::ShardArchiveHandler * getShardArchiveHandler(bool tryRecovery) override
Definition: Application.cpp:641
ripple::ApplicationImp::m_inboundLedgers
std::unique_ptr< InboundLedgers > m_inboundLedgers
Definition: Application.cpp:198
ripple::ApplicationImp::peerReservations_
std::unique_ptr< PeerReservationTable > peerReservations_
Definition: Application.cpp:204
ripple::setup_ServerHandler
ServerHandler::Setup setup_ServerHandler(Config const &config, std::ostream &&log)
Definition: ServerHandlerImp.cpp:1171
ripple::ApplicationImp::loadLedgerFromFile
std::shared_ptr< Ledger > loadLedgerFromFile(std::string const &ledgerID)
Definition: Application.cpp:1726
ripple::ApplicationImp::checkSigs
bool checkSigs() const override
Definition: Application.cpp:1619
ripple::ApplicationImp::journal
beast::Journal journal(std::string const &name) override
Definition: Application.cpp:2092
ripple::base_uint< 256 >
ripple::ApplicationImp::entropyTimer_
boost::asio::steady_timer entropyTimer_
Definition: Application.cpp:218
ripple::ApplicationImp::getMaxDisallowedLedger
LedgerIndex getMaxDisallowedLedger() override
Ensure that a newly-started validator does not sign proposals older than the last ledger it persisted...
Definition: Application.cpp:1141
ripple::ApplicationImp::nodeToShards
bool nodeToShards()
Definition: Application.cpp:2098
ripple::ApplicationImp::hashRouter_
std::unique_ptr< HashRouter > hashRouter_
Definition: Application.cpp:212
ripple::ApplicationImp::getMasterMutex
Application::MutexType & getMasterMutex() override
Definition: Application.cpp:699
ripple::HashRouter::getDefaultRecoverLimit
static std::uint32_t getDefaultRecoverLimit()
Definition: HashRouter.h:162
ripple::ApplicationImp::m_ledgerMaster
std::unique_ptr< LedgerMaster > m_ledgerMaster
Definition: Application.cpp:196
ripple::RPC::doCommand
Status doCommand(RPC::JsonContext &context, Json::Value &result)
Execute an RPC command and store the results in a Json::Value.
Definition: RPCHandler.cpp:246
ripple::setup_Overlay
Overlay::Setup setup_Overlay(BasicConfig const &config)
Definition: OverlayImpl.cpp:1537
ripple::ApplicationImp::logs
Logs & logs() override
Definition: Application.cpp:492
ripple::ApplicationImp::getPerfLog
perf::PerfLog & getPerfLog() override
Definition: Application.cpp:615
ripple::ApplicationImp::m_jobQueue
std::unique_ptr< JobQueue > m_jobQueue
Definition: Application.cpp:174
ripple::ApplicationImp::checkSigs_
std::atomic< bool > checkSigs_
Definition: Application.cpp:230
std::reference_wrapper
ripple::make_ServerHandler
std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_service &io_service, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
Definition: ServerHandlerImp.cpp:1183
ripple::RelationalDBInterface::getMaxLedgerSeq
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
ripple::loadByHash
std::shared_ptr< Ledger > loadByHash(uint256 const &ledgerHash, Application &app, bool acquire)
Definition: Ledger.cpp:1074
ripple::TxQ
Transaction Queue.
Definition: TxQ.h:56
ripple::ApplicationImp::numberOfThreads
static std::size_t numberOfThreads(Config const &config)
Definition: Application.cpp:242
ripple::base_uint::isZero
bool isZero() const
Definition: base_uint.h:511
ripple::ApplicationImp::getSHAMapStore
SHAMapStore & getSHAMapStore() override
Definition: Application.cpp:795
ripple::Role::ADMIN
@ ADMIN
ripple::detail::supportedAmendments
std::map< std::string, DefaultVote > const & supportedAmendments()
Amendments that this server supports and the default voting behavior.
Definition: Feature.cpp:314
beast::PropertyStream::Source::add
void add(Source &source)
Add a child source.
Definition: beast_PropertyStream.cpp:196
ripple::ApplicationImp::getAmendmentTable
AmendmentTable & getAmendmentTable() override
Definition: Application.cpp:735
ripple::ApplicationImp::loadOldLedger
bool loadOldLedger(std::string const &ledgerID, bool replay, bool isFilename)
Definition: Application.cpp:1861
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
std::atomic::load
T load(T... args)
ripple::Config
Definition: Config.h:68
ripple::ApplicationImp::io_latency_sampler::cancel
void cancel()
Definition: Application.cpp:149
ripple::PublicKey::size
std::size_t size() const noexcept
Definition: PublicKey.h:87
ripple::Cluster
Definition: Cluster.h:38
std::thread::hardware_concurrency
T hardware_concurrency(T... args)
ripple::CachedSLEs
Caches SLEs by their digest.
Definition: CachedSLEs.h:32
ripple::ValidatorList
Definition: ValidatorList.h:172
ripple::ApplicationImp::getResourceManager
Resource::Manager & getResourceManager() override
Definition: Application.cpp:711
ripple::ApplicationImp::peerReservations
PeerReservationTable & peerReservations() override
Definition: Application.cpp:789
ripple::ApplicationImp::publisherManifests
ManifestCache & publisherManifests() override
Definition: Application.cpp:777
ripple::ApplicationImp::m_amendmentTable
std::unique_ptr< AmendmentTable > m_amendmentTable
Definition: Application.cpp:210
ripple::Config::NETWORK
@ NETWORK
Definition: Config.h:132
ripple::ApplicationImp::overlay
Overlay & overlay() override
Definition: Application.cpp:829
ripple::megabytes
constexpr auto megabytes(T value) noexcept
Definition: ByteUtilities.h:34
ripple::ApplicationImp::pendingSaves
PendingSaves & pendingSaves() override
Definition: Application.cpp:801
ripple::ApplicationImp::m_collectorManager
std::unique_ptr< CollectorManager > m_collectorManager
Definition: Application.cpp:173
ripple::ApplicationImp::nodeFamily_
NodeFamily nodeFamily_
Definition: Application.cpp:189
ripple::HashRouter::getDefaultHoldTime
static std::chrono::seconds getDefaultHoldTime()
Definition: HashRouter.h:154
ripple::LedgerFill::full
@ full
Definition: LedgerToJson.h:49
std::unique_lock
STL class.
beast::io_latency_probe::sample
void sample(Handler &&handler)
Initiate continuous i/o latency sampling.
Definition: io_latency_probe.h:119
ripple::ApplicationImp::m_txMaster
TransactionMaster m_txMaster
Definition: Application.cpp:171
ripple::NodeStore::DatabaseShard
A collection of historical shards.
Definition: DatabaseShard.h:37
ripple::LoadFeeTrack
Manages the current fee schedule.
Definition: LoadFeeTrack.h:43
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:313
ripple::CachedSLEs::expire
void expire()
Discard expired entries.
Definition: CachedSLEs.cpp:26
ripple::ApplicationImp::mut_
std::mutex mut_
Definition: Application.cpp:227
ripple::ValidatorList::listed
bool listed(PublicKey const &identity) const
Returns true if public key is included on any lists.
Definition: ValidatorList.cpp:1349
ripple::ApplicationImp::validatorSites
ValidatorSite & validatorSites() override
Definition: Application.cpp:765
ripple::ApplicationImp::nodeIdentity
std::pair< PublicKey, SecretKey > const & nodeIdentity() override
Definition: Application.cpp:536
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
ripple::ApplicationImp::io_latency_sampler::m_event
beast::insight::Event m_event
Definition: Application.cpp:100
std::chrono::time_point
beast::insight::Event
A metric for reporting event timing.
Definition: Event.h:40
ripple::ApplicationImp::config_
std::unique_ptr< Config > config_
Definition: Application.cpp:162
ripple::BuildInfo::getVersionString
std::string const & getVersionString()
Server version.
Definition: BuildInfo.cpp:61
ripple::OrderBookDB::setup
void setup(std::shared_ptr< ReadView const > const &ledger)
Definition: OrderBookDB.cpp:43
beast::basic_logstream
Definition: Journal.h:428
ripple::ReportingETL
This class is responsible for continuously extracting data from a p2p node, and writing that data to ...
Definition: ReportingETL.h:70
ripple::ApplicationImp::getLastFullLedger
std::shared_ptr< Ledger > getLastFullLedger()
Definition: Application.cpp:1686
ripple::TimeKeeper::closeTime
virtual time_point closeTime() const =0
Returns the close time, in network time.
ripple::Family
Definition: Family.h:32
ripple::ValidatorKeys::configInvalid
bool configInvalid() const
Definition: ValidatorKeys.h:49
ripple::ClosureCounter
The role of a ClosureCounter is to assist in shutdown by letting callers wait for the completion of c...
Definition: ClosureCounter.h:54
ripple::ApplicationImp::isTimeToStop
bool isTimeToStop
Definition: Application.cpp:228
ripple::ApplicationImp::m_io_latency_sampler
io_latency_sampler m_io_latency_sampler
Definition: Application.cpp:234
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::SizedItem::burstSize
@ burstSize
std::uint32_t
std::condition_variable::wait
T wait(T... args)
ripple::ApplicationImp::gotTXSet
void gotTXSet(std::shared_ptr< SHAMap > const &set, bool fromAcquire)
Definition: Application.cpp:602
std::atomic< std::chrono::milliseconds >
ripple::ApplicationImp::startGenesisLedger
void startGenesisLedger()
Definition: Application.cpp:1666
ripple::ApplicationImp::m_signals
boost::asio::signal_set m_signals
Definition: Application.cpp:224
ripple::TimeKeeper
Manages various times used by the server.
Definition: TimeKeeper.h:32
ripple::ApplicationImp::timeKeeper
TimeKeeper & timeKeeper() override
Definition: Application.cpp:524
beast::io_latency_probe< std::chrono::steady_clock >
ripple::OrderBookDB
Definition: OrderBookDB.h:31
ripple::ApplicationImp::io_latency_sampler::operator()
void operator()(Duration const &elapsed)
Definition: Application.cpp:126
ripple::NodeStore::Database::sweep
virtual void sweep()=0
Remove expired entries from the positive and negative caches.
ripple::ApplicationImp::getRelationalDBInterface
RelationalDBInterface & getRelationalDBInterface() override
Definition: Application.cpp:843
ripple::InboundLedgers
Manages the lifetime of inbound ledgers.
Definition: InboundLedgers.h:33
ripple::OpenLedger
Represents the open ledger.
Definition: OpenLedger.h:49
ripple::Validations::flush
void flush()
Flush all current validations.
Definition: Validations.h:1087
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::Application::Application
Application()
Definition: Application.cpp:2131
ripple::ApplicationImp::setMaxDisallowedLedger
void setMaxDisallowedLedger()
Definition: Application.cpp:2119
ripple::Resource::Manager
Tracks load and resource consumption.
Definition: ResourceManager.h:36
ripple::ApplicationImp::shardFamily_
std::unique_ptr< ShardFamily > shardFamily_
Definition: Application.cpp:191
ripple::ApplicationImp::io_latency_sampler::lastSample_
std::atomic< std::chrono::milliseconds > lastSample_
Definition: Application.cpp:103
ripple::ApplicationImp::setSweepTimer
void setSweepTimer()
Definition: Application.cpp:1044
ripple::ApplicationImp::overlay_
std::unique_ptr< Overlay > overlay_
Definition: Application.cpp:222
ripple::BuildInfo::getFullVersionString
std::string const & getFullVersionString()
Full server version string.
Definition: BuildInfo.cpp:74
ripple::ApplicationImp::openLedger
OpenLedger & openLedger() override
Definition: Application.cpp:813
ripple::ApplicationImp::pendingSaves_
PendingSaves pendingSaves_
Definition: Application.cpp:177
ripple::ApplicationImp::m_resolver
std::unique_ptr< ResolverAsio > m_resolver
Definition: Application.cpp:232
ripple::ApplicationImp::getTxQ
TxQ & getTxQ() override
Definition: Application.cpp:836
ripple::PeerReservationTable
Definition: PeerReservationTable.h:79
ripple::ManifestCache
Remembers manifests with the highest sequence number.
Definition: Manifest.h:223
ripple::LedgerReplayer::sweep
void sweep()
Remove completed tasks.
Definition: LedgerReplayer.cpp:219
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Config::FRESH
@ FRESH
Definition: Config.h:132
ripple::Resource::make_Manager
std::unique_ptr< Manager > make_Manager(beast::insight::Collector::ptr const &collector, beast::Journal journal)
Definition: ResourceManager.cpp:175
ripple::ApplicationImp::getTempNodeCache
NodeCache & getTempNodeCache() override
Definition: Application.cpp:621
ripple::ApplicationImp::io_latency_sampler::get
std::chrono::milliseconds get() const
Definition: Application.cpp:143
beast::io_latency_probe::cancel
void cancel()
Cancel all pending i/o.
Definition: io_latency_probe.h:84
Json::Value::removeMember
Value removeMember(const char *key)
Remove and return the named member.
Definition: json_value.cpp:907
ripple::ApplicationImp::grpcServer_
std::unique_ptr< GRPCServer > grpcServer_
Definition: Application.cpp:236
std::endl
T endl(T... args)
ripple::OpenView::rawTxInsert
void rawTxInsert(key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
Add a transaction to the tx map.
Definition: OpenView.cpp:261
ripple::RPC::ShardArchiveHandler::tryMakeRecoveryHandler
static std::unique_ptr< ShardArchiveHandler > tryMakeRecoveryHandler(Application &app)
Definition: ShardArchiveHandler.cpp:55
ripple::ApplicationImp::getJobQueue
JobQueue & getJobQueue() override
Definition: Application.cpp:530
ripple::ApplicationImp::fdRequired
int fdRequired() const override
Definition: Application.cpp:1638
ripple::ApplicationImp::doSweep
void doSweep()
Definition: Application.cpp:1103
beast::PropertyStream::Source::Source
Source(std::string const &name)
Definition: beast_PropertyStream.cpp:176
ripple::Overlay
Manages the set of connected peers.
Definition: Overlay.h:51
ripple::ApplicationImp::io_latency_sampler
Definition: Application.cpp:97
limits
ripple::ApplicationImp::getOrderBookDB
OrderBookDB & getOrderBookDB() override
Definition: Application.cpp:717
ripple::ApplicationImp
Definition: Application.cpp:94
ripple::ApplicationImp::initRDBMS
bool initRDBMS()
Definition: Application.cpp:872
ripple::ApplicationImp::getLoadManager
LoadManager & getLoadManager() override
Definition: Application.cpp:705
beast::lexicalCastChecked
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
Definition: LexicalCast.h:266
ripple::make_PeerSetBuilder
std::unique_ptr< PeerSetBuilder > make_PeerSetBuilder(Application &app)
Definition: PeerSet.cpp:144
ripple::ApplicationImp::io_latency_sampler::m_probe
beast::io_latency_probe< std::chrono::steady_clock > m_probe
Definition: Application.cpp:102
ripple::ApplicationImp::isStopping
bool isStopping() const override
Definition: Application.cpp:1631
ripple::ApplicationImp::accountIDCache_
AccountIDCache accountIDCache_
Definition: Application.cpp:178
std
STL namespace.
ripple::ApplicationImp::m_nodeStoreScheduler
NodeStoreScheduler m_nodeStoreScheduler
Definition: Application.cpp:175
ripple::ApplicationImp::m_loadManager
std::unique_ptr< LoadManager > m_loadManager
Definition: Application.cpp:214
ripple::create_genesis
const create_genesis_t create_genesis
Definition: Ledger.cpp:62
ripple::Config::REPLAY
@ REPLAY
Definition: Config.h:132
ripple::ApplicationImp::getInboundTransactions
InboundTransactions & getInboundTransactions() override
Definition: Application.cpp:590
ripple::makeWalletDB
std::unique_ptr< DatabaseCon > makeWalletDB(DatabaseCon::Setup const &setup)
makeWalletDB Opens wallet DB and returns it.
Definition: RelationalDBInterface_global.cpp:40
Json::Reader::parse
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Definition: json_reader.cpp:74
condition_variable
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:33
ripple::Resource::Charge
A consumption charge.
Definition: Charge.h:30
ripple::SizedItem::sweepInterval
@ sweepInterval
ripple::DatabaseCon
Definition: DatabaseCon.h:81
ripple::RPC::apiMaximumSupportedVersion
constexpr unsigned int apiMaximumSupportedVersion
Definition: RPCHelpers.h:224
ripple::ApplicationImp::mFeeTrack
std::unique_ptr< LoadFeeTrack > mFeeTrack
Definition: Application.cpp:211
ripple::ApplicationImp::getFeeTrack
LoadFeeTrack & getFeeTrack() override
Definition: Application.cpp:741
ripple::addJson
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Object or Json::Value with a description of the ledger.
Definition: LedgerToJson.cpp:281
ripple::RPC::ShardArchiveHandler
Handles the download and import of one or more shard archives.
Definition: ShardArchiveHandler.h:40
ripple::LedgerReplayer
Manages the lifetime of ledger replay tasks.
Definition: LedgerReplayer.h:72
beast::severities::kDebug
@ kDebug
Definition: Journal.h:35
ripple::ApplicationImp::io_latency_sampler::m_journal
beast::Journal m_journal
Definition: Application.cpp:101
ripple::ApplicationImp::config
Config & config() override
Definition: Application.cpp:498
ripple::ApplicationImp::validators_
std::unique_ptr< ValidatorList > validators_
Definition: Application.cpp:207
std::string::empty
T empty(T... args)
ripple::ApplicationImp::getLedgerCleaner
LedgerCleaner & getLedgerCleaner() override
Definition: Application.cpp:572
ripple::ApplicationImp::m_journal
beast::Journal m_journal
Definition: Application.cpp:166
ripple::SizedItem::ledgerSize
@ ledgerSize
ripple::Validations< RCLValidationsAdaptor >
ripple::ClosureCounter::join
void join(char const *name, std::chrono::milliseconds wait, beast::Journal j)
Returns once all counted in-flight closures are destroyed.
Definition: ClosureCounter.h:166
optional
beast::io_latency_probe::cancel_async
void cancel_async()
Definition: io_latency_probe.h:91
mutex
ripple::ApplicationImp::io_latency_sampler::io_latency_sampler
io_latency_sampler(beast::insight::Event ev, beast::Journal journal, std::chrono::milliseconds interval, boost::asio::io_service &ios)
Definition: Application.cpp:106
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::ApplicationImp::serverHandler_
std::unique_ptr< ServerHandler > serverHandler_
Definition: Application.cpp:209
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:38
ripple::make_AmendmentTable
std::unique_ptr< AmendmentTable > make_AmendmentTable(Application &app, std::chrono::seconds majorityTime, std::vector< AmendmentTable::FeatureInfo > const &supported, Section const &enabled, Section const &vetoed, beast::Journal journal)
Definition: AmendmentTable.cpp:789
ripple::ApplicationImp::validatorManifests_
std::unique_ptr< ManifestCache > validatorManifests_
Definition: Application.cpp:205
BasicApp
Definition: BasicApp.h:29
ripple::ApplicationImp::m_pathRequests
std::unique_ptr< PathRequests > m_pathRequests
Definition: Application.cpp:195
ripple::ApplicationImp::m_networkOPs
std::unique_ptr< NetworkOPs > m_networkOPs
Definition: Application.cpp:202
ripple::ApplicationImp::getNodeFamily
Family & getNodeFamily() override
Definition: Application.cpp:510
ripple::PathRequests
Definition: PathRequests.h:33
ripple::ApplicationImp::txQ_
std::unique_ptr< TxQ > txQ_
Definition: Application.cpp:215
ripple::ApplicationImp::cachedSLEs_
CachedSLEs cachedSLEs_
Definition: Application.cpp:182
std::max
T max(T... args)
ripple::base_uint::parseHex
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition: base_uint.h:475
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:120
ripple::ApplicationImp::m_masterMutex
Application::MutexType m_masterMutex
Definition: Application.cpp:168
ripple::NodeStore::Manager::make_Database
virtual std::unique_ptr< Database > make_Database(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
ripple::getRegisteredFeature
std::optional< uint256 > getRegisteredFeature(std::string const &name)
Definition: Feature.cpp:336
ripple::LedgerCleaner
Check the ledger/transaction databases to make sure they have continuity.
Definition: LedgerCleaner.h:32
BasicApp::get_io_service
boost::asio::io_service & get_io_service()
Definition: BasicApp.h:41
ripple::ApplicationImp::initNodeStore
bool initNodeStore()
Definition: Application.cpp:898
ripple::ApplicationImp::maxDisallowedLedger_
std::atomic< LedgerIndex > maxDisallowedLedger_
Definition: Application.cpp:1149
ripple::make_SHAMapStore
std::unique_ptr< SHAMapStore > make_SHAMapStore(Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:738
ripple::ApplicationImp::publisherManifests_
std::unique_ptr< ManifestCache > publisherManifests_
Definition: Application.cpp:206
ripple::AmendmentTable
The amendment table stores the list of enabled and potential amendments.
Definition: AmendmentTable.h:37
ripple::ApplicationImp::getMasterTransaction
TransactionMaster & getMasterTransaction() override
Definition: Application.cpp:609
std::unique_ptr
STL class.
ripple::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition: chrono.h:56
ripple::Config::LOAD_FILE
@ LOAD_FILE
Definition: Config.h:132
ripple::ApplicationImp::io_latency_sampler::start
void start()
Definition: Application.cpp:119
std::condition_variable::notify_all
T notify_all(T... args)
ripple::ApplicationImp::reportingETL_
std::unique_ptr< ReportingETL > reportingETL_
Definition: Application.cpp:237
Json::Value::isObjectOrNull
bool isObjectOrNull() const
Definition: json_value.cpp:1033
ripple::ApplicationImp::getValidations
RCLValidations & getValidations() override
Definition: Application.cpp:753
ripple::ApplicationImp::setEntropyTimer
void setEntropyTimer()
Definition: Application.cpp:1074
ripple::make_Application
std::unique_ptr< Application > make_Application(std::unique_ptr< Config > config, std::unique_ptr< Logs > logs, std::unique_ptr< TimeKeeper > timeKeeper)
Definition: Application.cpp:2138
ripple::ValidatorKeys::manifest
std::string manifest
Definition: ValidatorKeys.h:43
std::ref
T ref(T... args)
std::exception::what
T what(T... args)
ripple::ApplicationImp::start
void start(bool withTimers) override
Definition: Application.cpp:1560
Json::Value
Represents a JSON value.
Definition: json_value.h:145
beast::insight::Event::notify
void notify(std::chrono::duration< Rep, Period > const &value) const
Push an event notification.
Definition: Event.h:64
ripple::ApplicationImp::logs_
std::unique_ptr< Logs > logs_
Definition: Application.cpp:163
ripple::InboundTransactions
Manages the acquisition and lifetime of transaction sets.
Definition: InboundTransactions.h:35
variant
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469
ripple::ClosureCounter::wrap
std::optional< Substitute< Closure > > wrap(Closure &&closure)
Wrap the passed closure with a reference counter.
Definition: ClosureCounter.h:192
std::ifstream
STL class.
beast
Definition: base_uint.h:657
std::chrono