diff --git a/src/ripple_app/ledger/LedgerHistory.cpp b/src/ripple_app/ledger/LedgerHistory.cpp index fee648bb5..4791d7a08 100644 --- a/src/ripple_app/ledger/LedgerHistory.cpp +++ b/src/ripple_app/ledger/LedgerHistory.cpp @@ -86,6 +86,7 @@ Ledger::pointer LedgerHistory::getLedgerBySeq (std::uint32_t index) assert (ret->getLedgerSeq () == index); { + // Add this ledger to the local tracking by index LedgersByHash::ScopedLockType sl (m_ledgers_by_hash.peekMutex ()); assert (ret->isImmutable ()); @@ -127,7 +128,7 @@ void LedgerHistory::builtLedger (Ledger::ref ledger) ConsensusValidated::ScopedLockType sl ( m_consensus_validated.peekMutex()); - boost::shared_ptr< std::pair< LedgerHash, LedgerHash > > entry = boost::make_shared>(); + auto entry = boost::make_shared>(); m_consensus_validated.canonicalize(index, entry, false); if (entry->first != hash) diff --git a/src/ripple_app/ledger/LedgerHistory.h b/src/ripple_app/ledger/LedgerHistory.h index d55153a47..149659c88 100644 --- a/src/ripple_app/ledger/LedgerHistory.h +++ b/src/ripple_app/ledger/LedgerHistory.h @@ -23,35 +23,70 @@ namespace ripple { // VFALCO TODO Rename to OldLedgers ? + +/** Retains historical ledgers. */ class LedgerHistory : beast::LeakChecked { public: LedgerHistory (); + /** Track a ledger + @return `true` if the ledger was already tracked + */ bool addLedger (Ledger::pointer ledger, bool validated); + /** Get the ledgers_by_hash cache hit rate + @return the hit rate + */ float getCacheHitRate () { return m_ledgers_by_hash.getHitRate (); } + /** Get a ledger given its squence number + @param ledgerIndex The sequence number of the desired ledger + */ Ledger::pointer getLedgerBySeq (LedgerIndex ledgerIndex); + /** Get a ledger's hash given its sequence number + @param ledgerIndex The sequence number of the desired ledger + @return The hash of the specified ledger + */ LedgerHash getLedgerHash (LedgerIndex ledgerIndex); + /** Retrieve a ledger given its hash + @param ledgerHash The hash of the requested ledger + @return The ledger requested + */ Ledger::pointer getLedgerByHash (LedgerHash const& ledgerHash); + /** Set the history cache's paramters + @param size The target size of the cache + @param age The target age of the cache, in seconds + */ void tune (int size, int age); + /** Remove stale cache entries + */ void sweep () { m_ledgers_by_hash.sweep (); m_consensus_validated.sweep (); } + /** Report that we have locally built a particular ledger + */ void builtLedger (Ledger::ref); + + /** Report that we have validated a particular ledger + */ void validatedLedger (Ledger::ref); + /** Repair a hash to index mapping + @param ledgerIndex The index whose mapping is to be repaired + @param ledgerHash The hash it is to be mapped to + @return `true` if the mapping was repaired + */ bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash); private: @@ -59,7 +94,10 @@ private: LedgersByHash m_ledgers_by_hash; - //typedef std::pair + // Maps ledger indexes to the corresponding hashes + // For debug and logging purposes + // 1) The hash of a ledger with that index we build + // 2) The hash of a ledger with that index we validated typedef TaggedCache > ConsensusValidated; ConsensusValidated m_consensus_validated;