rippled
Ledger.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/ledger/AcceptedLedger.h>
21 #include <ripple/app/ledger/InboundLedgers.h>
22 #include <ripple/app/ledger/Ledger.h>
23 #include <ripple/app/ledger/LedgerMaster.h>
24 #include <ripple/app/ledger/LedgerToJson.h>
25 #include <ripple/app/ledger/OrderBookDB.h>
26 #include <ripple/app/ledger/PendingSaves.h>
27 #include <ripple/app/ledger/TransactionMaster.h>
28 #include <ripple/app/main/Application.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/rdb/backend/PostgresDatabase.h>
33 #include <ripple/app/rdb/backend/SQLiteDatabase.h>
34 #include <ripple/basics/Log.h>
35 #include <ripple/basics/StringUtilities.h>
36 #include <ripple/basics/contract.h>
37 #include <ripple/beast/core/LexicalCast.h>
38 #include <ripple/consensus/LedgerTiming.h>
39 #include <ripple/core/Config.h>
40 #include <ripple/core/JobQueue.h>
41 #include <ripple/core/Pg.h>
42 #include <ripple/core/SociDB.h>
43 #include <ripple/json/to_string.h>
44 #include <ripple/nodestore/Database.h>
45 #include <ripple/protocol/Feature.h>
46 #include <ripple/protocol/HashPrefix.h>
47 #include <ripple/protocol/Indexes.h>
48 #include <ripple/protocol/PublicKey.h>
49 #include <ripple/protocol/SecretKey.h>
50 #include <ripple/protocol/UintTypes.h>
51 #include <ripple/protocol/digest.h>
52 #include <ripple/protocol/jss.h>
53 #include <boost/optional.hpp>
54 #include <cassert>
55 #include <utility>
56 #include <vector>
57 
58 #include <ripple/nodestore/impl/DatabaseNodeImp.h>
59 
60 namespace ripple {
61 
63 
64 uint256
66 {
67  // VFALCO This has to match addRaw in View.h.
68  return sha512Half(
70  std::uint32_t(info.seq),
71  std::uint64_t(info.drops.drops()),
72  info.parentHash,
73  info.txHash,
74  info.accountHash,
78  std::uint8_t(info.closeFlags));
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 class Ledger::sles_iter_impl : public sles_type::iter_base
84 {
85 private:
87 
88 public:
89  sles_iter_impl() = delete;
91  operator=(sles_iter_impl const&) = delete;
92 
93  sles_iter_impl(sles_iter_impl const&) = default;
94 
96  {
97  }
98 
100  copy() const override
101  {
102  return std::make_unique<sles_iter_impl>(*this);
103  }
104 
105  bool
106  equal(base_type const& impl) const override
107  {
108  if (auto const p = dynamic_cast<sles_iter_impl const*>(&impl))
109  return iter_ == p->iter_;
110  return false;
111  }
112 
113  void
114  increment() override
115  {
116  ++iter_;
117  }
118 
120  dereference() const override
121  {
122  SerialIter sit(iter_->slice());
123  return std::make_shared<SLE const>(sit, iter_->key());
124  }
125 };
126 
127 //------------------------------------------------------------------------------
128 
129 class Ledger::txs_iter_impl : public txs_type::iter_base
130 {
131 private:
132  bool metadata_;
134 
135 public:
136  txs_iter_impl() = delete;
138  operator=(txs_iter_impl const&) = delete;
139 
140  txs_iter_impl(txs_iter_impl const&) = default;
141 
143  : metadata_(metadata), iter_(std::move(iter))
144  {
145  }
146 
148  copy() const override
149  {
150  return std::make_unique<txs_iter_impl>(*this);
151  }
152 
153  bool
154  equal(base_type const& impl) const override
155  {
156  if (auto const p = dynamic_cast<txs_iter_impl const*>(&impl))
157  return iter_ == p->iter_;
158  return false;
159  }
160 
161  void
162  increment() override
163  {
164  ++iter_;
165  }
166 
168  dereference() const override
169  {
170  auto const& item = *iter_;
171  if (metadata_)
172  return deserializeTxPlusMeta(item);
173  return {deserializeTx(item), nullptr};
174  }
175 };
176 
177 //------------------------------------------------------------------------------
178 
181  Config const& config,
182  std::vector<uint256> const& amendments,
183  Family& family)
184  : mImmutable(false)
185  , txMap_(SHAMapType::TRANSACTION, family)
186  , stateMap_(SHAMapType::STATE, family)
187  , rules_{config.features}
189 {
190  info_.seq = 1;
191  info_.drops = INITIAL_XRP;
192  info_.closeTimeResolution = ledgerGenesisTimeResolution;
193 
194  static auto const id = calcAccountID(
195  generateKeyPair(KeyType::secp256k1, generateSeed("masterpassphrase"))
196  .first);
197  {
198  auto const sle = std::make_shared<SLE>(keylet::account(id));
199  sle->setFieldU32(sfSequence, 1);
200  sle->setAccountID(sfAccount, id);
201  sle->setFieldAmount(sfBalance, info_.drops);
202  rawInsert(sle);
203  }
204 
205  if (!amendments.empty())
206  {
207  auto const sle = std::make_shared<SLE>(keylet::amendments());
208  sle->setFieldV256(sfAmendments, STVector256{amendments});
209  rawInsert(sle);
210  }
211 
212  {
213  auto sle = std::make_shared<SLE>(keylet::fees());
214  // Whether featureXRPFees is supported will depend on startup options.
215  if (std::find(amendments.begin(), amendments.end(), featureXRPFees) !=
216  amendments.end())
217  {
218  sle->at(sfBaseFeeDrops) = config.FEES.reference_fee;
219  sle->at(sfReserveBaseDrops) = config.FEES.account_reserve;
220  sle->at(sfReserveIncrementDrops) = config.FEES.owner_reserve;
221  }
222  else
223  {
224  if (auto const f =
225  config.FEES.reference_fee.dropsAs<std::uint64_t>())
226  sle->at(sfBaseFee) = *f;
227  if (auto const f =
228  config.FEES.account_reserve.dropsAs<std::uint32_t>())
229  sle->at(sfReserveBase) = *f;
230  if (auto const f =
231  config.FEES.owner_reserve.dropsAs<std::uint32_t>())
232  sle->at(sfReserveIncrement) = *f;
234  }
235  rawInsert(sle);
236  }
237 
238  stateMap_.flushDirty(hotACCOUNT_NODE);
239  setImmutable();
240 }
241 
243  LedgerInfo const& info,
244  bool& loaded,
245  bool acquire,
246  Config const& config,
247  Family& family,
248  beast::Journal j)
249  : mImmutable(true)
250  , txMap_(SHAMapType::TRANSACTION, info.txHash, family)
251  , stateMap_(SHAMapType::STATE, info.accountHash, family)
252  , rules_(config.features)
253  , info_(info)
254  , j_(j)
255 {
256  loaded = true;
257 
258  if (info_.txHash.isNonZero() &&
259  !txMap_.fetchRoot(SHAMapHash{info_.txHash}, nullptr))
260  {
261  if (config.reporting())
262  {
263  // Reporting should never have incomplete data
264  Throw<std::runtime_error>("Missing tx map root for ledger");
265  }
266  loaded = false;
267  JLOG(j.warn()) << "Don't have transaction root for ledger" << info_.seq;
268  }
269 
270  if (info_.accountHash.isNonZero() &&
271  !stateMap_.fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
272  {
273  if (config.reporting())
274  {
275  // Reporting should never have incomplete data
276  Throw<std::runtime_error>("Missing state map root for ledger");
277  }
278  loaded = false;
279  JLOG(j.warn()) << "Don't have state data root for ledger" << info_.seq;
280  }
281 
284 
285  defaultFees(config);
286  if (!setup())
287  loaded = false;
288 
289  if (!loaded)
290  {
292  if (acquire && !config.reporting())
294  }
295 }
296 
297 // Create a new ledger that follows this one
298 Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
299  : mImmutable(false)
300  , txMap_(SHAMapType::TRANSACTION, prevLedger.txMap_.family())
301  , stateMap_(prevLedger.stateMap_, true)
302  , fees_(prevLedger.fees_)
303  , rules_(prevLedger.rules_)
304  , j_(beast::Journal(beast::Journal::getNullSink()))
305 {
306  info_.seq = prevLedger.info_.seq + 1;
307  info_.parentCloseTime = prevLedger.info_.closeTime;
308  info_.hash = prevLedger.info().hash + uint256(1);
309  info_.drops = prevLedger.info().drops;
311  info_.parentHash = prevLedger.info().hash;
313  prevLedger.info_.closeTimeResolution,
314  getCloseAgree(prevLedger.info()),
315  info_.seq);
316 
317  if (prevLedger.info_.closeTime == NetClock::time_point{})
318  {
320  }
321  else
322  {
323  info_.closeTime =
325  }
326 }
327 
328 Ledger::Ledger(LedgerInfo const& info, Config const& config, Family& family)
329  : mImmutable(true)
330  , txMap_(SHAMapType::TRANSACTION, info.txHash, family)
331  , stateMap_(SHAMapType::STATE, info.accountHash, family)
332  , rules_{config.features}
333  , info_(info)
335 {
336  info_.hash = calculateLedgerHash(info_);
337 }
338 
340  std::uint32_t ledgerSeq,
341  NetClock::time_point closeTime,
342  Config const& config,
343  Family& family)
344  : mImmutable(false)
345  , txMap_(SHAMapType::TRANSACTION, family)
346  , stateMap_(SHAMapType::STATE, family)
347  , rules_{config.features}
349 {
350  info_.seq = ledgerSeq;
351  info_.closeTime = closeTime;
352  info_.closeTimeResolution = ledgerDefaultTimeResolution;
353  defaultFees(config);
354  setup();
355 }
356 
357 void
359 {
360  // Force update, since this is the only
361  // place the hash transitions to valid
362  if (!mImmutable && rehash)
363  {
366  }
367 
368  if (rehash)
370 
371  mImmutable = true;
374  setup();
375 }
376 
377 void
379  NetClock::time_point closeTime,
380  NetClock::duration closeResolution,
381  bool correctCloseTime)
382 {
383  // Used when we witnessed the consensus.
384  assert(!open());
385 
386  info_.closeTime = closeTime;
387  info_.closeTimeResolution = closeResolution;
388  info_.closeFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
389  setImmutable();
390 }
391 
392 bool
393 Ledger::addSLE(SLE const& sle)
394 {
395  auto const s = sle.getSerializer();
396  return stateMap_.addItem(
398 }
399 
400 //------------------------------------------------------------------------------
401 
404 {
405  SerialIter sit(item.slice());
406  return std::make_shared<STTx const>(sit);
407 }
408 
411 {
413  result;
414  SerialIter sit(item.slice());
415  {
416  SerialIter s(sit.getSlice(sit.getVLDataLength()));
417  result.first = std::make_shared<STTx const>(s);
418  }
419  {
420  SerialIter s(sit.getSlice(sit.getVLDataLength()));
421  result.second = std::make_shared<STObject const>(s, sfMetadata);
422  }
423  return result;
424 }
425 
426 //------------------------------------------------------------------------------
427 
428 bool
429 Ledger::exists(Keylet const& k) const
430 {
431  // VFALCO NOTE Perhaps check the type for debug builds?
432  return stateMap_.hasItem(k.key);
433 }
434 
435 bool
436 Ledger::exists(uint256 const& key) const
437 {
438  return stateMap_.hasItem(key);
439 }
440 
442 Ledger::succ(uint256 const& key, std::optional<uint256> const& last) const
443 {
444  auto item = stateMap_.upper_bound(key);
445  if (item == stateMap_.end())
446  return std::nullopt;
447  if (last && item->key() >= last)
448  return std::nullopt;
449  return item->key();
450 }
451 
453 Ledger::read(Keylet const& k) const
454 {
455  if (k.key == beast::zero)
456  {
457  assert(false);
458  return nullptr;
459  }
460  auto const& item = stateMap_.peekItem(k.key);
461  if (!item)
462  return nullptr;
463  auto sle = std::make_shared<SLE>(SerialIter{item->slice()}, item->key());
464  if (!k.check(*sle))
465  return nullptr;
466  return sle;
467 }
468 
469 //------------------------------------------------------------------------------
470 
471 auto
472 Ledger::slesBegin() const -> std::unique_ptr<sles_type::iter_base>
473 {
474  return std::make_unique<sles_iter_impl>(stateMap_.begin());
475 }
476 
477 auto
478 Ledger::slesEnd() const -> std::unique_ptr<sles_type::iter_base>
479 {
480  return std::make_unique<sles_iter_impl>(stateMap_.end());
481 }
482 
483 auto
486 {
487  return std::make_unique<sles_iter_impl>(stateMap_.upper_bound(key));
488 }
489 
490 auto
491 Ledger::txsBegin() const -> std::unique_ptr<txs_type::iter_base>
492 {
493  return std::make_unique<txs_iter_impl>(!open(), txMap_.begin());
494 }
495 
496 auto
497 Ledger::txsEnd() const -> std::unique_ptr<txs_type::iter_base>
498 {
499  return std::make_unique<txs_iter_impl>(!open(), txMap_.end());
500 }
501 
502 bool
503 Ledger::txExists(uint256 const& key) const
504 {
505  return txMap_.hasItem(key);
506 }
507 
508 auto
509 Ledger::txRead(key_type const& key) const -> tx_type
510 {
511  auto const& item = txMap_.peekItem(key);
512  if (!item)
513  return {};
514  if (!open())
515  {
516  auto result = deserializeTxPlusMeta(*item);
517  return {std::move(result.first), std::move(result.second)};
518  }
519  return {deserializeTx(*item), nullptr};
520 }
521 
522 auto
524 {
526  // VFALCO Unfortunately this loads the item
527  // from the NodeStore needlessly.
528  if (!stateMap_.peekItem(key, digest))
529  return std::nullopt;
530  return digest.as_uint256();
531 }
532 
533 //------------------------------------------------------------------------------
534 
535 void
537 {
538  if (!stateMap_.delItem(sle->key()))
539  LogicError("Ledger::rawErase: key not found");
540 }
541 
542 void
544 {
545  if (!stateMap_.delItem(key))
546  LogicError("Ledger::rawErase: key not found");
547 }
548 
549 void
551 {
552  Serializer ss;
553  sle->add(ss);
554  if (!stateMap_.addGiveItem(
556  make_shamapitem(sle->key(), ss.slice())))
557  LogicError("Ledger::rawInsert: key already exists");
558 }
559 
560 void
562 {
563  Serializer ss;
564  sle->add(ss);
567  make_shamapitem(sle->key(), ss.slice())))
568  LogicError("Ledger::rawReplace: key not found");
569 }
570 
571 void
573  uint256 const& key,
575  std::shared_ptr<Serializer const> const& metaData)
576 {
577  assert(metaData);
578 
579  // low-level - just add to table
580  Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
581  s.addVL(txn->peekData());
582  s.addVL(metaData->peekData());
583  if (!txMap_.addGiveItem(
585  LogicError("duplicate_tx: " + to_string(key));
586 }
587 
588 uint256
590  uint256 const& key,
592  std::shared_ptr<Serializer const> const& metaData)
593 {
594  assert(metaData);
595 
596  // low-level - just add to table
597  Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
598  s.addVL(txn->peekData());
599  s.addVL(metaData->peekData());
600  auto item = make_shamapitem(key, s.slice());
601  auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key());
602  if (!txMap_.addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, std::move(item)))
603  LogicError("duplicate_tx: " + to_string(key));
604 
605  return hash;
606 }
607 
608 bool
610 {
611  bool ret = true;
612 
613  try
614  {
616  }
617  catch (SHAMapMissingNode const&)
618  {
619  ret = false;
620  }
621  catch (std::exception const& ex)
622  {
623  JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
624  Rethrow();
625  }
626 
627  try
628  {
629  if (auto const sle = read(keylet::fees()))
630  {
631  bool oldFees = false;
632  bool newFees = false;
633  {
634  auto const baseFee = sle->at(~sfBaseFee);
635  auto const reserveBase = sle->at(~sfReserveBase);
636  auto const reserveIncrement = sle->at(~sfReserveIncrement);
637  if (baseFee)
638  fees_.base = *baseFee;
639  if (reserveBase)
640  fees_.reserve = *reserveBase;
641  if (reserveIncrement)
642  fees_.increment = *reserveIncrement;
643  oldFees = baseFee || reserveBase || reserveIncrement;
644  }
645  {
646  auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
647  auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
648  auto const reserveIncrementXRP =
649  sle->at(~sfReserveIncrementDrops);
650  auto assign = [&ret](
651  XRPAmount& dest,
652  std::optional<STAmount> const& src) {
653  if (src)
654  {
655  if (src->native())
656  dest = src->xrp();
657  else
658  ret = false;
659  }
660  };
661  assign(fees_.base, baseFeeXRP);
662  assign(fees_.reserve, reserveBaseXRP);
663  assign(fees_.increment, reserveIncrementXRP);
664  newFees = baseFeeXRP || reserveBaseXRP || reserveIncrementXRP;
665  }
666  if (oldFees && newFees)
667  // Should be all of one or the other, but not both
668  ret = false;
669  if (!rules_.enabled(featureXRPFees) && newFees)
670  // Can't populate the new fees before the amendment is enabled
671  ret = false;
672  }
673  }
674  catch (SHAMapMissingNode const&)
675  {
676  ret = false;
677  }
678  catch (std::exception const& ex)
679  {
680  JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
681  Rethrow();
682  }
683 
684  return ret;
685 }
686 
687 void
689 {
690  assert(fees_.base == 0 && fees_.reserve == 0 && fees_.increment == 0);
691  if (fees_.base == 0)
692  fees_.base = config.FEES.reference_fee;
693  if (fees_.reserve == 0)
695  if (fees_.increment == 0)
697 }
698 
700 Ledger::peek(Keylet const& k) const
701 {
702  auto const& value = stateMap_.peekItem(k.key);
703  if (!value)
704  return nullptr;
705  auto sle = std::make_shared<SLE>(SerialIter{value->slice()}, value->key());
706  if (!k.check(*sle))
707  return nullptr;
708  return sle;
709 }
710 
713 {
714  hash_set<PublicKey> negUnl;
715  if (auto sle = read(keylet::negativeUNL());
716  sle && sle->isFieldPresent(sfDisabledValidators))
717  {
718  auto const& nUnlData = sle->getFieldArray(sfDisabledValidators);
719  for (auto const& n : nUnlData)
720  {
721  if (n.isFieldPresent(sfPublicKey))
722  {
723  auto d = n.getFieldVL(sfPublicKey);
724  auto s = makeSlice(d);
725  if (!publicKeyType(s))
726  {
727  continue;
728  }
729  negUnl.emplace(s);
730  }
731  }
732  }
733 
734  return negUnl;
735 }
736 
739 {
740  if (auto sle = read(keylet::negativeUNL());
741  sle && sle->isFieldPresent(sfValidatorToDisable))
742  {
743  auto d = sle->getFieldVL(sfValidatorToDisable);
744  auto s = makeSlice(d);
745  if (publicKeyType(s))
746  return PublicKey(s);
747  }
748 
749  return std::nullopt;
750 }
751 
754 {
755  if (auto sle = read(keylet::negativeUNL());
756  sle && sle->isFieldPresent(sfValidatorToReEnable))
757  {
758  auto d = sle->getFieldVL(sfValidatorToReEnable);
759  auto s = makeSlice(d);
760  if (publicKeyType(s))
761  return PublicKey(s);
762  }
763 
764  return std::nullopt;
765 }
766 
767 void
769 {
770  auto sle = peek(keylet::negativeUNL());
771  if (!sle)
772  return;
773 
774  bool const hasToDisable = sle->isFieldPresent(sfValidatorToDisable);
775  bool const hasToReEnable = sle->isFieldPresent(sfValidatorToReEnable);
776 
777  if (!hasToDisable && !hasToReEnable)
778  return;
779 
780  STArray newNUnl;
781  if (sle->isFieldPresent(sfDisabledValidators))
782  {
783  auto const& oldNUnl = sle->getFieldArray(sfDisabledValidators);
784  for (auto v : oldNUnl)
785  {
786  if (hasToReEnable && v.isFieldPresent(sfPublicKey) &&
787  v.getFieldVL(sfPublicKey) ==
788  sle->getFieldVL(sfValidatorToReEnable))
789  continue;
790  newNUnl.push_back(v);
791  }
792  }
793 
794  if (hasToDisable)
795  {
797  newNUnl.back().setFieldVL(
798  sfPublicKey, sle->getFieldVL(sfValidatorToDisable));
800  }
801 
802  if (!newNUnl.empty())
803  {
804  sle->setFieldArray(sfDisabledValidators, newNUnl);
805  if (hasToReEnable)
806  sle->makeFieldAbsent(sfValidatorToReEnable);
807  if (hasToDisable)
808  sle->makeFieldAbsent(sfValidatorToDisable);
809  rawReplace(sle);
810  }
811  else
812  {
813  rawErase(sle);
814  }
815 }
816 
817 //------------------------------------------------------------------------------
818 bool
819 Ledger::walkLedger(beast::Journal j, bool parallel) const
820 {
821  std::vector<SHAMapMissingNode> missingNodes1;
822  std::vector<SHAMapMissingNode> missingNodes2;
823 
825  !stateMap_.fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
826  {
827  missingNodes1.emplace_back(
829  }
830  else
831  {
832  if (parallel)
833  return stateMap_.walkMapParallel(missingNodes1, 32);
834  else
835  stateMap_.walkMap(missingNodes1, 32);
836  }
837 
838  if (!missingNodes1.empty())
839  {
840  if (auto stream = j.info())
841  {
842  stream << missingNodes1.size() << " missing account node(s)";
843  stream << "First: " << missingNodes1[0].what();
844  }
845  }
846 
847  if (txMap_.getHash().isZero() && info_.txHash.isNonZero() &&
848  !txMap_.fetchRoot(SHAMapHash{info_.txHash}, nullptr))
849  {
850  missingNodes2.emplace_back(
852  }
853  else
854  {
855  txMap_.walkMap(missingNodes2, 32);
856  }
857 
858  if (!missingNodes2.empty())
859  {
860  if (auto stream = j.info())
861  {
862  stream << missingNodes2.size() << " missing transaction node(s)";
863  stream << "First: " << missingNodes2[0].what();
864  }
865  }
866  return missingNodes1.empty() && missingNodes2.empty();
867 }
868 
869 bool
871 {
875  {
876  return true;
877  }
878 
879  Json::Value j = getJson({*this, {}});
880 
881  j[jss::accountTreeHash] = to_string(info_.accountHash);
882  j[jss::transTreeHash] = to_string(info_.txHash);
883 
884  JLOG(ledgerJ.fatal()) << "ledger is not sensible" << j;
885 
886  assert(false);
887 
888  return false;
889 }
890 
891 // update the skip list with the information from our previous ledger
892 // VFALCO TODO Document this skip list concept
893 void
895 {
896  if (info_.seq == 0) // genesis ledger has no previous ledger
897  return;
898 
899  std::uint32_t prevIndex = info_.seq - 1;
900 
901  // update record of every 256th ledger
902  if ((prevIndex & 0xff) == 0)
903  {
904  auto const k = keylet::skip(prevIndex);
905  auto sle = peek(k);
906  std::vector<uint256> hashes;
907 
908  bool created;
909  if (!sle)
910  {
911  sle = std::make_shared<SLE>(k);
912  created = true;
913  }
914  else
915  {
916  hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
917  created = false;
918  }
919 
920  assert(hashes.size() <= 256);
921  hashes.push_back(info_.parentHash);
922  sle->setFieldV256(sfHashes, STVector256(hashes));
923  sle->setFieldU32(sfLastLedgerSequence, prevIndex);
924  if (created)
925  rawInsert(sle);
926  else
927  rawReplace(sle);
928  }
929 
930  // update record of past 256 ledger
931  auto const k = keylet::skip();
932  auto sle = peek(k);
933  std::vector<uint256> hashes;
934  bool created;
935  if (!sle)
936  {
937  sle = std::make_shared<SLE>(k);
938  created = true;
939  }
940  else
941  {
942  hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
943  created = false;
944  }
945  assert(hashes.size() <= 256);
946  if (hashes.size() == 256)
947  hashes.erase(hashes.begin());
948  hashes.push_back(info_.parentHash);
949  sle->setFieldV256(sfHashes, STVector256(hashes));
950  sle->setFieldU32(sfLastLedgerSequence, prevIndex);
951  if (created)
952  rawInsert(sle);
953  else
954  rawReplace(sle);
955 }
956 
957 bool
959 {
960  return info_.seq % FLAG_LEDGER_INTERVAL == 0;
961 }
962 bool
964 {
965  return (info_.seq + 1) % FLAG_LEDGER_INTERVAL == 0;
966 }
967 
968 bool
970 {
971  return seq % FLAG_LEDGER_INTERVAL == 0;
972 }
973 
974 static bool
976  Application& app,
977  std::shared_ptr<Ledger const> const& ledger,
978  bool current)
979 {
980  auto j = app.journal("Ledger");
981  auto seq = ledger->info().seq;
982  if (!app.pendingSaves().startWork(seq))
983  {
984  // The save was completed synchronously
985  JLOG(j.debug()) << "Save aborted";
986  return true;
987  }
988 
989  auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
990  if (!db)
991  Throw<std::runtime_error>("Failed to get relational database");
992 
993  auto const res = db->saveValidatedLedger(ledger, current);
994 
995  // Clients can now trust the database for
996  // information about this ledger sequence.
997  app.pendingSaves().finishWork(seq);
998  return res;
999 }
1000 
1004 bool
1006  Application& app,
1007  std::shared_ptr<Ledger const> const& ledger,
1008  bool isSynchronous,
1009  bool isCurrent)
1010 {
1011  if (!app.getHashRouter().setFlags(ledger->info().hash, SF_SAVED))
1012  {
1013  // We have tried to save this ledger recently
1014  auto stream = app.journal("Ledger").debug();
1015  JLOG(stream) << "Double pend save for " << ledger->info().seq;
1016 
1017  if (!isSynchronous || !app.pendingSaves().pending(ledger->info().seq))
1018  {
1019  // Either we don't need it to be finished
1020  // or it is finished
1021  return true;
1022  }
1023  }
1024 
1025  assert(ledger->isImmutable());
1026 
1027  if (!app.pendingSaves().shouldWork(ledger->info().seq, isSynchronous))
1028  {
1029  auto stream = app.journal("Ledger").debug();
1030  JLOG(stream) << "Pend save with seq in pending saves "
1031  << ledger->info().seq;
1032 
1033  return true;
1034  }
1035 
1036  // See if we can use the JobQueue.
1037  if (!isSynchronous &&
1038  app.getJobQueue().addJob(
1040  std::to_string(ledger->seq()),
1041  [&app, ledger, isCurrent]() {
1042  saveValidatedLedger(app, ledger, isCurrent);
1043  }))
1044  {
1045  return true;
1046  }
1047 
1048  // The JobQueue won't do the Job. Do the save synchronously.
1049  return saveValidatedLedger(app, ledger, isCurrent);
1050 }
1051 
1052 void
1054 {
1055  stateMap_.unshare();
1056  txMap_.unshare();
1057 }
1058 
1059 void
1061 {
1063  txMap_.invariants();
1064 }
1065 //------------------------------------------------------------------------------
1066 
1067 /*
1068  * Make ledger using info loaded from database.
1069  *
1070  * @param LedgerInfo: Ledger information.
1071  * @param app: Link to the Application.
1072  * @param acquire: Acquire the ledger if not found locally.
1073  * @return Shared pointer to the ledger.
1074  */
1076 loadLedgerHelper(LedgerInfo const& info, Application& app, bool acquire)
1077 {
1078  bool loaded;
1079  auto ledger = std::make_shared<Ledger>(
1080  info,
1081  loaded,
1082  acquire,
1083  app.config(),
1084  app.getNodeFamily(),
1085  app.journal("Ledger"));
1086 
1087  if (!loaded)
1088  ledger.reset();
1089 
1090  return ledger;
1091 }
1092 
1093 static void
1095  std::shared_ptr<Ledger> const& ledger,
1096  Config const& config,
1097  beast::Journal j)
1098 {
1099  if (!ledger)
1100  return;
1101 
1102  assert(
1103  ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
1104  ledger->read(keylet::fees()));
1105  ledger->setImmutable();
1106 
1107  JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->info().hash);
1108 
1109  ledger->setFull();
1110 }
1111 
1114 {
1115  const std::optional<LedgerInfo> info =
1117  if (!info)
1118  return {std::shared_ptr<Ledger>(), {}, {}};
1119  return {loadLedgerHelper(*info, app, true), info->seq, info->hash};
1120 }
1121 
1123 loadByIndex(std::uint32_t ledgerIndex, Application& app, bool acquire)
1124 {
1125  if (std::optional<LedgerInfo> info =
1126  app.getRelationalDatabase().getLedgerInfoByIndex(ledgerIndex))
1127  {
1128  std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
1129  finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
1130  return ledger;
1131  }
1132  return {};
1133 }
1134 
1136 loadByHash(uint256 const& ledgerHash, Application& app, bool acquire)
1137 {
1138  if (std::optional<LedgerInfo> info =
1139  app.getRelationalDatabase().getLedgerInfoByHash(ledgerHash))
1140  {
1141  std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
1142  finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
1143  assert(!ledger || ledger->info().hash == ledgerHash);
1144  return ledger;
1145  }
1146  return {};
1147 }
1148 
1149 std::vector<
1152 {
1153  if (!app.config().reporting())
1154  {
1155  assert(false);
1156  Throw<std::runtime_error>(
1157  "flatFetchTransactions: not running in reporting mode");
1158  }
1159 
1160  std::vector<
1162  txns;
1163  auto start = std::chrono::system_clock::now();
1164  auto nodeDb =
1165  dynamic_cast<NodeStore::DatabaseNodeImp*>(&(app.getNodeStore()));
1166  if (!nodeDb)
1167  {
1168  assert(false);
1169  Throw<std::runtime_error>(
1170  "Called flatFetchTransactions but database is not DatabaseNodeImp");
1171  }
1172  auto objs = nodeDb->fetchBatch(nodestoreHashes);
1173 
1174  auto end = std::chrono::system_clock::now();
1175  JLOG(app.journal("Ledger").debug())
1176  << " Flat fetch time : " << ((end - start).count() / 1000000000.0)
1177  << " number of transactions " << nodestoreHashes.size();
1178  assert(objs.size() == nodestoreHashes.size());
1179  for (size_t i = 0; i < objs.size(); ++i)
1180  {
1181  uint256& nodestoreHash = nodestoreHashes[i];
1182  auto& obj = objs[i];
1183  if (obj)
1184  {
1185  auto node = SHAMapTreeNode::makeFromPrefix(
1186  makeSlice(obj->getData()), SHAMapHash{nodestoreHash});
1187  if (!node)
1188  {
1189  assert(false);
1190  Throw<std::runtime_error>(
1191  "flatFetchTransactions : Error making SHAMap node");
1192  }
1193  auto item = (static_cast<SHAMapLeafNode*>(node.get()))->peekItem();
1194  if (!item)
1195  {
1196  assert(false);
1197  Throw<std::runtime_error>(
1198  "flatFetchTransactions : Error reading SHAMap node");
1199  }
1200  auto txnPlusMeta = deserializeTxPlusMeta(*item);
1201  if (!txnPlusMeta.first || !txnPlusMeta.second)
1202  {
1203  assert(false);
1204  Throw<std::runtime_error>(
1205  "flatFetchTransactions : Error deserializing SHAMap node");
1206  }
1207  txns.push_back(std::move(txnPlusMeta));
1208  }
1209  else
1210  {
1211  assert(false);
1212  Throw<std::runtime_error>(
1213  "flatFetchTransactions : Containing SHAMap node not found");
1214  }
1215  }
1216  return txns;
1217 }
1218 std::vector<
1221 {
1222  if (!app.config().reporting())
1223  {
1224  assert(false);
1225  return {};
1226  }
1227 
1228  auto const db =
1229  dynamic_cast<PostgresDatabase*>(&app.getRelationalDatabase());
1230  if (!db)
1231  Throw<std::runtime_error>("Failed to get relational database");
1232 
1233  auto nodestoreHashes = db->getTxHashes(ledger.info().seq);
1234 
1235  return flatFetchTransactions(app, nodestoreHashes);
1236 }
1237 } // namespace ripple
ripple::SQLiteDatabase
Definition: SQLiteDatabase.h:27
ripple::STArray::empty
bool empty() const
Definition: STArray.h:254
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::Ledger::slesUpperBound
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition: Ledger.cpp:484
ripple::FeeSetup::reference_fee
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition: Config.h:72
ripple::Application
Definition: Application.h:115
ripple::Ledger::sles_iter_impl::sles_iter_impl
sles_iter_impl(SHAMap::const_iterator iter)
Definition: Ledger.cpp:95
ripple::Ledger::slesBegin
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition: Ledger.cpp:472
ripple::Application::getNodeFamily
virtual Family & getNodeFamily()=0
ripple::SHAMap::invariants
void invariants() const
Definition: SHAMap.cpp:1188
ripple::Ledger::addSLE
bool addSLE(SLE const &sle)
Definition: Ledger.cpp:393
ripple::STLedgerEntry::key
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
Definition: STLedgerEntry.h:113
ripple::isFlagLedger
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
Definition: Ledger.cpp:969
ripple::Ledger::rawReplace
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition: Ledger.cpp:561
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::sfBaseFeeDrops
const SF_AMOUNT sfBaseFeeDrops
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:241
ripple::sfReserveBase
const SF_UINT32 sfReserveBase
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::featureXRPFees
const uint256 featureXRPFees
ripple::Ledger::mImmutable
bool mImmutable
Definition: Ledger.h:406
ripple::Ledger::sles_iter_impl
Definition: Ledger.cpp:83
ripple::STLedgerEntry
Definition: STLedgerEntry.h:30
ripple::sfMetadata
const SField sfMetadata
ripple::Ledger::isVotingLedger
bool isVotingLedger() const
Returns true if the ledger directly precedes a flag ledger.
Definition: Ledger.cpp:963
ripple::Ledger::succ
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
Return the key of the next state item.
Definition: Ledger.cpp:442
ripple::Ledger::txRead
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition: Ledger.cpp:509
ripple::Rules::enabled
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:94
std::shared_ptr
STL class.
ripple::LedgerInfo::parentHash
uint256 parentHash
Definition: ReadView.h:94
ripple::keylet::amendments
Keylet const & amendments() noexcept
The index of the amendment table.
Definition: Indexes.cpp:163
ripple::SHAMap::getHash
SHAMapHash getHash() const
Definition: SHAMap.cpp:852
ripple::loadByIndex
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
Definition: Ledger.cpp:1123
ripple::HashPrefix::txNode
@ txNode
transaction plus metadata
ripple::SHAMap::updateGiveItem
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:864
utility
ripple::Ledger::fees_
Fees fees_
Definition: Ledger.h:417
std::exception
STL class.
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:537
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::Ledger::unshare
void unshare() const
Definition: Ledger.cpp:1053
ripple::SHAMap::peekItem
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition: SHAMap.cpp:592
ripple::Ledger::slesEnd
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition: Ledger.cpp:478
ripple::ReadView::txs_type
Definition: ReadView.h:146
ripple::sfFirstLedgerSequence
const SF_UINT32 sfFirstLedgerSequence
ripple::SHAMapNodeType::tnACCOUNT_STATE
@ tnACCOUNT_STATE
std::unordered_set
STL class.
ripple::PendingSaves::pending
bool pending(LedgerIndex seq)
Return true if a ledger is in the progress of being saved.
Definition: PendingSaves.h:84
std::pair
ripple::SHAMapType::TRANSACTION
@ TRANSACTION
ripple::LedgerInfo::hash
uint256 hash
Definition: ReadView.h:91
ripple::XRPAmount::drops
constexpr value_type drops() const
Returns the number of drops.
Definition: XRPAmount.h:172
ripple::make_shamapitem
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition: SHAMapItem.h:160
ripple::sfSequence
const SF_UINT32 sfSequence
ripple::hotACCOUNT_NODE
@ hotACCOUNT_NODE
Definition: NodeObject.h:35
ripple::Ledger::walkLedger
bool walkLedger(beast::Journal j, bool parallel=false) const
Definition: Ledger.cpp:819
vector
std::find
T find(T... args)
std::vector::size
T size(T... args)
ripple::Ledger::defaultFees
void defaultFees(Config const &config)
Definition: Ledger.cpp:688
ripple::Ledger::sles_iter_impl::dereference
sles_type::value_type dereference() const override
Definition: Ledger.cpp:120
std::chrono::duration
ripple::NodeStore::DatabaseNodeImp
Definition: DatabaseNodeImp.h:30
ripple::keylet::skip
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition: Indexes.cpp:145
ripple::getLatestLedger
std::tuple< std::shared_ptr< Ledger >, std::uint32_t, uint256 > getLatestLedger(Application &app)
Definition: Ledger.cpp:1113
ripple::FLAG_LEDGER_INTERVAL
constexpr std::uint32_t FLAG_LEDGER_INTERVAL
Definition: Ledger.h:426
ripple::STObject::getSerializer
Serializer getSerializer() const
Definition: STObject.h:898
std::unordered_set::emplace
T emplace(T... args)
ripple::Ledger::exists
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition: Ledger.cpp:429
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
ripple::Ledger::txs_iter_impl::equal
bool equal(base_type const &impl) const override
Definition: Ledger.cpp:154
ripple::STArray::push_back
void push_back(STObject const &object)
Definition: STArray.h:212
ripple::Ledger::peek
std::shared_ptr< SLE > peek(Keylet const &k) const
Definition: Ledger.cpp:700
ripple::SHAMapHash::isZero
bool isZero() const
Definition: SHAMapHash.h:53
ripple::Ledger::invariants
void invariants() const
Definition: Ledger.cpp:1060
ripple::roundCloseTime
std::chrono::time_point< Clock, Duration > roundCloseTime(std::chrono::time_point< Clock, Duration > closeTime, std::chrono::duration< Rep, Period > closeResolution)
Calculates the close time for a ledger, given a close time resolution.
Definition: LedgerTiming.h:129
std::tuple
ripple::Ledger::txs_iter_impl::operator=
txs_iter_impl & operator=(txs_iter_impl const &)=delete
ripple::SHAMap::begin
const_iterator begin() const
Definition: SHAMap.h:746
ripple::JobQueue::addJob
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
Definition: JobQueue.h:166
ripple::LedgerInfo::seq
LedgerIndex seq
Definition: ReadView.h:83
ripple::Ledger::rawTxInsert
void rawTxInsert(uint256 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: Ledger.cpp:572
ripple::STObject::setFieldVL
void setFieldVL(SField const &field, Blob const &)
Definition: STObject.cpp:695
ripple::PendingSaves::startWork
bool startWork(LedgerIndex seq)
Start working on a ledger.
Definition: PendingSaves.h:51
ripple::Ledger::txs_iter_impl::txs_iter_impl
txs_iter_impl(bool metadata, SHAMap::const_iterator iter)
Definition: Ledger.cpp:142
ripple::Fees::reserve
XRPAmount reserve
Definition: ReadView.h:52
ripple::RelationalDatabase::getNewestLedgerInfo
virtual std::optional< LedgerInfo > getNewestLedgerInfo()=0
getNewestLedgerInfo Returns the info of the newest saved ledger.
ripple::Ledger::rawErase
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition: Ledger.cpp:536
ripple::SHAMapType::STATE
@ STATE
ripple::RelationalDatabase::getLedgerInfoByIndex
virtual std::optional< LedgerInfo > getLedgerInfoByIndex(LedgerIndex ledgerSeq)=0
getLedgerInfoByIndex Returns a ledger by its sequence.
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
ripple::Ledger::updateNegativeUNL
void updateNegativeUNL()
update the Negative UNL ledger component.
Definition: Ledger.cpp:768
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::LedgerInfo::txHash
uint256 txHash
Definition: ReadView.h:92
ripple::Ledger::info_
LedgerInfo info_
Definition: Ledger.h:419
ripple::SHAMap::addItem
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:844
ripple::finishLoadByIndexOrHash
static void finishLoadByIndexOrHash(std::shared_ptr< Ledger > const &ledger, Config const &config, beast::Journal j)
Definition: Ledger.cpp:1094
ripple::XRP_LEDGER_EARLIEST_FEES
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_FEES
The XRP Ledger mainnet's earliest ledger with a FeeSettings object.
Definition: SystemParameters.h:73
ripple::deserializeTx
std::shared_ptr< STTx const > deserializeTx(SHAMapItem const &item)
Deserialize a SHAMapItem containing a single STTx.
Definition: Ledger.cpp:403
ripple::SHAMapHash
Definition: SHAMapHash.h:32
ripple::generateKeyPair
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
Definition: SecretKey.cpp:351
ripple::INITIAL_XRP
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
Definition: SystemParameters.h:43
ripple::SHAMapMissingNode
Definition: SHAMapMissingNode.h:55
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::detail::ReadViewFwdRange< std::shared_ptr< SLE const > >::value_type
std::shared_ptr< SLE const > value_type
Definition: ReadViewFwdRange.h:137
ripple::Ledger::validatorToDisable
std::optional< PublicKey > validatorToDisable() const
get the to be disabled validator's master public key if any
Definition: Ledger.cpp:738
ripple::Ledger::txsEnd
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition: Ledger.cpp:497
ripple::Fees::increment
XRPAmount increment
Definition: ReadView.h:53
std::vector::push_back
T push_back(T... args)
ripple::digest
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition: tokens.cpp:47
ripple::LedgerInfo::closeTime
NetClock::time_point closeTime
Definition: ReadView.h:114
ripple::publicKeyType
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
ripple::Keylet::key
uint256 key
Definition: Keylet.h:40
ripple::base_uint< 256 >
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition: Job.h:44
ripple::Ledger::info
LedgerInfo const & info() const override
Returns information about the ledger.
Definition: Ledger.h:152
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
ripple::SHAMap::hasItem
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition: SHAMap.cpp:690
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::Ledger::txExists
bool txExists(uint256 const &key) const override
Returns true if a tx exists in the tx map.
Definition: Ledger.cpp:503
ripple::saveValidatedLedger
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
Definition: Ledger.cpp:975
ripple::Ledger::txMap_
SHAMap txMap_
Definition: Ledger.h:409
ripple::loadByHash
std::shared_ptr< Ledger > loadByHash(uint256 const &ledgerHash, Application &app, bool acquire)
Definition: Ledger.cpp:1136
ripple::base_uint::isZero
bool isZero() const
Definition: base_uint.h:532
ripple::Ledger
Holds a ledger.
Definition: Ledger.h:76
ripple::SHAMap::addGiveItem
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition: SHAMap.cpp:774
ripple::Ledger::setFull
void setFull() const
Definition: Ledger.h:295
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:133
ripple::SHAMapItem
Definition: SHAMapItem.h:34
ripple::Config
Definition: Config.h:89
ripple::Application::pendingSaves
virtual PendingSaves & pendingSaves()=0
ripple::deserializeTxPlusMeta
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > deserializeTxPlusMeta(SHAMapItem const &item)
Deserialize a SHAMapItem containing STTx + STObject metadata.
Definition: Ledger.cpp:410
ripple::calculateLedgerHash
uint256 calculateLedgerHash(LedgerInfo const &info)
Definition: Ledger.cpp:65
ripple::Ledger::txs_iter_impl::copy
std::unique_ptr< base_type > copy() const override
Definition: Ledger.cpp:148
ripple::Rethrow
void Rethrow()
Rethrow the exception currently being handled.
Definition: contract.h:48
ripple::sfReserveIncrement
const SF_UINT32 sfReserveIncrement
ripple::Application::config
virtual Config & config()=0
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:148
ripple::Ledger::txs_iter_impl::iter_
SHAMap::const_iterator iter_
Definition: Ledger.cpp:133
ripple::SHAMap::const_iterator
Definition: SHAMap.h:638
ripple::Ledger::setAccepted
void setAccepted(NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime)
Definition: Ledger.cpp:378
ripple::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:158
ripple::STArray
Definition: STArray.h:28
ripple::Application::getRelationalDatabase
virtual RelationalDatabase & getRelationalDatabase()=0
ripple::Ledger::sles_iter_impl::iter_
SHAMap::const_iterator iter_
Definition: Ledger.cpp:86
ripple::create_genesis_t
Definition: Ledger.h:44
ripple::SHAMapNodeType::tnTRANSACTION_MD
@ tnTRANSACTION_MD
ripple::Ledger::isFlagLedger
bool isFlagLedger() const
Returns true if the ledger is a flag ledger.
Definition: Ledger.cpp:958
ripple::Ledger::sles_iter_impl::equal
bool equal(base_type const &impl) const override
Definition: Ledger.cpp:106
ripple::LedgerInfo::closeFlags
int closeFlags
Definition: ReadView.h:105
std::to_string
T to_string(T... args)
ripple::Ledger::sles_iter_impl::operator=
sles_iter_impl & operator=(sles_iter_impl const &)=delete
ripple::Application::getJobQueue
virtual JobQueue & getJobQueue()=0
ripple::sfValidatorToDisable
const SF_VL sfValidatorToDisable
ripple::RelationalDatabase::getLedgerInfoByHash
virtual std::optional< LedgerInfo > getLedgerInfoByHash(uint256 const &ledgerHash)=0
getLedgerInfoByHash Returns the info of the ledger with given hash.
ripple::Serializer::slice
Slice slice() const noexcept
Definition: Serializer.h:63
ripple::Ledger::rawInsert
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition: Ledger.cpp:550
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
std::chrono::time_point
std::vector::erase
T erase(T... args)
ripple::Ledger::assertSensible
bool assertSensible(beast::Journal ledgerJ) const
Definition: Ledger.cpp:870
ripple::Family
Definition: Family.h:32
ripple::ValStatus::current
@ current
This was a new validation and was added.
ripple::SerialIter
Definition: Serializer.h:310
ripple::PendingSaves::finishWork
void finishWork(LedgerIndex seq)
Finish working on a ledger.
Definition: PendingSaves.h:74
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::FeeSetup::account_reserve
XRPAmount account_reserve
The account reserve requirement in drops.
Definition: Config.h:75
ripple::Ledger::setup
bool setup()
Definition: Ledger.cpp:609
std::uint32_t
ripple::Ledger::sles_iter_impl::sles_iter_impl
sles_iter_impl()=delete
ripple::Ledger::txs_iter_impl::txs_iter_impl
txs_iter_impl()=delete
ripple::Ledger::isImmutable
bool isImmutable() const
Definition: Ledger.h:279
ripple::SHAMapItem::slice
Slice slice() const
Definition: SHAMapItem.h:105
ripple::jtPUBLEDGER
@ jtPUBLEDGER
Definition: Job.h:69
ripple::sfReserveIncrementDrops
const SF_AMOUNT sfReserveIncrementDrops
ripple::Ledger::validatorToReEnable
std::optional< PublicKey > validatorToReEnable() const
get the to be re-enabled validator's master public key if any
Definition: Ledger.cpp:753
ripple::PendingSaves::shouldWork
bool shouldWork(LedgerIndex seq, bool isSynchronous)
Check if a ledger should be dispatched.
Definition: PendingSaves.h:99
ripple::sfReserveBaseDrops
const SF_AMOUNT sfReserveBaseDrops
ripple::Config::FEE_UNITS_DEPRECATED
static constexpr std::uint32_t FEE_UNITS_DEPRECATED
Definition: Config.h:165
ripple::LedgerInfo::drops
XRPAmount drops
Definition: ReadView.h:96
ripple::SHAMap::fetchRoot
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition: SHAMap.cpp:904
ripple::SHAMap::walkMap
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Definition: SHAMapDelta.cpp:236
ripple::Ledger::setImmutable
void setImmutable(bool rehash=true)
Definition: Ledger.cpp:358
ripple::KeyType::secp256k1
@ secp256k1
ripple::Serializer
Definition: Serializer.h:39
ripple::getJson
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
Definition: LedgerToJson.cpp:296
ripple::Ledger::read
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: Ledger.cpp:453
ripple::SHAMapTreeNode::makeFromPrefix
static std::shared_ptr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
Definition: SHAMapTreeNode.cpp:148
ripple::sfBaseFee
const SF_UINT64 sfBaseFee
ripple::SHAMap::upper_bound
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
Definition: SHAMap.cpp:615
ripple::getCloseAgree
bool getCloseAgree(LedgerInfo const &info)
Definition: ReadView.h:351
ripple::sfHashes
const SF_VECTOR256 sfHashes
ripple::generateSeed
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition: Seed.cpp:69
ripple::Ledger::txsBegin
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition: Ledger.cpp:491
ripple::SHAMap::setImmutable
void setImmutable()
Definition: SHAMap.h:600
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
std::vector::emplace_back
T emplace_back(T... args)
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ReadView::sles_type
Definition: ReadView.h:135
ripple::SHAMap::walkMapParallel
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
Definition: SHAMapDelta.cpp:278
ripple::Config::features
std::unordered_set< uint256, beast::uhash<> > features
Definition: Config.h:282
ripple::Ledger::stateMap_
SHAMap stateMap_
Definition: Ledger.h:412
ripple::Application::getNodeStore
virtual NodeStore::Database & getNodeStore()=0
ripple::Application::journal
virtual beast::Journal journal(std::string const &name)=0
ripple::ShardState::acquire
@ acquire
ripple::STArray::emplace_back
void emplace_back(Args &&... args)
Definition: STArray.h:206
ripple::ReadView::seq
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition: ReadView.h:193
std::vector::begin
T begin(T... args)
ripple::SHAMap::end
const_iterator end() const
Definition: SHAMap.h:752
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::LedgerInfo::closeTimeResolution
NetClock::duration closeTimeResolution
Definition: ReadView.h:108
ripple::sha512Half
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition: digest.h:216
ripple::create_genesis
const create_genesis_t create_genesis
Definition: Ledger.cpp:62
cassert
ripple::sfDisabledValidator
const SField sfDisabledValidator
ripple::Ledger::updateSkipList
void updateSkipList()
Definition: Ledger.cpp:894
ripple::SHAMap::unshare
int unshare()
Convert any modified nodes to shared.
Definition: SHAMap.cpp:985
ripple::FeeSetup::owner_reserve
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition: Config.h:78
ripple::SerialIter::getVLDataLength
int getVLDataLength()
Definition: Serializer.cpp:470
ripple::PostgresDatabase
Definition: PostgresDatabase.h:27
ripple::Ledger::open
bool open() const override
Returns true if this reflects an open ledger.
Definition: Ledger.h:146
ripple::sfBalance
const SF_AMOUNT sfBalance
std::chrono::duration::count
T count(T... args)
ripple::sfReferenceFeeUnits
const SF_UINT32 sfReferenceFeeUnits
ripple::Ledger::txs_iter_impl::metadata_
bool metadata_
Definition: Ledger.cpp:132
ripple::STVector256
Definition: STVector256.h:29
ripple::makeRulesGivenLedger
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition: ReadView.cpp:69
ripple::Serializer::addVL
int addVL(Blob const &vector)
Definition: Serializer.cpp:200
ripple::Ledger::negativeUNL
hash_set< PublicKey > negativeUNL() const
get Negative UNL validators' master public keys
Definition: Ledger.cpp:712
std::vector::empty
T empty(T... args)
ripple::SHAMapType
SHAMapType
Definition: SHAMapMissingNode.h:32
ripple::Ledger::txs_iter_impl
Definition: Ledger.cpp:129
std::optional
ripple::STArray::back
STObject & back()
Definition: STArray.h:193
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
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:41
ripple::keylet::fees
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Definition: Indexes.cpp:171
ripple::ledgerGenesisTimeResolution
constexpr auto ledgerGenesisTimeResolution
Close time resolution in genesis ledger.
Definition: LedgerTiming.h:47
ripple::Keylet::check
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.
Definition: Keylet.cpp:26
ripple::sfAccount
const SF_ACCOUNT sfAccount
ripple::LedgerInfo
Information about the notional ledger backing the view.
Definition: ReadView.h:75
ripple::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapHash.h:43
ripple::getNextLedgerTimeResolution
std::chrono::duration< Rep, Period > getNextLedgerTimeResolution(std::chrono::duration< Rep, Period > previousResolution, bool previousAgree, Seq ledgerSeq)
Calculates the close time resolution for the specified ledger.
Definition: LedgerTiming.h:80
ripple::Family::missingNodeAcquireByHash
virtual void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum)=0
Acquire ledger that has a missing node by ledger hash.
ripple::Ledger::rawTxInsertWithHash
uint256 rawTxInsertWithHash(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)
Definition: Ledger.cpp:589
ripple::sfLastLedgerSequence
const SF_UINT32 sfLastLedgerSequence
ripple::ledgerDefaultTimeResolution
constexpr auto ledgerDefaultTimeResolution
Initial resolution of ledger close time.
Definition: LedgerTiming.h:44
ripple::keylet::negativeUNL
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition: Indexes.cpp:179
ripple::Ledger::txs_iter_impl::dereference
txs_type::value_type dereference() const override
Definition: Ledger.cpp:168
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:1005
ripple::Ledger::Ledger
Ledger(Ledger const &)=delete
std::unique_ptr
STL class.
ripple::Ledger::digest
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
Definition: Ledger.cpp:523
ripple::Ledger::j_
beast::Journal j_
Definition: Ledger.h:420
ripple::loadLedgerHelper
std::shared_ptr< Ledger > loadLedgerHelper(LedgerInfo const &info, Application &app, bool acquire)
Definition: Ledger.cpp:1076
ripple::Config::FEES
FeeSetup FEES
Definition: Config.h:209
ripple::SHAMap::delItem
bool delItem(uint256 const &id)
Definition: SHAMap.cpp:696
ripple::Ledger::txs_iter_impl::increment
void increment() override
Definition: Ledger.cpp:162
ripple::STObject::setFieldU32
void setFieldU32(SField const &field, std::uint32_t)
Definition: STObject.cpp:659
ripple::Ledger::sles_iter_impl::copy
std::unique_ptr< base_type > copy() const override
Definition: Ledger.cpp:100
ripple::sfDisabledValidators
const SField sfDisabledValidators
ripple::sfPublicKey
const SF_VL sfPublicKey
ripple::Application::getHashRouter
virtual HashRouter & getHashRouter()=0
ripple::Ledger::sles_iter_impl::increment
void increment() override
Definition: Ledger.cpp:114
ripple::HashRouter::setFlags
bool setFlags(uint256 const &key, int flags)
Set the flags on a hash.
Definition: HashRouter.cpp:102
ripple::LedgerInfo::accountHash
uint256 accountHash
Definition: ReadView.h:93
ripple::Ledger::rules_
Rules rules_
Definition: Ledger.h:418
std::exception::what
T what(T... args)
ripple::Fees::base
XRPAmount base
Definition: ReadView.h:51
ripple::SerialIter::getSlice
Slice getSlice(std::size_t bytes)
Definition: Serializer.cpp:495
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::sfAmendments
const SF_VECTOR256 sfAmendments
ripple::sLCF_NoConsensusTime
static const std::uint32_t sLCF_NoConsensusTime
Definition: ReadView.h:348
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:98
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::sfValidatorToReEnable
const SF_VL sfValidatorToReEnable
ripple::LedgerInfo::parentCloseTime
NetClock::time_point parentCloseTime
Definition: ReadView.h:84
ripple::flatFetchTransactions
std::vector< std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > > flatFetchTransactions(Application &app, std::vector< uint256 > &nodestoreHashes)
Definition: Ledger.cpp:1151
beast
Definition: base_uint.h:641
std::chrono::system_clock::now
T now(T... args)