rippled
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
xrpl::LedgerHistory Class Reference

Retains historical ledgers. More...

#include <LedgerHistory.h>

Collaboration diagram for xrpl::LedgerHistory:
Collaboration graph
[legend]

Classes

struct  cv_entry
 

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, cv_entry >
 

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 mismatch_counter_
 
LedgersByHash m_ledgers_by_hash
 
ConsensusValidated m_consensus_validated
 
std::map< LedgerIndex, LedgerHashmLedgersByIndex
 
beast::Journal j_
 

Detailed Description

Retains historical ledgers.

Definition at line 16 of file LedgerHistory.h.

Member Typedef Documentation

◆ LedgersByHash

Definition at line 102 of file LedgerHistory.h.

◆ ConsensusValidated

Definition at line 121 of file LedgerHistory.h.

Constructor & Destructor Documentation

◆ LedgerHistory()

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

Definition at line 13 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 29 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 55 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 88 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 46 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 367 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 402 of file LedgerHistory.cpp.

◆ fixIndex()

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

Repair a hash to index mapping.

Ensure m_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 435 of file LedgerHistory.cpp.

◆ clearLedgerCachePrior()

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

Definition at line 449 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 263 of file LedgerHistory.cpp.

Member Data Documentation

◆ app_

Application& xrpl::LedgerHistory::app_
private

Definition at line 98 of file LedgerHistory.h.

◆ collector_

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

Definition at line 99 of file LedgerHistory.h.

◆ mismatch_counter_

beast::insight::Counter xrpl::LedgerHistory::mismatch_counter_
private

Definition at line 100 of file LedgerHistory.h.

◆ m_ledgers_by_hash

LedgersByHash xrpl::LedgerHistory::m_ledgers_by_hash
private

Definition at line 104 of file LedgerHistory.h.

◆ m_consensus_validated

ConsensusValidated xrpl::LedgerHistory::m_consensus_validated
private

Definition at line 122 of file LedgerHistory.h.

◆ mLedgersByIndex

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

Definition at line 125 of file LedgerHistory.h.

◆ j_

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

Definition at line 127 of file LedgerHistory.h.