xrpld
Loading...
Searching...
No Matches
LedgerHistory.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4
5#include <xrpl/beast/insight/Collector.h>
6#include <xrpl/ledger/Ledger.h>
7#include <xrpl/protocol/RippleLedgerHash.h>
8
9#include <optional>
10
11namespace xrpl {
12
13// VFALCO TODO Rename to OldLedgers ?
14
17{
18public:
20
24 bool
25 insert(std::shared_ptr<Ledger const> const& ledger, bool validated);
26
30 float
32 {
33 return ledgersByHash_.getHitRate();
34 }
35
38 getLedgerBySeq(LedgerIndex ledgerIndex);
39
42 getLedgerByHash(LedgerHash const& ledgerHash);
43
49 getLedgerHash(LedgerIndex ledgerIndex);
50
53 void
55 {
56 ledgersByHash_.sweep();
57 consensusValidated_.sweep();
58 }
59
61 void
62 builtLedger(std::shared_ptr<Ledger const> const&, uint256 const& consensusHash, json::Value);
63
65 void
68 std::optional<uint256> const& consensusHash);
69
75 bool
76 fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
77
78 void
80
81private:
92 void
94 LedgerHash const& built,
95 LedgerHash const& valid,
96 std::optional<uint256> const& builtConsensusHash,
97 std::optional<uint256> const& validatedConsensusHash,
98 json::Value const& consensus);
99
103
105
107
108 // Maps ledger indexes to the corresponding hashes
109 // For debug and logging purposes
110 struct CvEntry
111 {
112 // Hash of locally built ledger
114 // Hash of the validated ledger
116 // Hash of locally accepted consensus transaction set
118 // Hash of validated consensus transaction set
120 // Consensus metadata of built ledger
122 };
125
126 // Maps ledger indexes to the corresponding hash.
128
130};
131
132} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
std::shared_ptr< Collector > ptr
Definition Collector.h:26
A metric for measuring an integral value.
Definition Counter.h:19
Represents a JSON value.
Definition json_value.h:130
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:59
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:259
uint256 LedgerHash
BaseUInt< 256 > uint256
Definition base_uint.h:562
std::optional< uint256 > builtConsensusHash
std::optional< LedgerHash > validated
std::optional< uint256 > validatedConsensusHash
std::optional< LedgerHash > built
std::optional< json::Value > consensus