From e7cf3e80848b9323d2d80ebd1cff9f2c00dfe9d1 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 25 Aug 2014 17:13:05 -0700 Subject: [PATCH] Add ledger.history.mismatch insight statistic --- src/ripple/module/app/ledger/LedgerHistory.cpp | 16 ++++++++++++++-- src/ripple/module/app/ledger/LedgerHistory.h | 8 +++++++- src/ripple/module/app/ledger/LedgerMaster.cpp | 16 ++++++++++++---- src/ripple/module/app/ledger/LedgerMaster.h | 12 ++++++++++-- src/ripple/module/app/main/Application.cpp | 4 ++-- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/ripple/module/app/ledger/LedgerHistory.cpp b/src/ripple/module/app/ledger/LedgerHistory.cpp index cbf8d8947..0716c4887 100644 --- a/src/ripple/module/app/ledger/LedgerHistory.cpp +++ b/src/ripple/module/app/ledger/LedgerHistory.cpp @@ -31,8 +31,11 @@ namespace ripple { // FIXME: Need to clean up ledgers by index at some point -LedgerHistory::LedgerHistory () - : m_ledgers_by_hash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE, +LedgerHistory::LedgerHistory ( + beast::insight::Collector::ptr const& collector) + : collector_ (collector) + , mismatch_counter_ (collector->make_counter ("ledger.history", "mismatch")) + , m_ledgers_by_hash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE, get_seconds_clock (), deprecatedLogs().journal("TaggedCache")) , m_consensus_validated ("ConsensusValidated", 64, 300, get_seconds_clock (), deprecatedLogs().journal("TaggedCache")) @@ -158,14 +161,23 @@ void LedgerHistory::validatedLedger (Ledger::ref ledger) if (entry->second != hash) { + bool mismatch (false); + if (entry->second.isNonZero() && (entry->second != hash)) { WriteLog (lsERROR, LedgerMaster) << "MISMATCH: seq=" << index << " validated:" << entry->second << " then:" << hash; + mismatch = true; } + if (entry->first.isNonZero() && (entry->first != hash)) { WriteLog (lsERROR, LedgerMaster) << "MISMATCH: seq=" << index << " built:" << entry->first << " validated:" << hash; + mismatch = true; } + + if (mismatch) + ++mismatch_counter_; + entry->second = hash; } } diff --git a/src/ripple/module/app/ledger/LedgerHistory.h b/src/ripple/module/app/ledger/LedgerHistory.h index 149659c88..f722f5360 100644 --- a/src/ripple/module/app/ledger/LedgerHistory.h +++ b/src/ripple/module/app/ledger/LedgerHistory.h @@ -20,6 +20,8 @@ #ifndef RIPPLE_LEDGERHISTORY_H #define RIPPLE_LEDGERHISTORY_H +#include + namespace ripple { // VFALCO TODO Rename to OldLedgers ? @@ -28,7 +30,8 @@ namespace ripple { class LedgerHistory : beast::LeakChecked { public: - LedgerHistory (); + explicit + LedgerHistory (beast::insight::Collector::ptr const& collector); /** Track a ledger @return `true` if the ledger was already tracked @@ -90,6 +93,9 @@ public: bool fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash); private: + beast::insight::Collector::ptr collector_; + beast::insight::Counter mismatch_counter_; + typedef TaggedCache LedgersByHash; LedgersByHash m_ledgers_by_hash; diff --git a/src/ripple/module/app/ledger/LedgerMaster.cpp b/src/ripple/module/app/ledger/LedgerMaster.cpp index 121700abf..e370d7d59 100644 --- a/src/ripple/module/app/ledger/LedgerMaster.cpp +++ b/src/ripple/module/app/ledger/LedgerMaster.cpp @@ -18,8 +18,10 @@ //============================================================================== #include +#include #include #include +#include // namespace ripple { @@ -77,9 +79,12 @@ public: //-------------------------------------------------------------------------- - explicit LedgerMasterImp (Stoppable& parent, beast::Journal journal) + LedgerMasterImp (Stoppable& parent, + beast::insight::Collector::ptr const& collector, + beast::Journal journal) : LedgerMaster (parent) , m_journal (journal) + , mLedgerHistory (collector) , mHeldTransactions (uint256 ()) , mLedgerCleaner (LedgerCleaner::New(*this, deprecatedLogs().journal("LedgerCleaner"))) , mMinValidations (0) @@ -1473,10 +1478,13 @@ bool LedgerMaster::shouldAcquire ( return ret; } - -LedgerMaster* LedgerMaster::New (Stoppable& parent, beast::Journal journal) +std::unique_ptr +make_LedgerMaster (beast::Stoppable& parent, + beast::insight::Collector::ptr const& collector, + beast::Journal journal) { - return new LedgerMasterImp (parent, journal); + return std::make_unique ( + parent, collector, journal); } } // ripple diff --git a/src/ripple/module/app/ledger/LedgerMaster.h b/src/ripple/module/app/ledger/LedgerMaster.h index ef5cd80c8..a3e2058a7 100644 --- a/src/ripple/module/app/ledger/LedgerMaster.h +++ b/src/ripple/module/app/ledger/LedgerMaster.h @@ -20,6 +20,11 @@ #ifndef RIPPLE_LEDGERMASTER_H_INCLUDED #define RIPPLE_LEDGERMASTER_H_INCLUDED +// VFALCO TODO Make a header that forward declares Collector and +// its smart pointer container a-la boost. +// +#include + namespace ripple { // Tracks the current ledger and any ledgers in the process of closing @@ -43,8 +48,6 @@ public: typedef std::unique_lock ScopedLockType; typedef beast::GenericScopedUnlock ScopedUnlockType; - static LedgerMaster* New (Stoppable& parent, beast::Journal journal); - virtual ~LedgerMaster () = 0; virtual LedgerIndex getCurrentLedgerIndex () = 0; @@ -147,6 +150,11 @@ public: std::uint32_t ledgerHistory, std::uint32_t targetLedger); }; +std::unique_ptr +make_LedgerMaster (beast::Stoppable& parent, + beast::insight::Collector::ptr const& collector, + beast::Journal journal); + } // ripple #endif diff --git a/src/ripple/module/app/main/Application.cpp b/src/ripple/module/app/main/Application.cpp index 1f06e125e..8df6edbc2 100644 --- a/src/ripple/module/app/main/Application.cpp +++ b/src/ripple/module/app/main/Application.cpp @@ -286,8 +286,8 @@ public: , m_pathRequests (new PathRequests ( m_logs.journal("PathRequest"), m_collectorManager->collector ())) - , m_ledgerMaster (LedgerMaster::New ( - *m_jobQueue, m_logs.journal("LedgerMaster"))) + , m_ledgerMaster (make_LedgerMaster (*m_jobQueue, + m_collectorManager->collector (), m_logs.journal("LedgerMaster"))) // VFALCO NOTE must come before NetworkOPs to prevent a crash due // to dependencies in the destructor.