rippled
Loading...
Searching...
No Matches
LedgerHistory.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_LEDGER_LEDGERHISTORY_H_INCLUDED
21#define RIPPLE_APP_LEDGER_LEDGERHISTORY_H_INCLUDED
22
23#include <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/main/Application.h>
25#include <xrpl/beast/insight/Collector.h>
26#include <xrpl/beast/insight/Event.h>
27#include <xrpl/protocol/RippleLedgerHash.h>
28
29#include <optional>
30
31namespace ripple {
32
33// VFALCO TODO Rename to OldLedgers ?
34
37{
38public:
40 beast::insight::Collector::ptr const& collector,
41 Application& app);
42
46 bool
47 insert(std::shared_ptr<Ledger const> const& ledger, bool validated);
48
52 float
54 {
56 }
57
60 getLedgerBySeq(LedgerIndex ledgerIndex);
61
64 getLedgerByHash(LedgerHash const& ledgerHash);
65
71 getLedgerHash(LedgerIndex ledgerIndex);
72
75 void
77 {
80 }
81
83 void
86 uint256 const& consensusHash,
88
90 void
93 std::optional<uint256> const& consensusHash);
94
100 bool
101 fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
102
103 void
105
106private:
117 void
119 LedgerHash const& built,
120 LedgerHash const& valid,
121 std::optional<uint256> const& builtConsensusHash,
122 std::optional<uint256> const& validatedConsensusHash,
123 Json::Value const& consensus);
124
128
130
132
133 // Maps ledger indexes to the corresponding hashes
134 // For debug and logging purposes
135 struct cv_entry
136 {
137 // Hash of locally built ledger
139 // Hash of the validated ledger
141 // Hash of locally accepted consensus transaction set
143 // Hash of validated consensus transaction set
145 // Consensus metadata of built ledger
147 };
150
151 // Maps ledger indexes to the corresponding hash.
153
155};
156
157} // namespace ripple
158
159#endif
Represents a JSON value.
Definition: json_value.h:147
A generic endpoint for log messages.
Definition: Journal.h:59
A metric for measuring an integral value.
Definition: Counter.h:39
Retains historical ledgers.
Definition: LedgerHistory.h:37
std::map< LedgerIndex, LedgerHash > mLedgersByIndex
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
Definition: LedgerHistory.h:53
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
Report that we have locally built a particular ledger.
void sweep()
Remove stale cache entries.
Definition: LedgerHistory.h:76
LedgersByHash m_ledgers_by_hash
ConsensusValidated m_consensus_validated
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.
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
void clearLedgerCachePrior(LedgerIndex seq)
beast::insight::Collector::ptr collector_
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
beast::insight::Counter mismatch_counter_
bool insert(std::shared_ptr< Ledger const > const &ledger, bool validated)
Track a ledger.
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
Map/cache combination.
Definition: TaggedCache.h:57
TER valid(PreclaimContext const &ctx, AccountID const &src)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::optional< LedgerHash > built
std::optional< uint256 > validatedConsensusHash
std::optional< Json::Value > consensus
std::optional< uint256 > builtConsensusHash
std::optional< LedgerHash > validated