rippled
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ripple::OpenLedger Class Reference

Represents the open ledger. More...

Collaboration diagram for ripple::OpenLedger:
Collaboration graph
[legend]

Public Types

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

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. More...
 
bool empty () const
 Returns true if there are no transactions. More...
 
std::shared_ptr< OpenView const > current () const
 Returns a view to the current open ledger. More...
 
bool modify (modify_type const &f)
 Modify the open ledger. More...
 
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 const &suffix="", modify_type const &f={})
 Accept a new ledger. More...
 

Private Types

enum  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. More...
 
static Result apply_one (Application &app, OpenView &view, std::shared_ptr< STTx const > const &tx, bool retry, ApplyFlags flags, beast::Journal j)
 

Private Attributes

const beast::Journal j_
 
CachedSLEscache_
 
std::mutex modify_mutex_
 
std::mutex current_mutex_
 
std::shared_ptr< OpenView const > current_
 

Detailed Description

Represents the open ledger.

Definition at line 49 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 70 of file OpenLedger.h.

Member Enumeration Documentation

◆ Result

Enumerator
success 
failure 
retry 

Definition at line 190 of file OpenLedger.h.

Constructor & Destructor Documentation

◆ OpenLedger() [1/3]

ripple::OpenLedger::OpenLedger ( )
delete

◆ OpenLedger() [2/3]

ripple::OpenLedger::OpenLedger ( OpenLedger const &  )
delete

◆ OpenLedger() [3/3]

ripple::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 34 of file OpenLedger.cpp.

Member Function Documentation

◆ operator=()

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

◆ empty()

bool ripple::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 43 of file OpenLedger.cpp.

◆ current()

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

◆ modify()

bool ripple::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 57 of file OpenLedger.cpp.

◆ accept()

void ripple::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 const &  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 71 of file OpenLedger.cpp.

◆ apply()

template<class FwdRange >
void ripple::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 209 of file OpenLedger.h.

◆ create()

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

Definition at line 147 of file OpenLedger.cpp.

◆ apply_one()

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

Definition at line 158 of file OpenLedger.cpp.

Member Data Documentation

◆ j_

const beast::Journal ripple::OpenLedger::j_
private

Definition at line 52 of file OpenLedger.h.

◆ cache_

CachedSLEs& ripple::OpenLedger::cache_
private

Definition at line 53 of file OpenLedger.h.

◆ modify_mutex_

std::mutex ripple::OpenLedger::modify_mutex_
mutableprivate

Definition at line 54 of file OpenLedger.h.

◆ current_mutex_

std::mutex ripple::OpenLedger::current_mutex_
mutableprivate

Definition at line 55 of file OpenLedger.h.

◆ current_

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

Definition at line 56 of file OpenLedger.h.