xrpld
Loading...
Searching...
No Matches
LedgerHistory.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/insight/Collector.h>
7#include <xrpl/beast/insight/Counter.h>
8#include <xrpl/beast/utility/Journal.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/ledger/Ledger.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/RippleLedgerHash.h>
13
14#include <map>
15#include <memory>
16#include <optional>
17
18namespace xrpl {
19
20// VFALCO TODO Rename to OldLedgers ?
21
26{
27public:
29
34 bool
35 insert(std::shared_ptr<Ledger const> const& ledger, bool validated);
36
41 float
43 {
44 return ledgersByHash_.getHitRate();
45 }
46
51 getLedgerBySeq(LedgerIndex ledgerIndex);
52
57 getLedgerByHash(LedgerHash const& ledgerHash);
58
65 getLedgerHash(LedgerIndex ledgerIndex);
66
70 void
72 {
73 ledgersByHash_.sweep();
74 consensusValidated_.sweep();
75 }
76
80 void
81 builtLedger(std::shared_ptr<Ledger const> const&, uint256 const& consensusHash, json::Value);
82
86 void
89 std::optional<uint256> const& consensusHash);
90
97 bool
98 fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
99
100 void
102
103private:
115 void
117 LedgerHash const& built,
118 LedgerHash const& valid,
119 std::optional<uint256> const& builtConsensusHash,
120 std::optional<uint256> const& validatedConsensusHash,
121 json::Value const& consensus);
122
126
128
130
131 // Maps ledger indexes to the corresponding hashes
132 // For debug and logging purposes
133 struct CvEntry
134 {
135 // Hash of locally built ledger
137 // Hash of the validated ledger
139 // Hash of locally accepted consensus transaction set
141 // Hash of validated consensus transaction set
143 // Consensus metadata of built ledger
145 };
148
149 // Maps ledger indexes to the corresponding hash.
151
153};
154
155} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
std::shared_ptr< Collector > ptr
Definition Collector.h:29
A metric for measuring an integral value.
Definition Counter.h:20
Represents a JSON value.
Definition json_value.h:117
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
ConsensusValidated consensusValidated_
beast::insight::Collector::ptr collector_
bool insert(std::shared_ptr< Ledger const > const &ledger, bool validated)
Track a ledger.
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, json::Value)
Report that we have locally built a particular ledger.
LedgerHistory(beast::insight::Collector::ptr const &collector, Application &app)
void sweep()
Remove stale cache entries.
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.
beast::insight::Counter mismatchCounter_
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
beast::Journal j_
LedgersByHash ledgersByHash_
void clearLedgerCachePrior(LedgerIndex seq)
std::map< LedgerIndex, LedgerHash > ledgersByIndex_
TaggedCache< LedgerIndex, CvEntry > ConsensusValidated
TaggedCache< LedgerHash, Ledger const > LedgersByHash
Map/cache combination.
Definition TaggedCache.h:67
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:370
uint256 LedgerHash
BaseUInt< 256 > uint256
Definition base_uint.h:580
std::optional< uint256 > builtConsensusHash
std::optional< LedgerHash > validated
std::optional< uint256 > validatedConsensusHash
std::optional< LedgerHash > built
std::optional< json::Value > consensus