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& sa = detail::supportedAmendments();
1254  std::vector<std::string> saHashes;
1255  saHashes.reserve(sa.size());
1256  for (auto const& name : sa)
1257  {
1258  auto const f = getRegisteredFeature(name);
1259  BOOST_ASSERT(f);
1260  if (f)
1261  saHashes.push_back(to_string(*f) + " " + name);
1262  }
1263  Section supportedAmendments("Supported Amendments");
1264  supportedAmendments.append(saHashes);
1265 
1266  Section enabledAmendments = config_->section(SECTION_AMENDMENTS);
1267 
1269  *this,
1270  config().AMENDMENT_MAJORITY_TIME,
1271  supportedAmendments,
1272  enabledAmendments,
1273  config_->section(SECTION_VETO_AMENDMENTS),
1274  logs_->journal("Amendments"));
1275  }
1276 
1278 
1279  auto const startUp = config_->START_UP;
1280  if (!config_->reporting())
1281  {
1282  if (startUp == Config::FRESH)
1283  {
1284  JLOG(m_journal.info()) << "Starting new Ledger";
1285 
1287  }
1288  else if (
1289  startUp == Config::LOAD || startUp == Config::LOAD_FILE ||
1290  startUp == Config::REPLAY)
1291  {
1292  JLOG(m_journal.info()) << "Loading specified Ledger";
1293 
1294  if (!loadOldLedger(
1295  config_->START_LEDGER,
1296  startUp == Config::REPLAY,
1297  startUp == Config::LOAD_FILE))
1298  {
1299  JLOG(m_journal.error())
1300  << "The specified ledger could not be loaded.";
1301  return false;
1302  }
1303  }
1304  else if (startUp == Config::NETWORK)
1305  {
1306  // This should probably become the default once we have a stable
1307  // network.
1308  if (!config_->standalone())
1309  m_networkOPs->setNeedNetworkLedger();
1310 
1312  }
1313  else
1314  {
1316  }
1317  }
1318 
1319  if (!config().reporting())
1320  m_orderBookDB.setup(getLedgerMaster().getCurrentLedger());
1321 
1322  nodeIdentity_ = getNodeIdentity(*this);
1323 
1324  if (!cluster_->load(config().section(SECTION_CLUSTER_NODES)))
1325  {
1326  JLOG(m_journal.fatal()) << "Invalid entry in cluster configuration.";
1327  return false;
1328  }
1329 
1330  if (!config().reporting())
1331  {
1332  {
1334  return false;
1335 
1336  if (!validatorManifests_->load(
1337  getWalletDB(),
1338  "ValidatorManifests",
1340  config()
1341  .section(SECTION_VALIDATOR_KEY_REVOCATION)
1342  .values()))
1343  {
1344  JLOG(m_journal.fatal())
1345  << "Invalid configured validator manifest.";
1346  return false;
1347  }
1348 
1349  publisherManifests_->load(getWalletDB(), "PublisherManifests");
1350 
1351  // Setup trusted validators
1352  if (!validators_->load(
1354  config().section(SECTION_VALIDATORS).values(),
1355  config().section(SECTION_VALIDATOR_LIST_KEYS).values()))
1356  {
1357  JLOG(m_journal.fatal())
1358  << "Invalid entry in validator configuration.";
1359  return false;
1360  }
1361  }
1362 
1363  if (!validatorSites_->load(
1364  config().section(SECTION_VALIDATOR_LIST_SITES).values()))
1365  {
1366  JLOG(m_journal.fatal())
1367  << "Invalid entry in [" << SECTION_VALIDATOR_LIST_SITES << "]";
1368  return false;
1369  }
1370  }
1371  //----------------------------------------------------------------------
1372  //
1373  // Server
1374  //
1375  //----------------------------------------------------------------------
1376 
1377  // VFALCO NOTE Unfortunately, in stand-alone mode some code still
1378  // foolishly calls overlay(). When this is fixed we can
1379  // move the instantiation inside a conditional:
1380  //
1381  // if (!config_.standalone())
1382  if (!config_->reporting())
1383  {
1385  *this,
1387  *serverHandler_,
1389  *m_resolver,
1390  get_io_service(),
1391  *config_,
1392  m_collectorManager->collector());
1393  add(*overlay_); // add to PropertyStream
1394  }
1395 
1396  if (!config_->standalone())
1397  {
1398  // NodeStore import into the ShardStore requires the SQLite database
1399  if (config_->nodeToShard && !nodeToShards())
1400  return false;
1401  }
1402 
1403  // start first consensus round
1404  if (!config_->reporting() &&
1405  !m_networkOPs->beginConsensus(
1406  m_ledgerMaster->getClosedLedger()->info().hash))
1407  {
1408  JLOG(m_journal.fatal()) << "Unable to start consensus";
1409  return false;
1410  }
1411 
1412  {
1413  try
1414  {
1415  auto setup = setup_ServerHandler(
1417  setup.makeContexts();
1418  serverHandler_->setup(setup, m_journal);
1419  }
1420  catch (std::exception const& e)
1421  {
1422  if (auto stream = m_journal.fatal())
1423  {
1424  stream << "Unable to setup server handler";
1425  if (std::strlen(e.what()) > 0)
1426  stream << ": " << e.what();
1427  }
1428  return false;
1429  }
1430  }
1431 
1432  // Begin connecting to network.
1433  if (!config_->standalone())
1434  {
1435  // Should this message be here, conceptually? In theory this sort
1436  // of message, if displayed, should be displayed from PeerFinder.
1437  if (config_->PEER_PRIVATE && config_->IPS_FIXED.empty())
1438  {
1439  JLOG(m_journal.warn())
1440  << "No outbound peer connections will be made";
1441  }
1442 
1443  // VFALCO NOTE the state timer resets the deadlock detector.
1444  //
1445  m_networkOPs->setStateTimer();
1446  }
1447  else
1448  {
1449  JLOG(m_journal.warn()) << "Running in standalone mode";
1450 
1451  m_networkOPs->setStandAlone();
1452  }
1453 
1454  if (config_->canSign())
1455  {
1456  JLOG(m_journal.warn()) << "*** The server is configured to allow the "
1457  "'sign' and 'sign_for'";
1458  JLOG(m_journal.warn()) << "*** commands. These commands have security "
1459  "implications and have";
1460  JLOG(m_journal.warn()) << "*** been deprecated. They will be removed "
1461  "in a future release of";
1462  JLOG(m_journal.warn()) << "*** rippled.";
1463  JLOG(m_journal.warn()) << "*** If you do not use them to sign "
1464  "transactions please edit your";
1465  JLOG(m_journal.warn())
1466  << "*** configuration file and remove the [enable_signing] stanza.";
1467  JLOG(m_journal.warn()) << "*** If you do use them to sign transactions "
1468  "please migrate to a";
1469  JLOG(m_journal.warn())
1470  << "*** standalone signing solution as soon as possible.";
1471  }
1472 
1473  //
1474  // Execute start up rpc commands.
1475  //
1476  for (auto cmd : config_->section(SECTION_RPC_STARTUP).lines())
1477  {
1478  Json::Reader jrReader;
1479  Json::Value jvCommand;
1480 
1481  if (!jrReader.parse(cmd, jvCommand))
1482  {
1483  JLOG(m_journal.fatal()) << "Couldn't parse entry in ["
1484  << SECTION_RPC_STARTUP << "]: '" << cmd;
1485  }
1486 
1487  if (!config_->quiet())
1488  {
1489  JLOG(m_journal.fatal())
1490  << "Startup RPC: " << jvCommand << std::endl;
1491  }
1492 
1495  RPC::JsonContext context{
1496  {journal("RPCHandler"),
1497  *this,
1498  loadType,
1499  getOPs(),
1500  getLedgerMaster(),
1501  c,
1502  Role::ADMIN,
1503  {},
1504  {},
1506  jvCommand};
1507 
1508  Json::Value jvResult;
1509  RPC::doCommand(context, jvResult);
1510 
1511  if (!config_->quiet())
1512  {
1513  JLOG(m_journal.fatal()) << "Result: " << jvResult << std::endl;
1514  }
1515  }
1516 
1517  RPC::ShardArchiveHandler* shardArchiveHandler = nullptr;
1518  if (shardStore_)
1519  {
1520  try
1521  {
1522  // Create a ShardArchiveHandler if recovery
1523  // is needed (there's a state database left
1524  // over from a previous run).
1525  auto handler = getShardArchiveHandler(true);
1526 
1527  // Recovery is needed.
1528  if (handler)
1529  shardArchiveHandler = handler;
1530  }
1531  catch (std::exception const& e)
1532  {
1533  JLOG(m_journal.fatal())
1534  << "Exception when starting ShardArchiveHandler from "
1535  "state database: "
1536  << e.what();
1537 
1538  return false;
1539  }
1540  }
1541 
1542  if (shardArchiveHandler && !shardArchiveHandler->start())
1543  {
1544  JLOG(m_journal.fatal()) << "Failed to start ShardArchiveHandler.";
1545 
1546  return false;
1547  }
1548 
1549  validatorSites_->start();
1550 
1551  if (reportingETL_)
1552  reportingETL_->start();
1553 
1554  return true;
1555 }
1556 
1557 void
1558 ApplicationImp::start(bool withTimers)
1559 {
1560  JLOG(m_journal.info()) << "Application starting. Version is "
1562 
1563  if (withTimers)
1564  {
1565  setSweepTimer();
1566  setEntropyTimer();
1567  }
1568 
1570  m_resolver->start();
1571  m_loadManager->start();
1572  m_shaMapStore->start();
1573  if (overlay_)
1574  overlay_->start();
1575  grpcServer_->start();
1576  ledgerCleaner_->start();
1577  perfLog_->start();
1578 }
1579 
1580 void
1582 {
1583  if (!config_->standalone())
1584  {
1585  // VFALCO NOTE This seems unnecessary. If we properly refactor the load
1586  // manager then the deadlock detector can just always be
1587  // "armed"
1588  //
1590  }
1591 
1592  {
1594  cv_.wait(lk, [this] { return isTimeToStop; });
1595  }
1596 
1597  JLOG(m_journal.info()) << "Received shutdown request";
1598  stop();
1599  JLOG(m_journal.info()) << "Done.";
1600 }
1601 
1602 void
1604 {
1605  // Unblock the main thread (which is sitting in run()).
1606  // When we get C++20 this can use std::latch.
1607  std::lock_guard lk{mut_};
1608 
1609  if (!isTimeToStop)
1610  {
1611  isTimeToStop = true;
1612  cv_.notify_all();
1613  }
1614 }
1615 
1616 bool
1618 {
1619  return checkSigs_;
1620 }
1621 
1622 void
1624 {
1625  checkSigs_ = check;
1626 }
1627 
1628 bool
1630 {
1631  std::lock_guard lk{mut_};
1632  return isTimeToStop;
1633 }
1634 
1635 int
1637 {
1638  // Standard handles, config file, misc I/O etc:
1639  int needed = 128;
1640 
1641  // 2x the configured peer limit for peer connections:
1642  if (overlay_)
1643  needed += 2 * overlay_->limit();
1644 
1645  // the number of fds needed by the backend (internally
1646  // doubled if online delete is enabled).
1647  needed += std::max(5, m_shaMapStore->fdRequired());
1648 
1649  if (shardStore_)
1650  needed += shardStore_->fdRequired();
1651 
1652  // One fd per incoming connection a port can accept, or
1653  // if no limit is set, assume it'll handle 256 clients.
1654  for (auto const& p : serverHandler_->setup().ports)
1655  needed += std::max(256, p.limit);
1656 
1657  // The minimum number of file descriptors we need is 1024:
1658  return std::max(1024, needed);
1659 }
1660 
1661 //------------------------------------------------------------------------------
1662 
1663 void
1665 {
1666  std::vector<uint256> initialAmendments =
1667  (config_->START_UP == Config::FRESH) ? m_amendmentTable->getDesired()
1669 
1670  std::shared_ptr<Ledger> const genesis = std::make_shared<Ledger>(
1671  create_genesis, *config_, initialAmendments, nodeFamily_);
1672  m_ledgerMaster->storeLedger(genesis);
1673 
1674  auto const next =
1675  std::make_shared<Ledger>(*genesis, timeKeeper().closeTime());
1676  next->updateSkipList();
1677  next->setImmutable(*config_);
1678  openLedger_.emplace(next, cachedSLEs_, logs_->journal("OpenLedger"));
1679  m_ledgerMaster->storeLedger(next);
1680  m_ledgerMaster->switchLCL(next);
1681 }
1682 
1685 {
1686  auto j = journal("Ledger");
1687 
1688  try
1689  {
1690  auto const [ledger, seq, hash] = getLatestLedger(*this);
1691 
1692  if (!ledger)
1693  return ledger;
1694 
1695  ledger->setImmutable(*config_);
1696 
1697  if (getLedgerMaster().haveLedger(seq))
1698  ledger->setValidated();
1699 
1700  if (ledger->info().hash == hash)
1701  {
1702  JLOG(j.trace()) << "Loaded ledger: " << hash;
1703  return ledger;
1704  }
1705 
1706  if (auto stream = j.error())
1707  {
1708  stream << "Failed on ledger";
1709  Json::Value p;
1710  addJson(p, {*ledger, nullptr, LedgerFill::full});
1711  stream << p;
1712  }
1713 
1714  return {};
1715  }
1716  catch (SHAMapMissingNode const& mn)
1717  {
1718  JLOG(j.warn()) << "Ledger in database: " << mn.what();
1719  return {};
1720  }
1721 }
1722 
1725 {
1726  try
1727  {
1728  std::ifstream ledgerFile(name, std::ios::in);
1729 
1730  if (!ledgerFile)
1731  {
1732  JLOG(m_journal.fatal()) << "Unable to open file '" << name << "'";
1733  return nullptr;
1734  }
1735 
1736  Json::Reader reader;
1737  Json::Value jLedger;
1738 
1739  if (!reader.parse(ledgerFile, jLedger))
1740  {
1741  JLOG(m_journal.fatal()) << "Unable to parse ledger JSON";
1742  return nullptr;
1743  }
1744 
1745  std::reference_wrapper<Json::Value> ledger(jLedger);
1746 
1747  // accept a wrapped ledger
1748  if (ledger.get().isMember("result"))
1749  ledger = ledger.get()["result"];
1750 
1751  if (ledger.get().isMember("ledger"))
1752  ledger = ledger.get()["ledger"];
1753 
1754  std::uint32_t seq = 1;
1755  auto closeTime = timeKeeper().closeTime();
1756  using namespace std::chrono_literals;
1757  auto closeTimeResolution = 30s;
1758  bool closeTimeEstimated = false;
1759  std::uint64_t totalDrops = 0;
1760 
1761  if (ledger.get().isMember("accountState"))
1762  {
1763  if (ledger.get().isMember(jss::ledger_index))
1764  {
1765  seq = ledger.get()[jss::ledger_index].asUInt();
1766  }
1767 
1768  if (ledger.get().isMember("close_time"))
1769  {
1770  using tp = NetClock::time_point;
1771  using d = tp::duration;
1772  closeTime = tp{d{ledger.get()["close_time"].asUInt()}};
1773  }
1774  if (ledger.get().isMember("close_time_resolution"))
1775  {
1776  using namespace std::chrono;
1777  closeTimeResolution =
1778  seconds{ledger.get()["close_time_resolution"].asUInt()};
1779  }
1780  if (ledger.get().isMember("close_time_estimated"))
1781  {
1782  closeTimeEstimated =
1783  ledger.get()["close_time_estimated"].asBool();
1784  }
1785  if (ledger.get().isMember("total_coins"))
1786  {
1787  totalDrops = beast::lexicalCastThrow<std::uint64_t>(
1788  ledger.get()["total_coins"].asString());
1789  }
1790 
1791  ledger = ledger.get()["accountState"];
1792  }
1793 
1794  if (!ledger.get().isArrayOrNull())
1795  {
1796  JLOG(m_journal.fatal()) << "State nodes must be an array";
1797  return nullptr;
1798  }
1799 
1800  auto loadLedger =
1801  std::make_shared<Ledger>(seq, closeTime, *config_, nodeFamily_);
1802  loadLedger->setTotalDrops(totalDrops);
1803 
1804  for (Json::UInt index = 0; index < ledger.get().size(); ++index)
1805  {
1806  Json::Value& entry = ledger.get()[index];
1807 
1808  if (!entry.isObjectOrNull())
1809  {
1810  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1811  return nullptr;
1812  }
1813 
1814  uint256 uIndex;
1815 
1816  if (!uIndex.parseHex(entry[jss::index].asString()))
1817  {
1818  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1819  return nullptr;
1820  }
1821 
1822  entry.removeMember(jss::index);
1823 
1824  STParsedJSONObject stp("sle", ledger.get()[index]);
1825 
1826  if (!stp.object || uIndex.isZero())
1827  {
1828  JLOG(m_journal.fatal()) << "Invalid entry in ledger";
1829  return nullptr;
1830  }
1831 
1832  // VFALCO TODO This is the only place that
1833  // constructor is used, try to remove it
1834  STLedgerEntry sle(*stp.object, uIndex);
1835 
1836  if (!loadLedger->addSLE(sle))
1837  {
1838  JLOG(m_journal.fatal())
1839  << "Couldn't add serialized ledger: " << uIndex;
1840  return nullptr;
1841  }
1842  }
1843 
1844  loadLedger->stateMap().flushDirty(hotACCOUNT_NODE);
1845 
1846  loadLedger->setAccepted(
1847  closeTime, closeTimeResolution, !closeTimeEstimated, *config_);
1848 
1849  return loadLedger;
1850  }
1851  catch (std::exception const& x)
1852  {
1853  JLOG(m_journal.fatal()) << "Ledger contains invalid data: " << x.what();
1854  return nullptr;
1855  }
1856 }
1857 
1858 bool
1860  std::string const& ledgerID,
1861  bool replay,
1862  bool isFileName)
1863 {
1864  try
1865  {
1866  std::shared_ptr<Ledger const> loadLedger, replayLedger;
1867 
1868  if (isFileName)
1869  {
1870  if (!ledgerID.empty())
1871  loadLedger = loadLedgerFromFile(ledgerID);
1872  }
1873  else if (ledgerID.length() == 64)
1874  {
1875  uint256 hash;
1876 
1877  if (hash.parseHex(ledgerID))
1878  {
1879  loadLedger = loadByHash(hash, *this);
1880 
1881  if (!loadLedger)
1882  {
1883  // Try to build the ledger from the back end
1884  auto il = std::make_shared<InboundLedger>(
1885  *this,
1886  hash,
1887  0,
1889  stopwatch(),
1890  make_DummyPeerSet(*this));
1891  if (il->checkLocal())
1892  loadLedger = il->getLedger();
1893  }
1894  }
1895  }
1896  else if (ledgerID.empty() || boost::iequals(ledgerID, "latest"))
1897  {
1898  loadLedger = getLastFullLedger();
1899  }
1900  else
1901  {
1902  // assume by sequence
1903  std::uint32_t index;
1904 
1905  if (beast::lexicalCastChecked(index, ledgerID))
1906  loadLedger = loadByIndex(index, *this);
1907  }
1908 
1909  if (!loadLedger)
1910  return false;
1911 
1912  if (replay)
1913  {
1914  // Replay a ledger close with same prior ledger and transactions
1915 
1916  // this ledger holds the transactions we want to replay
1917  replayLedger = loadLedger;
1918 
1919  JLOG(m_journal.info()) << "Loading parent ledger";
1920 
1921  loadLedger = loadByHash(replayLedger->info().parentHash, *this);
1922  if (!loadLedger)
1923  {
1924  JLOG(m_journal.info())
1925  << "Loading parent ledger from node store";
1926 
1927  // Try to build the ledger from the back end
1928  auto il = std::make_shared<InboundLedger>(
1929  *this,
1930  replayLedger->info().parentHash,
1931  0,
1933  stopwatch(),
1934  make_DummyPeerSet(*this));
1935 
1936  if (il->checkLocal())
1937  loadLedger = il->getLedger();
1938 
1939  if (!loadLedger)
1940  {
1941  JLOG(m_journal.fatal()) << "Replay ledger missing/damaged";
1942  assert(false);
1943  return false;
1944  }
1945  }
1946  }
1947  using namespace std::chrono_literals;
1948  using namespace date;
1949  static constexpr NetClock::time_point ledgerWarnTimePoint{
1950  sys_days{January / 1 / 2018} - sys_days{January / 1 / 2000}};
1951  if (loadLedger->info().closeTime < ledgerWarnTimePoint)
1952  {
1953  JLOG(m_journal.fatal())
1954  << "\n\n*** WARNING ***\n"
1955  "You are replaying a ledger from before "
1956  << to_string(ledgerWarnTimePoint)
1957  << " UTC.\n"
1958  "This replay will not handle your ledger as it was "
1959  "originally "
1960  "handled.\nConsider running an earlier version of rippled "
1961  "to "
1962  "get the older rules.\n*** CONTINUING ***\n";
1963  }
1964 
1965  JLOG(m_journal.info()) << "Loading ledger " << loadLedger->info().hash
1966  << " seq:" << loadLedger->info().seq;
1967 
1968  if (loadLedger->info().accountHash.isZero())
1969  {
1970  JLOG(m_journal.fatal()) << "Ledger is empty.";
1971  assert(false);
1972  return false;
1973  }
1974 
1975  if (!loadLedger->walkLedger(journal("Ledger")))
1976  {
1977  JLOG(m_journal.fatal()) << "Ledger is missing nodes.";
1978  assert(false);
1979  return false;
1980  }
1981 
1982  if (!loadLedger->assertSensible(journal("Ledger")))
1983  {
1984  JLOG(m_journal.fatal()) << "Ledger is not sensible.";
1985  assert(false);
1986  return false;
1987  }
1988 
1989  m_ledgerMaster->setLedgerRangePresent(
1990  loadLedger->info().seq, loadLedger->info().seq);
1991 
1992  m_ledgerMaster->switchLCL(loadLedger);
1993  loadLedger->setValidated();
1994  m_ledgerMaster->setFullLedger(loadLedger, true, false);
1995  openLedger_.emplace(
1996  loadLedger, cachedSLEs_, logs_->journal("OpenLedger"));
1997 
1998  if (replay)
1999  {
2000  // inject transaction(s) from the replayLedger into our open ledger
2001  // and build replay structure
2002  auto replayData =
2003  std::make_unique<LedgerReplay>(loadLedger, replayLedger);
2004 
2005  for (auto const& [_, tx] : replayData->orderedTxns())
2006  {
2007  (void)_;
2008  auto txID = tx->getTransactionID();
2009 
2010  auto s = std::make_shared<Serializer>();
2011  tx->add(*s);
2012 
2014 
2015  openLedger_->modify(
2016  [&txID, &s](OpenView& view, beast::Journal j) {
2017  view.rawTxInsert(txID, std::move(s), nullptr);
2018  return true;
2019  });
2020  }
2021 
2022  m_ledgerMaster->takeReplay(std::move(replayData));
2023  }
2024  }
2025  catch (SHAMapMissingNode const& mn)
2026  {
2027  JLOG(m_journal.fatal())
2028  << "While loading specified ledger: " << mn.what();
2029  return false;
2030  }
2031  catch (boost::bad_lexical_cast&)
2032  {
2033  JLOG(m_journal.fatal())
2034  << "Ledger specified '" << ledgerID << "' is not valid";
2035  return false;
2036  }
2037 
2038  return true;
2039 }
2040 
2041 bool
2043 {
2044  if (!config().ELB_SUPPORT)
2045  return true;
2046 
2047  if (isStopping())
2048  {
2049  reason = "Server is shutting down";
2050  return false;
2051  }
2052 
2053  if (getOPs().isNeedNetworkLedger())
2054  {
2055  reason = "Not synchronized with network yet";
2056  return false;
2057  }
2058 
2059  if (getOPs().isAmendmentBlocked())
2060  {
2061  reason = "Server version too old";
2062  return false;
2063  }
2064 
2065  if (getOPs().isUNLBlocked())
2066  {
2067  reason = "No valid validator list available";
2068  return false;
2069  }
2070 
2071  if (getOPs().getOperatingMode() < OperatingMode::SYNCING)
2072  {
2073  reason = "Not synchronized with network";
2074  return false;
2075  }
2076 
2077  if (!getLedgerMaster().isCaughtUp(reason))
2078  return false;
2079 
2080  if (getFeeTrack().isLoadedLocal())
2081  {
2082  reason = "Too much load";
2083  return false;
2084  }
2085 
2086  return true;
2087 }
2088 
2091 {
2092  return logs_->journal(name);
2093 }
2094 
2095 bool
2097 {
2098  assert(overlay_);
2099  assert(!config_->standalone());
2100 
2101  if (config_->section(ConfigSection::shardDatabase()).empty())
2102  {
2103  JLOG(m_journal.fatal())
2104  << "The [shard_db] configuration setting must be set";
2105  return false;
2106  }
2107  if (!shardStore_)
2108  {
2109  JLOG(m_journal.fatal()) << "Invalid [shard_db] configuration";
2110  return false;
2111  }
2112  shardStore_->importDatabase(getNodeStore());
2113  return true;
2114 }
2115 
2116 void
2118 {
2120  if (seq)
2121  maxDisallowedLedger_ = *seq;
2122 
2123  JLOG(m_journal.trace())
2124  << "Max persisted ledger is " << maxDisallowedLedger_;
2125 }
2126 
2127 //------------------------------------------------------------------------------
2128 
2129 Application::Application() : beast::PropertyStream::Source("app")
2130 {
2131 }
2132 
2133 //------------------------------------------------------------------------------
2134 
2137  std::unique_ptr<Config> config,
2138  std::unique_ptr<Logs> logs,
2139  std::unique_ptr<TimeKeeper> timeKeeper)
2140 {
2141  return std::make_unique<ApplicationImp>(
2142  std::move(config), std::move(logs), std::move(timeKeeper));
2143 }
2144 
2145 } // 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:1840
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:2042
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:1534
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
std::vector::reserve
T reserve(T... args)
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< std::string >
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:1581
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:1603
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:3777
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
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:1171
ripple::ApplicationImp::loadLedgerFromFile
std::shared_ptr< Ledger > loadLedgerFromFile(std::string const &ledgerID)
Definition: Application.cpp:1724
ripple::ApplicationImp::checkSigs
bool checkSigs() const override
Definition: Application.cpp:1617
ripple::ApplicationImp::journal
beast::Journal journal(std::string const &name) override
Definition: Application.cpp:2090
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:2096
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:1429
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:508
ripple::ApplicationImp::getSHAMapStore
SHAMapStore & getSHAMapStore() override
Definition: Application.cpp:795
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:735
ripple::ApplicationImp::loadOldLedger
bool loadOldLedger(std::string const &ledgerID, bool replay, bool isFilename)
Definition: Application.cpp:1859
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::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: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:1684
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:1664
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:2129
ripple::ApplicationImp::setMaxDisallowedLedger
void setMaxDisallowedLedger()
Definition: Application.cpp:2117
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::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: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:1636
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:1629
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:39
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:472
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:147
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:36
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:2136
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:1558
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:654
std::chrono