rippled
Loading...
Searching...
No Matches
libxrpl/ledger/Ledger.cpp
1#include <xrpl/basics/Log.h>
2#include <xrpl/basics/contract.h>
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/json/to_string.h>
5#include <xrpl/ledger/Ledger.h>
6#include <xrpl/ledger/LedgerTiming.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/HashPrefix.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/PublicKey.h>
11#include <xrpl/protocol/SecretKey.h>
12#include <xrpl/protocol/digest.h>
13#include <xrpl/protocol/jss.h>
14
15#include <utility>
16#include <vector>
17
18namespace xrpl {
19
21
22//------------------------------------------------------------------------------
23
24class Ledger::sles_iter_impl : public sles_type::iter_base
25{
26private:
28
29public:
30 sles_iter_impl() = delete;
32 operator=(sles_iter_impl const&) = delete;
33
34 sles_iter_impl(sles_iter_impl const&) = default;
35
39
41 copy() const override
42 {
44 }
45
46 bool
47 equal(base_type const& impl) const override
48 {
49 if (auto const p = dynamic_cast<sles_iter_impl const*>(&impl))
50 return iter_ == p->iter_;
51 return false;
52 }
53
54 void
55 increment() override
56 {
57 ++iter_;
58 }
59
60 sles_type::value_type
61 dereference() const override
62 {
63 SerialIter sit(iter_->slice());
64 return std::make_shared<SLE const>(sit, iter_->key());
65 }
66};
67
68//------------------------------------------------------------------------------
69
70class Ledger::txs_iter_impl : public txs_type::iter_base
71{
72private:
75
76public:
77 txs_iter_impl() = delete;
79 operator=(txs_iter_impl const&) = delete;
80
81 txs_iter_impl(txs_iter_impl const&) = default;
82
83 txs_iter_impl(bool metadata, SHAMap::const_iterator iter) : metadata_(metadata), iter_(iter)
84 {
85 }
86
88 copy() const override
89 {
91 }
92
93 bool
94 equal(base_type const& impl) const override
95 {
96 if (auto const p = dynamic_cast<txs_iter_impl const*>(&impl))
97 return iter_ == p->iter_;
98 return false;
99 }
100
101 void
102 increment() override
103 {
104 ++iter_;
105 }
106
107 txs_type::value_type
108 dereference() const override
109 {
110 auto const& item = *iter_;
111 if (metadata_)
113 return {Ledger::deserializeTx(item), nullptr};
114 }
115};
116
117//------------------------------------------------------------------------------
118
121 Rules const& rules,
122 Fees const& fees,
123 std::vector<uint256> const& amendments,
124 Family& family)
125 : mImmutable(false)
126 , txMap_(SHAMapType::TRANSACTION, family)
127 , stateMap_(SHAMapType::STATE, family)
128 , fees_(fees)
129 , rules_(rules)
130 , j_(beast::Journal(beast::Journal::getNullSink()))
131{
132 header_.seq = 1;
135
136 static auto const id =
138 {
139 auto const sle = std::make_shared<SLE>(keylet::account(id));
140 sle->setFieldU32(sfSequence, 1);
141 sle->setAccountID(sfAccount, id);
142 sle->setFieldAmount(sfBalance, header_.drops);
143 rawInsert(sle);
144 }
145
146 if (!amendments.empty())
147 {
148 auto const sle = std::make_shared<SLE>(keylet::amendments());
149 sle->setFieldV256(sfAmendments, STVector256{amendments});
150 rawInsert(sle);
151 }
152
153 {
155 // Whether featureXRPFees is supported will depend on startup options.
156 if (std::find(amendments.begin(), amendments.end(), featureXRPFees) != amendments.end())
157 {
158 sle->at(sfBaseFeeDrops) = fees.base;
159 sle->at(sfReserveBaseDrops) = fees.reserve;
160 sle->at(sfReserveIncrementDrops) = fees.increment;
161 }
162 else
163 {
164 if (auto const f = fees.base.dropsAs<std::uint64_t>())
165 sle->at(sfBaseFee) = *f;
166 if (auto const f = fees.reserve.dropsAs<std::uint32_t>())
167 sle->at(sfReserveBase) = *f;
168 if (auto const f = fees.increment.dropsAs<std::uint32_t>())
169 sle->at(sfReserveIncrement) = *f;
170 sle->at(sfReferenceFeeUnits) = FEE_UNITS_DEPRECATED;
171 }
172 rawInsert(sle);
173 }
174
176 setImmutable();
177}
178
180 LedgerHeader const& info,
181 bool& loaded,
182 bool acquire,
183 Rules const& rules,
184 Fees const& fees,
185 Family& family,
187 : mImmutable(true)
188 , txMap_(SHAMapType::TRANSACTION, info.txHash, family)
189 , stateMap_(SHAMapType::STATE, info.accountHash, family)
190 , fees_(fees)
191 , rules_(rules)
192 , header_(info)
193 , j_(j)
194{
195 loaded = true;
196
197 if (header_.txHash.isNonZero() && !txMap_.fetchRoot(SHAMapHash{header_.txHash}, nullptr))
198 {
199 loaded = false;
200 JLOG(j.warn()) << "Don't have transaction root for ledger" << header_.seq;
201 }
202
204 !stateMap_.fetchRoot(SHAMapHash{header_.accountHash}, nullptr))
205 {
206 loaded = false;
207 JLOG(j.warn()) << "Don't have state data root for ledger" << header_.seq;
208 }
209
212
213 if (!setup())
214 loaded = false;
215
216 if (!loaded)
217 {
219 if (acquire)
221 }
222}
223
224// Create a new ledger that follows this one
225Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
226 : mImmutable(false)
227 , txMap_(SHAMapType::TRANSACTION, prevLedger.txMap_.family())
228 , stateMap_(prevLedger.stateMap_, true)
229 , fees_(prevLedger.fees_)
230 , rules_(prevLedger.rules_)
231 , j_(beast::Journal(beast::Journal::getNullSink()))
232{
233 header_.seq = prevLedger.header_.seq + 1;
235 header_.hash = prevLedger.header().hash + uint256(1);
236 header_.drops = prevLedger.header().drops;
238 header_.parentHash = prevLedger.header().hash;
240 prevLedger.header_.closeTimeResolution, getCloseAgree(prevLedger.header()), header_.seq);
241
242 if (prevLedger.header_.closeTime == NetClock::time_point{})
243 {
245 }
246 else
247 {
249 }
250}
251
252Ledger::Ledger(LedgerHeader const& info, Rules const& rules, Family& family)
253 : mImmutable(true)
254 , txMap_(SHAMapType::TRANSACTION, info.txHash, family)
255 , stateMap_(SHAMapType::STATE, info.accountHash, family)
256 , rules_(rules)
257 , header_(info)
258 , j_(beast::Journal(beast::Journal::getNullSink()))
259{
261}
262
264 std::uint32_t ledgerSeq,
265 NetClock::time_point closeTime,
266 Rules const& rules,
267 Fees const& fees,
268 Family& family)
269 : mImmutable(false)
270 , txMap_(SHAMapType::TRANSACTION, family)
271 , stateMap_(SHAMapType::STATE, family)
272 , fees_(fees)
273 , rules_(rules)
274 , j_(beast::Journal(beast::Journal::getNullSink()))
275{
276 header_.seq = ledgerSeq;
277 header_.closeTime = closeTime;
279 setup();
280}
281
282void
284{
285 // Force update, since this is the only
286 // place the hash transitions to valid
287 if (!mImmutable && rehash)
288 {
291 }
292
293 if (rehash)
295
296 mImmutable = true;
299 setup();
300}
301
302void
304 NetClock::time_point closeTime,
305 NetClock::duration closeResolution,
306 bool correctCloseTime)
307{
308 // Used when we witnessed the consensus.
309 XRPL_ASSERT(!open(), "xrpl::Ledger::setAccepted : valid ledger state");
310
311 header_.closeTime = closeTime;
312 header_.closeTimeResolution = closeResolution;
313 header_.closeFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
314 setImmutable();
315}
316
317bool
319{
320 auto const s = sle.getSerializer();
321 return stateMap_.addItem(
323}
324
325//------------------------------------------------------------------------------
326
329{
330 SerialIter sit(item.slice());
332}
333
336{
338 SerialIter sit(item.slice());
339 {
340 SerialIter s(sit.getSlice(sit.getVLDataLength()));
342 }
343 {
344 SerialIter s(sit.getSlice(sit.getVLDataLength()));
345 result.second = std::make_shared<STObject const>(s, sfMetadata);
346 }
347 return result;
348}
349
350//------------------------------------------------------------------------------
351
352bool
353Ledger::exists(Keylet const& k) const
354{
355 // VFALCO NOTE Perhaps check the type for debug builds?
356 return stateMap_.hasItem(k.key);
357}
358
359bool
360Ledger::exists(uint256 const& key) const
361{
362 return stateMap_.hasItem(key);
363}
364
366Ledger::succ(uint256 const& key, std::optional<uint256> const& last) const
367{
368 auto item = stateMap_.upper_bound(key);
369 if (item == stateMap_.end())
370 return std::nullopt;
371 if (last && item->key() >= last)
372 return std::nullopt;
373 return item->key();
374}
375
377Ledger::read(Keylet const& k) const
378{
379 if (k.key == beast::zero)
380 {
381 // LCOV_EXCL_START
382 UNREACHABLE("xrpl::Ledger::read : zero key");
383 return nullptr;
384 // LCOV_EXCL_STOP
385 }
386 auto const& item = stateMap_.peekItem(k.key);
387 if (!item)
388 return nullptr;
389 auto sle = std::make_shared<SLE>(SerialIter{item->slice()}, item->key());
390 if (!k.check(*sle))
391 return nullptr;
392 return sle;
393}
394
395//------------------------------------------------------------------------------
396
397auto
398Ledger::slesBegin() const -> std::unique_ptr<sles_type::iter_base>
399{
401}
402
403auto
404Ledger::slesEnd() const -> std::unique_ptr<sles_type::iter_base>
405{
407}
408
409auto
411{
412 return std::make_unique<sles_iter_impl>(stateMap_.upper_bound(key));
413}
414
415auto
416Ledger::txsBegin() const -> std::unique_ptr<txs_type::iter_base>
417{
419}
420
421auto
422Ledger::txsEnd() const -> std::unique_ptr<txs_type::iter_base>
423{
425}
426
427bool
428Ledger::txExists(uint256 const& key) const
429{
430 return txMap_.hasItem(key);
431}
432
433auto
434Ledger::txRead(key_type const& key) const -> tx_type
435{
436 auto const& item = txMap_.peekItem(key);
437 if (!item)
438 return {};
439 if (!open())
440 {
441 auto result = deserializeTxPlusMeta(*item);
442 return {std::move(result.first), std::move(result.second)};
443 }
444 return {deserializeTx(*item), nullptr};
445}
446
447auto
449{
451 // VFALCO Unfortunately this loads the item
452 // from the NodeStore needlessly.
453 if (!stateMap_.peekItem(key, digest))
454 return std::nullopt;
455 return digest.as_uint256();
456}
457
458//------------------------------------------------------------------------------
459
460void
462{
463 if (!stateMap_.delItem(sle->key()))
464 LogicError("Ledger::rawErase: key not found");
465}
466
467void
469{
470 if (!stateMap_.delItem(key))
471 LogicError("Ledger::rawErase: key not found");
472}
473
474void
476{
477 Serializer ss;
478 sle->add(ss);
481 LogicError("Ledger::rawInsert: key already exists");
482}
483
484void
486{
487 Serializer ss;
488 sle->add(ss);
491 LogicError("Ledger::rawReplace: key not found");
492}
493
494void
496 uint256 const& key,
498 std::shared_ptr<Serializer const> const& metaData)
499{
500 XRPL_ASSERT(metaData, "xrpl::Ledger::rawTxInsert : non-null metadata input");
501
502 // low-level - just add to table
503 Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
504 s.addVL(txn->peekData());
505 s.addVL(metaData->peekData());
507 LogicError("duplicate_tx: " + to_string(key));
508}
509
512 uint256 const& key,
514 std::shared_ptr<Serializer const> const& metaData)
515{
516 XRPL_ASSERT(metaData, "xrpl::Ledger::rawTxInsertWithHash : non-null metadata input");
517
518 // low-level - just add to table
519 Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
520 s.addVL(txn->peekData());
521 s.addVL(metaData->peekData());
522 auto item = make_shamapitem(key, s.slice());
523 auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key());
525 LogicError("duplicate_tx: " + to_string(key));
526
527 return hash;
528}
529
530bool
532{
533 bool ret = true;
534
535 try
536 {
538 }
539 catch (SHAMapMissingNode const&)
540 {
541 ret = false;
542 }
543 catch (std::exception const& ex)
544 {
545 JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
546 Rethrow();
547 }
548
549 try
550 {
551 if (auto const sle = read(keylet::fees()))
552 {
553 bool oldFees = false;
554 bool newFees = false;
555 {
556 auto const baseFee = sle->at(~sfBaseFee);
557 auto const reserveBase = sle->at(~sfReserveBase);
558 auto const reserveIncrement = sle->at(~sfReserveIncrement);
559 if (baseFee)
560 fees_.base = *baseFee;
561 if (reserveBase)
562 fees_.reserve = *reserveBase;
563 if (reserveIncrement)
564 fees_.increment = *reserveIncrement;
565 oldFees = baseFee || reserveBase || reserveIncrement;
566 }
567 {
568 auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
569 auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
570 auto const reserveIncrementXRP = sle->at(~sfReserveIncrementDrops);
571 auto assign = [&ret](XRPAmount& dest, std::optional<STAmount> const& src) {
572 if (src)
573 {
574 if (src->native())
575 {
576 dest = src->xrp();
577 }
578 else
579 {
580 ret = false;
581 }
582 }
583 };
584 assign(fees_.base, baseFeeXRP);
585 assign(fees_.reserve, reserveBaseXRP);
586 assign(fees_.increment, reserveIncrementXRP);
587 newFees = baseFeeXRP || reserveBaseXRP || reserveIncrementXRP;
588 }
589 if (oldFees && newFees)
590 {
591 // Should be all of one or the other, but not both
592 ret = false;
593 }
594 if (!rules_.enabled(featureXRPFees) && newFees)
595 {
596 // Can't populate the new fees before the amendment is enabled
597 ret = false;
598 }
599 }
600 }
601 catch (SHAMapMissingNode const&)
602 {
603 ret = false;
604 }
605 catch (std::exception const& ex)
606 {
607 JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
608 Rethrow();
609 }
610
611 return ret;
612}
613
615Ledger::peek(Keylet const& k) const
616{
617 auto const& value = stateMap_.peekItem(k.key);
618 if (!value)
619 return nullptr;
620 auto sle = std::make_shared<SLE>(SerialIter{value->slice()}, value->key());
621 if (!k.check(*sle))
622 return nullptr;
623 return sle;
624}
625
628{
629 hash_set<PublicKey> negUnl;
630 if (auto sle = read(keylet::negativeUNL()); sle && sle->isFieldPresent(sfDisabledValidators))
631 {
632 auto const& nUnlData = sle->getFieldArray(sfDisabledValidators);
633 for (auto const& n : nUnlData)
634 {
635 if (n.isFieldPresent(sfPublicKey))
636 {
637 auto d = n.getFieldVL(sfPublicKey);
638 auto s = makeSlice(d);
639 if (!publicKeyType(s))
640 {
641 continue;
642 }
643 negUnl.emplace(s);
644 }
645 }
646 }
647
648 return negUnl;
649}
650
653{
654 if (auto sle = read(keylet::negativeUNL()); sle && sle->isFieldPresent(sfValidatorToDisable))
655 {
656 auto d = sle->getFieldVL(sfValidatorToDisable);
657 auto s = makeSlice(d);
658 if (publicKeyType(s))
659 return PublicKey(s);
660 }
661
662 return std::nullopt;
663}
664
667{
668 if (auto sle = read(keylet::negativeUNL()); sle && sle->isFieldPresent(sfValidatorToReEnable))
669 {
670 auto d = sle->getFieldVL(sfValidatorToReEnable);
671 auto s = makeSlice(d);
672 if (publicKeyType(s))
673 return PublicKey(s);
674 }
675
676 return std::nullopt;
677}
678
679void
681{
682 auto sle = peek(keylet::negativeUNL());
683 if (!sle)
684 return;
685
686 bool const hasToDisable = sle->isFieldPresent(sfValidatorToDisable);
687 bool const hasToReEnable = sle->isFieldPresent(sfValidatorToReEnable);
688
689 if (!hasToDisable && !hasToReEnable)
690 return;
691
692 STArray newNUnl;
693 if (sle->isFieldPresent(sfDisabledValidators))
694 {
695 auto const& oldNUnl = sle->getFieldArray(sfDisabledValidators);
696 for (auto const& v : oldNUnl)
697 {
698 if (hasToReEnable && v.isFieldPresent(sfPublicKey) &&
699 v.getFieldVL(sfPublicKey) == sle->getFieldVL(sfValidatorToReEnable))
700 continue;
701 newNUnl.push_back(v);
702 }
703 }
704
705 if (hasToDisable)
706 {
707 newNUnl.push_back(STObject::makeInnerObject(sfDisabledValidator));
708 newNUnl.back().setFieldVL(sfPublicKey, sle->getFieldVL(sfValidatorToDisable));
709 newNUnl.back().setFieldU32(sfFirstLedgerSequence, seq());
710 }
711
712 if (!newNUnl.empty())
713 {
714 sle->setFieldArray(sfDisabledValidators, newNUnl);
715 if (hasToReEnable)
716 sle->makeFieldAbsent(sfValidatorToReEnable);
717 if (hasToDisable)
718 sle->makeFieldAbsent(sfValidatorToDisable);
719 rawReplace(sle);
720 }
721 else
722 {
723 rawErase(sle);
724 }
725}
726
727//------------------------------------------------------------------------------
728bool
729Ledger::walkLedger(beast::Journal j, bool parallel) const
730{
731 std::vector<SHAMapMissingNode> missingNodes1;
732 std::vector<SHAMapMissingNode> missingNodes2;
733
735 !stateMap_.fetchRoot(SHAMapHash{header_.accountHash}, nullptr))
736 {
738 }
739 else
740 {
741 if (parallel)
742 {
743 return stateMap_.walkMapParallel(missingNodes1, 32);
744 }
745
746 stateMap_.walkMap(missingNodes1, 32);
747 }
748
749 if (!missingNodes1.empty())
750 {
751 if (auto stream = j.info())
752 {
753 stream << missingNodes1.size() << " missing account node(s)";
754 stream << "First: " << missingNodes1[0].what();
755 }
756 }
757
759 !txMap_.fetchRoot(SHAMapHash{header_.txHash}, nullptr))
760 {
762 }
763 else
764 {
765 txMap_.walkMap(missingNodes2, 32);
766 }
767
768 if (!missingNodes2.empty())
769 {
770 if (auto stream = j.info())
771 {
772 stream << missingNodes2.size() << " missing transaction node(s)";
773 stream << "First: " << missingNodes2[0].what();
774 }
775 }
776 return missingNodes1.empty() && missingNodes2.empty();
777}
778
779bool
781{
782 if (header_.hash.isZero())
783 return false;
785 return false;
787 return false;
789 return false;
790 return true;
791}
792
793// update the skip list with the information from our previous ledger
794// VFALCO TODO Document this skip list concept
795void
797{
798 if (header_.seq == 0) // genesis ledger has no previous ledger
799 return;
800
801 std::uint32_t const prevIndex = header_.seq - 1;
802
803 // update record of every 256th ledger
804 if ((prevIndex & 0xff) == 0)
805 {
806 auto const k = keylet::skip(prevIndex);
807 auto sle = peek(k);
809
810 bool created = false;
811 if (!sle)
812 {
813 sle = std::make_shared<SLE>(k);
814 created = true;
815 }
816 else
817 {
818 hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
819 created = false;
820 }
821
822 XRPL_ASSERT(
823 hashes.size() <= 256, "xrpl::Ledger::updateSkipList : first maximum hashes size");
825 sle->setFieldV256(sfHashes, STVector256(hashes));
826 sle->setFieldU32(sfLastLedgerSequence, prevIndex);
827 if (created)
828 {
829 rawInsert(sle);
830 }
831 else
832 {
833 rawReplace(sle);
834 }
835 }
836
837 // update record of past 256 ledger
838 auto const k = keylet::skip();
839 auto sle = peek(k);
841 bool created = false;
842 if (!sle)
843 {
844 sle = std::make_shared<SLE>(k);
845 created = true;
846 }
847 else
848 {
849 hashes = static_cast<decltype(hashes)>(sle->getFieldV256(sfHashes));
850 created = false;
851 }
852 XRPL_ASSERT(hashes.size() <= 256, "xrpl::Ledger::updateSkipList : second maximum hashes size");
853 if (hashes.size() == 256)
854 hashes.erase(hashes.begin());
856 sle->setFieldV256(sfHashes, STVector256(hashes));
857 sle->setFieldU32(sfLastLedgerSequence, prevIndex);
858 if (created)
859 {
860 rawInsert(sle);
861 }
862 else
863 {
864 rawReplace(sle);
865 }
866}
867
868bool
870{
871 return ::xrpl::isFlagLedger(header_.seq);
872}
873bool
875{
876 return ::xrpl::isVotingLedger(header_.seq + 1);
877}
878
879void
881{
883 txMap_.unshare();
884}
885
886void
892
893} // namespace xrpl
T begin(T... args)
A generic endpoint for log messages.
Definition Journal.h:40
Stream error() const
Definition Journal.h:319
Stream info() const
Definition Journal.h:307
Stream warn() const
Definition Journal.h:313
virtual void missingNodeAcquireByHash(uint256 const &refHash, std::uint32_t refNum)=0
Acquire ledger that has a missing node by ledger hash.
sles_iter_impl(sles_iter_impl const &)=default
bool equal(base_type const &impl) const override
std::unique_ptr< base_type > copy() const override
sles_iter_impl & operator=(sles_iter_impl const &)=delete
sles_type::value_type dereference() const override
sles_iter_impl(SHAMap::const_iterator iter)
bool equal(base_type const &impl) const override
txs_iter_impl(txs_iter_impl const &)=default
std::unique_ptr< base_type > copy() const override
txs_iter_impl(bool metadata, SHAMap::const_iterator iter)
txs_type::value_type dereference() const override
txs_iter_impl & operator=(txs_iter_impl const &)=delete
bool txExists(uint256 const &key) const override
std::unique_ptr< txs_type::iter_base > txsEnd() const override
bool isFlagLedger() const
Returns true if the ledger is a flag ledger.
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
void rawTxInsert(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
std::optional< PublicKey > validatorToDisable() const
get the to be disabled validator's master public key if any
uint256 rawTxInsertWithHash(uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
void updateNegativeUNL()
update the Negative UNL ledger component.
bool isVotingLedger() const
Returns true if the ledger directly precedes a flag ledger.
std::unique_ptr< sles_type::iter_base > slesBegin() const override
hash_set< PublicKey > negativeUNL() const
get Negative UNL validators' master public keys
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
void setImmutable(bool rehash=true)
bool open() const override
Returns true if this reflects an open ledger.
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
static std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > deserializeTxPlusMeta(SHAMapItem const &item)
Deserialize a SHAMapItem containing STTx + STObject metadata.
LedgerHeader const & header() const override
Returns information about the ledger.
void setAccepted(NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime)
Ledger(Ledger const &)=delete
static std::shared_ptr< STTx const > deserializeTx(SHAMapItem const &item)
Deserialize a SHAMapItem containing a single STTx.
std::shared_ptr< SLE > peek(Keylet const &k) const
bool addSLE(SLE const &sle)
std::unique_ptr< txs_type::iter_base > txsBegin() const override
std::unique_ptr< sles_type::iter_base > slesEnd() const override
std::optional< uint256 > succ(uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
Fees const & fees() const override
Returns the fees for the base ledger.
bool walkLedger(beast::Journal j, bool parallel=false) const
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
std::optional< PublicKey > validatorToReEnable() const
get the to be re-enabled validator's master public key if any
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
bool exists(Keylet const &k) const override
Determine if a state item exists.
A public key.
Definition PublicKey.h:42
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:97
Rules controlling protocol behavior.
Definition Rules.h:18
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition Rules.cpp:120
uint256 const & as_uint256() const
Definition SHAMapHash.h:24
bool isZero() const
Definition SHAMapHash.h:34
Slice slice() const
Definition SHAMapItem.h:84
bool addItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition SHAMap.cpp:807
const_iterator upper_bound(uint256 const &id) const
Find the first item after the given item.
Definition SHAMap.cpp:579
const_iterator end() const
Definition SHAMap.h:698
const_iterator begin() const
Definition SHAMap.h:692
boost::intrusive_ptr< SHAMapItem const > const & peekItem(uint256 const &id) const
Definition SHAMap.cpp:556
int flushDirty(NodeObjectType t)
Flush modified nodes to the nodestore and convert them to shared.
Definition SHAMap.cpp:952
bool walkMapParallel(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
void walkMap(std::vector< SHAMapMissingNode > &missingNodes, int maxMissing) const
bool hasItem(uint256 const &id) const
Does the tree have an item with the given ID?
Definition SHAMap.cpp:647
int unshare()
Convert any modified nodes to shared.
Definition SHAMap.cpp:945
bool updateGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition SHAMap.cpp:825
void setImmutable()
Definition SHAMap.h:544
void invariants() const
Definition SHAMap.cpp:1147
bool addGiveItem(SHAMapNodeType type, boost::intrusive_ptr< SHAMapItem const > item)
Definition SHAMap.cpp:738
bool fetchRoot(SHAMapHash const &hash, SHAMapSyncFilter *filter)
Definition SHAMap.cpp:865
SHAMapHash getHash() const
Definition SHAMap.cpp:813
bool delItem(uint256 const &id)
Definition SHAMap.cpp:653
void push_back(STObject const &object)
Definition STArray.h:189
bool empty() const
Definition STArray.h:231
STObject & back()
Definition STArray.h:170
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
void setFieldVL(SField const &field, Blob const &)
Definition STObject.cpp:777
void setFieldU32(SField const &field, std::uint32_t)
Definition STObject.cpp:735
Serializer getSerializer() const
Definition STObject.h:980
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:73
Slice getSlice(std::size_t bytes)
int addVL(Blob const &vector)
Slice slice() const noexcept
Definition Serializer.h:44
std::optional< Dest > dropsAs() const
Definition XRPAmount.h:167
bool isZero() const
Definition base_uint.h:513
bool isNonZero() const
Definition base_uint.h:518
T emplace_back(T... args)
T emplace(T... args)
T empty(T... args)
T erase(T... args)
T find(T... args)
T is_same_v
STL namespace.
Keylet const & skip() noexcept
The index of the "short" skip list.
Definition Indexes.cpp:177
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
Definition Indexes.cpp:207
Keylet const & amendments() noexcept
The index of the amendment table.
Definition Indexes.cpp:193
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Definition Indexes.cpp:200
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition tokens.cpp:138
boost::intrusive_ptr< SHAMapItem > make_shamapitem(uint256 const &tag, Slice data)
Definition SHAMapItem.h:139
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
Definition digest.h:204
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:602
XRPL_NO_SANITIZE_ADDRESS void Rethrow()
Rethrow the exception currently being handled.
Definition contract.h:33
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:50
create_genesis_t const create_genesis
auto constexpr ledgerDefaultTimeResolution
Initial resolution of ledger close time.
@ hotACCOUNT_NODE
Definition NodeObject.h:15
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:57
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.
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
bool getCloseAgree(LedgerHeader const &info)
uint256 calculateLedgerHash(LedgerHeader const &info)
Calculate the hash of a ledger header.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
base_uint< 256 > uint256
Definition base_uint.h:531
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.
@ open
We haven't closed our ledger yet, but others might have.
constexpr std::uint32_t FEE_UNITS_DEPRECATED
static std::uint32_t const sLCF_NoConsensusTime
AccountID calcAccountID(PublicKey const &pk)
auto constexpr ledgerGenesisTimeResolution
Close time resolution in genesis ledger.
@ txNode
transaction plus metadata
constexpr XRPAmount INITIAL_XRP
Configure the native currency.
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:215
T push_back(T... args)
T size(T... args)
Reflects the fee settings for a particular ledger.
XRPAmount reserve
Minimum XRP an account must hold to exist on the ledger.
XRPAmount increment
Additional XRP reserve required per owned ledger object.
XRPAmount base
Cost of a reference transaction in drops.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
uint256 key
Definition Keylet.h:20
bool check(STLedgerEntry const &) const
Returns true if the SLE matches the type.
Definition Keylet.cpp:9
Information about the notional ledger backing the view.
NetClock::time_point parentCloseTime
NetClock::duration closeTimeResolution
NetClock::time_point closeTime
T what(T... args)