xrpld
Loading...
Searching...
No Matches
xrpl::CachedView< Base > Class Template Referenceabstract

Wraps a DigestAwareReadView to provide caching. More...

#include <CachedView.h>

Inheritance diagram for xrpl::CachedView< Base >:
Collaboration diagram for xrpl::CachedView< Base >:

Public Types

using BaseType = Base
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

 CachedView ()=delete
 CachedView (CachedView const &)=delete
CachedView & operator= (CachedView const &)=delete
 CachedView (std::shared_ptr< Base const > const &base, CachedSLEs &cache)
std::shared_ptr< Base const > const & base () const
 Returns the base type.
bool exists (Keylet const &k) const override
 Determine if a state item exists.
SLE::const_pointer read (Keylet const &k) const override
 Return the state item associated with a key.
bool open () const override
 Returns true if this reflects an open ledger.
LedgerHeader const & header () const override
 Returns information about the ledger.
Fees const & fees () const override
 Returns the fees for the base ledger.
Rules const & rules () const override
 Returns the tx processing rules.
std::optional< key_type > succ (key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
 Return the key of the next state item.
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
virtual std::unique_ptr< SlesType::IterBase > slesUpperBound (key_type const &key) const =0
std::unique_ptr< TxsType::IterBase > txsBegin () const override
std::unique_ptr< TxsType::IterBase > txsEnd () const override
bool txExists (key_type const &key) const override
 Returns true if a tx exists in the tx map.
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.
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 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

Public Attributes

SlesType sles
 Iterable range of ledger state items.
TxsType txs

Private Attributes

std::shared_ptr< Base const > sp_
DigestAwareReadView const & base_
CachedSLEs & cache_
std::mutex mutex_
std::unordered_map< key_type, UInt256, HardenedHash<> > map_

Detailed Description

template<class Base>
class xrpl::CachedView< Base >

Wraps a DigestAwareReadView to provide caching.

Template Parameters
BaseA subclass of DigestAwareReadView

Definition at line 142 of file CachedView.h.

Member Typedef Documentation

◆ BaseType

template<class Base>
using xrpl::CachedView< Base >::BaseType = Base

Definition at line 150 of file CachedView.h.

◆ DigestType

Definition at line 281 of file ReadView.h.

◆ TxType

Definition at line 43 of file ReadView.h.

◆ key_type

using xrpl::ReadView::key_type = UInt256
inherited

Definition at line 45 of file ReadView.h.

◆ mapped_type

Definition at line 47 of file ReadView.h.

Constructor & Destructor Documentation

◆ CachedView() [1/3]

template<class Base>
xrpl::CachedView< Base >::CachedView ( )
delete

◆ CachedView() [2/3]

template<class Base>
xrpl::CachedView< Base >::CachedView ( CachedView< Base > const & )
delete

◆ CachedView() [3/3]

template<class Base>
xrpl::CachedView< Base >::CachedView ( std::shared_ptr< Base const > const & base,
CachedSLEs & cache )

Definition at line 157 of file CachedView.h.

Member Function Documentation

◆ operator=()

template<class Base>
CachedView & xrpl::CachedView< Base >::operator= ( CachedView< Base > const & )
delete

◆ base()

template<class Base>
std::shared_ptr< Base const > const & xrpl::CachedView< Base >::base ( ) const

Returns the base type.

Note
This breaks encapsulation and bypasses the cache.

Definition at line 168 of file CachedView.h.

◆ exists()

bool xrpl::detail::CachedViewImpl::exists ( Keylet const & k) const
overridevirtualinherited

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 xrpl::ReadView.

Definition at line 16 of file CachedView.cpp.

◆ read()

SLE::const_pointer xrpl::detail::CachedViewImpl::read ( Keylet const & k) const
overridevirtualinherited

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 xrpl::ReadView.

Definition at line 22 of file CachedView.cpp.

◆ open()

bool xrpl::detail::CachedViewImpl::open ( ) const
overridevirtualinherited

Returns true if this reflects an open ledger.

Implements xrpl::ReadView.

Definition at line 52 of file CachedView.h.

◆ header()

LedgerHeader const & xrpl::detail::CachedViewImpl::header ( ) const
overridevirtualinherited

Returns information about the ledger.

Implements xrpl::ReadView.

Definition at line 58 of file CachedView.h.

◆ fees()

Fees const & xrpl::detail::CachedViewImpl::fees ( ) const
overridevirtualinherited

Returns the fees for the base ledger.

Implements xrpl::ReadView.

Definition at line 64 of file CachedView.h.

◆ rules()

Rules const & xrpl::detail::CachedViewImpl::rules ( ) const
overridevirtualinherited

Returns the tx processing rules.

Implements xrpl::ReadView.

Definition at line 70 of file CachedView.h.

◆ succ()

std::optional< key_type > xrpl::detail::CachedViewImpl::succ ( key_type const & key,
std::optional< key_type > const & last = std::nullopt ) const
overridevirtualinherited

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 xrpl::ReadView.

Definition at line 76 of file CachedView.h.

◆ slesBegin()

std::unique_ptr< SlesType::IterBase > xrpl::detail::CachedViewImpl::slesBegin ( ) const
overridevirtualinherited

Implements xrpl::ReadView.

Definition at line 82 of file CachedView.h.

◆ slesEnd()

std::unique_ptr< SlesType::IterBase > xrpl::detail::CachedViewImpl::slesEnd ( ) const
overridevirtualinherited

Implements xrpl::ReadView.

Definition at line 88 of file CachedView.h.

◆ slesUpperBound() [1/2]

std::unique_ptr< SlesType::IterBase > xrpl::detail::CachedViewImpl::slesUpperBound ( UInt256 const & key) const
overrideinherited

Definition at line 94 of file CachedView.h.

◆ slesUpperBound() [2/2]

virtual std::unique_ptr< SlesType::IterBase > xrpl::ReadView::slesUpperBound ( key_type const & key) const
nodiscardpure virtualinherited

◆ txsBegin()

std::unique_ptr< TxsType::IterBase > xrpl::detail::CachedViewImpl::txsBegin ( ) const
overridevirtualinherited

Implements xrpl::ReadView.

Definition at line 100 of file CachedView.h.

◆ txsEnd()

std::unique_ptr< TxsType::IterBase > xrpl::detail::CachedViewImpl::txsEnd ( ) const
overridevirtualinherited

Implements xrpl::ReadView.

Definition at line 106 of file CachedView.h.

◆ txExists()

bool xrpl::detail::CachedViewImpl::txExists ( key_type const & key) const
overridevirtualinherited

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 xrpl::ReadView.

Definition at line 112 of file CachedView.h.

◆ txRead()

TxType xrpl::detail::CachedViewImpl::txRead ( key_type const & key) const
overridevirtualinherited

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 xrpl::ReadView.

Definition at line 118 of file CachedView.h.

◆ digest()

std::optional< DigestType > xrpl::detail::CachedViewImpl::digest ( key_type const & key) const
overridevirtualinherited

Return the digest associated with the key.

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

Implements xrpl::DigestAwareReadView.

Definition at line 128 of file CachedView.h.

◆ parentCloseTime()

NetClock::time_point xrpl::ReadView::parentCloseTime ( ) const
nodiscardinherited

Returns the close time of the previous ledger.

Definition at line 106 of file ReadView.h.

◆ seq()

LedgerIndex xrpl::ReadView::seq ( ) const
nodiscardinherited

Returns the sequence number of the base ledger.

Definition at line 115 of file ReadView.h.

◆ balanceHookIOU()

virtual STAmount xrpl::ReadView::balanceHookIOU ( AccountID const & account,
AccountID const & issuer,
STAmount const & amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 180 of file ReadView.h.

◆ balanceHookMPT()

virtual STAmount xrpl::ReadView::balanceHookMPT ( AccountID const & account,
MPTIssue const & issue,
std::int64_t amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 190 of file ReadView.h.

◆ balanceHookSelfIssueMPT()

virtual STAmount xrpl::ReadView::balanceHookSelfIssueMPT ( MPTIssue const & issue,
std::int64_t amount ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 200 of file ReadView.h.

◆ ownerCountHook()

virtual OwnerCounts xrpl::ReadView::ownerCountHook ( AccountID const & account,
OwnerCounts const & count ) const
nodiscardvirtualinherited

Reimplemented in xrpl::PaymentSandbox.

Definition at line 211 of file ReadView.h.

Member Data Documentation

◆ sp_

template<class Base>
std::shared_ptr<Base const> xrpl::CachedView< Base >::sp_
private

Definition at line 147 of file CachedView.h.

◆ base_

DigestAwareReadView const& xrpl::detail::CachedViewImpl::base_
privateinherited

Definition at line 26 of file CachedView.h.

◆ cache_

CachedSLEs& xrpl::detail::CachedViewImpl::cache_
privateinherited

Definition at line 27 of file CachedView.h.

◆ mutex_

std::mutex xrpl::detail::CachedViewImpl::mutex_
mutableprivateinherited

Definition at line 28 of file CachedView.h.

◆ map_

std::unordered_map<key_type, UInt256, HardenedHash<> > xrpl::detail::CachedViewImpl::map_
mutableprivateinherited

Definition at line 29 of file CachedView.h.

◆ sles

SlesType xrpl::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 267 of file ReadView.h.

◆ txs

TxsType xrpl::ReadView::txs
inherited

Definition at line 270 of file ReadView.h.