xrpld
Loading...
Searching...
No Matches
xrpl::OpenLedger Class Reference

Represents the open ledger. More...

#include <OpenLedger.h>

Collaboration diagram for xrpl::OpenLedger:

Public Types

using modify_type = std::function<bool(OpenView&, beast::Journal)>
 Signature for modification functions.

Public Member Functions

 OpenLedger ()=delete
 OpenLedger (OpenLedger const &)=delete
OpenLedgeroperator= (OpenLedger const &)=delete
 OpenLedger (std::shared_ptr< Ledger const > const &ledger, CachedSLEs &cache, beast::Journal journal)
 Create a new open ledger object.
bool empty () const
 Returns true if there are no transactions.
std::shared_ptr< OpenView const > current () const
 Returns a view to the current open ledger.
bool modify (modify_type const &f)
 Modify the open ledger.
void accept (Application &app, Rules const &rules, std::shared_ptr< Ledger const > const &ledger, OrderedTxs const &locals, bool retriesFirst, OrderedTxs &retries, ApplyFlags flags, std::string_view suffix="", modify_type const &f={})
 Accept a new ledger.

Private Types

enum class  Result { Success , Failure , Retry }

Private Member Functions

std::shared_ptr< OpenViewcreate (Rules const &rules, std::shared_ptr< Ledger const > const &ledger)

Static Private Member Functions

template<class FwdRange>
static void apply (Application &app, OpenView &view, ReadView const &check, FwdRange const &txs, OrderedTxs &retries, ApplyFlags flags, beast::Journal j)
 Algorithm for applying transactions.
static Result applyOne (Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, bool retry, ApplyFlags flags, beast::Journal j)

Private Attributes

beast::Journal const j_
CachedSLEscache_
std::mutex modifyMutex_
std::mutex currentMutex_
std::shared_ptr< OpenView const > current_

Detailed Description

Represents the open ledger.

Definition at line 32 of file OpenLedger.h.

Member Typedef Documentation

◆ modify_type

Signature for modification functions.

The modification function is called during apply and modify with an OpenView to accumulate changes and the Journal to use for logging.

A return value of true informs OpenLedger that changes were made. Always returning true won't cause harm, but it may be sub-optimal.

Definition at line 53 of file OpenLedger.h.

Member Enumeration Documentation

◆ Result

enum class xrpl::OpenLedger::Result
strongprivate
Enumerator
Success 
Failure 
Retry 

Definition at line 173 of file OpenLedger.h.

Constructor & Destructor Documentation

◆ OpenLedger() [1/3]

xrpl::OpenLedger::OpenLedger ( )
delete

◆ OpenLedger() [2/3]

xrpl::OpenLedger::OpenLedger ( OpenLedger const & )
delete

◆ OpenLedger() [3/3]

xrpl::OpenLedger::OpenLedger ( std::shared_ptr< Ledger const > const & ledger,
CachedSLEs & cache,
beast::Journal journal )
explicit

Create a new open ledger object.

Parameters
ledgerA closed ledger

Definition at line 41 of file OpenLedger.cpp.

Member Function Documentation

◆ operator=()

OpenLedger & xrpl::OpenLedger::operator= ( OpenLedger const & )
delete

◆ empty()

bool xrpl::OpenLedger::empty ( ) const

Returns true if there are no transactions.

The behavior of ledger closing can be different depending on whether or not transactions exist in the open ledger.

Note
The value returned is only meaningful for that specific instant in time. An open, empty ledger can become non empty from subsequent modifications. Caller is responsible for synchronizing the meaning of the return value.

Definition at line 50 of file OpenLedger.cpp.

◆ current()

std::shared_ptr< OpenView const > xrpl::OpenLedger::current ( ) const

Returns a view to the current open ledger.

Thread safety: Can be called concurrently from any thread.

Effects: The caller is given ownership of a non-modifiable snapshot of the open ledger at the time of the call.

Definition at line 57 of file OpenLedger.cpp.

◆ modify()

bool xrpl::OpenLedger::modify ( modify_type const & f)

Modify the open ledger.

Thread safety: Can be called concurrently from any thread.

If f returns true, the changes made in the OpenView will be published to the open ledger.

Returns
true if the open view was changed

Definition at line 64 of file OpenLedger.cpp.

◆ accept()

void xrpl::OpenLedger::accept ( Application & app,
Rules const & rules,
std::shared_ptr< Ledger const > const & ledger,
OrderedTxs const & locals,
bool retriesFirst,
OrderedTxs & retries,
ApplyFlags flags,
std::string_view suffix = "",
modify_type const & f = {} )

Accept a new ledger.

Thread safety: Can be called concurrently from any thread.

Effects:

A new open view based on the accepted ledger
is created, and the list of retriable
transactions is optionally applied first
depending on the value of `retriesFirst`.

The transactions in the current open view
are applied to the new open view.

The list of local transactions are applied
to the new open view.

The optional modify function f is called
to perform further modifications to the
open view, atomically. Changes made in
the modify function are not visible to
callers until accept() returns.

Any failed, retriable transactions are left
in `retries` for the caller.

The current view is atomically set to the
new open view.
Parameters
rulesThe rules for the open ledger
ledgerA new closed ledger

Definition at line 78 of file OpenLedger.cpp.

◆ apply()

template<class FwdRange>
void xrpl::OpenLedger::apply ( Application & app,
OpenView & view,
ReadView const & check,
FwdRange const & txs,
OrderedTxs & retries,
ApplyFlags flags,
beast::Journal j )
staticprivate

Algorithm for applying transactions.

This has the retry logic and ordering semantics used for consensus and building the open ledger.

Definition at line 192 of file OpenLedger.h.

◆ create()

std::shared_ptr< OpenView > xrpl::OpenLedger::create ( Rules const & rules,
std::shared_ptr< Ledger const > const & ledger )
private

Definition at line 165 of file OpenLedger.cpp.

◆ applyOne()

auto xrpl::OpenLedger::applyOne ( Application & app,
OpenView & view,
std::shared_ptr< STTx const > const & tx,
bool retry,
ApplyFlags flags,
beast::Journal j )
staticprivate

Definition at line 172 of file OpenLedger.cpp.

Member Data Documentation

◆ j_

beast::Journal const xrpl::OpenLedger::j_
private

Definition at line 35 of file OpenLedger.h.

◆ cache_

CachedSLEs& xrpl::OpenLedger::cache_
private

Definition at line 36 of file OpenLedger.h.

◆ modifyMutex_

std::mutex xrpl::OpenLedger::modifyMutex_
mutableprivate

Definition at line 37 of file OpenLedger.h.

◆ currentMutex_

std::mutex xrpl::OpenLedger::currentMutex_
mutableprivate

Definition at line 38 of file OpenLedger.h.

◆ current_

std::shared_ptr<OpenView const> xrpl::OpenLedger::current_
private

Definition at line 39 of file OpenLedger.h.