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