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/protocol/RippleLedgerHash.h>
27
28#include <optional>
29
30namespace ripple {
31
32// VFALCO TODO Rename to OldLedgers ?
33
36{
37public:
39 beast::insight::Collector::ptr const& collector,
40 Application& app);
41
45 bool
46 insert(std::shared_ptr<Ledger const> const& ledger, bool validated);
47
51 float
53 {
55 }
56
59 getLedgerBySeq(LedgerIndex ledgerIndex);
60
63 getLedgerByHash(LedgerHash const& ledgerHash);
64
70 getLedgerHash(LedgerIndex ledgerIndex);
71
74 void
76 {
79 }
80
82 void
85 uint256 const& consensusHash,
87
89 void
92 std::optional<uint256> const& consensusHash);
93
99 bool
100 fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
101
102 void
104
105private:
116 void
118 LedgerHash const& built,
119 LedgerHash const& valid,
120 std::optional<uint256> const& builtConsensusHash,
121 std::optional<uint256> const& validatedConsensusHash,
122 Json::Value const& consensus);
123
127
129
131
132 // Maps ledger indexes to the corresponding hashes
133 // For debug and logging purposes
134 struct cv_entry
135 {
136 // Hash of locally built ledger
138 // Hash of the validated ledger
140 // Hash of locally accepted consensus transaction set
142 // Hash of validated consensus transaction set
144 // Consensus metadata of built ledger
146 };
149
150 // Maps ledger indexes to the corresponding hash.
152
154};
155
156} // namespace ripple
157
158#endif
Represents a JSON value.
Definition: json_value.h:148
A generic endpoint for log messages.
Definition: Journal.h:60
A metric for measuring an integral value.
Definition: Counter.h:39
Retains historical ledgers.
Definition: LedgerHistory.h:36
std::map< LedgerIndex, LedgerHash > mLedgersByIndex
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
Definition: LedgerHistory.h:52
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:75
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:58
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