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 namespace ripple {
30 
31 // VFALCO TODO Rename to OldLedgers ?
32 
35 {
36 public:
38  beast::insight::Collector::ptr const& collector,
39  Application& app);
40 
44  bool
45  insert(std::shared_ptr<Ledger const> ledger, bool validated);
46 
50  float
52  {
54  }
55 
58  getLedgerBySeq(LedgerIndex ledgerIndex);
59 
62  getLedgerByHash(LedgerHash const& ledgerHash);
63 
69  getLedgerHash(LedgerIndex ledgerIndex);
70 
75  void
76  tune(int size, std::chrono::seconds age);
77 
80  void
82  {
85  }
86 
88  void
91  uint256 const& consensusHash,
92  Json::Value);
93 
95  void
98  boost::optional<uint256> const& consensusHash);
99 
105  bool
106  fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash);
107 
108  void
110 
111 private:
122  void
124  LedgerHash const& built,
125  LedgerHash const& valid,
126  boost::optional<uint256> const& builtConsensusHash,
127  boost::optional<uint256> const& validatedConsensusHash,
128  Json::Value const& consensus);
129 
133 
135 
137 
138  // Maps ledger indexes to the corresponding hashes
139  // For debug and logging purposes
140  struct cv_entry
141  {
142  // Hash of locally built ledger
143  boost::optional<LedgerHash> built;
144  // Hash of the validated ledger
145  boost::optional<LedgerHash> validated;
146  // Hash of locally accepted consensus transaction set
147  boost::optional<uint256> builtConsensusHash;
148  // Hash of validated consensus transaction set
149  boost::optional<uint256> validatedConsensusHash;
150  // Consensus metadata of built ledger
151  boost::optional<Json::Value> consensus;
152  };
155 
156  // Maps ledger indexes to the corresponding hash.
158 
160 };
161 
162 } // namespace ripple
163 
164 #endif
ripple::Application
Definition: Application.h:101
std::shared_ptr< Collector >
ripple::TaggedCache< LedgerHash, Ledger const >
ripple::LedgerHistory::cv_entry::validatedConsensusHash
boost::optional< uint256 > validatedConsensusHash
Definition: LedgerHistory.h:149
beast::insight::Counter
A metric for measuring an integral value.
Definition: Counter.h:38
ripple::TaggedCache::sweep
void sweep()
Definition: TaggedCache.h:169
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:157
ripple::LedgerHistory::j_
beast::Journal j_
Definition: LedgerHistory.h:159
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::cv_entry::validated
boost::optional< LedgerHash > validated
Definition: LedgerHistory.h:145
ripple::LedgerHistory
Retains historical ledgers.
Definition: LedgerHistory.h:34
ripple::LedgerHistory::sweep
void sweep()
Remove stale cache entries.
Definition: LedgerHistory.h:81
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:143
ripple::LedgerHistory::m_consensus_validated
ConsensusValidated m_consensus_validated
Definition: LedgerHistory.h:154
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::app_
Application & app_
Definition: LedgerHistory.h:130
ripple::LedgerHistory::getLedgerByHash
std::shared_ptr< Ledger const > getLedgerByHash(LedgerHash const &ledgerHash)
Retrieve a ledger given its hash.
Definition: LedgerHistory.cpp:125
ripple::LedgerHistory::collector_
beast::insight::Collector::ptr collector_
Definition: LedgerHistory.h:131
ripple::LedgerHistory::handleMismatch
void handleMismatch(LedgerHash const &built, LedgerHash const &valid, boost::optional< uint256 > const &builtConsensusHash, boost::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::LedgerHistory::validatedLedger
void validatedLedger(std::shared_ptr< Ledger const > const &, boost::optional< uint256 > const &consensusHash)
Report that we have validated a particular ledger.
Definition: LedgerHistory.cpp:472
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::built
boost::optional< LedgerHash > built
Definition: LedgerHistory.h:143
ripple::LedgerHistory::cv_entry::builtConsensusHash
boost::optional< uint256 > builtConsensusHash
Definition: LedgerHistory.h:147
ripple::LedgerHistory::cv_entry::consensus
boost::optional< Json::Value > consensus
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:51
ripple::LedgerHistory::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerHistory.cpp:534
ripple::LedgerHistory::mismatch_counter_
beast::insight::Counter mismatch_counter_
Definition: LedgerHistory.h:132
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:136
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::LedgerHistory::cv_entry
Definition: LedgerHistory.h:140