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

Retains historical ledgers. More...

#include <LedgerHistory.h>

Collaboration diagram for xrpl::LedgerHistory:

Classes

struct  CvEntry

Public Member Functions

 LedgerHistory (beast::insight::Collector::ptr const &collector, Application &app)
bool insert (std::shared_ptr< Ledger const > const &ledger, bool validated)
 Track a ledger.
float getCacheHitRate ()
 Get the ledgers_by_hash cache hit rate.
std::shared_ptr< Ledger const > getLedgerBySeq (LedgerIndex ledgerIndex)
 Get a ledger given its sequence number.
std::shared_ptr< Ledger const > getLedgerByHash (LedgerHash const &ledgerHash)
 Retrieve a ledger given its hash.
LedgerHash getLedgerHash (LedgerIndex ledgerIndex)
 Get a ledger's hash given its sequence number.
void sweep ()
 Remove stale cache entries.
void builtLedger (std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, json::Value)
 Report that we have locally built a particular ledger.
void validatedLedger (std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
 Report that we have validated a particular ledger.
bool fixIndex (LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
 Repair a hash to index mapping.
void clearLedgerCachePrior (LedgerIndex seq)

Private Types

using LedgersByHash = TaggedCache<LedgerHash, Ledger const>
using ConsensusValidated = TaggedCache<LedgerIndex, CvEntry>

Private Member Functions

void handleMismatch (LedgerHash const &built, LedgerHash const &valid, std::optional< uint256 > const &builtConsensusHash, std::optional< uint256 > const &validatedConsensusHash, json::Value const &consensus)
 Log details in the case where we build one ledger but validate a different one.

Private Attributes

Applicationapp_
beast::insight::Collector::ptr collector_
beast::insight::Counter mismatchCounter_
LedgersByHash ledgersByHash_
ConsensusValidated consensusValidated_
std::map< LedgerIndex, LedgerHashledgersByIndex_
beast::Journal j_

Detailed Description

Retains historical ledgers.

Definition at line 16 of file LedgerHistory.h.

Member Typedef Documentation

◆ LedgersByHash

Definition at line 104 of file LedgerHistory.h.

◆ ConsensusValidated

Constructor & Destructor Documentation

◆ LedgerHistory()

xrpl::LedgerHistory::LedgerHistory ( beast::insight::Collector::ptr const & collector,
Application & app )

Definition at line 36 of file LedgerHistory.cpp.

Member Function Documentation

◆ insert()

bool xrpl::LedgerHistory::insert ( std::shared_ptr< Ledger const > const & ledger,
bool validated )

Track a ledger.

Returns
true if the ledger was already tracked

Definition at line 57 of file LedgerHistory.cpp.

◆ getCacheHitRate()

float xrpl::LedgerHistory::getCacheHitRate ( )

Get the ledgers_by_hash cache hit rate.

Returns
the hit rate

Definition at line 31 of file LedgerHistory.h.

◆ getLedgerBySeq()

std::shared_ptr< Ledger const > xrpl::LedgerHistory::getLedgerBySeq ( LedgerIndex ledgerIndex)

Get a ledger given its sequence number.

Definition at line 84 of file LedgerHistory.cpp.

◆ getLedgerByHash()

std::shared_ptr< Ledger const > xrpl::LedgerHistory::getLedgerByHash ( LedgerHash const & ledgerHash)

Retrieve a ledger given its hash.

Definition at line 121 of file LedgerHistory.cpp.

◆ getLedgerHash()

LedgerHash xrpl::LedgerHistory::getLedgerHash ( LedgerIndex ledgerIndex)

Get a ledger's hash given its sequence number.

Parameters
ledgerIndexThe sequence number of the desired ledger
Returns
The hash of the specified ledger

Definition at line 75 of file LedgerHistory.cpp.

◆ sweep()

void xrpl::LedgerHistory::sweep ( )

Remove stale cache entries.

Definition at line 54 of file LedgerHistory.h.

◆ builtLedger()

void xrpl::LedgerHistory::builtLedger ( std::shared_ptr< Ledger const > const & ledger,
uint256 const & consensusHash,
json::Value consensus )

Report that we have locally built a particular ledger.

Definition at line 427 of file LedgerHistory.cpp.

◆ validatedLedger()

void xrpl::LedgerHistory::validatedLedger ( std::shared_ptr< Ledger const > const & ledger,
std::optional< uint256 > const & consensusHash )

Report that we have validated a particular ledger.

Definition at line 467 of file LedgerHistory.cpp.

◆ fixIndex()

bool xrpl::LedgerHistory::fixIndex ( LedgerIndex ledgerIndex,
LedgerHash const & ledgerHash )

Repair a hash to index mapping.

Ensure ledgers_by_hash_ doesn't have the wrong hash for a particular index.

Parameters
ledgerIndexThe index whose mapping is to be repaired
ledgerHashThe hash it is to be mapped to
Returns
false if the mapping was repaired

Definition at line 508 of file LedgerHistory.cpp.

◆ clearLedgerCachePrior()

void xrpl::LedgerHistory::clearLedgerCachePrior ( LedgerIndex seq)

Definition at line 522 of file LedgerHistory.cpp.

◆ handleMismatch()

void xrpl::LedgerHistory::handleMismatch ( LedgerHash const & built,
LedgerHash const & valid,
std::optional< uint256 > const & builtConsensusHash,
std::optional< uint256 > const & validatedConsensusHash,
json::Value const & consensus )
private

Log details in the case where we build one ledger but validate a different one.

Parameters
builtThe hash of the ledger we built
validThe hash of the ledger we deemed fully valid
builtConsensusHashThe hash of the consensus transaction for the ledger we built
validatedConsensusHashThe hash of the validated ledger's consensus transaction set
consensusThe status of the consensus round

Definition at line 313 of file LedgerHistory.cpp.

Member Data Documentation

◆ app_

Application& xrpl::LedgerHistory::app_
private

Definition at line 100 of file LedgerHistory.h.

◆ collector_

beast::insight::Collector::ptr xrpl::LedgerHistory::collector_
private

Definition at line 101 of file LedgerHistory.h.

◆ mismatchCounter_

beast::insight::Counter xrpl::LedgerHistory::mismatchCounter_
private

Definition at line 102 of file LedgerHistory.h.

◆ ledgersByHash_

LedgersByHash xrpl::LedgerHistory::ledgersByHash_
private

Definition at line 106 of file LedgerHistory.h.

◆ consensusValidated_

ConsensusValidated xrpl::LedgerHistory::consensusValidated_
private

Definition at line 124 of file LedgerHistory.h.

◆ ledgersByIndex_

std::map<LedgerIndex, LedgerHash> xrpl::LedgerHistory::ledgersByIndex_
private

Definition at line 127 of file LedgerHistory.h.

◆ j_

beast::Journal xrpl::LedgerHistory::j_
private

Definition at line 129 of file LedgerHistory.h.