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  auto const item = *iter_;
123  SerialIter sit(item.slice());
124  return std::make_shared<SLE const>(sit, item.key());
125  }
126 };
127 
128 //------------------------------------------------------------------------------
129 
130 class Ledger::txs_iter_impl : public txs_type::iter_base
131 {
132 private:
133  bool metadata_;
135 
136 public:
137  txs_iter_impl() = delete;
139  operator=(txs_iter_impl const&) = delete;
140 
141  txs_iter_impl(txs_iter_impl const&) = default;
142 
144  : metadata_(metadata), iter_(std::move(iter))
145  {
146  }
147 
149  copy() const override
150  {
151  return std::make_unique<txs_iter_impl>(*this);
152  }
153 
154  bool
155  equal(base_type const& impl) const override
156  {
157  if (auto const p = dynamic_cast<txs_iter_impl const*>(&impl))
158  return iter_ == p->iter_;
159  return false;
160  }
161 
162  void
163  increment() override
164  {
165  ++iter_;
166  }
167 
169  dereference() const override
170  {
171  auto const item = *iter_;
172  if (metadata_)
173  return deserializeTxPlusMeta(item);
174  return {deserializeTx(item), nullptr};
175  }
176 };
177 
178 //------------------------------------------------------------------------------
179 
182  Config const& config,
183  std::vector<uint256> const& amendments,
184  Family& family)
185  : mImmutable(false)
186  , txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
187  , stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
188  , rules_{config.features}
190 {
191  info_.seq = 1;
192  info_.drops = INITIAL_XRP;
193  info_.closeTimeResolution = ledgerGenesisTimeResolution;
194 
195  static auto const id = calcAccountID(
196  generateKeyPair(KeyType::secp256k1, generateSeed("masterpassphrase"))
197  .first);
198  {
199  auto const sle = std::make_shared<SLE>(keylet::account(id));
200  sle->setFieldU32(sfSequence, 1);
201  sle->setAccountID(sfAccount, id);
202  sle->setFieldAmount(sfBalance, info_.drops);
203  rawInsert(sle);
204  }
205 
206  if (!amendments.empty())
207  {
208  auto const sle = std::make_shared<SLE>(keylet::amendments());
209  sle->setFieldV256(sfAmendments, STVector256{amendments});
210  rawInsert(sle);
211  }
212 
213  {
214  auto sle = std::make_shared<SLE>(keylet::fees());
215  // Whether featureXRPFees is supported will depend on startup options.
216  if (std::find(amendments.begin(), amendments.end(), featureXRPFees) !=
217  amendments.end())
218  {
219  sle->at(sfBaseFeeDrops) = config.FEES.reference_fee;
220  sle->at(sfReserveBaseDrops) = config.FEES.account_reserve;
221  sle->at(sfReserveIncrementDrops) = config.FEES.owner_reserve;
222  }
223  else
224  {
225  if (auto const f =
226  config.FEES.reference_fee.dropsAs<std::uint64_t>())
227  sle->at(sfBaseFee) = *f;
228  if (auto const f =
229  config.FEES.account_reserve.dropsAs<std::uint32_t>())
230  sle->at(sfReserveBase) = *f;
231  if (auto const f =
232  config.FEES.owner_reserve.dropsAs<std::uint32_t>())
233  sle->at(sfReserveIncrement) = *f;
235  }
236  rawInsert(sle);
237  }
238 
239  stateMap_->flushDirty(hotACCOUNT_NODE);
240  setImmutable();
241 }
242 
244  LedgerInfo const& info,
245  bool& loaded,
246  bool acquire,
247  Config const& config,
248  Family& family,
249  beast::Journal j)
250  : mImmutable(true)
251  , txMap_(std::make_shared<SHAMap>(
253  info.txHash,
254  family))
255  , stateMap_(
256  std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
257  , rules_(config.features)
258  , info_(info)
259  , j_(j)
260 {
261  loaded = true;
262 
263  if (info_.txHash.isNonZero() &&
264  !txMap_->fetchRoot(SHAMapHash{info_.txHash}, nullptr))
265  {
266  if (config.reporting())
267  {
268  // Reporting should never have incomplete data
269  Throw<std::runtime_error>("Missing tx map root for ledger");
270  }
271  loaded = false;
272  JLOG(j.warn()) << "Don't have transaction root for ledger" << info_.seq;
273  }
274 
275  if (info_.accountHash.isNonZero() &&
276  !stateMap_->fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
277  {
278  if (config.reporting())
279  {
280  // Reporting should never have incomplete data
281  Throw<std::runtime_error>("Missing state map root for ledger");
282  }
283  loaded = false;
284  JLOG(j.warn()) << "Don't have state data root for ledger" << info_.seq;
285  }
286 
287  txMap_->setImmutable();
288  stateMap_->setImmutable();
289 
290  defaultFees(config);
291  if (!setup())
292  loaded = false;
293 
294  if (!loaded)
295  {
297  if (acquire && !config.reporting())
299  }
300 }
301 
302 // Create a new ledger that follows this one
303 Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
304  : mImmutable(false)
305  , txMap_(std::make_shared<SHAMap>(
307  prevLedger.stateMap_->family()))
308  , stateMap_(prevLedger.stateMap_->snapShot(true))
309  , fees_(prevLedger.fees_)
310  , rules_(prevLedger.rules_)
311  , j_(beast::Journal(beast::Journal::getNullSink()))
312 {
313  info_.seq = prevLedger.info_.seq + 1;
314  info_.parentCloseTime = prevLedger.info_.closeTime;
315  info_.hash = prevLedger.info().hash + uint256(1);
316  info_.drops = prevLedger.info().drops;
318  info_.parentHash = prevLedger.info().hash;
320  prevLedger.info_.closeTimeResolution,
321  getCloseAgree(prevLedger.info()),
322  info_.seq);
323 
324  if (prevLedger.info_.closeTime == NetClock::time_point{})
325  {
327  }
328  else
329  {
330  info_.closeTime =
332  }
333 }
334 
335 Ledger::Ledger(LedgerInfo const& info, Config const& config, Family& family)
336  : mImmutable(true)
337  , txMap_(std::make_shared<SHAMap>(
339  info.txHash,
340  family))
341  , stateMap_(
342  std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
343  , rules_{config.features}
344  , info_(info)
346 {
347  info_.hash = calculateLedgerHash(info_);
348 }
349 
351  std::uint32_t ledgerSeq,
352  NetClock::time_point closeTime,
353  Config const& config,
354  Family& family)
355  : mImmutable(false)
356  , txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
357  , stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
358  , rules_{config.features}
360 {
361  info_.seq = ledgerSeq;
362  info_.closeTime = closeTime;
363  info_.closeTimeResolution = ledgerDefaultTimeResolution;
364  defaultFees(config);
365  setup();
366 }
367 
368 void
370 {
371  // Force update, since this is the only
372  // place the hash transitions to valid
373  if (!mImmutable && rehash)
374  {
375  info_.txHash = txMap_->getHash().as_uint256();
376  info_.accountHash = stateMap_->getHash().as_uint256();
377  }
378 
379  if (rehash)
381 
382  mImmutable = true;
383  txMap_->setImmutable();
384  stateMap_->setImmutable();
385  setup();
386 }
387 
388 void
390  NetClock::time_point closeTime,
391  NetClock::duration closeResolution,
392  bool correctCloseTime)
393 {
394  // Used when we witnessed the consensus.
395  assert(!open());
396 
397  info_.closeTime = closeTime;
398  info_.closeTimeResolution = closeResolution;
399  info_.closeFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
400  setImmutable();
401 }
402 
403 bool
404 Ledger::addSLE(SLE const& sle)
405 {
406  auto const s = sle.getSerializer();
407  SHAMapItem item(sle.key(), s.slice());
408  return stateMap_->addItem(SHAMapNodeType::tnACCOUNT_STATE, std::move(item));
409 }
410 
411 //------------------------------------------------------------------------------
412 
415 {
416  SerialIter sit(item.slice());
417  return std::make_shared<STTx const>(sit);
418 }
419 
422 {
424  result;
425  SerialIter sit(item.slice());
426  {
427  SerialIter s(sit.getSlice(sit.getVLDataLength()));
428  result.first = std::make_shared<STTx const>(s);
429  }
430  {
431  SerialIter s(sit.getSlice(sit.getVLDataLength()));
432  result.second = std::make_shared<STObject const>(s, sfMetadata);
433  }
434  return result;
435 }
436 
437 //------------------------------------------------------------------------------
438 
439 bool
440 Ledger::exists(Keylet const& k) const
441 {
442  // VFALCO NOTE Perhaps check the type for debug builds?
443  return stateMap_->hasItem(k.key);
444 }
445 
446 bool
447 Ledger::exists(uint256 const& key) const
448 {
449  return stateMap_->hasItem(key);
450 }
451 
453 Ledger::succ(uint256 const& key, std::optional<uint256> const& last) const
454 {
455  auto item = stateMap_->upper_bound(key);
456  if (item == stateMap_->end())
457  return std::nullopt;
458  if (last && item->key() >= last)
459  return std::nullopt;
460  return item->key();
461 }
462 
464 Ledger::read(Keylet const& k) const
465 {
466  if (k.key == beast::zero)
467  {
468  assert(false);
469  return nullptr;
470  }
471  auto const& item = stateMap_->peekItem(k.key);
472  if (!item)
473  return nullptr;
474  auto sle = std::make_shared<SLE>(SerialIter{item->slice()}, item->key());
475  if (!k.check(*sle))
476  return nullptr;
477  return sle;
478 }
479 
480 //------------------------------------------------------------------------------
481 
482 auto
483 Ledger::slesBegin() const -> std::unique_ptr<sles_type::iter_base>
484 {
485  return std::make_unique<sles_iter_impl>(stateMap_->begin());
486 }
487 
488 auto
489 Ledger::slesEnd() const -> std::unique_ptr<sles_type::iter_base>
490 {
491  return std::make_unique<sles_iter_impl>(stateMap_->end());
492 }
493 
494 auto
497 {
498  return std::make_unique<sles_iter_impl>(stateMap_->upper_bound(key));
499 }
500 
501 auto
502 Ledger::txsBegin() const -> std::unique_ptr<txs_type::iter_base>
503 {
504  return std::make_unique<txs_iter_impl>(!open(), txMap_->begin());
505 }
506 
507 auto
508 Ledger::txsEnd() const -> std::unique_ptr<txs_type::iter_base>
509 {
510  return std::make_unique<txs_iter_impl>(!open(), txMap_->end());
511 }
512 
513 bool
514 Ledger::txExists(uint256 const& key) const
515 {
516  return txMap_->hasItem(key);
517 }
518 
519 auto
520 Ledger::txRead(key_type const& key) const -> tx_type
521 {
522  assert(txMap_);
523  auto const& item = txMap_->peekItem(key);
524  if (!item)
525  return {};
526  if (!open())
527  {
528  auto result = deserializeTxPlusMeta(*item);
529  return {std::move(result.first), std::move(result.second)};
530  }
531  return {deserializeTx(*item), nullptr};
532 }
533 
534 auto
536 {
538  // VFALCO Unfortunately this loads the item
539  // from the NodeStore needlessly.
540  if (!stateMap_->peekItem(key, digest))
541  return std::nullopt;
542  return digest.as_uint256();
543 }
544 
545 //------------------------------------------------------------------------------
546 
547 void
549 {
550  if (!stateMap_->delItem(sle->key()))
551  LogicError("Ledger::rawErase: key not found");
552 }
553 
554 void
556 {
557  if (!stateMap_->delItem(key))
558  LogicError("Ledger::rawErase: key not found");
559 }
560 
561 void
563 {
564  Serializer ss;
565  sle->add(ss);
566  if (!stateMap_->addGiveItem(
568  std::make_shared<SHAMapItem const>(sle->key(), ss.slice())))
569  LogicError("Ledger::rawInsert: key already exists");
570 }
571 
572 void
574 {
575  Serializer ss;
576  sle->add(ss);
577  if (!stateMap_->updateGiveItem(
579  std::make_shared<SHAMapItem const>(sle->key(), ss.slice())))
580  LogicError("Ledger::rawReplace: key not found");
581 }
582 
583 void
585  uint256 const& key,
587  std::shared_ptr<Serializer const> const& metaData)
588 {
589  assert(metaData);
590 
591  // low-level - just add to table
592  Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
593  s.addVL(txn->peekData());
594  s.addVL(metaData->peekData());
595  if (!txMap().addGiveItem(
597  std::make_shared<SHAMapItem const>(key, s.slice())))
598  LogicError("duplicate_tx: " + to_string(key));
599 }
600 
601 uint256
603  uint256 const& key,
605  std::shared_ptr<Serializer const> const& metaData)
606 {
607  assert(metaData);
608 
609  // low-level - just add to table
610  Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
611  s.addVL(txn->peekData());
612  s.addVL(metaData->peekData());
613  auto item = std::make_shared<SHAMapItem const>(key, s.slice());
614  auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key());
615  if (!txMap().addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, std::move(item)))
616  LogicError("duplicate_tx: " + to_string(key));
617 
618  return hash;
619 }
620 
621 bool
623 {
624  bool ret = true;
625 
626  try
627  {
629  }
630  catch (SHAMapMissingNode const&)
631  {
632  ret = false;
633  }
634  catch (std::exception const& ex)
635  {
636  JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
637  Rethrow();
638  }
639 
640  try
641  {
642  if (auto const sle = read(keylet::fees()))
643  {
644  bool oldFees = false;
645  bool newFees = false;
646  {
647  auto const baseFee = sle->at(~sfBaseFee);
648  auto const reserveBase = sle->at(~sfReserveBase);
649  auto const reserveIncrement = sle->at(~sfReserveIncrement);
650  if (baseFee)
651  fees_.base = *baseFee;
652  if (reserveBase)
653  fees_.reserve = *reserveBase;
654  if (reserveIncrement)
655  fees_.increment = *reserveIncrement;
656  oldFees = baseFee || reserveBase || reserveIncrement;
657  }
658  {
659  auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
660  auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
661  auto const reserveIncrementXRP =
662  sle->at(~sfReserveIncrementDrops);
663  auto assign = [&ret](
664  XRPAmount& dest,
665  std::optional<STAmount> const& src) {
666  if (src)
667  {
668  if (src->native())
669  dest = src->xrp();
670  else
671  ret = false;
672  }
673  };
674  assign(fees_.base, baseFeeXRP);
675  assign(fees_.reserve, reserveBaseXRP);
676  assign(fees_.increment, reserveIncrementXRP);
677  newFees = baseFeeXRP || reserveBaseXRP || reserveIncrementXRP;
678  }
679  if (oldFees && newFees)
680  // Should be all of one or the other, but not both
681  ret = false;
682  if (!rules_.enabled(featureXRPFees) && newFees)
683  // Can't populate the new fees before the amendment is enabled
684  ret = false;
685  }
686  }
687  catch (SHAMapMissingNode const&)
688  {
689  ret = false;
690  }
691  catch (std::exception const& ex)
692  {
693  JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
694  Rethrow();
695  }
696 
697  return ret;
698 }
699 
700 void
702 {
703  assert(fees_.base == 0 && fees_.reserve == 0 && fees_.increment == 0);
704  if (fees_.base == 0)
705  fees_.base = config.FEES.reference_fee;
706  if (fees_.reserve == 0)
708  if (fees_.increment == 0)
710 }
711 
713 Ledger::peek(Keylet const& k) const
714 {
715  auto const& value = stateMap_->peekItem(k.key);
716  if (!value)
717  return nullptr;
718  auto sle = std::make_shared<SLE>(SerialIter{value->slice()}, value->key());
719  if (!k.check(*sle))
720  return nullptr;
721  return sle;
722 }
723 
726 {
727  hash_set<PublicKey> negUnl;
728  if (auto sle = read(keylet::negativeUNL());
729  sle && sle->isFieldPresent(sfDisabledValidators))
730  {
731  auto const& nUnlData = sle->getFieldArray(sfDisabledValidators);
732  for (auto const& n : nUnlData)
733  {
734  if (n.isFieldPresent(sfPublicKey))
735  {
736  auto d = n.getFieldVL(sfPublicKey);
737  auto s = makeSlice(d);
738  if (!publicKeyType(s))
739  {
740  continue;
741  }
742  negUnl.emplace(s);
743  }
744  }
745  }
746 
747  return negUnl;
748 }
749 
752 {
753  if (auto sle = read(keylet::negativeUNL());
754  sle && sle->isFieldPresent(sfValidatorToDisable))
755  {
756  auto d = sle->getFieldVL(sfValidatorToDisable);
757  auto s = makeSlice(d);
758  if (publicKeyType(s))
759  return PublicKey(s);
760  }
761 
762  return std::nullopt;
763 }
764 
767 {
768  if (auto sle = read(keylet::negativeUNL());
769  sle && sle->isFieldPresent(sfValidatorToReEnable))
770  {
771  auto d = sle->getFieldVL(sfValidatorToReEnable);
772  auto s = makeSlice(d);
773  if (publicKeyType(s))
774  return PublicKey(s);
775  }
776 
777  return std::nullopt;
778 }
779 
780 void
782 {
783  auto sle = peek(keylet::negativeUNL());
784  if (!sle)
785  return;
786 
787  bool const hasToDisable = sle->isFieldPresent(sfValidatorToDisable);
788  bool const hasToReEnable = sle->isFieldPresent(sfValidatorToReEnable);
789 
790  if (!hasToDisable && !hasToReEnable)
791  return;
792 
793  STArray newNUnl;
794  if (sle->isFieldPresent(sfDisabledValidators))
795  {
796  auto const& oldNUnl = sle->getFieldArray(sfDisabledValidators);
797  for (auto v : oldNUnl)
798  {
799  if (hasToReEnable && v.isFieldPresent(sfPublicKey) &&
800  v.getFieldVL(sfPublicKey) ==
801  sle->getFieldVL(sfValidatorToReEnable))
802  continue;
803  newNUnl.push_back(v);
804  }
805  }
806 
807  if (hasToDisable)
808  {
810  newNUnl.back().setFieldVL(
811  sfPublicKey, sle->getFieldVL(sfValidatorToDisable));
813  }
814 
815  if (!newNUnl.empty())
816  {
817  sle->setFieldArray(sfDisabledValidators, newNUnl);
818  if (hasToReEnable)
819  sle->makeFieldAbsent(sfValidatorToReEnable);
820  if (hasToDisable)
821  sle->makeFieldAbsent(sfValidatorToDisable);
822  rawReplace(sle);
823  }
824  else
825  {
826  rawErase(sle);
827  }
828 }
829 
830 //------------------------------------------------------------------------------
831 bool
832 Ledger::walkLedger(beast::Journal j, bool parallel) const
833 {
834  std::vector<SHAMapMissingNode> missingNodes1;
835  std::vector<SHAMapMissingNode> missingNodes2;
836 
837  if (stateMap_->getHash().isZero() && !info_.accountHash.isZero() &&
838  !stateMap_->fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
839  {
840  missingNodes1.emplace_back(
842  }
843  else
844  {
845  if (parallel)
846  return stateMap_->walkMapParallel(missingNodes1, 32);
847  else
848  stateMap_->walkMap(missingNodes1, 32);
849  }
850 
851  if (!missingNodes1.empty())
852  {
853  if (auto stream = j.info())
854  {
855  stream << missingNodes1.size() << " missing account node(s)";
856  stream << "First: " << missingNodes1[0].what();
857  }
858  }
859 
860  if (txMap_->getHash().isZero() && info_.txHash.isNonZero() &&
861  !txMap_->fetchRoot(SHAMapHash{info_.txHash}, nullptr))
862  {
863  missingNodes2.emplace_back(
865  }
866  else
867  {
868  txMap_->walkMap(missingNodes2, 32);
869  }
870 
871  if (!missingNodes2.empty())
872  {
873  if (auto stream = j.info())
874  {
875  stream << missingNodes2.size() << " missing transaction node(s)";
876  stream << "First: " << missingNodes2[0].what();
877  }
878  }
879  return missingNodes1.empty() && missingNodes2.empty();
880 }
881 
882 bool
884 {
886  txMap_ && (info_.accountHash == stateMap_->getHash().as_uint256()) &&
887  (info_.txHash == txMap_->getHash().as_uint256()))
888  {
889  return true;
890  }
891 
892  Json::Value j = getJson({*this, {}});
893 
894  j[jss::accountTreeHash] = to_string(info_.accountHash);
895  j[jss::transTreeHash] = to_string(info_.txHash);
896 
897  JLOG(ledgerJ.fatal()) << "ledger is not sensible" << j;
898 
899  assert(false);
900 
901  return false;
902 }
903 
904 // update the skip list with the information from our previous ledger
905 // VFALCO TODO Document this skip list concept
906 void
908 {
909  if (info_.seq == 0) // genesis ledger has no previous ledger
910  return;
911 
912  std::uint32_t prevIndex = info_.seq - 1;
913 
914  // update record of every 256th ledger
915  if ((prevIndex & 0xff) == 0)
916  {
917  auto const k = keylet::skip(prevIndex);
918  auto sle = peek(k);
919  std::vector<uint256> hashes;
920 
921  bool created;
922  if (!sle)
923  {
924  sle = std::make_shared<SLE>(k);
925  created = true;
926  }
927  else
928  {
929  hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
930  created = false;
931  }
932 
933  assert(hashes.size() <= 256);
934  hashes.push_back(info_.parentHash);
935  sle->setFieldV256(sfHashes, STVector256(hashes));
936  sle->setFieldU32(sfLastLedgerSequence, prevIndex);
937  if (created)
938  rawInsert(sle);
939  else
940  rawReplace(sle);
941  }
942 
943  // update record of past 256 ledger
944  auto const k = keylet::skip();
945  auto sle = peek(k);
946  std::vector<uint256> hashes;
947  bool created;
948  if (!sle)
949  {
950  sle = std::make_shared<SLE>(k);
951  created = true;
952  }
953  else
954  {
955  hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
956  created = false;
957  }
958  assert(hashes.size() <= 256);
959  if (hashes.size() == 256)
960  hashes.erase(hashes.begin());
961  hashes.push_back(info_.parentHash);
962  sle->setFieldV256(sfHashes, STVector256(hashes));
963  sle->setFieldU32(sfLastLedgerSequence, prevIndex);
964  if (created)
965  rawInsert(sle);
966  else
967  rawReplace(sle);
968 }
969 
970 bool
972 {
973  return info_.seq % FLAG_LEDGER_INTERVAL == 0;
974 }
975 bool
977 {
978  return (info_.seq + 1) % FLAG_LEDGER_INTERVAL == 0;
979 }
980 
981 bool
983 {
984  return seq % FLAG_LEDGER_INTERVAL == 0;
985 }
986 
987 static bool
989  Application& app,
990  std::shared_ptr<Ledger const> const& ledger,
991  bool current)
992 {
993  auto j = app.journal("Ledger");
994  auto seq = ledger->info().seq;
995  if (!app.pendingSaves().startWork(seq))
996  {
997  // The save was completed synchronously
998  JLOG(j.debug()) << "Save aborted";
999  return true;
1000  }
1001 
1002  auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
1003  if (!db)
1004  Throw<std::runtime_error>("Failed to get relational database");
1005 
1006  auto const res = db->saveValidatedLedger(ledger, current);
1007 
1008  // Clients can now trust the database for
1009  // information about this ledger sequence.
1010  app.pendingSaves().finishWork(seq);
1011  return res;
1012 }
1013 
1017 bool
1019  Application& app,
1020  std::shared_ptr<Ledger const> const& ledger,
1021  bool isSynchronous,
1022  bool isCurrent)
1023 {
1024  if (!app.getHashRouter().setFlags(ledger->info().hash, SF_SAVED))
1025  {
1026  // We have tried to save this ledger recently
1027  auto stream = app.journal("Ledger").debug();
1028  JLOG(stream) << "Double pend save for " << ledger->info().seq;
1029 
1030  if (!isSynchronous || !app.pendingSaves().pending(ledger->info().seq))
1031  {
1032  // Either we don't need it to be finished
1033  // or it is finished
1034  return true;
1035  }
1036  }
1037 
1038  assert(ledger->isImmutable());
1039 
1040  if (!app.pendingSaves().shouldWork(ledger->info().seq, isSynchronous))
1041  {
1042  auto stream = app.journal("Ledger").debug();
1043  JLOG(stream) << "Pend save with seq in pending saves "
1044  << ledger->info().seq;
1045 
1046  return true;
1047  }
1048 
1049  JobType const jobType{isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER};
1050  char const* const jobName{
1051  isCurrent ? "Ledger::pendSave" : "Ledger::pendOldSave"};
1052 
1053  // See if we can use the JobQueue.
1054  if (!isSynchronous &&
1055  app.getJobQueue().addJob(jobType, jobName, [&app, ledger, isCurrent]() {
1056  saveValidatedLedger(app, ledger, isCurrent);
1057  }))
1058  {
1059  return true;
1060  }
1061 
1062  // The JobQueue won't do the Job. Do the save synchronously.
1063  return saveValidatedLedger(app, ledger, isCurrent);
1064 }
1065 
1066 void
1068 {
1069  stateMap_->unshare();
1070  txMap_->unshare();
1071 }
1072 
1073 void
1075 {
1076  stateMap_->invariants();
1077  txMap_->invariants();
1078 }
1079 //------------------------------------------------------------------------------
1080 
1081 /*
1082  * Make ledger using info loaded from database.
1083  *
1084  * @param LedgerInfo: Ledger information.
1085  * @param app: Link to the Application.
1086  * @param acquire: Acquire the ledger if not found locally.
1087  * @return Shared pointer to the ledger.
1088  */
1090 loadLedgerHelper(LedgerInfo const& info, Application& app, bool acquire)
1091 {
1092  bool loaded;
1093  auto ledger = std::make_shared<Ledger>(
1094  info,
1095  loaded,
1096  acquire,
1097  app.config(),
1098  app.getNodeFamily(),
1099  app.journal("Ledger"));
1100 
1101  if (!loaded)
1102  ledger.reset();
1103 
1104  return ledger;
1105 }
1106 
1107 static void
1109  std::shared_ptr<Ledger> const& ledger,
1110  Config const& config,
1111  beast::Journal j)
1112 {
1113  if (!ledger)
1114  return;
1115 
1116  assert(
1117  ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
1118  ledger->read(keylet::fees()));
1119  ledger->setImmutable();
1120 
1121  JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->info().hash);
1122 
1123  ledger->setFull();
1124 }
1125 
1128 {
1129  const std::optional<LedgerInfo> info =
1131  if (!info)
1132  return {std::shared_ptr<Ledger>(), {}, {}};
1133  return {loadLedgerHelper(*info, app, true), info->seq, info->hash};
1134 }
1135 
1137 loadByIndex(std::uint32_t ledgerIndex, Application& app, bool acquire)
1138 {
1139  if (std::optional<LedgerInfo> info =
1140  app.getRelationalDatabase().getLedgerInfoByIndex(ledgerIndex))
1141  {
1142  std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
1143  finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
1144  return ledger;
1145  }
1146  return {};
1147 }
1148 
1150 loadByHash(uint256 const& ledgerHash, Application& app, bool acquire)
1151 {
1152  if (std::optional<LedgerInfo> info =
1153  app.getRelationalDatabase().getLedgerInfoByHash(ledgerHash))
1154  {
1155  std::shared_ptr<Ledger> ledger = loadLedgerHelper(*info, app, acquire);
1156  finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger"));
1157  assert(!ledger || ledger->info().hash == ledgerHash);
1158  return ledger;
1159  }
1160  return {};
1161 }
1162 
1163 std::vector<
1166 {
1167  if (!app.config().reporting())
1168  {
1169  assert(false);
1170  Throw<std::runtime_error>(
1171  "flatFetchTransactions: not running in reporting mode");
1172  }
1173 
1174  std::vector<
1176  txns;
1177  auto start = std::chrono::system_clock::now();
1178  auto nodeDb =
1179  dynamic_cast<NodeStore::DatabaseNodeImp*>(&(app.getNodeStore()));
1180  if (!nodeDb)
1181  {
1182  assert(false);
1183  Throw<std::runtime_error>(
1184  "Called flatFetchTransactions but database is not DatabaseNodeImp");
1185  }
1186  auto objs = nodeDb->fetchBatch(nodestoreHashes);
1187 
1188  auto end = std::chrono::system_clock::now();
1189  JLOG(app.journal("Ledger").debug())
1190  << " Flat fetch time : " << ((end - start).count() / 1000000000.0)
1191  << " number of transactions " << nodestoreHashes.size();
1192  assert(objs.size() == nodestoreHashes.size());
1193  for (size_t i = 0; i < objs.size(); ++i)
1194  {
1195  uint256& nodestoreHash = nodestoreHashes[i];
1196  auto& obj = objs[i];
1197  if (obj)
1198  {
1199  auto node = SHAMapTreeNode::makeFromPrefix(
1200  makeSlice(obj->getData()), SHAMapHash{nodestoreHash});
1201  if (!node)
1202  {
1203  assert(false);
1204  Throw<std::runtime_error>(
1205  "flatFetchTransactions : Error making SHAMap node");
1206  }
1207  auto item = (static_cast<SHAMapLeafNode*>(node.get()))->peekItem();
1208  if (!item)
1209  {
1210  assert(false);
1211  Throw<std::runtime_error>(
1212  "flatFetchTransactions : Error reading SHAMap node");
1213  }
1214  auto txnPlusMeta = deserializeTxPlusMeta(*item);
1215  if (!txnPlusMeta.first || !txnPlusMeta.second)
1216  {
1217  assert(false);
1218  Throw<std::runtime_error>(
1219  "flatFetchTransactions : Error deserializing SHAMap node");
1220  }
1221  txns.push_back(std::move(txnPlusMeta));
1222  }
1223  else
1224  {
1225  assert(false);
1226  Throw<std::runtime_error>(
1227  "flatFetchTransactions : Containing SHAMap node not found");
1228  }
1229  }
1230  return txns;
1231 }
1232 std::vector<
1235 {
1236  if (!app.config().reporting())
1237  {
1238  assert(false);
1239  return {};
1240  }
1241 
1242  auto const db =
1243  dynamic_cast<PostgresDatabase*>(&app.getRelationalDatabase());
1244  if (!db)
1245  Throw<std::runtime_error>("Failed to get relational database");
1246 
1247  auto nodestoreHashes = db->getTxHashes(ledger.info().seq);
1248 
1249  return flatFetchTransactions(app, nodestoreHashes);
1250 }
1251 } // 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:495
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:483
ripple::Application::getNodeFamily
virtual Family & getNodeFamily()=0
ripple::Ledger::addSLE
bool addSLE(SLE const &sle)
Definition: Ledger.cpp:404
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:982
ripple::Ledger::rawReplace
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition: Ledger.cpp:573
ripple::HashPrefix::ledgerMaster
@ ledgerMaster
ledger master data for signing
ripple::Ledger::txMap_
std::shared_ptr< SHAMap > txMap_
Definition: Ledger.h:404
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:402
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:976
ripple::Ledger::succ
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
Definition: Ledger.cpp:453
ripple::Ledger::txRead
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition: Ledger.cpp:520
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::loadByIndex
std::shared_ptr< Ledger > loadByIndex(std::uint32_t ledgerIndex, Application &app, bool acquire)
Definition: Ledger.cpp:1137
ripple::HashPrefix::txNode
@ txNode
transaction plus metadata
utility
ripple::Ledger::fees_
Fees fees_
Definition: Ledger.h:410
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:1067
ripple::Ledger::slesEnd
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition: Ledger.cpp:489
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::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:832
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:701
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:1127
ripple::FLAG_LEDGER_INTERVAL
constexpr std::uint32_t FLAG_LEDGER_INTERVAL
Definition: Ledger.h:419
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:440
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:155
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:713
ripple::Ledger::invariants
void invariants() const
Definition: Ledger.cpp:1074
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::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
Definition: Ledger.cpp:584
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:143
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:548
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:781
ripple::SHAMapLeafNode
Definition: SHAMapLeafNode.h:32
ripple::LedgerInfo::txHash
uint256 txHash
Definition: ReadView.h:92
ripple::Ledger::info_
LedgerInfo info_
Definition: Ledger.h:412
ripple::finishLoadByIndexOrHash
static void finishLoadByIndexOrHash(std::shared_ptr< Ledger > const &ledger, Config const &config, beast::Journal j)
Definition: Ledger.cpp:1108
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:414
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:751
ripple::Ledger::txsEnd
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition: Ledger.cpp:508
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:148
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
ripple::Config::reporting
bool reporting() const
Definition: Config.h:336
ripple::Ledger::txExists
bool txExists(uint256 const &key) const override
Definition: Ledger.cpp:514
ripple::saveValidatedLedger
static bool saveValidatedLedger(Application &app, std::shared_ptr< Ledger const > const &ledger, bool current)
Definition: Ledger.cpp:988
ripple::loadByHash
std::shared_ptr< Ledger > loadByHash(uint256 const &ledgerHash, Application &app, bool acquire)
Definition: Ledger.cpp:1150
ripple::base_uint::isZero
bool isZero() const
Definition: base_uint.h:532
ripple::Ledger
Holds a ledger.
Definition: Ledger.h:76
ripple::Ledger::setFull
void setFull() const
Definition: Ledger.h:291
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:31
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:421
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:149
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:134
ripple::SHAMap::const_iterator
Definition: SHAMap.h:630
ripple::Ledger::setAccepted
void setAccepted(NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime)
Definition: Ledger.cpp:389
ripple::calcAccountID
AccountID calcAccountID(PublicKey const &pk)
Definition: AccountID.cpp:158
ripple::SHAMap
A SHAMap is both a radix tree with a fan-out of 16 and a Merkle tree.
Definition: SHAMap.h:95
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:971
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
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:562
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:883
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:622
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:275
ripple::SHAMapItem::slice
Slice slice() const
Definition: SHAMapItem.h:51
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:766
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:164
ripple::LedgerInfo::drops
XRPAmount drops
Definition: ReadView.h:96
ripple::Ledger::setImmutable
void setImmutable(bool rehash=true)
Definition: Ledger.cpp:369
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:464
ripple::SHAMapTreeNode::makeFromPrefix
static std::shared_ptr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
Definition: SHAMapTreeNode.cpp:148
ripple::Ledger::txMap
SHAMap const & txMap() const
Definition: Ledger.h:318
ripple::sfBaseFee
const SF_UINT64 sfBaseFee
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:502
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::Config::features
std::unordered_set< uint256, beast::uhash<> > features
Definition: Config.h:281
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)
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::Ledger::stateMap_
std::shared_ptr< SHAMap > stateMap_
Definition: Ledger.h:405
ripple::sfDisabledValidator
const SField sfDisabledValidator
ripple::Ledger::updateSkipList
void updateSkipList()
Definition: Ledger.cpp:907
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:142
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:133
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:725
std::vector::empty
T empty(T... args)
ripple::SHAMapType
SHAMapType
Definition: SHAMapMissingNode.h:32
ripple::Ledger::txs_iter_impl
Definition: Ledger.cpp:130
std::optional
ripple::STArray::back
STObject & back()
Definition: STArray.h:193
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::JobType
JobType
Definition: Job.h:35
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::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:602
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:169
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:1018
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:535
ripple::Ledger::j_
beast::Journal j_
Definition: Ledger.h:413
ripple::loadLedgerHelper
std::shared_ptr< Ledger > loadLedgerHelper(LedgerInfo const &info, Application &app, bool acquire)
Definition: Ledger.cpp:1090
ripple::Config::FEES
FeeSetup FEES
Definition: Config.h:208
ripple::Ledger::txs_iter_impl::increment
void increment() override
Definition: Ledger.cpp:163
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:411
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:1165
beast
Definition: base_uint.h:641
std::chrono::system_clock::now
T now(T... args)