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