rippled
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ripple::Ledger Class Referencefinal

Holds a ledger. More...

Inheritance diagram for ripple::Ledger:
Inheritance graph
[legend]
Collaboration diagram for ripple::Ledger:
Collaboration graph
[legend]

Classes

class  sles_iter_impl
 
class  txs_iter_impl
 

Public Types

using digest_type = uint256
 
using tx_type = std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > >
 
using key_type = uint256
 
using mapped_type = std::shared_ptr< SLE const >
 

Public Member Functions

 Ledger (Ledger const &)=delete
 
Ledgeroperator= (Ledger const &)=delete
 
 Ledger (Ledger &&)=delete
 
Ledgeroperator= (Ledger &&)=delete
 
 Ledger (create_genesis_t, Config const &config, std::vector< uint256 > const &amendments, Family &family)
 Create the Genesis ledger. More...
 
 Ledger (LedgerInfo const &info, Config const &config, Family &family)
 
 Ledger (LedgerInfo const &info, bool &loaded, bool acquire, Config const &config, Family &family, beast::Journal j)
 Used for ledgers loaded from JSON files. More...
 
 Ledger (Ledger const &previous, NetClock::time_point closeTime)
 Create a new ledger following a previous ledger. More...
 
 Ledger (std::uint32_t ledgerSeq, NetClock::time_point closeTime, Config const &config, Family &family)
 
 ~Ledger ()=default
 
bool open () const override
 Returns true if this reflects an open ledger. More...
 
LedgerInfo const & info () const override
 Returns information about the ledger. More...
 
void setLedgerInfo (LedgerInfo const &info)
 
Fees const & fees () const override
 Returns the fees for the base ledger. More...
 
Rules const & rules () const override
 Returns the tx processing rules. More...
 
bool exists (Keylet const &k) const override
 Determine if a state item exists. More...
 
bool exists (uint256 const &key) const
 
std::optional< uint256succ (uint256 const &key, std::optional< uint256 > const &last=std::nullopt) const override
 Return the key of the next state item. More...
 
std::shared_ptr< SLE const > read (Keylet const &k) const override
 Return the state item associated with a key. More...
 
std::unique_ptr< sles_type::iter_baseslesBegin () const override
 
std::unique_ptr< sles_type::iter_baseslesEnd () const override
 
std::unique_ptr< sles_type::iter_baseslesUpperBound (uint256 const &key) const override
 
std::unique_ptr< txs_type::iter_basetxsBegin () const override
 
std::unique_ptr< txs_type::iter_basetxsEnd () const override
 
bool txExists (uint256 const &key) const override
 Returns true if a tx exists in the tx map. More...
 
tx_type txRead (key_type const &key) const override
 Read a transaction from the tx map. More...
 
std::optional< digest_typedigest (key_type const &key) const override
 Return the digest associated with the key. More...
 
void rawErase (std::shared_ptr< SLE > const &sle) override
 Delete an existing state item. More...
 
void rawInsert (std::shared_ptr< SLE > const &sle) override
 Unconditionally insert a state item. More...
 
void rawErase (uint256 const &key)
 
void rawReplace (std::shared_ptr< SLE > const &sle) override
 Unconditionally replace a state item. More...
 
void rawDestroyXRP (XRPAmount const &fee) override
 Destroy XRP. More...
 
