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

Retains historical ledgers. More...

Collaboration diagram for ripple::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. More...
 
float getCacheHitRate ()
 Get the ledgers_by_hash cache hit rate. More...
 
std::shared_ptr< Ledger const > getLedgerBySeq (LedgerIndex ledgerIndex)
 Get a ledger given its sequence number. More...
 
std::shared_ptr< Ledger const > getLedgerByHash (LedgerHash const &ledgerHash)
 Retrieve a ledger given its hash. More...
 
LedgerHash getLedgerHash (LedgerIndex ledgerIndex)
 Get a ledger's hash given its sequence number. More...
 
void sweep ()
 Remove stale cache entries. More...
 
void builtLedger (std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
 Report that we have locally built a particular ledger. More...
 
void validatedLedger (std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
 Report that we have validated a particular ledger. More...
 
bool fixIndex (LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
 Repair a hash to index mapping. More...
 
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. More...
 

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 36 of file LedgerHistory.h.

Member Typedef Documentation

◆ LedgersByHash

Definition at line 129 of file LedgerHistory.h.

◆ ConsensusValidated

Definition at line 148 of file LedgerHistory.h.

Constructor & Destructor Documentation

◆ LedgerHistory()

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

Definition at line 31 of file LedgerHistory.cpp.

Member Function Documentation

◆ insert()

bool ripple::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 54 of file LedgerHistory.cpp.

◆ getCacheHitRate()

float ripple::LedgerHistory::getCacheHitRate ( )

Get the ledgers_by_hash cache hit rate.

Returns
the hit rate

Definition at line 53 of file LedgerHistory.h.

◆ getLedgerBySeq()

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

Get a ledger given its sequence number.

Definition at line 83 of file LedgerHistory.cpp.

◆ getLedgerByHash()

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

Retrieve a ledger given its hash.

Definition at line 116 of file LedgerHistory.cpp.

◆ getLedgerHash()

LedgerHash ripple::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 74 of file LedgerHistory.cpp.

◆ sweep()

void ripple::LedgerHistory::sweep ( )

Remove stale cache entries.

Definition at line 76 of file LedgerHistory.h.

◆ builtLedger()

void ripple::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 426 of file LedgerHistory.cpp.

◆ validatedLedger()

void ripple::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 ripple::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
true if the mapping was repaired

Definition at line 508 of file LedgerHistory.cpp.

◆ clearLedgerCachePrior()

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

Definition at line 522 of file LedgerHistory.cpp.

◆ handleMismatch()

void ripple::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 318 of file LedgerHistory.cpp.

Member Data Documentation

◆ app_

Application& ripple::LedgerHistory::app_
private

Definition at line 125 of file LedgerHistory.h.

◆ collector_

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

Definition at line 126 of file LedgerHistory.h.

◆ mismatch_counter_

beast::insight::Counter ripple::LedgerHistory::mismatch_counter_
private

Definition at line 127 of file LedgerHistory.h.

◆ m_ledgers_by_hash

LedgersByHash ripple::LedgerHistory::m_ledgers_by_hash
private

Definition at line 131 of file LedgerHistory.h.

◆ m_consensus_validated

ConsensusValidated ripple::LedgerHistory::m_consensus_validated
private

Definition at line 149 of file LedgerHistory.h.

◆ mLedgersByIndex

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

Definition at line 152 of file LedgerHistory.h.

◆ j_

beast::Journal ripple::LedgerHistory::j_
private

Definition at line 154 of file LedgerHistory.h.