xrpld
Loading...
Searching...
No Matches
xrpl::test::csf::Ledger Class Reference

A ledger is a set of observed transactions and a sequence number identifying the ledger. More...

#include <ledgers.h>

Collaboration diagram for xrpl::test::csf::Ledger:

Classes

struct  MakeGenesis
struct  Instance

Public Types

using Seq = TaggedInteger<std::uint32_t, SeqTag>
using ID = TaggedInteger<std::uint32_t, IdTag>

Public Member Functions

 Ledger (MakeGenesis)
 Ledger ()
ID id () const
Seq seq () const
NetClock::duration closeTimeResolution () const
bool closeAgree () const
NetClock::time_point closeTime () const
NetClock::time_point parentCloseTime () const
ID parentID () const
TxSetType const & txs () const
bool isAncestor (Ledger const &ancestor) const
 Determine whether ancestor is really an ancestor of this ledger.
ID operator[] (Seq seq) const
 Return the id of the ancestor with the given seq (if exists/known).
json::Value getJson () const

Private Member Functions

 Ledger (ID id, Instance const *i)

Private Attributes

ID id_ {0}
Instance const * instance_

Static Private Attributes

static Instance const kGenesis

Friends

class LedgerOracle
Ledger::Seq mismatch (Ledger const &a, Ledger const &o)
 Return the sequence number of the first mismatching ancestor.
bool operator< (Ledger const &a, Ledger const &b)

Detailed Description

A ledger is a set of observed transactions and a sequence number identifying the ledger.

Peers in the consensus process are trying to agree on a set of transactions to include in a ledger. For simulation, each transaction is a single integer and the ledger is the set of observed integers. This means future ledgers have prior ledgers as subsets, e.g.

Ledger 0 :  {}
Ledger 1 :  {1,4,5}
Ledger 2 :  {1,2,4,5,10}
....

Ledgers are immutable value types. All ledgers with the same sequence number, transactions, close time, etc. will have the same ledger ID. The LedgerOracle class below manages ID assignments for a simulation and is the only way to close and create a new ledger. Since the parent ledger ID is part of type, this also means ledgers with distinct histories will have distinct ids, even if they have the same set of transactions, sequence number and close time.

Definition at line 40 of file ledgers.h.

Member Typedef Documentation

◆ Seq

Definition at line 46 of file ledgers.h.

◆ ID

Definition at line 49 of file ledgers.h.

Constructor & Destructor Documentation

◆ Ledger() [1/3]

xrpl::test::csf::Ledger::Ledger ( ID id,
Instance const * i )
private

Definition at line 133 of file ledgers.h.

◆ Ledger() [2/3]

xrpl::test::csf::Ledger::Ledger ( MakeGenesis )

Definition at line 138 of file ledgers.h.

◆ Ledger() [3/3]

xrpl::test::csf::Ledger::Ledger ( )

Definition at line 144 of file ledgers.h.

Member Function Documentation

◆ id()

ID xrpl::test::csf::Ledger::id ( ) const
nodiscard

Definition at line 149 of file ledgers.h.

◆ seq()

Seq xrpl::test::csf::Ledger::seq ( ) const
nodiscard

Definition at line 155 of file ledgers.h.

◆ closeTimeResolution()

NetClock::duration xrpl::test::csf::Ledger::closeTimeResolution ( ) const
nodiscard

Definition at line 161 of file ledgers.h.

◆ closeAgree()

bool xrpl::test::csf::Ledger::closeAgree ( ) const
nodiscard

Definition at line 167 of file ledgers.h.

◆ closeTime()

NetClock::time_point xrpl::test::csf::Ledger::closeTime ( ) const
nodiscard

Definition at line 173 of file ledgers.h.

◆ parentCloseTime()

NetClock::time_point xrpl::test::csf::Ledger::parentCloseTime ( ) const
nodiscard

Definition at line 179 of file ledgers.h.

◆ parentID()

ID xrpl::test::csf::Ledger::parentID ( ) const
nodiscard

Definition at line 185 of file ledgers.h.

◆ txs()

TxSetType const & xrpl::test::csf::Ledger::txs ( ) const
nodiscard

Definition at line 191 of file ledgers.h.

◆ isAncestor()

bool xrpl::test::csf::Ledger::isAncestor ( Ledger const & ancestor) const
nodiscard

Determine whether ancestor is really an ancestor of this ledger.

Definition at line 30 of file ledgers.cpp.

◆ operator[]()

Ledger::ID xrpl::test::csf::Ledger::operator[] ( Seq seq) const

Return the id of the ancestor with the given seq (if exists/known).

Definition at line 38 of file ledgers.cpp.

◆ getJson()

json::Value xrpl::test::csf::Ledger::getJson ( ) const
nodiscard

Definition at line 21 of file ledgers.cpp.

◆ LedgerOracle

friend class LedgerOracle
friend

Definition at line 42 of file ledgers.h.

◆ mismatch

Ledger::Seq mismatch ( Ledger const & a,
Ledger const & o )
friend

Return the sequence number of the first mismatching ancestor.

Definition at line 48 of file ledgers.cpp.

◆ operator<

bool operator< ( Ledger const & a,
Ledger const & b )
friend

Definition at line 213 of file ledgers.h.

Member Data Documentation

◆ kGenesis

Ledger::Instance const xrpl::test::csf::Ledger::kGenesis
staticprivate

Definition at line 131 of file ledgers.h.

◆ id_

ID xrpl::test::csf::Ledger::id_ {0}
private

Definition at line 220 of file ledgers.h.

◆ instance_

Instance const* xrpl::test::csf::Ledger::instance_
private

Definition at line 221 of file ledgers.h.