|
xrpld
|
Holds a ledger. More...
#include <Ledger.h>


Classes | |
| class | SlesIterImpl |
| class | TxsIterImpl |
Public Types | |
| using | DigestType = UInt256 |
| using | TxType = std::pair<std::shared_ptr<STTx const>, std::shared_ptr<STObject const>> |
| using | key_type = UInt256 |
| using | mapped_type = SLE::const_pointer |
Public Member Functions | |
| Ledger (Ledger const &)=delete | |
| Ledger & | operator= (Ledger const &)=delete |
| Ledger (Ledger &&)=delete | |
| Ledger & | operator= (Ledger &&)=delete |
| Ledger (CreateGenesisT, Rules rules, Fees const &fees, std::vector< UInt256 > const &amendments, Family &family) | |
| Create the Genesis ledger. | |
| Ledger (LedgerHeader const &info, Rules rules, Family &family) | |
| Ledger (LedgerHeader const &info, bool &loaded, bool acquire, Rules rules, Fees const &fees, Family &family, beast::Journal j) | |
| Used for ledgers loaded from JSON files. | |
| Ledger (Ledger const &previous, NetClock::time_point closeTime) | |
| Create a new ledger following a previous ledger. | |
| Ledger (std::uint32_t ledgerSeq, NetClock::time_point closeTime, Rules rules, Fees const &fees, Family &family) | |
| ~Ledger () override=default | |
| bool | open () const override |
| Returns true if this reflects an open ledger. | |
| LedgerHeader const & | header () const override |
| Returns information about the ledger. | |
| void | setLedgerInfo (LedgerHeader const &info) |
| Fees const & | fees () const override |
| Returns the fees for the base ledger. | |
| Rules const & | rules () const override |
| Returns the tx processing rules. | |
| bool | exists (Keylet const &k) const override |
| Determine if a state item exists. | |
| bool | exists (UInt256 const &key) const |
| std::optional< UInt256 > | succ (UInt256 const &key, std::optional< UInt256 > const &last=std::nullopt) const override |
| SLE::const_pointer | read (Keylet const &k) const override |
| Return the state item associated with a key. | |
| std::unique_ptr< SlesType::IterBase > | slesBegin () const override |
| std::unique_ptr< SlesType::IterBase > | slesEnd () const override |
| std::unique_ptr< SlesType::IterBase > | slesUpperBound (UInt256 const &key) const override |
| std::unique_ptr< TxsType::IterBase > | txsBegin () const override |
| std::unique_ptr< TxsType::IterBase > | txsEnd () const override |
| bool | txExists (UInt256 const &key) const override |
| TxType | txRead (key_type const &key) const override |
| Read a transaction from the tx map. | |
| std::optional< DigestType > | digest (key_type const &key) const override |
| Return the digest associated with the key. | |
| void | rawErase (SLE::Ref sle) override |
| Delete an existing state item. | |
| void | rawInsert (SLE::Ref sle) override |
| Unconditionally insert a state item. | |
| void | rawErase (UInt256 const &key) |
| void | rawReplace (SLE::Ref sle) override |
| Unconditionally replace a state item. | |
| void | rawDestroyXRP (XRPAmount const &fee) override |
| Destroy XRP. | |
| void | rawTxInsert (UInt256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override |
| void | setValidated () const |
| bool | setAccepted (NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime) |
| Mark this ledger as accepted and attempt to make it immutable. | |
| bool | setImmutable (bool rehash=true) |
| Mark this ledger as immutable, so it can no longer be modified. | |
| bool | isImmutable () const |
| bool | mapsValid () const |
| void | setFull () const |
| Mark this ledger as "should be full", indicating that the local server wants all the corresponding nodes in durable storage. | |
| void | setTotalDrops (std::uint64_t totDrops) |
| SHAMap const & | stateMap () const |
| SHAMap & | stateMap () |
| SHAMap const & | txMap () const |
| SHAMap & | txMap () |
| bool | addSLE (SLE const &sle) |
| void | updateSkipList () |
| bool | walkLedger (beast::Journal j, bool parallel=false) const |
| bool | isSensible () const |
| void | invariants () const |
| void | unshare () const |
| HashSet< PublicKey > | negativeUNL () const |
| get Negative UNL validators' master public keys | |
| std::optional< PublicKey > | validatorToDisable () const |
| get the to be disabled validator's master public key if any | |
| std::optional< PublicKey > | validatorToReEnable () const |
| get the to be re-enabled validator's master public key if any | |
| void | updateNegativeUNL () |
| update the Negative UNL ledger component. | |
| bool | isFlagLedger () const |
| Returns true if the ledger is a flag ledger. | |
| bool | isVotingLedger () const |
| Returns true if the ledger directly precedes a flag ledger. | |
| SLE::pointer | peek (Keylet const &k) const |
| T | shared_from_this (T... args) |
| T | weak_from_this (T... args) |
| NetClock::time_point | parentCloseTime () const |
| Returns the close time of the previous ledger. | |
| LedgerIndex | seq () const |
| Returns the sequence number of the base ledger. | |
| virtual std::optional< key_type > | succ (key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0 |
| Return the key of the next state item. | |
| virtual STAmount | balanceHookIOU (AccountID const &account, AccountID const &issuer, STAmount const &amount) const |
| virtual STAmount | balanceHookMPT (AccountID const &account, MPTIssue const &issue, std::int64_t amount) const |
| virtual STAmount | balanceHookSelfIssueMPT (MPTIssue const &issue, std::int64_t amount) const |
| virtual OwnerCounts | ownerCountHook (AccountID const &account, OwnerCounts const &count) const |
| virtual std::unique_ptr< SlesType::IterBase > | slesUpperBound (key_type const &key) const =0 |
| virtual bool | txExists (key_type const &key) const =0 |
| Returns true if a tx exists in the tx map. | |
| virtual void | rawTxInsert (ReadView::key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)=0 |
| Add a transaction to the tx map. | |
Public Attributes | |
| SlesType | sles |
| Iterable range of ledger state items. | |
| TxsType | txs |
| friend | Object |
Private Member Functions | |
| bool | setup () |
| bool | setMapsImmutable () |
| Make both maps immutable. | |
Static Private Member Functions | |
| static std::shared_ptr< STTx const > | deserializeTx (SHAMapItem const &item) |
| Deserialize a SHAMapItem containing a single STTx. | |
| static std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > | deserializeTxPlusMeta (SHAMapItem const &item) |
| Deserialize a SHAMapItem containing STTx + STObject metadata. | |
| static auto & | getCounter () noexcept |
Private Attributes | |
| bool | immutable_ |
| SHAMap | txMap_ |
| SHAMap | stateMap_ |
| std::mutex | mutex_ |
| Fees | fees_ |
| Rules | rules_ |
| LedgerHeader | header_ |
| beast::Journal | j_ |
Holds a ledger.
The ledger is composed of two SHAMaps. The state map holds all of the ledger entries such as account roots and order books. The tx map holds all of the transactions and associated metadata that made it into that particular ledger. Most of the operations on a ledger are concerned with the state map.
This can hold just the header, a partial set of data, or the entire set of data. It all depends on what is in the corresponding SHAMap entry. Various functions are provided to populate or depopulate the caches that the object holds references to.
Ledgers are constructed as either mutable or immutable.
1) If you are the sole owner of a mutable ledger, you can do whatever you want with no need for locks.
2) If you have an immutable ledger, you cannot ever change it, so no need for locks.
3) Mutable ledgers cannot be shared.
Definition at line 72 of file include/xrpl/ledger/Ledger.h.
|
inherited |
Definition at line 281 of file ReadView.h.
|
inherited |
Definition at line 43 of file ReadView.h.
|
inherited |
Definition at line 45 of file ReadView.h.
|
inherited |
Definition at line 47 of file ReadView.h.
|
delete |
|
delete |
| xrpl::Ledger::Ledger | ( | CreateGenesisT | , |
| Rules | rules, | ||
| Fees const & | fees, | ||
| std::vector< UInt256 > const & | amendments, | ||
| Family & | family ) |
Create the Genesis ledger.
The Genesis ledger contains a single account whose AccountID is generated with a Generator using the seed computed from the string "masterpassphrase" and ordinal zero.
The account has an XRP balance equal to the total amount of XRP in the system. No more XRP than the amount which starts in this account can ever exist, with amounts used to pay fees being destroyed.
Amendments specified are enabled in the genesis ledger
Definition at line 150 of file libxrpl/ledger/Ledger.cpp.
| xrpl::Ledger::Ledger | ( | LedgerHeader const & | info, |
| Rules | rules, | ||
| Family & | family ) |
Definition at line 293 of file libxrpl/ledger/Ledger.cpp.
| xrpl::Ledger::Ledger | ( | LedgerHeader const & | info, |
| bool & | loaded, | ||
| bool | acquire, | ||
| Rules | rules, | ||
| Fees const & | fees, | ||
| Family & | family, | ||
| beast::Journal | j ) |
Used for ledgers loaded from JSON files.
| acquire | If true, acquires the ledger if not found locally |
Definition at line 208 of file libxrpl/ledger/Ledger.cpp.
| xrpl::Ledger::Ledger | ( | Ledger const & | previous, |
| NetClock::time_point | closeTime ) |
Create a new ledger following a previous ledger.
The ledger will have the sequence number that follows previous, and have parentCloseTime == previous.closeTime.
Definition at line 266 of file libxrpl/ledger/Ledger.cpp.
| xrpl::Ledger::Ledger | ( | std::uint32_t | ledgerSeq, |
| NetClock::time_point | closeTime, | ||
| Rules | rules, | ||
| Fees const & | fees, | ||
| Family & | family ) |
Definition at line 304 of file libxrpl/ledger/Ledger.cpp.
|
overridedefault |
|
overridevirtual |
Returns true if this reflects an open ledger.
Implements xrpl::ReadView.
Definition at line 151 of file include/xrpl/ledger/Ledger.h.
|
overridevirtual |
Returns information about the ledger.
Implements xrpl::ReadView.
Definition at line 157 of file include/xrpl/ledger/Ledger.h.
| void xrpl::Ledger::setLedgerInfo | ( | LedgerHeader const & | info | ) |
Definition at line 163 of file include/xrpl/ledger/Ledger.h.
|
overridevirtual |
Returns the fees for the base ledger.
Implements xrpl::ReadView.
Definition at line 169 of file include/xrpl/ledger/Ledger.h.
|
overridevirtual |
Returns the tx processing rules.
Implements xrpl::ReadView.
Definition at line 175 of file include/xrpl/ledger/Ledger.h.
|
overridevirtual |
Determine if a state item exists.
Implements xrpl::ReadView.
Definition at line 426 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::exists | ( | UInt256 const & | key | ) | const |
Definition at line 433 of file libxrpl/ledger/Ledger.cpp.
|
override |
Definition at line 439 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Return the state item associated with a key.
Effects: If the key exists, gives the caller ownership of the non-modifiable corresponding SLE.
Implements xrpl::ReadView.
Definition at line 450 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Implements xrpl::ReadView.
Definition at line 471 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Implements xrpl::ReadView.
Definition at line 477 of file libxrpl/ledger/Ledger.cpp.
|
override |
Definition at line 483 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Implements xrpl::ReadView.
Definition at line 489 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Implements xrpl::ReadView.
Definition at line 495 of file libxrpl/ledger/Ledger.cpp.
|
override |
Definition at line 501 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Read a transaction from the tx map.
If the view represents an open ledger, the metadata object will be empty.
Implements xrpl::ReadView.
Definition at line 507 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Return the digest associated with the key.
Implements xrpl::DigestAwareReadView.
Definition at line 521 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Delete an existing state item.
The SLE is provided so the implementation can calculate metadata.
Implements xrpl::RawView.
Definition at line 534 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Unconditionally insert a state item.
Requirements: The key must not already exist.
Effects:
The key is associated with the SLE.
Implements xrpl::RawView.
Definition at line 548 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::rawErase | ( | UInt256 const & | key | ) |
Definition at line 541 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Unconditionally replace a state item.
Requirements:
The key must exist.
Effects:
The key is associated with the SLE.
Implements xrpl::RawView.
Definition at line 560 of file libxrpl/ledger/Ledger.cpp.
|
overridevirtual |
Destroy XRP.
This is used to pay for transaction fees.
Implements xrpl::RawView.
Definition at line 237 of file include/xrpl/ledger/Ledger.h.
|
override |
Definition at line 572 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::setValidated | ( | ) | const |
Definition at line 255 of file include/xrpl/ledger/Ledger.h.
|
nodiscard |
Mark this ledger as accepted and attempt to make it immutable.
The close-time fields are recorded first, since the ledger hash covers them.
| closeTime | The consensus-agreed close time. |
| closeResolution | The close time resolution. |
| correctCloseTime | Whether consensus agreed on the close time. If false, kSLcfNoConsensusTime is recorded in closeFlags instead. |
Definition at line 367 of file libxrpl/ledger/Ledger.cpp.
|
nodiscard |
Mark this ledger as immutable, so it can no longer be modified.
A ledger built or loaded locally cannot have an invalid map, since only a map syncing against hashes from outside can be proven impossible (see SHAMap::addKnownNode), so a caller on such a path may treat a false return as a broken internal invariant. A caller assembling a ledger from peer data may not: for it, false is an outcome a peer can produce.
| rehash | Whether to recompute the ledger hash from the header fields. The transaction and account hashes are recomputed from the maps too, but only the first time. |
Definition at line 324 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::isImmutable | ( | ) | const |
Definition at line 299 of file include/xrpl/ledger/Ledger.h.
|
nodiscard |
Definition at line 309 of file include/xrpl/ledger/Ledger.h.
| void xrpl::Ledger::setFull | ( | ) | const |
Mark this ledger as "should be full", indicating that the local server wants all the corresponding nodes in durable storage.
Const because it reflects metadata, not data this ledger shares with other nodes on the network.
Definition at line 322 of file include/xrpl/ledger/Ledger.h.
| void xrpl::Ledger::setTotalDrops | ( | std::uint64_t | totDrops | ) |
Definition at line 329 of file include/xrpl/ledger/Ledger.h.
| SHAMap const & xrpl::Ledger::stateMap | ( | ) | const |
Definition at line 335 of file include/xrpl/ledger/Ledger.h.
| SHAMap & xrpl::Ledger::stateMap | ( | ) |
Definition at line 341 of file include/xrpl/ledger/Ledger.h.
| SHAMap const & xrpl::Ledger::txMap | ( | ) | const |
Definition at line 347 of file include/xrpl/ledger/Ledger.h.
| SHAMap & xrpl::Ledger::txMap | ( | ) |
Definition at line 353 of file include/xrpl/ledger/Ledger.h.
| bool xrpl::Ledger::addSLE | ( | SLE const & | sle | ) |
Definition at line 392 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::updateSkipList | ( | ) |
Definition at line 870 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::walkLedger | ( | beast::Journal | j, |
| bool | parallel = false ) const |
Definition at line 803 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::isSensible | ( | ) | const |
Definition at line 854 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::invariants | ( | ) | const |
Definition at line 961 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::unshare | ( | ) | const |
Definition at line 954 of file libxrpl/ledger/Ledger.cpp.
get Negative UNL validators' master public keys
Definition at line 700 of file libxrpl/ledger/Ledger.cpp.
| std::optional< PublicKey > xrpl::Ledger::validatorToDisable | ( | ) | const |
get the to be disabled validator's master public key if any
Definition at line 725 of file libxrpl/ledger/Ledger.cpp.
| std::optional< PublicKey > xrpl::Ledger::validatorToReEnable | ( | ) | const |
get the to be re-enabled validator's master public key if any
Definition at line 739 of file libxrpl/ledger/Ledger.cpp.
| void xrpl::Ledger::updateNegativeUNL | ( | ) |
update the Negative UNL ledger component.
Definition at line 754 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::isFlagLedger | ( | ) | const |
Returns true if the ledger is a flag ledger.
Definition at line 943 of file libxrpl/ledger/Ledger.cpp.
| bool xrpl::Ledger::isVotingLedger | ( | ) | const |
Returns true if the ledger directly precedes a flag ledger.
Definition at line 948 of file libxrpl/ledger/Ledger.cpp.
| SLE::pointer xrpl::Ledger::peek | ( | Keylet const & | k | ) | const |
Definition at line 688 of file libxrpl/ledger/Ledger.cpp.
|
private |
Definition at line 588 of file libxrpl/ledger/Ledger.cpp.
|
staticprivate |
Deserialize a SHAMapItem containing a single STTx.
| item | The SHAMapItem to deserialize. |
| May | throw on deserialization error. |
Definition at line 401 of file libxrpl/ledger/Ledger.cpp.
|
staticprivate |
Deserialize a SHAMapItem containing STTx + STObject metadata.
The SHAMapItem must contain two variable length serialization objects.
| item | The SHAMapItem to deserialize. |
| May | throw on deserialization error. |
Definition at line 408 of file libxrpl/ledger/Ledger.cpp.
|
nodiscardprivate |
Make both maps immutable.
Each map is settled on its own, so neither is left mid-sync because the other refused.
Definition at line 464 of file include/xrpl/ledger/Ledger.h.
|
nodiscardinherited |
Returns the close time of the previous ledger.
Definition at line 106 of file ReadView.h.
|
nodiscardinherited |
Returns the sequence number of the base ledger.
Definition at line 115 of file ReadView.h.
|
nodiscardpure virtualinherited |
Return the key of the next state item.
This returns the key of the first state item whose key is greater than the specified key. If no such key is present, std::nullopt is returned.
If last is engaged, returns std::nullopt when the key returned would be outside the open interval (key, last).
Implemented in xrpl::detail::ApplyViewBase, xrpl::detail::CachedViewImpl, and xrpl::OpenView.
|
nodiscardvirtualinherited |
Reimplemented in xrpl::PaymentSandbox.
Definition at line 180 of file ReadView.h.
|
nodiscardvirtualinherited |
Reimplemented in xrpl::PaymentSandbox.
Definition at line 190 of file ReadView.h.
|
nodiscardvirtualinherited |
Reimplemented in xrpl::PaymentSandbox.
Definition at line 200 of file ReadView.h.
|
nodiscardvirtualinherited |
Reimplemented in xrpl::PaymentSandbox.
Definition at line 211 of file ReadView.h.
|
nodiscardpure virtualinherited |
|
nodiscardpure virtualinherited |
Returns true if a tx exists in the tx map.
A tx exists in the map if it is part of the base ledger, or if it is a newly inserted tx.
Implemented in xrpl::detail::ApplyViewBase, xrpl::detail::CachedViewImpl, and xrpl::OpenView.
|
pure virtualinherited |
Add a transaction to the tx map.
Closed ledgers must have metadata, while open ledgers omit metadata.
Implemented in xrpl::OpenView.
|
staticprivatenoexceptinherited |
Definition at line 113 of file CountedObject.h.
|
private |
Definition at line 471 of file include/xrpl/ledger/Ledger.h.
|
mutableprivate |
Definition at line 474 of file include/xrpl/ledger/Ledger.h.
|
mutableprivate |
Definition at line 477 of file include/xrpl/ledger/Ledger.h.
|
mutableprivate |
Definition at line 480 of file include/xrpl/ledger/Ledger.h.
|
private |
Definition at line 482 of file include/xrpl/ledger/Ledger.h.
|
private |
Definition at line 483 of file include/xrpl/ledger/Ledger.h.
|
private |
Definition at line 484 of file include/xrpl/ledger/Ledger.h.
|
private |
Definition at line 485 of file include/xrpl/ledger/Ledger.h.
|
inherited |
Iterable range of ledger state items.
Definition at line 267 of file ReadView.h.
|
inherited |
Definition at line 270 of file ReadView.h.
|
inherited |
Definition at line 138 of file CountedObject.h.