rippled
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 <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/main/Application.h>
25 #include <ripple/beast/insight/Collector.h>
26 #include <ripple/beast/insight/Event.h>
27 #include <ripple/protocol/RippleLedgerHash.h>
28 
29 #include <optional>
30 
31 namespace ripple {
32 
33 // VFALCO TODO Rename to OldLedgers ?
34 
37 {
38 public:
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,
87  Json::Value);
88 
90  void
93  std::optional<uint256> const& consensusHash);
94 
100  bool
101  fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
102 
103  void
105 
106 private:
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
ripple::Application
Definition: Application.h:115
ripple::TaggedCache::sweep
void sweep()
Definition: TaggedCache.h:204
std::shared_ptr< Collector >
ripple::LedgerHistory::handleMismatch
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.
Definition: LedgerHistory.cpp:318
ripple::TaggedCache< LedgerHash, Ledger const >
beast::insight::Counter
A metric for measuring an integral value.
Definition: Counter.h:38
ripple::LedgerHistory::fixIndex
bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const &ledgerHash)
Repair a hash to index mapping.
Definition: LedgerHistory.cpp:508
ripple::LedgerHistory::mLedgersByIndex
std::map< LedgerIndex, LedgerHash > mLedgersByIndex
Definition: LedgerHistory.h:152
ripple::LedgerHistory::j_
beast::Journal j_
Definition: LedgerHistory.h:154
ripple::LedgerHistory
Retains historical ledgers.
Definition: LedgerHistory.h:36
ripple::LedgerHistory::sweep
void sweep()
Remove stale cache entries.
Definition: LedgerHistory.h:76
ripple::LedgerHistory::getLedgerHash
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
Definition: LedgerHistory.cpp:74
ripple::LedgerHistory::insert
bool insert(std::shared_ptr< Ledger const > const &ledger, bool validated)
Track a ledger.
Definition: LedgerHistory.cpp:54
ripple::LedgerHistory::builtLedger
void builtLedger(std::shared_ptr< Ledger const > const &, uint256 const &consensusHash, Json::Value)
Report that we have locally built a particular ledger.
Definition: LedgerHistory.cpp:426
ripple::TaggedCache::getHitRate
float getHitRate()
Definition: TaggedCache.h:155
ripple::LedgerHistory::m_consensus_validated
ConsensusValidated m_consensus_validated
Definition: LedgerHistory.h:149
ripple::base_uint< 256 >
ripple::LedgerHistory::cv_entry::consensus
std::optional< Json::Value > consensus
Definition: LedgerHistory.h:146
ripple::LedgerHistory::app_
Application & app_
Definition: LedgerHistory.h:125
ripple::LedgerHistory::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
Definition: LedgerHistory.cpp:116
ripple::LedgerHistory::cv_entry::validated
std::optional< LedgerHash > validated
Definition: LedgerHistory.h:140
ripple::LedgerHistory::collector_
beast::insight::Collector::ptr collector_
Definition: LedgerHistory.h:126
ripple::LedgerHistory::validatedLedger
void validatedLedger(std::shared_ptr< Ledger const > const &, std::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
Definition: LedgerHistory.cpp:467
ripple::LedgerHistory::cv_entry::built
std::optional< LedgerHash > built
Definition: LedgerHistory.h:138
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::map
STL class.
ripple::LedgerHistory::getLedgerBySeq
std::shared_ptr< Ledger const > getLedgerBySeq(LedgerIndex ledgerIndex)
Get a ledger given its sequence number.
Definition: LedgerHistory.cpp:83
ripple::LedgerHistory::cv_entry::validatedConsensusHash
std::optional< uint256 > validatedConsensusHash
Definition: LedgerHistory.h:144
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerHistory::getCacheHitRate
float getCacheHitRate()
Get the ledgers_by_hash cache hit rate.
Definition: LedgerHistory.h:53
ripple::LedgerHistory::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerHistory.cpp:522
optional
ripple::LedgerHistory::cv_entry::builtConsensusHash
std::optional< uint256 > builtConsensusHash
Definition: LedgerHistory.h:142
ripple::LedgerHistory::mismatch_counter_
beast::insight::Counter mismatch_counter_
Definition: LedgerHistory.h:127
ripple::LedgerHistory::LedgerHistory
LedgerHistory(beast::insight::Collector::ptr const &collector, Application &app)
Definition: LedgerHistory.cpp:31
ripple::LedgerHistory::m_ledgers_by_hash
LedgersByHash m_ledgers_by_hash
Definition: LedgerHistory.h:131
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::LedgerHistory::cv_entry
Definition: LedgerHistory.h:135