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> 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 
77  void
78  tune(int size, std::chrono::seconds age);
79 
82  void
84  {
87  }
88 
90  void
93  uint256 const& consensusHash,
94  Json::Value);
95 
97  void
100  std::optional<uint256> const& consensusHash);
101 
107  bool
108  fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
109 
110  void
112 
113 private:
124  void
126  LedgerHash const& built,
127  LedgerHash const& valid,
128  std::optional<uint256> const& builtConsensusHash,
129  std::optional<uint256> const& validatedConsensusHash,
130  Json::Value const& consensus);
131 
135 
137 
139 
140  // Maps ledger indexes to the corresponding hashes
141  // For debug and logging purposes
142  struct cv_entry
143  {
144  // Hash of locally built ledger
146  // Hash of the validated ledger
148  // Hash of locally accepted consensus transaction set
150  // Hash of validated consensus transaction set
152  // Consensus metadata of built ledger
154  };
157 
158  // Maps ledger indexes to the corresponding hash.
160 
162 };
163 
164 } // namespace ripple
165 
166 #endif
ripple::Application
Definition: Application.h:115
ripple::TaggedCache::sweep
void sweep()
Definition: TaggedCache.h:200
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:323
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:513
ripple::LedgerHistory::mLedgersByIndex
std::map< LedgerIndex, LedgerHash > mLedgersByIndex
Definition: LedgerHistory.h:159
ripple::LedgerHistory::j_
beast::Journal j_
Definition: LedgerHistory.h:161
std::chrono::seconds
ripple::LedgerHistory::tune
void tune(int size, std::chrono::seconds age)
Set the history cache's parameters.
Definition: LedgerHistory.cpp:527
ripple::LedgerHistory
Retains historical ledgers.
Definition: LedgerHistory.h:36
ripple::LedgerHistory::sweep
void sweep()
Remove stale cache entries.
Definition: LedgerHistory.h:83
ripple::LedgerHistory::getLedgerHash
LedgerHash getLedgerHash(LedgerIndex ledgerIndex)
Get a ledger's hash given its sequence number.
Definition: LedgerHistory.cpp:80
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:431
ripple::TaggedCache::getHitRate
float getHitRate()
Definition: TaggedCache.h:155
ripple::LedgerHistory::m_consensus_validated
ConsensusValidated m_consensus_validated
Definition: LedgerHistory.h:156
ripple::base_uint< 256 >
ripple::LedgerHistory::insert
bool insert(std::shared_ptr< Ledger const > ledger, bool validated)
Track a ledger.
Definition: LedgerHistory.cpp:62
ripple::LedgerHistory::cv_entry::consensus
std::optional< Json::Value > consensus
Definition: LedgerHistory.h:153
ripple::LedgerHistory::app_
Application & app_
Definition: LedgerHistory.h:132
ripple::LedgerHistory::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
Definition: LedgerHistory.cpp:125
ripple::LedgerHistory::cv_entry::validated
std::optional< LedgerHash > validated
Definition: LedgerHistory.h:147
ripple::LedgerHistory::collector_
beast::insight::Collector::ptr collector_
Definition: LedgerHistory.h:133
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:472
ripple::LedgerHistory::cv_entry::built
std::optional< LedgerHash > built
Definition: LedgerHistory.h:145
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:92
ripple::LedgerHistory::cv_entry::validatedConsensusHash
std::optional< uint256 > validatedConsensusHash
Definition: LedgerHistory.h:151
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:534
optional
ripple::LedgerHistory::cv_entry::builtConsensusHash
std::optional< uint256 > builtConsensusHash
Definition: LedgerHistory.h:149
ripple::LedgerHistory::mismatch_counter_
beast::insight::Counter mismatch_counter_
Definition: LedgerHistory.h:134
ripple::LedgerHistory::LedgerHistory
LedgerHistory(beast::insight::Collector::ptr const &collector, Application &app)
Definition: LedgerHistory.cpp:39
ripple::LedgerHistory::m_ledgers_by_hash
LedgersByHash m_ledgers_by_hash
Definition: LedgerHistory.h:138
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::LedgerHistory::cv_entry
Definition: LedgerHistory.h:142