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

Writable ledger view that accumulates state and tx changes. More...

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

Classes

struct  txData
 
class  txs_iter_impl
 

Public Types

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

 OpenView ()=delete
 
OpenViewoperator= (OpenView &&)=delete
 
OpenViewoperator= (OpenView const &)=delete
 
 OpenView (OpenView &&)=default
 
 OpenView (OpenView const &)
 Construct a shallow copy. More...
 
 OpenView (ReadView const *base, std::shared_ptr< void const > hold=nullptr)
 Construct a new last closed ledger. More...
 
bool open () const override
 Returns true if this reflects an open ledger. More...
 
std::size_t txCount () const
 Return the number of tx inserted since creation. More...
 
void apply (TxsRawView &to) const
 Apply changes. More...
 
LedgerInfo const & info () const override
 Returns information about the ledger. More...
 
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...
 
std::optional< key_typesucc (key_type const &key, std::optional< key_type > 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 (key_type 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...
 
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 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 (key_type 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...
 
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
 
 OpenView (open_ledger_t, ReadView const *base, Rules const &rules, std::shared_ptr< void const > hold=nullptr)
 Construct an open ledger view. More...
 
 OpenView (open_ledger_t, Rules const &rules, std::shared_ptr< ReadView const > const &base)
 

Public Attributes

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

Private Types

using txs_map = std::map< key_type, txData, std::less< key_type >, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, txData > >>
 

Private Attributes

std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
 
txs_map txs_
 
Rules rules_
 
LedgerInfo info_
 
ReadView const * base_
 
detail::RawStateTable items_
 
std::shared_ptr< void const > hold_
 
bool open_ = true
 

Static Private Attributes

static constexpr size_t initialBufferSize = kilobytes(256)
 

Detailed Description

Writable ledger view that accumulates state and tx changes.

Note
Presented as ReadView to clients.

Definition at line 55 of file OpenView.h.

Member Typedef Documentation

◆ txs_map

using ripple::OpenView::txs_map = std::map< key_type, txData, std::less<key_type>, boost::container::pmr::polymorphic_allocator< std::pair<key_type const, txData> >>
private

Definition at line 87 of file OpenView.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

◆ OpenView() [1/6]

ripple::OpenView::OpenView ( )
delete

◆ OpenView() [2/6]

ripple::OpenView::OpenView ( OpenView &&  )
default

◆ OpenView() [3/6]

ripple::OpenView::OpenView ( OpenView const &  rhs)

Construct a shallow copy.

Effects:

Creates a new object with a copy of
the modification state table.

The objects managed by shared pointers are not duplicated but shared between instances. Since the SLEs are immutable, calls on the RawView interface cannot break invariants.

Definition at line 78 of file OpenView.cpp.

◆ OpenView() [4/6]

ripple::OpenView::OpenView ( open_ledger_t  ,
ReadView const *  base,
Rules const &  rules,
std::shared_ptr< void const >  hold = nullptr 
)

Construct an open ledger view.

Effects:

The sequence number is set to the
sequence number of parent plus one.

The parentCloseTime is set to the
closeTime of parent.

If `hold` is not nullptr, retains
ownership of a copy of `hold` until
the MetaView is destroyed.

Calls to rules() will return the
rules provided on construction.

The tx list starts empty and will contain all newly inserted tx.

Definition at line 91 of file OpenView.cpp.

◆ OpenView() [5/6]

ripple::OpenView::OpenView ( open_ledger_t  ,
Rules const &  rules,
std::shared_ptr< ReadView const > const &  base 
)

Definition at line 151 of file OpenView.h.

◆ OpenView() [6/6]

ripple::OpenView::OpenView ( ReadView const *  base,
std::shared_ptr< void const >  hold = nullptr 
)

Construct a new last closed ledger.

Effects:

The LedgerInfo is copied from the base.

The rules are inherited from the base.

The tx list starts empty and will contain all newly inserted tx.

Definition at line 111 of file OpenView.cpp.

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ open()

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

Returns true if this reflects an open ledger.

Implements ripple::ReadView.

Definition at line 175 of file OpenView.h.

◆ txCount()

std::size_t ripple::OpenView::txCount ( ) const

Return the number of tx inserted since creation.

This is used to set the "apply ordinal" when calculating transaction metadata.

Definition at line 124 of file OpenView.cpp.

◆ apply()

void ripple::OpenView::apply ( TxsRawView to) const

Apply changes.

Definition at line 130 of file OpenView.cpp.

◆ info()

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

Returns information about the ledger.

Implements ripple::ReadView.

Definition at line 140 of file OpenView.cpp.

◆ fees()

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

Returns the fees for the base ledger.

Implements ripple::ReadView.

Definition at line 146 of file OpenView.cpp.

◆ rules()

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

Returns the tx processing rules.

Implements ripple::ReadView.

Definition at line 152 of file OpenView.cpp.

◆ exists()

bool ripple::OpenView::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 158 of file OpenView.cpp.

◆ succ()

auto ripple::OpenView::succ ( key_type const &  key,
std::optional< key_type > 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 164 of file OpenView.cpp.

◆ read()

std::shared_ptr< SLE const > ripple::OpenView::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 171 of file OpenView.cpp.

◆ slesBegin()

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

Implements ripple::ReadView.

Definition at line 177 of file OpenView.cpp.

◆ slesEnd()

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

Implements ripple::ReadView.

Definition at line 183 of file OpenView.cpp.

◆ slesUpperBound()

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

Implements ripple::ReadView.

Definition at line 189 of file OpenView.cpp.

◆ txsBegin()

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

Implements ripple::ReadView.

Definition at line 196 of file OpenView.cpp.

◆ txsEnd()

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

Implements ripple::ReadView.

Definition at line 202 of file OpenView.cpp.

◆ txExists()

bool ripple::OpenView::txExists ( key_type 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 208 of file OpenView.cpp.

◆ txRead()

auto ripple::OpenView::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 214 of file OpenView.cpp.

◆ rawErase()

void ripple::OpenView::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 233 of file OpenView.cpp.

◆ rawInsert()

void ripple::OpenView::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 239 of file OpenView.cpp.

◆ rawReplace()

void ripple::OpenView::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 245 of file OpenView.cpp.

◆ rawDestroyXRP()

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

Destroy XRP.

This is used to pay for transaction fees.

Implements ripple::RawView.

Definition at line 251 of file OpenView.cpp.

◆ rawTxInsert()

void ripple::OpenView::rawTxInsert ( key_type 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 261 of file OpenView.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.

Member Data Documentation

◆ initialBufferSize

constexpr size_t ripple::OpenView::initialBufferSize = kilobytes(256)
staticconstexprprivate

Definition at line 61 of file OpenView.h.

◆ monotonic_resource_

std::unique_ptr<boost::container::pmr::monotonic_buffer_resource> ripple::OpenView::monotonic_resource_
private

Definition at line 92 of file OpenView.h.

◆ txs_

txs_map ripple::OpenView::txs_
private

Definition at line 93 of file OpenView.h.

◆ rules_

Rules ripple::OpenView::rules_
private

Definition at line 94 of file OpenView.h.

◆ info_

LedgerInfo ripple::OpenView::info_
private

Definition at line 95 of file OpenView.h.

◆ base_

ReadView const* ripple::OpenView::base_
private

Definition at line 96 of file OpenView.h.

◆ items_

detail::RawStateTable ripple::OpenView::items_
private

Definition at line 97 of file OpenView.h.

◆ hold_

std::shared_ptr<void const> ripple::OpenView::hold_
private

Definition at line 98 of file OpenView.h.

◆ open_

bool ripple::OpenView::open_ = true
private

Definition at line 99 of file OpenView.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.