void rawTxInsert (uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
 Add a transaction to the tx map. More...
 
uint256 rawTxInsertWithHash (uint256 const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData)
 
void setValidated () const
 
void setAccepted (NetClock::time_point closeTime, NetClock::duration closeResolution, bool correctCloseTime)
 
void setImmutable (bool rehash=true)
 
bool isImmutable () const
 
void setFull () const
 
void setTotalDrops (std::uint64_t totDrops)
 
SHAMap const & stateMap () const
 
SHAMapstateMap ()
 
SHAMap const & txMap () const
 
SHAMaptxMap ()
 
bool addSLE (SLE const &sle)
 
void updateSkipList ()
 
bool walkLedger (beast::Journal j, bool parallel=false) const
 
bool assertSensible (beast::Journal ledgerJ) const
 
void invariants () const
 
void unshare () const
 
hash_set< PublicKeynegativeUNL () const
 get Negative UNL validators' master public keys More...
 
std::optional< PublicKeyvalidatorToDisable () const
 get the to be disabled validator's master public key if any More...
 
std::optional< PublicKeyvalidatorToReEnable () const
 get the to be re-enabled validator's master public key if any More...
 
void updateNegativeUNL ()
 update the Negative UNL ledger component. More...
 
bool isFlagLedger () const
 Returns true if the ledger is a flag ledger. More...
 
bool isVotingLedger () const
 Returns true if the ledger directly precedes a flag ledger. More...
 
std::shared_ptr< SLEpeek (Keylet const &k) const
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 
NetClock::time_point parentCloseTime () const
 Returns the close time of the previous ledger. More...
 
LedgerIndex seq () const
 Returns the sequence number of the base ledger. More...
 
virtual STAmount balanceHook (AccountID const &account, AccountID const &issuer, STAmount const &amount) const
 
virtual std::uint32_t ownerCountHook (AccountID const &account, std::uint32_t count) const
 

Public Attributes

sles_type sles
 Iterable range of ledger state items. More...
 
txs_type txs
 

Private Member Functions

bool setup ()
 
void defaultFees (Config const &config)
 

Static Private Member Functions

static auto & getCounter () noexcept
 

Private Attributes

bool mImmutable
 
SHAMap txMap_
 
SHAMap stateMap_
 
std::mutex mutex_
 
Fees fees_
 
Rules rules_
 
LedgerInfo info_
 
beast::Journal j_
 

Detailed Description

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.

Note
Presented to clients as ReadView
Calls virtuals in the constructor, so marked as final

Definition at line 76 of file Ledger.h.

Member Typedef Documentation

◆ digest_type

Definition at line 332 of file ReadView.h.

◆ tx_type

Definition at line 129 of file ReadView.h.

◆ key_type

Definition at line 131 of file ReadView.h.

◆ mapped_type

Definition at line 133 of file ReadView.h.

Constructor & Destructor Documentation

◆ Ledger() [1/7]

ripple::Ledger::Ledger ( Ledger const &  )
delete

◆ Ledger() [2/7]

ripple::Ledger::Ledger ( Ledger &&  )
delete

◆ Ledger() [3/7]

ripple::Ledger::Ledger ( create_genesis_t  ,
Config const &  config,
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 179 of file Ledger.cpp.

◆ Ledger() [4/7]

ripple::Ledger::Ledger ( LedgerInfo const &  info,
Config const &  config,
Family family 
)

Definition at line 328 of file Ledger.cpp.

◆ Ledger() [5/7]

ripple::Ledger::Ledger ( LedgerInfo const &  info,
bool &  loaded,
bool  acquire,
Config const &  config,
Family family,
beast::Journal  j 
)

Used for ledgers loaded from JSON files.

Parameters
acquireIf true, acquires the ledger if not found locally

Definition at line 242 of file Ledger.cpp.

◆ Ledger() [6/7]

ripple::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 298 of file Ledger.cpp.

◆ Ledger() [7/7]

ripple::Ledger::Ledger ( std::uint32_t  ledgerSeq,
NetClock::time_point  closeTime,
Config const &  config,
Family family 
)

Definition at line 339 of file Ledger.cpp.

◆ ~Ledger()

ripple::Ledger::~Ledger ( )
default

Member Function Documentation

◆ operator=() [1/2]

Ledger& ripple::Ledger::operator= ( Ledger const &  )
delete

◆ operator=() [2/2]

Ledger& ripple::Ledger::operator= ( Ledger &&  )
delete

◆ open()

bool ripple::Ledger::open ( ) const
overridevirtual

Returns true if this reflects an open ledger.

Implements ripple::ReadView.

Definition at line 146 of file Ledger.h.

◆ info()

LedgerInfo const& ripple::Ledger::info ( ) const
overridevirtual

Returns information about the ledger.

Implements ripple::ReadView.

Definition at line 152 of file Ledger.h.

◆ setLedgerInfo()

void ripple::Ledger::setLedgerInfo ( LedgerInfo const &  info)

Definition at line 158 of file Ledger.h.

◆ fees()

Fees const& ripple::Ledger::fees ( ) const
overridevirtual

Returns the fees for the base ledger.

Implements ripple::ReadView.

Definition at line 164 of file Ledger.h.

◆ rules()

Rules const& ripple::Ledger::rules ( ) const
overridevirtual

Returns the tx processing rules.

Implements ripple::ReadView.

Definition at line 170 of file Ledger.h.

◆ exists() [1/2]

bool ripple::Ledger::exists ( Keylet const &  k) const
overridevirtual

Determine if a state item exists.

Note
This can be more efficient than calling read.
Returns
true if a SLE is associated with the specified key.

Implements ripple::ReadView.

Definition at line 429 of file Ledger.cpp.

◆ exists() [2/2]

bool ripple::Ledger::exists ( uint256 const &  key) const

Definition at line 436 of file Ledger.cpp.

◆ succ()

std::optional< uint256 > ripple::Ledger::succ ( uint256 const &  key,
std::optional< uint256 > const &  last = std::nullopt 
) const
overridevirtual

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).

Implements ripple::ReadView.

Definition at line 442 of file Ledger.cpp.

◆ read()

std::shared_ptr< SLE const > ripple::Ledger::read ( Keylet const &  k) const
overridevirtual

Return the state item associated with a key.

Effects: If the key exists, gives the caller ownership of the non-modifiable corresponding SLE.

Note
While the returned SLE is const from the perspective of the caller, it can be changed by other callers through raw operations.
Returns
nullptr if the key is not present or if the type does not match.

Implements ripple::ReadView.

Definition at line 453 of file Ledger.cpp.

◆ slesBegin()

auto ripple::Ledger::slesBegin ( ) const
overridevirtual

Implements ripple::ReadView.

Definition at line 472 of file Ledger.cpp.

◆ slesEnd()

auto ripple::Ledger::slesEnd ( ) const
overridevirtual

Implements ripple::ReadView.

Definition at line 478 of file Ledger.cpp.

◆ slesUpperBound()

auto ripple::Ledger::slesUpperBound ( uint256 const &  key) const
overridevirtual

Implements ripple::ReadView.

Definition at line 484 of file Ledger.cpp.

◆ txsBegin()

auto ripple::Ledger::txsBegin ( ) const
overridevirtual

Implements ripple::ReadView.

Definition at line 491 of file Ledger.cpp.

◆ txsEnd()

auto ripple::Ledger::txsEnd ( ) const
overridevirtual

Implements ripple::ReadView.

Definition at line 497 of file Ledger.cpp.

◆ txExists()

bool ripple::Ledger::txExists ( uint256 const &  key) const
overridevirtual

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.

Implements ripple::ReadView.

Definition at line 503 of file Ledger.cpp.

◆ txRead()

auto ripple::Ledger::txRead ( key_type const &  key) const
overridevirtual

Read a transaction from the tx map.

If the view represents an open ledger, the metadata object will be empty.

Returns
A pair of nullptr if the key is not found in the tx map.

Implements ripple::ReadView.

Definition at line 509 of file Ledger.cpp.

◆ digest()

auto ripple::Ledger::digest ( key_type const &  key) const
overridevirtual

Return the digest associated with the key.

Returns
std::nullopt if the item does not exist.

Implements ripple::DigestAwareReadView.

Definition at line 523 of file Ledger.cpp.

◆ rawErase() [1/2]

void ripple::Ledger::rawErase ( std::shared_ptr< SLE > const &  sle)
overridevirtual

Delete an existing state item.

The SLE is provided so the implementation can calculate metadata.

Implements ripple::RawView.

Definition at line 536 of file Ledger.cpp.

◆ rawInsert()

void ripple::Ledger::rawInsert ( std::shared_ptr< SLE > const &  sle)
overridevirtual

Unconditionally insert a state item.

Requirements: The key must not already exist.

Effects:

The key is associated with the SLE.
Note
The key is taken from the SLE

Implements ripple::RawView.

Definition at line 550 of file Ledger.cpp.

◆ rawErase() [2/2]

void ripple::Ledger::rawErase ( uint256 const &  key)

Definition at line 543 of file Ledger.cpp.

◆ rawReplace()

void ripple::Ledger::rawReplace ( std::shared_ptr< SLE > const &  sle)
overridevirtual

Unconditionally replace a state item.

Requirements:

The key must exist.

Effects:

The key is associated with the SLE.
Note
The key is taken from the SLE

Implements ripple::RawView.

Definition at line 561 of file Ledger.cpp.

◆ rawDestroyXRP()

void ripple::Ledger::rawDestroyXRP ( XRPAmount const &  fee)
overridevirtual

Destroy XRP.

This is used to pay for transaction fees.

Implements ripple::RawView.

Definition at line 233 of file Ledger.h.

◆ rawTxInsert()

void ripple::Ledger::rawTxInsert ( uint256 const &  key,
std::shared_ptr< Serializer const > const &  txn,
std::shared_ptr< Serializer const > const &  metaData 
)
overridevirtual

Add a transaction to the tx map.

Closed ledgers must have metadata, while open ledgers omit metadata.

Implements ripple::TxsRawView.

Definition at line 572 of file Ledger.cpp.

◆ rawTxInsertWithHash()

uint256 ripple::Ledger::rawTxInsertWithHash ( uint256 const &  key,
std::shared_ptr< Serializer const > const &  txn,
std::shared_ptr< Serializer const > const &  metaData 
)

Definition at line 589 of file Ledger.cpp.

◆ setValidated()

void ripple::Ledger::setValidated ( ) const

Definition at line 264 of file Ledger.h.

◆ setAccepted()

void ripple::Ledger::setAccepted ( NetClock::time_point  closeTime,
NetClock::duration  closeResolution,
bool  correctCloseTime 
)

Definition at line 378 of file Ledger.cpp.

◆ setImmutable()

void ripple::Ledger::setImmutable ( bool  rehash = true)

Definition at line 358 of file Ledger.cpp.

◆ isImmutable()

bool ripple::Ledger::isImmutable ( ) const

Definition at line 279 of file Ledger.h.

◆ setFull()

void ripple::Ledger::setFull ( ) const

Definition at line 295 of file Ledger.h.

◆ setTotalDrops()

void ripple::Ledger::setTotalDrops ( std::uint64_t  totDrops)

Definition at line 304 of file Ledger.h.

◆ stateMap() [1/2]

SHAMap const& ripple::Ledger::stateMap ( ) const

Definition at line 310 of file Ledger.h.

◆ stateMap() [2/2]

SHAMap& ripple::Ledger::stateMap ( )

Definition at line 316 of file Ledger.h.

◆ txMap() [1/2]

SHAMap const& ripple::Ledger::txMap ( ) const

Definition at line 322 of file Ledger.h.

◆ txMap() [2/2]

SHAMap& ripple::Ledger::txMap ( )

Definition at line 328 of file Ledger.h.

◆ addSLE()

bool ripple::Ledger::addSLE ( SLE const &  sle)

Definition at line 393 of file Ledger.cpp.

◆ updateSkipList()

void ripple::Ledger::updateSkipList ( )

Definition at line 894 of file Ledger.cpp.

◆ walkLedger()

bool ripple::Ledger::walkLedger ( beast::Journal  j,
bool  parallel = false 
) const

Definition at line 819 of file Ledger.cpp.

◆ assertSensible()

bool ripple::Ledger::assertSensible ( beast::Journal  ledgerJ) const

Definition at line 870 of file Ledger.cpp.

◆ invariants()

void ripple::Ledger::invariants ( ) const

Definition at line 1060 of file Ledger.cpp.

◆ unshare()

void ripple::Ledger::unshare ( ) const

Definition at line 1053 of file Ledger.cpp.

◆ negativeUNL()

hash_set< PublicKey > ripple::Ledger::negativeUNL ( ) const

get Negative UNL validators' master public keys

Returns
the public keys

Definition at line 712 of file Ledger.cpp.

◆ validatorToDisable()

std::optional< PublicKey > ripple::Ledger::validatorToDisable ( ) const

get the to be disabled validator's master public key if any

Returns
the public key if any

Definition at line 738 of file Ledger.cpp.

◆ validatorToReEnable()

std::optional< PublicKey > ripple::Ledger::validatorToReEnable ( ) const

get the to be re-enabled validator's master public key if any

Returns
the public key if any

Definition at line 753 of file Ledger.cpp.

◆ updateNegativeUNL()

void ripple::Ledger::updateNegativeUNL ( )

update the Negative UNL ledger component.

Note
must be called at and only at flag ledgers must be called before applying UNLModify Tx

Definition at line 768 of file Ledger.cpp.

◆ isFlagLedger()

bool ripple::Ledger::isFlagLedger ( ) const

Returns true if the ledger is a flag ledger.

Definition at line 958 of file Ledger.cpp.

◆ isVotingLedger()

bool ripple::Ledger::isVotingLedger ( ) const

Returns true if the ledger directly precedes a flag ledger.

Definition at line 963 of file Ledger.cpp.

◆ peek()

std::shared_ptr< SLE > ripple::Ledger::peek ( Keylet const &  k) const

Definition at line 700 of file Ledger.cpp.

◆ setup()

bool ripple::Ledger::setup ( )
private

Definition at line 609 of file Ledger.cpp.

◆ defaultFees()

void ripple::Ledger::defaultFees ( Config const &  config)
private

Definition at line 688 of file Ledger.cpp.

◆ parentCloseTime()

NetClock::time_point ripple::ReadView::parentCloseTime ( ) const
inherited

Returns the close time of the previous ledger.

Definition at line 186 of file ReadView.h.

◆ seq()

LedgerIndex ripple::ReadView::seq ( ) const
inherited

Returns the sequence number of the base ledger.

Definition at line 193 of file ReadView.h.

◆ balanceHook()

virtual STAmount ripple::ReadView::balanceHook ( AccountID const &  account,
AccountID const &  issuer,
STAmount const &  amount 
) const
virtualinherited

Reimplemented in ripple::PaymentSandbox.

Definition at line 253 of file ReadView.h.

◆ ownerCountHook()

virtual std::uint32_t ripple::ReadView::ownerCountHook ( AccountID const &  account,
std::uint32_t  count 
) const
virtualinherited

Reimplemented in ripple::PaymentSandbox.

Definition at line 267 of file ReadView.h.

◆ getCounter()

static auto& ripple::CountedObject< Ledger >::getCounter
staticprivatenoexceptinherited

Definition at line 128 of file CountedObject.h.

Member Data Documentation

◆ mImmutable

bool ripple::Ledger::mImmutable
private

Definition at line 406 of file Ledger.h.

◆ txMap_

SHAMap ripple::Ledger::txMap_
mutableprivate

Definition at line 409 of file Ledger.h.

◆ stateMap_

SHAMap ripple::Ledger::stateMap_
mutableprivate

Definition at line 412 of file Ledger.h.

◆ mutex_

std::mutex ripple::Ledger::mutex_
mutableprivate

Definition at line 415 of file Ledger.h.

◆ fees_

Fees ripple::Ledger::fees_
private

Definition at line 417 of file Ledger.h.

◆ rules_

Rules ripple::Ledger::rules_
private

Definition at line 418 of file Ledger.h.

◆ info_

LedgerInfo ripple::Ledger::info_
private

Definition at line 419 of file Ledger.h.

◆ j_

beast::Journal ripple::Ledger::j_
private

Definition at line 420 of file Ledger.h.

◆ sles

sles_type ripple::ReadView::sles
inherited

Iterable range of ledger state items.

Note
Visiting each state entry in the ledger can become quite expensive as the ledger grows.

Definition at line 320 of file ReadView.h.

◆ txs

txs_type ripple::ReadView::txs
inherited

Definition at line 323 of file ReadView.h.