rippled
LedgerMaster.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/Ledger.h>
22 #include <ripple/app/ledger/LedgerMaster.h>
23 #include <ripple/app/ledger/LedgerReplayer.h>
24 #include <ripple/app/ledger/OpenLedger.h>
25 #include <ripple/app/ledger/OrderBookDB.h>
26 #include <ripple/app/ledger/PendingSaves.h>
27 #include <ripple/app/main/Application.h>
28 #include <ripple/app/misc/AmendmentTable.h>
29 #include <ripple/app/misc/HashRouter.h>
30 #include <ripple/app/misc/LoadFeeTrack.h>
31 #include <ripple/app/misc/NetworkOPs.h>
32 #include <ripple/app/misc/SHAMapStore.h>
33 #include <ripple/app/misc/Transaction.h>
34 #include <ripple/app/misc/TxQ.h>
35 #include <ripple/app/misc/ValidatorList.h>
36 #include <ripple/app/paths/PathRequests.h>
37 #include <ripple/app/rdb/RelationalDBInterface_postgres.h>
38 #include <ripple/app/rdb/backend/RelationalDBInterfacePostgres.h>
39 #include <ripple/app/tx/apply.h>
40 #include <ripple/basics/Log.h>
41 #include <ripple/basics/MathUtilities.h>
42 #include <ripple/basics/TaggedCache.h>
43 #include <ripple/basics/UptimeClock.h>
44 #include <ripple/basics/contract.h>
45 #include <ripple/basics/safe_cast.h>
46 #include <ripple/core/DatabaseCon.h>
47 #include <ripple/core/Pg.h>
48 #include <ripple/core/TimeKeeper.h>
49 #include <ripple/nodestore/DatabaseShard.h>
50 #include <ripple/overlay/Overlay.h>
51 #include <ripple/overlay/Peer.h>
52 #include <ripple/protocol/BuildInfo.h>
53 #include <ripple/protocol/HashPrefix.h>
54 #include <ripple/protocol/digest.h>
55 #include <ripple/resource/Fees.h>
56 #include <algorithm>
57 #include <cassert>
58 #include <chrono>
59 #include <cstdlib>
60 #include <limits>
61 #include <memory>
62 #include <vector>
63 
64 namespace ripple {
65 
66 namespace {
67 
68 //==============================================================================
105 template <class MutexType>
106 class ScopedUnlock
107 {
109 
110 public:
121  explicit ScopedUnlock(std::unique_lock<MutexType>& lock) : lock_(lock)
122  {
123  assert(lock_.owns_lock());
124  lock_.unlock();
125  }
126 
127  ScopedUnlock(ScopedUnlock const&) = delete;
128  ScopedUnlock&
129  operator=(ScopedUnlock const&) = delete;
130 
138  ~ScopedUnlock() noexcept(false)
139  {
140  lock_.lock();
141  }
142 };
143 
144 } // namespace
145 
146 // Don't catch up more than 100 ledgers (cannot exceed 256)
147 static constexpr int MAX_LEDGER_GAP{100};
148 
149 // Don't acquire history if ledger is too old
151 
152 // Don't acquire history if write load is too high
153 static constexpr int MAX_WRITE_LOAD_ACQUIRE{8192};
154 
155 // Helper function for LedgerMaster::doAdvance()
156 // Return true if candidateLedger should be fetched from the network.
157 static bool
159  std::uint32_t const currentLedger,
160  std::uint32_t const ledgerHistory,
161  std::optional<LedgerIndex> const minimumOnline,
162  std::uint32_t const candidateLedger,
163  beast::Journal j)
164 {
165  bool const ret = [&]() {
166  // Fetch ledger if it may be the current ledger
167  if (candidateLedger >= currentLedger)
168  return true;
169 
170  // Or if it is within our configured history range:
171  if (currentLedger - candidateLedger <= ledgerHistory)
172  return true;
173 
174  // Or if greater than or equal to a specific minimum ledger.
175  // Do nothing if the minimum ledger to keep online is unknown.
176  return minimumOnline.has_value() && candidateLedger >= *minimumOnline;
177  }();
178 
179  JLOG(j.trace()) << "Missing ledger " << candidateLedger
180  << (ret ? " should" : " should NOT") << " be acquired";
181  return ret;
182 }
183 
185  Application& app,
187  beast::insight::Collector::ptr const& collector,
188  beast::Journal journal)
189  : app_(app)
190  , m_journal(journal)
191  , mLedgerHistory(collector, app)
192  , standalone_(app_.config().standalone())
193  , fetch_depth_(
194  app_.getSHAMapStore().clampFetchDepth(app_.config().FETCH_DEPTH))
195  , ledger_history_(app_.config().LEDGER_HISTORY)
196  , ledger_fetch_size_(app_.config().getValueFor(SizedItem::ledgerFetch))
197  , fetch_packs_(
198  "FetchPack",
199  65536,
200  std::chrono::seconds{45},
201  stopwatch,
202  app_.journal("TaggedCache"))
203  , m_stats(std::bind(&LedgerMaster::collect_metrics, this), collector)
204 {
205 }
206 
209 {
210  return app_.openLedger().current()->info().seq;
211 }
212 
215 {
216  return mValidLedgerSeq;
217 }
218 
219 bool
221  ReadView const& view,
223  char const* reason)
224 {
225  auto validLedger = getValidatedLedger();
226 
227  if (validLedger && !areCompatible(*validLedger, view, s, reason))
228  {
229  return false;
230  }
231 
232  {
234 
235  if ((mLastValidLedger.second != 0) &&
236  !areCompatible(
237  mLastValidLedger.first,
238  mLastValidLedger.second,
239  view,
240  s,
241  reason))
242  {
243  return false;
244  }
245  }
246 
247  return true;
248 }
249 
252 {
253  using namespace std::chrono_literals;
255  if (pubClose == 0s)
256  {
257  JLOG(m_journal.debug()) << "No published ledger";
258  return weeks{2};
259  }
260 
261  std::chrono::seconds ret = app_.timeKeeper().closeTime().time_since_epoch();
262  ret -= pubClose;
263  ret = (ret > 0s) ? ret : 0s;
264 
265  JLOG(m_journal.trace()) << "Published ledger age is " << ret.count();
266  return ret;
267 }
268 
271 {
272  using namespace std::chrono_literals;
273 
274 #ifdef RIPPLED_REPORTING
275  if (app_.config().reporting())
276  return static_cast<RelationalDBInterfacePostgres*>(
279 #endif
281  if (valClose == 0s)
282  {
283  JLOG(m_journal.debug()) << "No validated ledger";
284  return weeks{2};
285  }
286 
287  std::chrono::seconds ret = app_.timeKeeper().closeTime().time_since_epoch();
288  ret -= valClose;
289  ret = (ret > 0s) ? ret : 0s;
290 
291  JLOG(m_journal.trace()) << "Validated ledger age is " << ret.count();
292  return ret;
293 }
294 
295 bool
297 {
298  using namespace std::chrono_literals;
299 
300 #ifdef RIPPLED_REPORTING
301  if (app_.config().reporting())
302  return static_cast<RelationalDBInterfacePostgres*>(
304  ->isCaughtUp(reason);
305 #endif
306 
307  if (getPublishedLedgerAge() > 3min)
308  {
309  reason = "No recently-published ledger";
310  return false;
311  }
312  std::uint32_t validClose = mValidLedgerSign.load();
313  std::uint32_t pubClose = mPubLedgerClose.load();
314  if (!validClose || !pubClose)
315  {
316  reason = "No published ledger";
317  return false;
318  }
319  if (validClose > (pubClose + 90))
320  {
321  reason = "Published ledger lags validated ledger";
322  return false;
323  }
324  return true;
325 }
326 
327 void
329 {
331  std::optional<uint256> consensusHash;
332 
333  if (!standalone_)
334  {
335  auto validations = app_.validators().negativeUNLFilter(
336  app_.getValidations().getTrustedForLedger(l->info().hash));
337  times.reserve(validations.size());
338  for (auto const& val : validations)
339  times.push_back(val->getSignTime());
340 
341  if (!validations.empty())
342  consensusHash = validations.front()->getConsensusHash();
343  }
344 
345  NetClock::time_point signTime;
346 
347  if (!times.empty() && times.size() >= app_.validators().quorum())
348  {
349  // Calculate the sample median
350  std::sort(times.begin(), times.end());
351  auto const t0 = times[(times.size() - 1) / 2];
352  auto const t1 = times[times.size() / 2];
353  signTime = t0 + (t1 - t0) / 2;
354  }
355  else
356  {
357  signTime = l->info().closeTime;
358  }
359 
360  mValidLedger.set(l);
361  mValidLedgerSign = signTime.time_since_epoch().count();
362  assert(
366  mValidLedgerSeq = l->info().seq;
367 
368  app_.getOPs().updateLocalTx(*l);
370  mLedgerHistory.validatedLedger(l, consensusHash);
372  if (!app_.getOPs().isBlocked())
373  {
375  {
376  JLOG(m_journal.error()) << "One or more unsupported amendments "
377  "activated: server blocked.";
379  }
380  else if (!app_.getOPs().isAmendmentWarned() || l->isFlagLedger())
381  {
382  // Amendments can lose majority, so re-check periodically (every
383  // flag ledger), and clear the flag if appropriate. If an unknown
384  // amendment gains majority log a warning as soon as it's
385  // discovered, then again every flag ledger until the operator
386  // upgrades, the amendment loses majority, or the amendment goes
387  // live and the node gets blocked. Unlike being amendment blocked,
388  // this message may be logged more than once per session, because
389  // the node will otherwise function normally, and this gives
390  // operators an opportunity to see and resolve the warning.
391  if (auto const first =
393  {
394  JLOG(m_journal.error()) << "One or more unsupported amendments "
395  "reached majority. Upgrade before "
396  << to_string(*first)
397  << " to prevent your server from "
398  "becoming amendment blocked.";
400  }
401  else
403  }
404  }
405 }
406 
407 void
409 {
410  mPubLedger = l;
411  mPubLedgerClose = l->info().closeTime.time_since_epoch().count();
412  mPubLedgerSeq = l->info().seq;
413 }
414 
415 void
417  std::shared_ptr<Transaction> const& transaction)
418 {
420  mHeldTransactions.insert(transaction->getSTransaction());
421 }
422 
423 // Validate a ledger's close time and sequence number if we're considering
424 // jumping to that ledger. This helps defend against some rare hostile or
425 // diverged majority scenarios.
426 bool
428 {
429  assert(ledger);
430 
431  // Never jump to a candidate ledger that precedes our
432  // last validated ledger
433 
434  auto validLedger = getValidatedLedger();
435  if (validLedger && (ledger->info().seq < validLedger->info().seq))
436  {
437  JLOG(m_journal.trace())
438  << "Candidate for current ledger has low seq " << ledger->info().seq
439  << " < " << validLedger->info().seq;
440  return false;
441  }
442 
443  // Ensure this ledger's parent close time is within five minutes of
444  // our current time. If we already have a known fully-valid ledger
445  // we perform this check. Otherwise, we only do it if we've built a
446  // few ledgers as our clock can be off when we first start up
447 
448  auto closeTime = app_.timeKeeper().closeTime();
449  auto ledgerClose = ledger->info().parentCloseTime;
450 
451  using namespace std::chrono_literals;
452  if ((validLedger || (ledger->info().seq > 10)) &&
453  ((std::max(closeTime, ledgerClose) - std::min(closeTime, ledgerClose)) >
454  5min))
455  {
456  JLOG(m_journal.warn())
457  << "Candidate for current ledger has close time "
458  << to_string(ledgerClose) << " at network time "
459  << to_string(closeTime) << " seq " << ledger->info().seq;
460  return false;
461  }
462 
463  if (validLedger)
464  {
465  // Sequence number must not be too high. We allow ten ledgers
466  // for time inaccuracies plus a maximum run rate of one ledger
467  // every two seconds. The goal is to prevent a malicious ledger
468  // from increasing our sequence unreasonably high
469 
470  LedgerIndex maxSeq = validLedger->info().seq + 10;
471 
472  if (closeTime > validLedger->info().parentCloseTime)
473  maxSeq += std::chrono::duration_cast<std::chrono::seconds>(
474  closeTime - validLedger->info().parentCloseTime)
475  .count() /
476  2;
477 
478  if (ledger->info().seq > maxSeq)
479  {
480  JLOG(m_journal.warn())
481  << "Candidate for current ledger has high seq "
482  << ledger->info().seq << " > " << maxSeq;
483  return false;
484  }
485 
486  JLOG(m_journal.trace())
487  << "Acceptable seq range: " << validLedger->info().seq
488  << " <= " << ledger->info().seq << " <= " << maxSeq;
489  }
490 
491  return true;
492 }
493 
494 void
496 {
497  assert(lastClosed);
498  if (!lastClosed->isImmutable())
499  LogicError("mutable ledger in switchLCL");
500 
501  if (lastClosed->open())
502  LogicError("The new last closed ledger is open!");
503 
504  {
506  mClosedLedger.set(lastClosed);
507  }
508 
509  if (standalone_)
510  {
511  setFullLedger(lastClosed, true, false);
512  tryAdvance();
513  }
514  else
515  {
516  checkAccept(lastClosed);
517  }
518 }
519 
520 bool
521 LedgerMaster::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
522 {
523  return mLedgerHistory.fixIndex(ledgerIndex, ledgerHash);
524 }
525 
526 bool
528 {
529  bool validated = ledger->info().validated;
530  // Returns true if we already had the ledger
531  return mLedgerHistory.insert(std::move(ledger), validated);
532 }
533 
539 void
541 {
543 
544  app_.openLedger().modify([&](OpenView& view, beast::Journal j) {
545  bool any = false;
546  for (auto const& it : mHeldTransactions)
547  {
548  ApplyFlags flags = tapNONE;
549  auto const result =
550  app_.getTxQ().apply(app_, view, it.second, flags, j);
551  if (result.second)
552  any = true;
553  }
554  return any;
555  });
556 
557  // VFALCO TODO recreate the CanonicalTxSet object instead of resetting
558  // it.
559  // VFALCO NOTE The hash for an open ledger is undefined so we use
560  // something that is a reasonable substitute.
561  mHeldTransactions.reset(app_.openLedger().current()->info().parentHash);
562 }
563 
566 {
568 
570 }
571 
572 void
574 {
575  mBuildingLedgerSeq.store(i);
576 }
577 
578 bool
580 {
582  return boost::icl::contains(mCompleteLedgers, seq);
583 }
584 
585 void
587 {
589  mCompleteLedgers.erase(seq);
590 }
591 
592 // returns Ledgers we have all the nodes for
593 bool
595  std::uint32_t& minVal,
596  std::uint32_t& maxVal)
597 {
598  // Validated ledger is likely not stored in the DB yet so we use the
599  // published ledger which is.
600  maxVal = mPubLedgerSeq.load();
601 
602  if (!maxVal)
603  return false;
604 
606  {
608  maybeMin = prevMissing(mCompleteLedgers, maxVal);
609  }
610 
611  if (maybeMin == std::nullopt)
612  minVal = maxVal;
613  else
614  minVal = 1 + *maybeMin;
615 
616  return true;
617 }
618 
619 // Returns Ledgers we have all the nodes for and are indexed
620 bool
622 {
623  if (app_.config().reporting())
624  {
626  try
627  {
628  if (res == "empty" || res == "error" || res.empty())
629  return false;
630  else if (size_t delim = res.find('-'); delim != std::string::npos)
631  {
632  minVal = std::stol(res.substr(0, delim));
633  maxVal = std::stol(res.substr(delim + 1));
634  }
635  else
636  {
637  minVal = maxVal = std::stol(res);
638  }
639  return true;
640  }
641  catch (std::exception const& e)
642  {
643  JLOG(m_journal.error()) << "LedgerMaster::getValidatedRange: "
644  "exception parsing complete ledgers: "
645  << e.what();
646  return false;
647  }
648  }
649  if (!getFullValidatedRange(minVal, maxVal))
650  return false;
651 
652  // Remove from the validated range any ledger sequences that may not be
653  // fully updated in the database yet
654 
655  auto const pendingSaves = app_.pendingSaves().getSnapshot();
656 
657  if (!pendingSaves.empty() && ((minVal != 0) || (maxVal != 0)))
658  {
659  // Ensure we shrink the tips as much as possible. If we have 7-9 and
660  // 8,9 are invalid, we don't want to see the 8 and shrink to just 9
661  // because then we'll have nothing when we could have 7.
662  while (pendingSaves.count(maxVal) > 0)
663  --maxVal;
664  while (pendingSaves.count(minVal) > 0)
665  ++minVal;
666 
667  // Best effort for remaining exclusions
668  for (auto v : pendingSaves)
669  {
670  if ((v.first >= minVal) && (v.first <= maxVal))
671  {
672  if (v.first > ((minVal + maxVal) / 2))
673  maxVal = v.first - 1;
674  else
675  minVal = v.first + 1;
676  }
677  }
678 
679  if (minVal > maxVal)
680  minVal = maxVal = 0;
681  }
682 
683  return true;
684 }
685 
686 // Get the earliest ledger we will let peers fetch
689 {
690  // The earliest ledger we will let people fetch is ledger zero,
691  // unless that creates a larger range than allowed
692  std::uint32_t e = getClosedLedger()->info().seq;
693 
694  if (e > fetch_depth_)
695  e -= fetch_depth_;
696  else
697  e = 0;
698  return e;
699 }
700 
701 void
703 {
704  std::uint32_t seq = ledger->info().seq;
705  uint256 prevHash = ledger->info().parentHash;
706 
708 
709  std::uint32_t minHas = seq;
710  std::uint32_t maxHas = seq;
711 
712  NodeStore::Database& nodeStore{app_.getNodeStore()};
713  while (!job.shouldCancel() && seq > 0)
714  {
715  {
717  minHas = seq;
718  --seq;
719 
720  if (haveLedger(seq))
721  break;
722  }
723 
724  auto it(ledgerHashes.find(seq));
725 
726  if (it == ledgerHashes.end())
727  {
728  if (app_.isStopping())
729  return;
730 
731  {
733  mCompleteLedgers.insert(range(minHas, maxHas));
734  }
735  maxHas = minHas;
737  (seq < 500) ? 0 : (seq - 499), seq);
738  it = ledgerHashes.find(seq);
739 
740  if (it == ledgerHashes.end())
741  break;
742 
743  if (!nodeStore.fetchNodeObject(
744  ledgerHashes.begin()->second.ledgerHash,
745  ledgerHashes.begin()->first))
746  {
747  // The ledger is not backed by the node store
748  JLOG(m_journal.warn()) << "SQL DB ledger sequence " << seq
749  << " mismatches node store";
750  break;
751  }
752  }
753 
754  if (it->second.ledgerHash != prevHash)
755  break;
756 
757  prevHash = it->second.parentHash;
758  }
759 
760  {
762  mCompleteLedgers.insert(range(minHas, maxHas));
763  }
764  {
766  mFillInProgress = 0;
767  tryAdvance();
768  }
769 }
770 
773 void
775 {
776  LedgerIndex const ledgerIndex([&]() {
777  if (reason == InboundLedger::Reason::SHARD)
778  {
779  // Do not acquire a ledger sequence greater
780  // than the last ledger in the shard
781  auto const shardStore{app_.getShardStore()};
782  auto const shardIndex{shardStore->seqToShardIndex(missing)};
783  return std::min(missing + 1, shardStore->lastLedgerSeq(shardIndex));
784  }
785  return missing + 1;
786  }());
787 
788  auto const haveHash{getLedgerHashForHistory(ledgerIndex, reason)};
789  if (!haveHash || haveHash->isZero())
790  {
791  if (reason == InboundLedger::Reason::SHARD)
792  {
793  auto const shardStore{app_.getShardStore()};
794  auto const shardIndex{shardStore->seqToShardIndex(missing)};
795  if (missing < shardStore->lastLedgerSeq(shardIndex))
796  {
797  JLOG(m_journal.error())
798  << "No hash for fetch pack. "
799  << "Missing ledger sequence " << missing
800  << " while acquiring shard " << shardIndex;
801  }
802  }
803  else
804  {
805  JLOG(m_journal.error())
806  << "No hash for fetch pack. Missing Index " << missing;
807  }
808  return;
809  }
810 
811  // Select target Peer based on highest score. The score is randomized
812  // but biased in favor of Peers with low latency.
813  std::shared_ptr<Peer> target;
814  {
815  int maxScore = 0;
816  auto peerList = app_.overlay().getActivePeers();
817  for (auto const& peer : peerList)
818  {
819  if (peer->hasRange(missing, missing + 1))
820  {
821  int score = peer->getScore(true);
822  if (!target || (score > maxScore))
823  {
824  target = peer;
825  maxScore = score;
826  }
827  }
828  }
829  }
830 
831  if (target)
832  {
833  protocol::TMGetObjectByHash tmBH;
834  tmBH.set_query(true);
835  tmBH.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
836  tmBH.set_ledgerhash(haveHash->begin(), 32);
837  auto packet = std::make_shared<Message>(tmBH, protocol::mtGET_OBJECTS);
838 
839  target->send(packet);
840  JLOG(m_journal.trace()) << "Requested fetch pack for " << missing;
841  }
842  else
843  JLOG(m_journal.debug()) << "No peer for fetch pack";
844 }
845 
846 void
848 {
849  int invalidate = 0;
851 
852  for (std::uint32_t lSeq = ledger.info().seq - 1; lSeq > 0; --lSeq)
853  {
854  if (haveLedger(lSeq))
855  {
856  try
857  {
858  hash = hashOfSeq(ledger, lSeq, m_journal);
859  }
860  catch (std::exception const&)
861  {
862  JLOG(m_journal.warn())
863  << "fixMismatch encounters partial ledger";
864  clearLedger(lSeq);
865  return;
866  }
867 
868  if (hash)
869  {
870  // try to close the seam
871  auto otherLedger = getLedgerBySeq(lSeq);
872 
873  if (otherLedger && (otherLedger->info().hash == *hash))
874  {
875  // we closed the seam
876  if (invalidate != 0)
877  {
878  JLOG(m_journal.warn())
879  << "Match at " << lSeq << ", " << invalidate
880  << " prior ledgers invalidated";
881  }
882 
883  return;
884  }
885  }
886 
887  clearLedger(lSeq);
888  ++invalidate;
889  }
890  }
891 
892  // all prior ledgers invalidated
893  if (invalidate != 0)
894  {
895  JLOG(m_journal.warn())
896  << "All " << invalidate << " prior ledgers invalidated";
897  }
898 }
899 
900 void
902  std::shared_ptr<Ledger const> const& ledger,
903  bool isSynchronous,
904  bool isCurrent)
905 {
906  // A new ledger has been accepted as part of the trusted chain
907  JLOG(m_journal.debug()) << "Ledger " << ledger->info().seq
908  << " accepted :" << ledger->info().hash;
909  assert(ledger->stateMap().getHash().isNonZero());
910 
911  ledger->setValidated();
912  ledger->setFull();
913 
914  if (isCurrent)
915  mLedgerHistory.insert(ledger, true);
916 
917  {
918  // Check the SQL database's entry for the sequence before this
919  // ledger, if it's not this ledger's parent, invalidate it
921  ledger->info().seq - 1);
922  if (prevHash.isNonZero() && prevHash != ledger->info().parentHash)
923  clearLedger(ledger->info().seq - 1);
924  }
925 
926  pendSaveValidated(app_, ledger, isSynchronous, isCurrent);
927 
928  {
930  mCompleteLedgers.insert(ledger->info().seq);
931  }
932 
933  {
935 
936  if (ledger->info().seq > mValidLedgerSeq)
937  setValidLedger(ledger);
938  if (!mPubLedger)
939  {
940  setPubLedger(ledger);
941  app_.getOrderBookDB().setup(ledger);
942  }
943 
944  if (ledger->info().seq != 0 && haveLedger(ledger->info().seq - 1))
945  {
946  // we think we have the previous ledger, double check
947  auto prevLedger = getLedgerBySeq(ledger->info().seq - 1);
948 
949  if (!prevLedger ||
950  (prevLedger->info().hash != ledger->info().parentHash))
951  {
952  JLOG(m_journal.warn())
953  << "Acquired ledger invalidates previous ledger: "
954  << (prevLedger ? "hashMismatch" : "missingLedger");
955  fixMismatch(*ledger);
956  }
957  }
958  }
959 }
960 
961 void
963 {
964  clearLedger(seq);
966 }
967 
968 // Check if the specified ledger can become the new last fully-validated
969 // ledger.
970 void
972 {
973  std::size_t valCount = 0;
974 
975  if (seq != 0)
976  {
977  // Ledger is too old
978  if (seq < mValidLedgerSeq)
979  return;
980 
981  auto validations = app_.validators().negativeUNLFilter(
983  valCount = validations.size();
984  if (valCount >= app_.validators().quorum())
985  {
987  if (seq > mLastValidLedger.second)
988  mLastValidLedger = std::make_pair(hash, seq);
989  }
990 
991  if (seq == mValidLedgerSeq)
992  return;
993 
994  // Ledger could match the ledger we're already building
995  if (seq == mBuildingLedgerSeq)
996  return;
997  }
998 
999  auto ledger = mLedgerHistory.getLedgerByHash(hash);
1000 
1001  if (!ledger)
1002  {
1003  if ((seq != 0) && (getValidLedgerIndex() == 0))
1004  {
1005  // Set peers converged early if we can
1006  if (valCount >= app_.validators().quorum())
1007  app_.overlay().checkTracking(seq);
1008  }
1009 
1010  // FIXME: We may not want to fetch a ledger with just one
1011  // trusted validation
1012  ledger = app_.getInboundLedgers().acquire(
1013  hash, seq, InboundLedger::Reason::GENERIC);
1014  }
1015 
1016  if (ledger)
1017  checkAccept(ledger);
1018 }
1019 
1027 {
1028  return standalone_ ? 0 : app_.validators().quorum();
1029 }
1030 
1031 void
1033 {
1034  // Can we accept this ledger as our new last fully-validated ledger
1035 
1036  if (!canBeCurrent(ledger))
1037  return;
1038 
1039  // Can we advance the last fully-validated ledger? If so, can we
1040  // publish?
1042 
1043  if (ledger->info().seq <= mValidLedgerSeq)
1044  return;
1045 
1046  auto const minVal = getNeededValidations();
1047  auto validations = app_.validators().negativeUNLFilter(
1048  app_.getValidations().getTrustedForLedger(ledger->info().hash));
1049  auto const tvc = validations.size();
1050  if (tvc < minVal) // nothing we can do
1051  {
1052  JLOG(m_journal.trace())
1053  << "Only " << tvc << " validations for " << ledger->info().hash;
1054  return;
1055  }
1056 
1057  JLOG(m_journal.info()) << "Advancing accepted ledger to "
1058  << ledger->info().seq << " with >= " << minVal
1059  << " validations";
1060 
1061  ledger->setValidated();
1062  ledger->setFull();
1063  setValidLedger(ledger);
1064  if (!mPubLedger)
1065  {
1066  pendSaveValidated(app_, ledger, true, true);
1067  setPubLedger(ledger);
1068  app_.getOrderBookDB().setup(ledger);
1069  }
1070 
1071  std::uint32_t const base = app_.getFeeTrack().getLoadBase();
1072  auto fees = app_.getValidations().fees(ledger->info().hash, base);
1073  {
1074  auto fees2 =
1075  app_.getValidations().fees(ledger->info().parentHash, base);
1076  fees.reserve(fees.size() + fees2.size());
1077  std::copy(fees2.begin(), fees2.end(), std::back_inserter(fees));
1078  }
1079  std::uint32_t fee;
1080  if (!fees.empty())
1081  {
1082  std::sort(fees.begin(), fees.end());
1083  fee = fees[fees.size() / 2]; // median
1084  }
1085  else
1086  {
1087  fee = base;
1088  }
1089 
1090  app_.getFeeTrack().setRemoteFee(fee);
1091 
1092  tryAdvance();
1093 
1094  if (ledger->seq() % 256 == 0)
1095  {
1096  // Check if the majority of validators run a higher version rippled
1097  // software. If so print a warning.
1098  //
1099  // Once the HardenedValidations amendment is enabled, validators include
1100  // their rippled software version in the validation messages of every
1101  // (flag - 1) ledger. We wait for one ledger time before checking the
1102  // version information to accumulate more validation messages.
1103 
1104  auto currentTime = app_.timeKeeper().now();
1105  bool needPrint = false;
1106 
1107  // The variable upgradeWarningPrevTime_ will be set when and only when
1108  // the warning is printed.
1110  {
1111  // Have not printed the warning before, check if need to print.
1112  auto const vals = app_.getValidations().getTrustedForLedger(
1113  ledger->info().parentHash);
1114  std::size_t higherVersionCount = 0;
1115  std::size_t rippledCount = 0;
1116  for (auto const& v : vals)
1117  {
1118  if (v->isFieldPresent(sfServerVersion))
1119  {
1120  auto version = v->getFieldU64(sfServerVersion);
1121  higherVersionCount +=
1122  BuildInfo::isNewerVersion(version) ? 1 : 0;
1123  rippledCount +=
1124  BuildInfo::isRippledVersion(version) ? 1 : 0;
1125  }
1126  }
1127  // We report only if (1) we have accumulated validation messages
1128  // from 90% validators from the UNL, (2) 60% of validators
1129  // running the rippled implementation have higher version numbers,
1130  // and (3) the calculation won't cause divide-by-zero.
1131  if (higherVersionCount > 0 && rippledCount > 0)
1132  {
1133  constexpr std::size_t reportingPercent = 90;
1134  constexpr std::size_t cutoffPercent = 60;
1135  auto const unlSize{
1136  app_.validators().getQuorumKeys().second.size()};
1137  needPrint = unlSize > 0 &&
1138  calculatePercent(vals.size(), unlSize) >=
1139  reportingPercent &&
1140  calculatePercent(higherVersionCount, rippledCount) >=
1141  cutoffPercent;
1142  }
1143  }
1144  // To throttle the warning messages, instead of printing a warning
1145  // every flag ledger, we print every week.
1146  else if (currentTime - upgradeWarningPrevTime_ >= weeks{1})
1147  {
1148  // Printed the warning before, and assuming most validators
1149  // do not downgrade, we keep printing the warning
1150  // until the local server is restarted.
1151  needPrint = true;
1152  }
1153 
1154  if (needPrint)
1155  {
1156  upgradeWarningPrevTime_ = currentTime;
1157  auto const upgradeMsg =
1158  "Check for upgrade: "
1159  "A majority of trusted validators are "
1160  "running a newer version.";
1161  std::cerr << upgradeMsg << std::endl;
1162  JLOG(m_journal.error()) << upgradeMsg;
1163  }
1164  }
1165 }
1166 
1168 void
1170  std::shared_ptr<Ledger const> const& ledger,
1171  uint256 const& consensusHash,
1172  Json::Value consensus)
1173 {
1174  // Because we just built a ledger, we are no longer building one
1175  setBuildingLedger(0);
1176 
1177  // No need to process validations in standalone mode
1178  if (standalone_)
1179  return;
1180 
1181  mLedgerHistory.builtLedger(ledger, consensusHash, std::move(consensus));
1182 
1183  if (ledger->info().seq <= mValidLedgerSeq)
1184  {
1185  auto stream = app_.journal("LedgerConsensus").info();
1186  JLOG(stream) << "Consensus built old ledger: " << ledger->info().seq
1187  << " <= " << mValidLedgerSeq;
1188  return;
1189  }
1190 
1191  // See if this ledger can be the new fully-validated ledger
1192  checkAccept(ledger);
1193 
1194  if (ledger->info().seq <= mValidLedgerSeq)
1195  {
1196  auto stream = app_.journal("LedgerConsensus").debug();
1197  JLOG(stream) << "Consensus ledger fully validated";
1198  return;
1199  }
1200 
1201  // This ledger cannot be the new fully-validated ledger, but
1202  // maybe we saved up validations for some other ledger that can be
1203 
1204  auto validations = app_.validators().negativeUNLFilter(
1206 
1207  // Track validation counts with sequence numbers
1208  class valSeq
1209  {
1210  public:
1211  valSeq() : valCount_(0), ledgerSeq_(0)
1212  {
1213  ;
1214  }
1215 
1216  void
1217  mergeValidation(LedgerIndex seq)
1218  {
1219  valCount_++;
1220 
1221  // If we didn't already know the sequence, now we do
1222  if (ledgerSeq_ == 0)
1223  ledgerSeq_ = seq;
1224  }
1225 
1226  std::size_t valCount_;
1227  LedgerIndex ledgerSeq_;
1228  };
1229 
1230  // Count the number of current, trusted validations
1232  for (auto const& v : validations)
1233  {
1234  valSeq& vs = count[v->getLedgerHash()];
1235  vs.mergeValidation(v->getFieldU32(sfLedgerSequence));
1236  }
1237 
1238  auto const neededValidations = getNeededValidations();
1239  auto maxSeq = mValidLedgerSeq.load();
1240  auto maxLedger = ledger->info().hash;
1241 
1242  // Of the ledgers with sufficient validations,
1243  // find the one with the highest sequence
1244  for (auto& v : count)
1245  if (v.second.valCount_ > neededValidations)
1246  {
1247  // If we still don't know the sequence, get it
1248  if (v.second.ledgerSeq_ == 0)
1249  {
1250  if (auto l = getLedgerByHash(v.first))
1251  v.second.ledgerSeq_ = l->info().seq;
1252  }
1253 
1254  if (v.second.ledgerSeq_ > maxSeq)
1255  {
1256  maxSeq = v.second.ledgerSeq_;
1257  maxLedger = v.first;
1258  }
1259  }
1260 
1261  if (maxSeq > mValidLedgerSeq)
1262  {
1263  auto stream = app_.journal("LedgerConsensus").debug();
1264  JLOG(stream) << "Consensus triggered check of ledger";
1265  checkAccept(maxLedger, maxSeq);
1266  }
1267 }
1268 
1271  LedgerIndex index,
1272  InboundLedger::Reason reason)
1273 {
1274  // Try to get the hash of a ledger we need to fetch for history
1276  auto const& l{
1278 
1279  if (l && l->info().seq >= index)
1280  {
1281  ret = hashOfSeq(*l, index, m_journal);
1282  if (!ret)
1283  ret = walkHashBySeq(index, l, reason);
1284  }
1285 
1286  if (!ret)
1287  ret = walkHashBySeq(index, reason);
1288 
1289  return ret;
1290 }
1291 
1295 {
1297 
1298  JLOG(m_journal.trace()) << "findNewLedgersToPublish<";
1299 
1300  // No valid ledger, nothing to do
1301  if (mValidLedger.empty())
1302  {
1303  JLOG(m_journal.trace()) << "No valid journal, nothing to publish.";
1304  return {};
1305  }
1306 
1307  if (!mPubLedger)
1308  {
1309  JLOG(m_journal.info())
1310  << "First published ledger will be " << mValidLedgerSeq;
1311  return {mValidLedger.get()};
1312  }
1313 
1315  {
1316  JLOG(m_journal.warn()) << "Gap in validated ledger stream "
1317  << mPubLedgerSeq << " - " << mValidLedgerSeq - 1;
1318 
1319  auto valLedger = mValidLedger.get();
1320  ret.push_back(valLedger);
1321  setPubLedger(valLedger);
1322  app_.getOrderBookDB().setup(valLedger);
1323 
1324  return {valLedger};
1325  }
1326 
1328  {
1329  JLOG(m_journal.trace()) << "No valid journal, nothing to publish.";
1330  return {};
1331  }
1332 
1333  int acqCount = 0;
1334 
1335  auto pubSeq = mPubLedgerSeq + 1; // Next sequence to publish
1336  auto valLedger = mValidLedger.get();
1337  std::uint32_t valSeq = valLedger->info().seq;
1338 
1339  ScopedUnlock sul{sl};
1340  try
1341  {
1342  for (std::uint32_t seq = pubSeq; seq <= valSeq; ++seq)
1343  {
1344  JLOG(m_journal.trace())
1345  << "Trying to fetch/publish valid ledger " << seq;
1346 
1348  // This can throw
1349  auto hash = hashOfSeq(*valLedger, seq, m_journal);
1350  // VFALCO TODO Restructure this code so that zero is not
1351  // used.
1352  if (!hash)
1353  hash = beast::zero; // kludge
1354  if (seq == valSeq)
1355  {
1356  // We need to publish the ledger we just fully validated
1357  ledger = valLedger;
1358  }
1359  else if (hash->isZero())
1360  {
1361  JLOG(m_journal.fatal()) << "Ledger: " << valSeq
1362  << " does not have hash for " << seq;
1363  assert(false);
1364  }
1365  else
1366  {
1367  ledger = mLedgerHistory.getLedgerByHash(*hash);
1368  }
1369 
1370  if (!app_.config().LEDGER_REPLAY)
1371  {
1372  // Can we try to acquire the ledger we need?
1373  if (!ledger && (++acqCount < ledger_fetch_size_))
1374  ledger = app_.getInboundLedgers().acquire(
1375  *hash, seq, InboundLedger::Reason::GENERIC);
1376  }
1377 
1378  // Did we acquire the next ledger we need to publish?
1379  if (ledger && (ledger->info().seq == pubSeq))
1380  {
1381  ledger->setValidated();
1382  ret.push_back(ledger);
1383  ++pubSeq;
1384  }
1385  }
1386 
1387  JLOG(m_journal.trace())
1388  << "ready to publish " << ret.size() << " ledgers.";
1389  }
1390  catch (std::exception const&)
1391  {
1392  JLOG(m_journal.error())
1393  << "Exception while trying to find ledgers to publish.";
1394  }
1395 
1396  if (app_.config().LEDGER_REPLAY)
1397  {
1398  /* Narrow down the gap of ledgers, and try to replay them.
1399  * When replaying a ledger gap, if the local node has
1400  * the start ledger, it saves an expensive InboundLedger
1401  * acquire. If the local node has the finish ledger, it
1402  * saves a skip list acquire.
1403  */
1404  auto const& startLedger = ret.empty() ? mPubLedger : ret.back();
1405  auto finishLedger = valLedger;
1406  while (startLedger->seq() + 1 < finishLedger->seq())
1407  {
1408  if (auto const parent = mLedgerHistory.getLedgerByHash(
1409  finishLedger->info().parentHash);
1410  parent)
1411  {
1412  finishLedger = parent;
1413  }
1414  else
1415  {
1416  auto numberLedgers =
1417  finishLedger->seq() - startLedger->seq() + 1;
1418  JLOG(m_journal.debug())
1419  << "Publish LedgerReplays " << numberLedgers
1420  << " ledgers, from seq=" << startLedger->info().seq << ", "
1421  << startLedger->info().hash
1422  << " to seq=" << finishLedger->info().seq << ", "
1423  << finishLedger->info().hash;
1426  finishLedger->info().hash,
1427  numberLedgers);
1428  break;
1429  }
1430  }
1431  }
1432 
1433  return ret;
1434 }
1435 
1436 void
1438 {
1440 
1441  // Can't advance without at least one fully-valid ledger
1442  mAdvanceWork = true;
1443  if (!mAdvanceThread && !mValidLedger.empty())
1444  {
1445  mAdvanceThread = true;
1446  app_.getJobQueue().addJob(jtADVANCE, "advanceLedger", [this](Job&) {
1448 
1449  assert(!mValidLedger.empty() && mAdvanceThread);
1450 
1451  JLOG(m_journal.trace()) << "advanceThread<";
1452 
1453  try
1454  {
1455  doAdvance(sl);
1456  }
1457  catch (std::exception const& ex)
1458  {
1459  JLOG(m_journal.fatal()) << "doAdvance throws: " << ex.what();
1460  }
1461 
1462  mAdvanceThread = false;
1463  JLOG(m_journal.trace()) << "advanceThread>";
1464  });
1465  }
1466 }
1467 
1468 void
1470 {
1471  {
1474  {
1475  --mPathFindThread;
1476  return;
1477  }
1478  }
1479 
1480  while (!job.shouldCancel())
1481  {
1483  {
1485 
1486  if (!mValidLedger.empty() &&
1487  (!mPathLedger || (mPathLedger->info().seq != mValidLedgerSeq)))
1488  { // We have a new valid ledger since the last full pathfinding
1490  lastLedger = mPathLedger;
1491  }
1492  else if (mPathFindNewRequest)
1493  { // We have a new request but no new ledger
1494  lastLedger = app_.openLedger().current();
1495  }
1496  else
1497  { // Nothing to do
1498  --mPathFindThread;
1499  return;
1500  }
1501  }
1502 
1503  if (!standalone_)
1504  { // don't pathfind with a ledger that's more than 60 seconds old
1505  using namespace std::chrono;
1506  auto age = time_point_cast<seconds>(app_.timeKeeper().closeTime()) -
1507  lastLedger->info().closeTime;
1508  if (age > 1min)
1509  {
1510  JLOG(m_journal.debug())
1511  << "Published ledger too old for updating paths";
1513  --mPathFindThread;
1514  return;
1515  }
1516  }
1517 
1518  try
1519  {
1521  lastLedger, job.getCancelCallback());
1522  }
1523  catch (SHAMapMissingNode const& mn)
1524  {
1525  JLOG(m_journal.info()) << "During pathfinding: " << mn.what();
1526  if (lastLedger->open())
1527  {
1528  // our parent is the problem
1530  lastLedger->info().parentHash,
1531  lastLedger->info().seq - 1,
1533  }
1534  else
1535  {
1536  // this ledger is the problem
1538  lastLedger->info().hash,
1539  lastLedger->info().seq,
1541  }
1542  }
1543  }
1544 }
1545 
1546 bool
1548 {
1550  mPathFindNewRequest = newPFWork("pf:newRequest", ml);
1551  return mPathFindNewRequest;
1552 }
1553 
1554 bool
1556 {
1558  bool const ret = mPathFindNewRequest;
1559  mPathFindNewRequest = false;
1560  return ret;
1561 }
1562 
1563 // If the order book is radically updated, we need to reprocess all
1564 // pathfinding requests.
1565 bool
1567 {
1569  mPathLedger.reset();
1570 
1571  return newPFWork("pf:newOBDB", ml);
1572 }
1573 
1576 bool
1578  const char* name,
1580 {
1581  if (mPathFindThread < 2)
1582  {
1583  if (app_.getJobQueue().addJob(
1584  jtUPDATE_PF, name, [this](Job& j) { updatePaths(j); }))
1585  {
1586  ++mPathFindThread;
1587  }
1588  }
1589  // If we're stopping don't give callers the expectation that their
1590  // request will be fulfilled, even if it may be serviced.
1591  return mPathFindThread > 0 && !app_.isStopping();
1592 }
1593 
1596 {
1597  return m_mutex;
1598 }
1599 
1600 // The current ledger is the ledger we believe new transactions should go in
1603 {
1604  if (app_.config().reporting())
1605  {
1606  Throw<ReportingShouldProxy>();
1607  }
1608  return app_.openLedger().current();
1609 }
1610 
1613 {
1614 #ifdef RIPPLED_REPORTING
1615  if (app_.config().reporting())
1616  {
1618  if (!seq)
1619  return {};
1620  return getLedgerBySeq(*seq);
1621  }
1622 #endif
1623  return mValidLedger.get();
1624 }
1625 
1626 Rules
1628 {
1629  // Once we have a guarantee that there's always a last validated
1630  // ledger then we can dispense with the if.
1631 
1632  // Return the Rules from the last validated ledger.
1633  if (auto const ledger = getValidatedLedger())
1634  return ledger->rules();
1635 
1636  return Rules(app_.config().features);
1637 }
1638 
1639 // This is the last ledger we published to clients and can lag the validated
1640 // ledger.
1643 {
1644  std::lock_guard lock(m_mutex);
1645  return mPubLedger;
1646 }
1647 
1650 {
1651 #ifdef RIPPLED_REPORTING
1652  if (app_.config().reporting())
1653  return static_cast<RelationalDBInterfacePostgres*>(
1655  ->getCompleteLedgers();
1656 #endif
1658  return to_string(mCompleteLedgers);
1659 }
1660 
1663 {
1664  uint256 hash = getHashBySeq(ledgerIndex);
1665  return hash.isNonZero() ? getCloseTimeByHash(hash, ledgerIndex)
1666  : std::nullopt;
1667 }
1668 
1671  LedgerHash const& ledgerHash,
1672  std::uint32_t index)
1673 {
1674  auto nodeObject = app_.getNodeStore().fetchNodeObject(ledgerHash, index);
1675  if (nodeObject && (nodeObject->getData().size() >= 120))
1676  {
1677  SerialIter it(
1678  nodeObject->getData().data(), nodeObject->getData().size());
1679  if (safe_cast<HashPrefix>(it.get32()) == HashPrefix::ledgerMaster)
1680  {
1681  it.skip(
1682  4 + 8 + 32 + // seq drops parentHash
1683  32 + 32 + 4); // txHash acctHash parentClose
1685  }
1686  }
1687 
1688  return std::nullopt;
1689 }
1690 
1691 uint256
1693 {
1694  uint256 hash = mLedgerHistory.getLedgerHash(index);
1695 
1696  if (hash.isNonZero())
1697  return hash;
1698 
1700 }
1701 
1704 {
1705  std::optional<LedgerHash> ledgerHash;
1706 
1707  if (auto referenceLedger = mValidLedger.get())
1708  ledgerHash = walkHashBySeq(index, referenceLedger, reason);
1709 
1710  return ledgerHash;
1711 }
1712 
1715  std::uint32_t index,
1716  std::shared_ptr<ReadView const> const& referenceLedger,
1717  InboundLedger::Reason reason)
1718 {
1719  if (!referenceLedger || (referenceLedger->info().seq < index))
1720  {
1721  // Nothing we can do. No validated ledger.
1722  return std::nullopt;
1723  }
1724 
1725  // See if the hash for the ledger we need is in the reference ledger
1726  auto ledgerHash = hashOfSeq(*referenceLedger, index, m_journal);
1727  if (ledgerHash)
1728  return ledgerHash;
1729 
1730  // The hash is not in the reference ledger. Get another ledger which can
1731  // be located easily and should contain the hash.
1732  LedgerIndex refIndex = getCandidateLedger(index);
1733  auto const refHash = hashOfSeq(*referenceLedger, refIndex, m_journal);
1734  assert(refHash);
1735  if (refHash)
1736  {
1737  // Try the hash and sequence of a better reference ledger just found
1738  auto ledger = mLedgerHistory.getLedgerByHash(*refHash);
1739 
1740  if (ledger)
1741  {
1742  try
1743  {
1744  ledgerHash = hashOfSeq(*ledger, index, m_journal);
1745  }
1746  catch (SHAMapMissingNode const&)
1747  {
1748  ledger.reset();
1749  }
1750  }
1751 
1752  // Try to acquire the complete ledger
1753  if (!ledger)
1754  {
1755  if (auto const l = app_.getInboundLedgers().acquire(
1756  *refHash, refIndex, reason))
1757  {
1758  ledgerHash = hashOfSeq(*l, index, m_journal);
1759  assert(ledgerHash);
1760  }
1761  }
1762  }
1763  return ledgerHash;
1764 }
1765 
1768 {
1769  if (index <= mValidLedgerSeq)
1770  {
1771  // Always prefer a validated ledger
1772  if (auto valid = mValidLedger.get())
1773  {
1774  if (valid->info().seq == index)
1775  return valid;
1776 
1777  try
1778  {
1779  auto const hash = hashOfSeq(*valid, index, m_journal);
1780 
1781  if (hash)
1782  return mLedgerHistory.getLedgerByHash(*hash);
1783  }
1784  catch (std::exception const&)
1785  {
1786  // Missing nodes are already handled
1787  }
1788  }
1789  }
1790 
1791  if (auto ret = mLedgerHistory.getLedgerBySeq(index))
1792  return ret;
1793 
1794  auto ret = mClosedLedger.get();
1795  if (ret && (ret->info().seq == index))
1796  return ret;
1797 
1798  clearLedger(index);
1799  return {};
1800 }
1801 
1804 {
1805  if (auto ret = mLedgerHistory.getLedgerByHash(hash))
1806  return ret;
1807 
1808  auto ret = mClosedLedger.get();
1809  if (ret && (ret->info().hash == hash))
1810  return ret;
1811 
1812  return {};
1813 }
1814 
1815 void
1817 {
1819  mCompleteLedgers.insert(range(minV, maxV));
1820 }
1821 
1822 void
1824 {
1825  mLedgerHistory.tune(size, age);
1826 }
1827 
1828 void
1830 {
1832  fetch_packs_.sweep();
1833 }
1834 
1835 float
1837 {
1839 }
1840 
1841 void
1843 {
1845  if (seq > 0)
1846  mCompleteLedgers.erase(range(0u, seq - 1));
1847 }
1848 
1849 void
1851 {
1853 }
1854 
1855 void
1857 {
1858  replayData = std::move(replay);
1859 }
1860 
1863 {
1864  return std::move(replayData);
1865 }
1866 
1867 void
1869  std::uint32_t missing,
1870  bool& progress,
1871  InboundLedger::Reason reason,
1873 {
1874  ScopedUnlock sul{sl};
1875  if (auto hash = getLedgerHashForHistory(missing, reason))
1876  {
1877  assert(hash->isNonZero());
1878  auto ledger = getLedgerByHash(*hash);
1879  if (!ledger)
1880  {
1881  if (!app_.getInboundLedgers().isFailure(*hash))
1882  {
1883  ledger =
1884  app_.getInboundLedgers().acquire(*hash, missing, reason);
1885  if (!ledger && missing != fetch_seq_ &&
1886  missing > app_.getNodeStore().earliestLedgerSeq())
1887  {
1888  JLOG(m_journal.trace())
1889  << "fetchForHistory want fetch pack " << missing;
1890  fetch_seq_ = missing;
1891  getFetchPack(missing, reason);
1892  }
1893  else
1894  JLOG(m_journal.trace())
1895  << "fetchForHistory no fetch pack for " << missing;
1896  }
1897  else
1898  JLOG(m_journal.debug())
1899  << "fetchForHistory found failed acquire";
1900  }
1901  if (ledger)
1902  {
1903  auto seq = ledger->info().seq;
1904  assert(seq == missing);
1905  JLOG(m_journal.trace()) << "fetchForHistory acquired " << seq;
1906  if (reason == InboundLedger::Reason::SHARD)
1907  {
1908  ledger->setFull();
1909  {
1910  std::lock_guard lock(m_mutex);
1911  mShardLedger = ledger;
1912  }
1913  if (!ledger->stateMap().family().isShardBacked())
1914  app_.getShardStore()->storeLedger(ledger);
1915  }
1916  else
1917  {
1918  setFullLedger(ledger, false, false);
1919  int fillInProgress;
1920  {
1921  std::lock_guard lock(m_mutex);
1922  mHistLedger = ledger;
1923  fillInProgress = mFillInProgress;
1924  }
1925  if (fillInProgress == 0 &&
1927  ledger->info().parentHash)
1928  {
1929  {
1930  // Previous ledger is in DB
1931  std::lock_guard lock(m_mutex);
1932  mFillInProgress = seq;
1933  }
1935  jtADVANCE, "tryFill", [this, ledger](Job& j) {
1936  tryFill(j, ledger);
1937  });
1938  }
1939  }
1940  progress = true;
1941  }
1942  else
1943  {
1944  std::uint32_t fetchSz;
1945  if (reason == InboundLedger::Reason::SHARD)
1946  // Do not fetch ledger sequences lower
1947  // than the shard's first ledger sequence
1948  fetchSz = app_.getShardStore()->firstLedgerSeq(
1949  app_.getShardStore()->seqToShardIndex(missing));
1950  else
1951  // Do not fetch ledger sequences lower
1952  // than the earliest ledger sequence
1953  fetchSz = app_.getNodeStore().earliestLedgerSeq();
1954  fetchSz = missing >= fetchSz
1955  ? std::min(ledger_fetch_size_, (missing - fetchSz) + 1)
1956  : 0;
1957  try
1958  {
1959  for (std::uint32_t i = 0; i < fetchSz; ++i)
1960  {
1961  std::uint32_t seq = missing - i;
1962  if (auto h = getLedgerHashForHistory(seq, reason))
1963  {
1964  assert(h->isNonZero());
1965  app_.getInboundLedgers().acquire(*h, seq, reason);
1966  }
1967  }
1968  }
1969  catch (std::exception const&)
1970  {
1971  JLOG(m_journal.warn()) << "Threw while prefetching";
1972  }
1973  }
1974  }
1975  else
1976  {
1977  JLOG(m_journal.fatal())
1978  << "Can't find ledger following prevMissing " << missing;
1979  JLOG(m_journal.fatal())
1980  << "Pub:" << mPubLedgerSeq << " Val:" << mValidLedgerSeq;
1981  JLOG(m_journal.fatal())
1982  << "Ledgers: " << app_.getLedgerMaster().getCompleteLedgers();
1983  JLOG(m_journal.fatal())
1984  << "Acquire reason: "
1985  << (reason == InboundLedger::Reason::HISTORY ? "HISTORY" : "SHARD");
1986  clearLedger(missing + 1);
1987  progress = true;
1988  }
1989 }
1990 
1991 // Try to publish ledgers, acquire missing ledgers
1992 void
1994 {
1995  do
1996  {
1997  mAdvanceWork = false; // If there's work to do, we'll make progress
1998  bool progress = false;
1999 
2000  auto const pubLedgers = findNewLedgersToPublish(sl);
2001  if (pubLedgers.empty())
2002  {
2003  if (!standalone_ && !app_.getFeeTrack().isLoadedLocal() &&
2008  {
2009  // We are in sync, so can acquire
2012  {
2014  missing = prevMissing(
2016  mPubLedger->info().seq,
2018  }
2019  if (missing)
2020  {
2021  JLOG(m_journal.trace())
2022  << "tryAdvance discovered missing " << *missing;
2023  if ((mFillInProgress == 0 || *missing > mFillInProgress) &&
2024  shouldAcquire(
2028  *missing,
2029  m_journal))
2030  {
2031  JLOG(m_journal.trace())
2032  << "advanceThread should acquire";
2033  }
2034  else
2035  missing = std::nullopt;
2036  }
2037  if (!missing && mFillInProgress == 0)
2038  {
2039  if (auto shardStore = app_.getShardStore())
2040  {
2041  missing = shardStore->prepareLedger(mValidLedgerSeq);
2042  if (missing)
2044  }
2045  }
2046  if (missing)
2047  {
2048  fetchForHistory(*missing, progress, reason, sl);
2050  {
2051  JLOG(m_journal.debug())
2052  << "tryAdvance found last valid changed";
2053  progress = true;
2054  }
2055  }
2056  }
2057  else
2058  {
2059  mHistLedger.reset();
2060  mShardLedger.reset();
2061  JLOG(m_journal.trace()) << "tryAdvance not fetching history";
2062  }
2063  }
2064  else
2065  {
2066  JLOG(m_journal.trace()) << "tryAdvance found " << pubLedgers.size()
2067  << " ledgers to publish";
2068  for (auto ledger : pubLedgers)
2069  {
2070  {
2071  ScopedUnlock sul{sl};
2072  JLOG(m_journal.debug())
2073  << "tryAdvance publishing seq " << ledger->info().seq;
2074  setFullLedger(ledger, true, true);
2075  }
2076 
2077  setPubLedger(ledger);
2078 
2079  {
2080  ScopedUnlock sul{sl};
2081  app_.getOPs().pubLedger(ledger);
2082  }
2083  }
2084 
2086  progress = newPFWork("pf:newLedger", sl);
2087  }
2088  if (progress)
2089  mAdvanceWork = true;
2090  } while (mAdvanceWork);
2091 }
2092 
2093 void
2095 {
2096  fetch_packs_.canonicalize_replace_client(hash, data);
2097 }
2098 
2101 {
2102  Blob data;
2103  if (fetch_packs_.retrieve(hash, data))
2104  {
2105  fetch_packs_.del(hash, false);
2106  if (hash == sha512Half(makeSlice(data)))
2107  return data;
2108  }
2109  return std::nullopt;
2110 }
2111 
2112 void
2114 {
2115  if (!mGotFetchPackThread.test_and_set(std::memory_order_acquire))
2116  {
2117  app_.getJobQueue().addJob(jtLEDGER_DATA, "gotFetchPack", [&](Job&) {
2119  mGotFetchPackThread.clear(std::memory_order_release);
2120  });
2121  }
2122 }
2123 
2149 static void
2151  SHAMap const& want,
2152  SHAMap const* have,
2153  std::uint32_t cnt,
2154  protocol::TMGetObjectByHash* into,
2155  std::uint32_t seq,
2156  bool withLeaves = true)
2157 {
2158  assert(cnt != 0);
2159 
2160  Serializer s(1024);
2161 
2162  want.visitDifferences(
2163  have,
2164  [&s, withLeaves, &cnt, into, seq](SHAMapTreeNode const& n) -> bool {
2165  if (!withLeaves && n.isLeaf())
2166  return true;
2167 
2168  s.erase();
2169  n.serializeWithPrefix(s);
2170 
2171  auto const& hash = n.getHash().as_uint256();
2172 
2173  protocol::TMIndexedObject* obj = into->add_objects();
2174  obj->set_ledgerseq(seq);
2175  obj->set_hash(hash.data(), hash.size());
2176  obj->set_data(s.getDataPtr(), s.getLength());
2177 
2178  return --cnt != 0;
2179  });
2180 }
2181 
2182 void
2184  std::weak_ptr<Peer> const& wPeer,
2186  uint256 haveLedgerHash,
2187  UptimeClock::time_point uptime)
2188 {
2189  using namespace std::chrono_literals;
2190  if (UptimeClock::now() > uptime + 1s)
2191  {
2192  JLOG(m_journal.info()) << "Fetch pack request got stale";
2193  return;
2194  }
2195 
2196  if (app_.getFeeTrack().isLoadedLocal() || (getValidatedLedgerAge() > 40s))
2197  {
2198  JLOG(m_journal.info()) << "Too busy to make fetch pack";
2199  return;
2200  }
2201 
2202  auto peer = wPeer.lock();
2203 
2204  if (!peer)
2205  return;
2206 
2207  auto have = getLedgerByHash(haveLedgerHash);
2208 
2209  if (!have)
2210  {
2211  JLOG(m_journal.info())
2212  << "Peer requests fetch pack for ledger we don't have: " << have;
2213  peer->charge(Resource::feeRequestNoReply);
2214  return;
2215  }
2216 
2217  if (have->open())
2218  {
2219  JLOG(m_journal.warn())
2220  << "Peer requests fetch pack from open ledger: " << have;
2221  peer->charge(Resource::feeInvalidRequest);
2222  return;
2223  }
2224 
2225  if (have->info().seq < getEarliestFetch())
2226  {
2227  JLOG(m_journal.debug()) << "Peer requests fetch pack that is too early";
2228  peer->charge(Resource::feeInvalidRequest);
2229  return;
2230  }
2231 
2232  auto want = getLedgerByHash(have->info().parentHash);
2233 
2234  if (!want)
2235  {
2236  JLOG(m_journal.info())
2237  << "Peer requests fetch pack for ledger whose predecessor we "
2238  << "don't have: " << have;
2239  peer->charge(Resource::feeRequestNoReply);
2240  return;
2241  }
2242 
2243  try
2244  {
2245  Serializer hdr(128);
2246 
2247  protocol::TMGetObjectByHash reply;
2248  reply.set_query(false);
2249 
2250  if (request->has_seq())
2251  reply.set_seq(request->seq());
2252 
2253  reply.set_ledgerhash(request->ledgerhash());
2254  reply.set_type(protocol::TMGetObjectByHash::otFETCH_PACK);
2255 
2256  // Building a fetch pack:
2257  // 1. Add the header for the requested ledger.
2258  // 2. Add the nodes for the AccountStateMap of that ledger.
2259  // 3. If there are transactions, add the nodes for the
2260  // transactions of the ledger.
2261  // 4. If the FetchPack now contains at least 512 entries then stop.
2262  // 5. If not very much time has elapsed, then loop back and repeat
2263  // the same process adding the previous ledger to the FetchPack.
2264  do
2265  {
2266  std::uint32_t lSeq = want->info().seq;
2267 
2268  {
2269  // Serialize the ledger header:
2270  hdr.erase();
2271 
2273  addRaw(want->info(), hdr);
2274 
2275  // Add the data
2276  protocol::TMIndexedObject* obj = reply.add_objects();
2277  obj->set_hash(
2278  want->info().hash.data(), want->info().hash.size());
2279  obj->set_data(hdr.getDataPtr(), hdr.getLength());
2280  obj->set_ledgerseq(lSeq);
2281  }
2282 
2284  want->stateMap(), &have->stateMap(), 16384, &reply, lSeq);
2285 
2286  // We use nullptr here because transaction maps are per ledger
2287  // and so the requestor is unlikely to already have it.
2288  if (want->info().txHash.isNonZero())
2289  populateFetchPack(want->txMap(), nullptr, 512, &reply, lSeq);
2290 
2291  if (reply.objects().size() >= 512)
2292  break;
2293 
2294  have = std::move(want);
2295  want = getLedgerByHash(have->info().parentHash);
2296  } while (want && UptimeClock::now() <= uptime + 1s);
2297 
2298  auto msg = std::make_shared<Message>(reply, protocol::mtGET_OBJECTS);
2299 
2300  JLOG(m_journal.info())
2301  << "Built fetch pack with " << reply.objects().size() << " nodes ("
2302  << msg->getBufferSize() << " bytes)";
2303 
2304  peer->send(msg);
2305  }
2306  catch (std::exception const&)
2307  {
2308  JLOG(m_journal.warn()) << "Exception building fetch pach";
2309  }
2310 }
2311 
2314 {
2315  return fetch_packs_.getCacheSize();
2316 }
2317 
2318 // Returns the minimum ledger sequence in SQL database, if any.
2321 {
2323 }
2324 
2325 } // namespace ripple
ripple::NetworkOPs::pubLedger
virtual void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted)=0
beast::Journal::fatal
Stream fatal() const
Definition: Journal.h:339
ripple::ReadView::info
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
ripple::LedgerMaster::getValidatedRange
bool getValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
Definition: LedgerMaster.cpp:621
ripple::LedgerMaster::mPubLedger
std::shared_ptr< Ledger const > mPubLedger
Definition: LedgerMaster.h:348
ripple::Resource::feeInvalidRequest
const Charge feeInvalidRequest
Schedule of fees charged for imposing load on the server.
ripple::Application
Definition: Application.h:115
ripple::LedgerMaster::mClosedLedger
LedgerHolder mClosedLedger
Definition: LedgerMaster.h:342
ripple::SHAMap::visitDifferences
void visitDifferences(SHAMap const *have, std::function< bool(SHAMapTreeNode const &)>) const
Visit every node in this SHAMap that is not present in the specified SHAMap.
Definition: SHAMapSync.cpp:100
ripple::Application::getOrderBookDB
virtual OrderBookDB & getOrderBookDB()=0
ripple::InboundLedger::Reason::HISTORY
@ HISTORY
std::optional::has_value
T has_value(T... args)
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
std::lock
T lock(T... args)
ripple::makeSlice
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition: Slice.h:240
ripple::NodeStore::Database::getWriteLoad
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
ripple::LedgerMaster::getPublishedLedger
std::shared_ptr< ReadView const > getPublishedLedger()
Definition: LedgerMaster.cpp:1642
ripple::LedgerIndex
std::uint32_t LedgerIndex
A ledger index.
Definition: Protocol.h:57
std::bind
T bind(T... args)
ripple::LedgerMaster::fetch_packs_
TaggedCache< uint256, Blob > fetch_packs_
Definition: LedgerMaster.h:402
ripple::OpenLedger::current
std::shared_ptr< OpenView const > current() const
Returns a view to the current open ledger.
Definition: OpenLedger.cpp:50
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:51
ripple::LedgerMaster::makeFetchPack
void makeFetchPack(std::weak_ptr< Peer > const &wPeer, std::shared_ptr< protocol::TMGetObjectByHash > const &request, uint256 haveLedgerHash, UptimeClock::time_point uptime)
Definition: LedgerMaster.cpp:2183
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1850
std::string
STL class.
std::shared_ptr< Collector >
ripple::shouldAcquire
static bool shouldAcquire(std::uint32_t const currentLedger, std::uint32_t const ledgerHistory, std::optional< LedgerIndex > const minimumOnline, std::uint32_t const candidateLedger, beast::Journal j)
Definition: LedgerMaster.cpp:158
ripple::LedgerMaster::sweep
void sweep()
Definition: LedgerMaster.cpp:1829
ripple::SizedItem
SizedItem
Definition: Config.h:48
std::exception
STL class.
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:516
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::LedgerMaster::mBuildingLedgerSeq
std::atomic< LedgerIndex > mBuildingLedgerSeq
Definition: LedgerMaster.h:389
ripple::LedgerMaster::app_
Application & app_
Definition: LedgerMaster.h:336
ripple::sfLedgerSequence
const SF_UINT32 sfLedgerSequence
ripple::SHAMapStore::minimumOnline
virtual std::optional< LedgerIndex > minimumOnline() const =0
The minimum ledger to try and maintain in our database.
ripple::apply
std::pair< TER, bool > apply(Application &app, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
Definition: apply.cpp:109
ripple::LedgerMaster::mLedgerHistory
LedgerHistory mLedgerHistory
Definition: LedgerMaster.h:362
std::atomic_flag::test_and_set
T test_and_set(T... args)
ripple::LedgerMaster::mHeldTransactions
CanonicalTXSet mHeldTransactions
Definition: LedgerMaster.h:364
ripple::Serializer::erase
void erase()
Definition: Serializer.h:209
ripple::Config::LEDGER_REPLAY
bool LEDGER_REPLAY
Definition: Config.h:205
std::pair::second
T second
std::vector::reserve
T reserve(T... args)
ripple::CanonicalTXSet::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Definition: CanonicalTXSet.cpp:62
ripple::LedgerHistory::fixIndex
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
Definition: LedgerHistory.cpp:513
ripple::Validations::fees
std::vector< std::uint32_t > fees(ID const &ledgerID, std::uint32_t baseFee)
Returns fees reported by trusted full validators in the given ledger.
Definition: Validations.h:1076
ripple::LedgerHolder::set
void set(std::shared_ptr< Ledger const > ledger)
Definition: LedgerHolder.h:43
ripple::LedgerMaster::getValidLedgerIndex
LedgerIndex getValidLedgerIndex()
Definition: LedgerMaster.cpp:214
ripple::Application::getAmendmentTable
virtual AmendmentTable & getAmendmentTable()=0
ripple::addRaw
void addRaw(LedgerInfo const &info, Serializer &s, bool includeHash)
Definition: View.cpp:164
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::InboundLedger::Reason::GENERIC
@ GENERIC
vector
std::string::find
T find(T... args)
std::vector::size
T size(T... args)
ripple::Application::getRelationalDBInterface
virtual RelationalDBInterface & getRelationalDBInterface()=0
ripple::LedgerMaster::mHistLedger
std::shared_ptr< Ledger const > mHistLedger
Definition: LedgerMaster.h:354
ripple::LedgerMaster::getPublishedLedgerAge
std::chrono::seconds getPublishedLedgerAge()
Definition: LedgerMaster.cpp:251
std::back_inserter
T back_inserter(T... args)
ripple::LedgerMaster::upgradeWarningPrevTime_
TimeKeeper::time_point upgradeWarningPrevTime_
Definition: LedgerMaster.h:411
ripple::SHAMapTreeNode::serializeWithPrefix
virtual void serializeWithPrefix(Serializer &) const =0
Serialize the node in a format appropriate for hashing.
ripple::ValidatorList::getQuorumKeys
QuorumKeys getQuorumKeys() const
Get the quorum and all of the trusted keys.
Definition: ValidatorList.h:658
ripple::LedgerMaster::releaseReplay
std::unique_ptr< LedgerReplay > releaseReplay()
Definition: LedgerMaster.cpp:1862
std::chrono::minutes
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:29
ripple::SHAMapStore::onLedgerClosed
virtual void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger)=0
Called by LedgerMaster every time a ledger validates.
ripple::LedgerMaster::getValidatedRules
Rules getValidatedRules()
Definition: LedgerMaster.cpp:1627
ripple::AmendmentTable::doValidatedLedger
void doValidatedLedger(std::shared_ptr< ReadView const > const &lastValidatedLedger)
Called when a new fully-validated ledger is accepted.
Definition: AmendmentTable.h:92
ripple::LedgerMaster::mCompleteLock
std::recursive_mutex mCompleteLock
Definition: LedgerMaster.h:369
ripple::LedgerHistory::tune
void tune(int size, std::chrono::seconds age)
Set the history cache's parameters.
Definition: LedgerHistory.cpp:527
ripple::LedgerMaster::applyHeldTransactions
void applyHeldTransactions()
Apply held transactions to the open ledger This is normally called as we close the ledger.
Definition: LedgerMaster.cpp:540
ripple::LedgerMaster::switchLCL
void switchLCL(std::shared_ptr< Ledger const > const &lastClosed)
Definition: LedgerMaster.cpp:495
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
std::recursive_mutex
STL class.
ripple::LedgerMaster::newPFWork
bool newPFWork(const char *name, std::unique_lock< std::recursive_mutex > &)
A thread needs to be dispatched to handle pathfinding work of some kind.
Definition: LedgerMaster.cpp:1577
std::lock_guard
STL class.
ripple::NetworkOPs::setAmendmentBlocked
virtual void setAmendmentBlocked()=0
ripple::Application::getShardStore
virtual NodeStore::DatabaseShard * getShardStore()=0
ripple::NetworkOPs::isAmendmentWarned
virtual bool isAmendmentWarned()=0
ripple::LedgerMaster::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
Definition: LedgerMaster.cpp:1803
std::cerr
ripple::Application::isStopping
virtual bool isStopping() const =0
ripple::RelationalDBInterface::getHashByIndex
virtual uint256 getHashByIndex(LedgerIndex ledgerIndex)=0
getHashByIndex Returns hash of ledger with given sequence.
ripple::LedgerMaster::isNewPathRequest
bool isNewPathRequest()
Definition: LedgerMaster.cpp:1555
ripple::JobQueue::addJob
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
Definition: JobQueue.h:166
ripple::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition: chrono.h:88
std::vector::back
T back(T... args)
ripple::LedgerInfo::seq
LedgerIndex seq
Definition: ReadView.h:92
ripple::LoadFeeTrack::getLoadBase
std::uint32_t getLoadBase() const
Definition: LoadFeeTrack.h:87
ripple::jtUPDATE_PF
@ jtUPDATE_PF
Definition: Job.h:47
ripple::Application::timeKeeper
virtual TimeKeeper & timeKeeper()=0
ripple::LedgerMaster::getEarliestFetch
std::uint32_t getEarliestFetch()
Definition: LedgerMaster.cpp:688
ripple::Application::openLedger
virtual OpenLedger & openLedger()=0
ripple::LedgerMaster::walkHashBySeq
std::optional< LedgerHash > walkHashBySeq(std::uint32_t index, InboundLedger::Reason reason)
Walk to a ledger's hash using the skip list.
Definition: LedgerMaster.cpp:1703
ripple::tapNONE
@ tapNONE
Definition: ApplyView.h:30
ripple::SizedItem::ledgerFetch
@ ledgerFetch
ripple::LedgerHistory::sweep
void sweep()
Remove stale cache entries.
Definition: LedgerHistory.h:83
ripple::Resource::feeRequestNoReply
const Charge feeRequestNoReply
ripple::LedgerHistory::getLedgerHash
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
Definition: LedgerHistory.cpp:80
ripple::RelationalDBInterfacePostgres
Definition: RelationalDBInterfacePostgres.h:27
ripple::LedgerMaster::setFullLedger
void setFullLedger(std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Definition: LedgerMaster.cpp:901
std::sort
T sort(T... args)
ripple::LedgerMaster::tune
void tune(int size, std::chrono::seconds age)
Definition: LedgerMaster.cpp:1823
algorithm
ripple::Application::getOPs
virtual NetworkOPs & getOPs()=0
ripple::jtLEDGER_DATA
@ jtLEDGER_DATA
Definition: Job.h:53
ripple::LedgerMaster::fixMismatch
void fixMismatch(ReadView const &ledger)
Definition: LedgerMaster.cpp:847
std::atomic_flag::clear
T clear(T... args)
ripple::LedgerMaster::fetch_depth_
const std::uint32_t fetch_depth_
Definition: LedgerMaster.h:395
ripple::Application::getInboundLedgers
virtual InboundLedgers & getInboundLedgers()=0
ripple::LedgerHistory::builtLedger
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
Report that we have locally built a particular ledger.
Definition: LedgerHistory.cpp:431
ripple::Application::getFeeTrack
virtual LoadFeeTrack & getFeeTrack()=0
ripple::LedgerMaster::getCompleteLedgers
std::string getCompleteLedgers()
Definition: LedgerMaster.cpp:1649
ripple::LedgerMaster::ledger_fetch_size_
const std::uint32_t ledger_fetch_size_
Definition: LedgerMaster.h:400
ripple::RelationalDBInterface::getMinLedgerSeq
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
ripple::Job::getCancelCallback
CancelCallback getCancelCallback() const
Definition: Job.cpp:58
ripple::BuildInfo::isRippledVersion
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
Definition: BuildInfo.cpp:158
ripple::SHAMapMissingNode
Definition: SHAMapMissingNode.h:55
ripple::JobQueue::getJobCount
int getJobCount(JobType t) const
Jobs waiting at this priority.
Definition: JobQueue.cpp:109
std::vector::push_back
T push_back(T... args)
ripple::LedgerMaster::peekMutex
std::recursive_mutex & peekMutex()
Definition: LedgerMaster.cpp:1595
ripple::LedgerMaster::mGotFetchPackThread
std::atomic_flag mGotFetchPackThread
Definition: LedgerMaster.h:382
ripple::base_uint< 256 >
ripple::LoadFeeTrack::isLoadedLocal
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:123
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition: Job.h:43
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
ripple::LedgerMaster::mCompleteLedgers
RangeSet< std::uint32_t > mCompleteLedgers
Definition: LedgerMaster.h:370
std::stol
T stol(T... args)
ripple::NodeStore::Database::firstLedgerSeq
std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const noexcept
Calculates the first ledger sequence for a given shard index.
Definition: Database.h:256
ripple::Config::reporting
bool reporting() const
Definition: Config.h:308
ripple::UptimeClock::now
static time_point now()
Definition: UptimeClock.cpp:63
ripple::RelationalDBInterface::getMaxLedgerSeq
virtual std::optional< LedgerIndex > getMaxLedgerSeq()=0
getMaxLedgerSeq Returns maximum ledger sequence in Ledgers table.
ripple::LedgerMaster::mFillInProgress
int mFillInProgress
Definition: LedgerMaster.h:377
ripple::NetworkOPs::isNeedNetworkLedger
virtual bool isNeedNetworkLedger()=0
ripple::LedgerHistory::insert
bool insert(std::shared_ptr< Ledger const > ledger, bool validated)
Track a ledger.
Definition: LedgerHistory.cpp:62
ripple::sfServerVersion
const SF_UINT64 sfServerVersion
ripple::LedgerMaster::replayData
std::unique_ptr< LedgerReplay > replayData
Definition: LedgerMaster.h:367
ripple::LedgerMaster::gotFetchPack
void gotFetchPack(bool progress, std::uint32_t seq)
Definition: LedgerMaster.cpp:2113
ripple::LedgerMaster::fetchForHistory
void fetchForHistory(std::uint32_t missing, bool &progress, InboundLedger::Reason reason, std::unique_lock< std::recursive_mutex > &)
Definition: LedgerMaster.cpp:1868
ripple::LedgerMaster::getFetchPack
std::optional< Blob > getFetchPack(uint256 const &hash) override
Retrieves partial ledger data of the coresponding hash from peers.
Definition: LedgerMaster.cpp:2100
ripple::LedgerMaster::failedSave
void failedSave(std::uint32_t seq, uint256 const &hash)
Definition: LedgerMaster.cpp:962
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::InboundLedgers::acquire
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
std::atomic::load
T load(T... args)
ripple::Job::shouldCancel
bool shouldCancel() const
Returns true if the running job should make a best-effort cancel.
Definition: Job.cpp:71
ripple::NetworkOPs::setAmendmentWarned
virtual void setAmendmentWarned()=0
ripple::Application::pendingSaves
virtual PendingSaves & pendingSaves()=0
ripple::LedgerHolder::empty
bool empty()
Definition: LedgerHolder.h:62
ripple::LedgerHistory::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
Definition: LedgerHistory.cpp:125
ripple::Serializer::getDataPtr
const void * getDataPtr() const
Definition: Serializer.h:189
ripple::MAX_LEDGER_GAP
static constexpr int MAX_LEDGER_GAP
Definition: LedgerMaster.cpp:147
chrono
ripple::LedgerMaster::getFullValidatedRange
bool getFullValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
Definition: LedgerMaster.cpp:594
ripple::NetworkOPs::updateLocalTx
virtual void updateLocalTx(ReadView const &newValidLedger)=0
ripple::Application::config
virtual Config & config()=0
ripple::LedgerMaster::fixIndex
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Definition: LedgerMaster.cpp:521
ripple::isCurrent
bool isCurrent(ValidationParms const &p, NetClock::time_point now, NetClock::time_point signTime, NetClock::time_point seenTime)
Whether a validation is still current.
Definition: Validations.h:146
std::unique_lock
STL class.
ripple::SHAMap
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:95
ripple::populateFetchPack
static void populateFetchPack(SHAMap const &want, SHAMap const *have, std::uint32_t cnt, protocol::TMGetObjectByHash *into, std::uint32_t seq, bool withLeaves=true)
Populate a fetch pack with data from the map the recipient wants.
Definition: LedgerMaster.cpp:2150
ripple::LedgerHistory::validatedLedger
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
Definition: LedgerHistory.cpp:472
ripple::LedgerMaster::canBeCurrent
bool canBeCurrent(std::shared_ptr< Ledger const > const &ledger)
Check the sequence number and parent close time of a ledger against our clock and last validated ledg...
Definition: LedgerMaster.cpp:427
ripple::Application::getTxQ
virtual TxQ & getTxQ()=0
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
ripple::Application::getJobQueue
virtual JobQueue & getJobQueue()=0
ripple::LedgerMaster::haveLedger
bool haveLedger(std::uint32_t seq)
Definition: LedgerMaster.cpp:579
ripple::AmendmentTable::firstUnsupportedExpected
virtual std::optional< NetClock::time_point > firstUnsupportedExpected() const =0
ripple::calculatePercent
constexpr std::size_t calculatePercent(std::size_t count, std::size_t total)
Calculate one number divided by another number in percentage.
Definition: MathUtilities.h:44
beast::Journal::Stream
Provide a light-weight way to check active() before string formatting.
Definition: Journal.h:194
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
ripple::LedgerMaster::isCompatible
bool isCompatible(ReadView const &, beast::Journal::Stream, char const *reason)
Definition: LedgerMaster.cpp:220
std::chrono::time_point
ripple::LedgerMaster::minSqlSeq
std::optional< LedgerIndex > minSqlSeq()
Definition: LedgerMaster.cpp:2320
ripple::SHAMapTreeNode::isLeaf
virtual bool isLeaf() const =0
Determines if this is a leaf node.
ripple::hashOfSeq
std::optional< uint256 > hashOfSeq(ReadView const &ledger, LedgerIndex seq, beast::Journal journal)
Return the hash of a ledger by sequence.
Definition: View.cpp:644
ripple::OrderBookDB::setup
void setup(std::shared_ptr< ReadView const > const &ledger)
Definition: OrderBookDB.cpp:43
std::copy
T copy(T... args)
ripple::LedgerMaster::getLedgerBySeq
std::shared_ptr< Ledger const > getLedgerBySeq(std::uint32_t index)
Definition: LedgerMaster.cpp:1767
ripple::Overlay::getActivePeers
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
ripple::TimeKeeper::closeTime
virtual time_point closeTime() const =0
Returns the close time, in network time.
ripple::LedgerMaster::newPathRequest
bool newPathRequest()
Definition: LedgerMaster.cpp:1547
ripple::Job
Definition: Job.h:87
ripple::SerialIter
Definition: Serializer.h:310
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::Application::getValidations
virtual RCLValidations & getValidations()=0
std::uint32_t
ripple::LedgerReplayer::replay
void replay(InboundLedger::Reason r, uint256 const &finishLedgerHash, std::uint32_t totalNumLedgers)
Replay a range of ledgers.
Definition: LedgerReplayer.cpp:45
ripple::LedgerMaster::addHeldTransaction
void addHeldTransaction(std::shared_ptr< Transaction > const &trans)
Definition: LedgerMaster.cpp:416
ripple::SerialIter::skip
void skip(int num)
Definition: Serializer.cpp:352
ripple::LedgerMaster::setValidLedger
void setValidLedger(std::shared_ptr< Ledger const > const &l)
Definition: LedgerMaster.cpp:328
ripple::NetworkOPs::clearNeedNetworkLedger
virtual void clearNeedNetworkLedger()=0
std::map
STL class.
ripple::LedgerHistory::getLedgerBySeq
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
Definition: LedgerHistory.cpp:92
ripple::LedgerMaster::mPathFindNewRequest
bool mPathFindNewRequest
Definition: LedgerMaster.h:380
ripple::NodeStore::Database::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous)
Fetch a node object.
Definition: Database.cpp:158
ripple::range
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
Definition: RangeSet.h:53
ripple::Application::getPathRequests
virtual PathRequests & getPathRequests()=0
ripple::LedgerHolder::get
std::shared_ptr< Ledger const > get()
Definition: LedgerHolder.h:55
ripple::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > const &txn)
Definition: CanonicalTXSet.cpp:52
ripple::prevMissing
std::optional< T > prevMissing(RangeSet< T > const &rs, T t, T minVal=0)
Find the largest value not in the set that is less than a given value.
Definition: RangeSet.h:182
ripple::LedgerMaster::getCurrentLedger
std::shared_ptr< ReadView const > getCurrentLedger()
Definition: LedgerMaster.cpp:1602
ripple::PendingSaves::getSnapshot
std::map< LedgerIndex, bool > getSnapshot() const
Get a snapshot of the pending saves.
Definition: PendingSaves.h:137
ripple::Validations::getTrustedForLedger
std::vector< WrappedValidationType > getTrustedForLedger(ID const &ledgerID)
Get trusted full validations for a specific ledger.
Definition: Validations.h:1053
ripple::LedgerMaster::newOrderBookDB
bool newOrderBookDB()
Definition: LedgerMaster.cpp:1566
ripple::LedgerMaster::getNeededValidations
std::size_t getNeededValidations()
Determines how many validations are needed to fully validate a ledger.
Definition: LedgerMaster.cpp:1026
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::ValidatorList::negativeUNLFilter
std::vector< std::shared_ptr< STValidation > > negativeUNLFilter(std::vector< std::shared_ptr< STValidation >> &&validations) const
Remove validations that are from validators on the negative UNL.
Definition: ValidatorList.cpp:1958
ripple::areCompatible
bool areCompatible(ReadView const &validLedger, ReadView const &testLedger, beast::Journal::Stream &s, const char *reason)
Return false if the test ledger is provably incompatible with the valid ledger, that is,...
Definition: View.cpp:482
ripple::LedgerMaster::mAdvanceThread
bool mAdvanceThread
Definition: LedgerMaster.h:373
ripple::LedgerMaster::checkAccept
void checkAccept(std::shared_ptr< Ledger const > const &ledger)
Definition: LedgerMaster.cpp:1032
ripple::Application::validators
virtual ValidatorList & validators()=0
ripple::AmendmentTable::hasUnsupportedEnabled
virtual bool hasUnsupportedEnabled() const =0
returns true if one or more amendments on the network have been enabled that this server does not sup...
std::weak_ptr< Peer >
std::min
T min(T... args)
ripple::SHAMapTreeNode::getHash
SHAMapHash const & getHash() const
Return the hash of this node.
Definition: SHAMapTreeNode.h:143
ripple::LedgerMaster::max_ledger_difference_
const LedgerIndex max_ledger_difference_
Definition: LedgerMaster.h:408
ripple::Serializer
Definition: Serializer.h:39
ripple::LedgerMaster::getFetchPackCacheSize
std::size_t getFetchPackCacheSize() const
Definition: LedgerMaster.cpp:2313
std::string::substr
T substr(T... args)
ripple::BuildInfo::isNewerVersion
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
Definition: BuildInfo.cpp:165
ripple::LedgerMaster::mPathLedger
std::shared_ptr< Ledger const > mPathLedger
Definition: LedgerMaster.h:351
ripple::LedgerMaster::getValidatedLedgerAge
std::chrono::seconds getValidatedLedgerAge()
Definition: LedgerMaster.cpp:270
ripple::LedgerMaster::getClosedLedger
std::shared_ptr< Ledger const > getClosedLedger()
Definition: LedgerMaster.h:98
ripple::LedgerMaster::mAdvanceWork
bool mAdvanceWork
Definition: LedgerMaster.h:376
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:192
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NetworkOPs::isBlocked
virtual bool isBlocked()=0
ripple::Config::features
std::unordered_set< uint256, beast::uhash<> > features
Definition: Config.h:256
ripple::NodeStore::Database::storeLedger
virtual bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger)=0
Store a ledger from a different database.
ripple::LedgerMaster::mPubLedgerClose
std::atomic< std::uint32_t > mPubLedgerClose
Definition: LedgerMaster.h:385
ripple::Application::getNodeStore
virtual NodeStore::Database & getNodeStore()=0
ripple::Application::journal
virtual beast::Journal journal(std::string const &name)=0
ripple::LedgerMaster::ledger_history_
const std::uint32_t ledger_history_
Definition: LedgerMaster.h:398
ripple::LedgerMaster::mPubLedgerSeq
std::atomic< LedgerIndex > mPubLedgerSeq
Definition: LedgerMaster.h:386
cstdlib
std::endl
T endl(T... args)
ripple::LedgerHistory::getCacheHitRate
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
Definition: LedgerHistory.h:53
ripple::LedgerMaster::getCloseTimeBySeq
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
Definition: LedgerMaster.cpp:1662
limits
ripple::LedgerMaster::addFetchPack
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > data)
Definition: LedgerMaster.cpp:2094
ripple::LedgerMaster::clearLedger
void clearLedger(std::uint32_t seq)
Definition: LedgerMaster.cpp:586
std::vector::begin
T begin(T... args)
ripple::NodeStore::Database::seqToShardIndex
std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq) const noexcept
Calculates the shard index for a given ledger sequence.
Definition: Database.h:282
ripple::NetworkOPs::clearAmendmentWarned
virtual void clearAmendmentWarned()=0
ripple::LedgerMaster::getLedgerHashForHistory
std::optional< LedgerHash > getLedgerHashForHistory(LedgerIndex index, InboundLedger::Reason reason)
Definition: LedgerMaster.cpp:1270
ripple::LedgerMaster::m_journal
beast::Journal m_journal
Definition: LedgerMaster.h:337
std
STL namespace.
ripple::LogicError
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
Definition: contract.cpp:48
ripple::sha512Half
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition: digest.h:216
cassert
ripple::MAX_LEDGER_AGE_ACQUIRE
static constexpr std::chrono::minutes MAX_LEDGER_AGE_ACQUIRE
Definition: LedgerMaster.cpp:150
ripple::LedgerMaster::mValidLedgerSeq
std::atomic< LedgerIndex > mValidLedgerSeq
Definition: LedgerMaster.h:388
ripple::LedgerMaster::getCurrentLedgerIndex
LedgerIndex getCurrentLedgerIndex()
Definition: LedgerMaster.cpp:208
ripple::TimeKeeper::now
virtual time_point now() const override=0
Returns the estimate of wall time, in network time.
ripple::Application::overlay
virtual Overlay & overlay()=0
std::chrono::seconds::count
T count(T... args)
ripple::LedgerMaster::takeReplay
void takeReplay(std::unique_ptr< LedgerReplay > replay)
Definition: LedgerMaster.cpp:1856
ripple::LedgerMaster::getValidatedLedger
std::shared_ptr< Ledger const > getValidatedLedger()
Definition: LedgerMaster.cpp:1612
ripple::LedgerMaster::mLastValidLedger
std::pair< uint256, LedgerIndex > mLastValidLedger
Definition: LedgerMaster.h:360
std::vector::empty
T empty(T... args)
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:131
ripple::LedgerHistory::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerHistory.cpp:534
std::optional
ripple::Overlay::checkTracking
virtual void checkTracking(std::uint32_t index)=0
Calls the checkTracking function on each peer.
ripple::LedgerMaster::mShardLedger
std::shared_ptr< Ledger const > mShardLedger
Definition: LedgerMaster.h:357
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::LedgerMaster::updatePaths
void updatePaths(Job &job)
Definition: LedgerMaster.cpp:1469
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:38
std::make_pair
T make_pair(T... args)
ripple::Serializer::add32
int add32(std::uint32_t i)
Definition: Serializer.cpp:38
ripple::LedgerMaster::storeLedger
bool storeLedger(std::shared_ptr< Ledger const > ledger)
Definition: LedgerMaster.cpp:527
std::vector::end
T end(T... args)
ripple::InboundLedger::Reason
Reason
Definition: InboundLedger.h:46
ripple::Application::getLedgerReplayer
virtual LedgerReplayer & getLedgerReplayer()=0
ripple::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapHash.h:43
ripple::Application::getSHAMapStore
virtual SHAMapStore & getSHAMapStore()=0
ripple::LedgerMaster::setLedgerRangePresent
void setLedgerRangePresent(std::uint32_t minV, std::uint32_t maxV)
Definition: LedgerMaster.cpp:1816
ripple::NodeStore::Database::earliestLedgerSeq
std::uint32_t earliestLedgerSeq() const noexcept
Definition: Database.h:237
ripple::jtADVANCE
@ jtADVANCE
Definition: Job.h:59
std::max
T max(T... args)
ripple::RelationalDBInterface::getHashesByIndex
virtual std::optional< LedgerHashPair > getHashesByIndex(LedgerIndex ledgerIndex)=0
getHashesByIndex Returns hash of the ledger and hash of parent ledger for the ledger of given sequenc...
ripple::Serializer::getLength
int getLength() const
Definition: Serializer.h:199
ripple::getCandidateLedger
LedgerIndex getCandidateLedger(LedgerIndex requested)
Find a ledger index from which we could easily get the requested ledger.
Definition: View.h:162
ripple::LedgerMaster::consensusBuilt
void consensusBuilt(std::shared_ptr< Ledger const > const &ledger, uint256 const &consensusHash, Json::Value consensus)
Report that the consensus process built a particular ledger.
Definition: LedgerMaster.cpp:1169
ripple::PathRequests::updateAll
void updateAll(std::shared_ptr< ReadView const > const &ledger, Job::CancelCallback shouldCancel)
Update all of the contained PathRequest instances.
Definition: PathRequests.cpp:58
ripple::SerialIter::get32
std::uint32_t get32()
Definition: Serializer.cpp:386
ripple::LedgerMaster::mValidLedger
LedgerHolder mValidLedger
Definition: LedgerMaster.h:345
ripple::LedgerMaster::fetch_seq_
std::uint32_t fetch_seq_
Definition: LedgerMaster.h:404
ripple::LoadFeeTrack::setRemoteFee
void setRemoteFee(std::uint32_t f)
Definition: LoadFeeTrack.h:59
ripple::LedgerMaster::getHashBySeq
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
Definition: LedgerMaster.cpp:1692
ripple::LedgerMaster::findNewLedgersToPublish
std::vector< std::shared_ptr< Ledger const > > findNewLedgersToPublish(std::unique_lock< std::recursive_mutex > &)
Definition: LedgerMaster.cpp:1293
ripple::pendSaveValidated
bool pendSaveValidated(Application &app, std::shared_ptr< Ledger const > const &ledger, bool isSynchronous, bool isCurrent)
Save, or arrange to save, a fully-validated ledger Returns false on error.
Definition: Ledger.cpp:944
ripple::LedgerMaster::isCaughtUp
bool isCaughtUp(std::string &reason)
Definition: LedgerMaster.cpp:296
std::unique_ptr
STL class.
ripple::LedgerMaster::getCloseTimeByHash
std::optional< NetClock::time_point > getCloseTimeByHash(LedgerHash const &ledgerHash, LedgerIndex ledgerIndex)
Definition: LedgerMaster.cpp:1670
ripple::LedgerMaster::mPathFindThread
int mPathFindThread
Definition: LedgerMaster.h:379
ripple::InboundLedger::Reason::SHARD
@ SHARD
ripple::LedgerMaster::mValidLedgerSign
std::atomic< std::uint32_t > mValidLedgerSign
Definition: LedgerMaster.h:387
ripple::LedgerMaster::setBuildingLedger
void setBuildingLedger(LedgerIndex index)
Definition: LedgerMaster.cpp:573
ripple::LedgerMaster::doAdvance
void doAdvance(std::unique_lock< std::recursive_mutex > &)
Definition: LedgerMaster.cpp:1993
std::unordered_map
STL class.
ripple::LedgerMaster::tryAdvance
void tryAdvance()
Definition: LedgerMaster.cpp:1437
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1842
ripple::LedgerMaster::setPubLedger
void setPubLedger(std::shared_ptr< Ledger const > const &l)
Definition: LedgerMaster.cpp:408
beast::abstract_clock< NetClock >::time_point
typename NetClock ::time_point time_point
Definition: abstract_clock.h:63
ripple::LedgerMaster::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Get the next transaction held for a particular account if any.
Definition: LedgerMaster.cpp:565
ripple::OpenLedger::modify
bool modify(modify_type const &f)
Modify the open ledger.
Definition: OpenLedger.cpp:57
ripple::LedgerMaster::LedgerMaster
LedgerMaster(Application &app, Stopwatch &stopwatch, beast::insight::Collector::ptr const &collector, beast::Journal journal)
Definition: LedgerMaster.cpp:184
ripple::InboundLedgers::isFailure
virtual bool isFailure(uint256 const &h)=0
ripple::LedgerMaster::tryFill
void tryFill(Job &job, std::shared_ptr< Ledger const > ledger)
Definition: LedgerMaster.cpp:702
std::exception::what
T what(T... args)
ripple::LedgerMaster::getCacheHitRate
float getCacheHitRate()
Definition: LedgerMaster.cpp:1836
ripple::CanonicalTXSet::reset
void reset(LedgerHash const &salt)
Definition: CanonicalTXSet.h:129
ripple::MAX_WRITE_LOAD_ACQUIRE
static constexpr int MAX_WRITE_LOAD_ACQUIRE
Definition: LedgerMaster.cpp:153
ripple::ValidatorList::quorum
std::size_t quorum() const
Get quorum value for current trusted key set.
Definition: ValidatorList.h:492
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::Application::getMaxDisallowedLedger
virtual LedgerIndex getMaxDisallowedLedger()=0
Ensure that a newly-started validator does not sign proposals older than the last ledger it persisted...
ripple::LedgerMaster::m_mutex
std::recursive_mutex m_mutex
Definition: LedgerMaster.h:339
ripple::Validations::currentTrusted
std::vector< WrappedValidationType > currentTrusted()
Get the currently trusted full validations.
Definition: Validations.h:995
ripple::LedgerMaster::collect_metrics
void collect_metrics()
Definition: LedgerMaster.h:437
ripple::LedgerMaster::standalone_
const bool standalone_
Definition: LedgerMaster.h:392
std::chrono