From bdd22e4d513d91071945204952a499e2478f926c Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sun, 12 Apr 2020 01:53:32 -0700 Subject: [PATCH] Improve reporting of missing node exceptions --- Builds/CMake/RippledCore.cmake | 1 - src/ripple/app/consensus/RCLConsensus.cpp | 4 +- src/ripple/app/ledger/Ledger.cpp | 8 +-- src/ripple/app/ledger/OrderBookDB.cpp | 4 +- src/ripple/app/ledger/impl/LedgerCleaner.cpp | 4 +- src/ripple/app/ledger/impl/LedgerMaster.cpp | 6 +-- src/ripple/app/main/Application.cpp | 8 +-- src/ripple/rpc/impl/RPCHelpers.cpp | 5 +- src/ripple/shamap/SHAMapMissingNode.h | 41 +++++++++------ src/ripple/shamap/impl/SHAMapMissingNode.cpp | 53 -------------------- 10 files changed, 44 insertions(+), 90 deletions(-) delete mode 100644 src/ripple/shamap/impl/SHAMapMissingNode.cpp diff --git a/Builds/CMake/RippledCore.cmake b/Builds/CMake/RippledCore.cmake index 56502aa669..6e677b37e2 100644 --- a/Builds/CMake/RippledCore.cmake +++ b/Builds/CMake/RippledCore.cmake @@ -638,7 +638,6 @@ target_sources (rippled PRIVATE src/ripple/shamap/impl/SHAMap.cpp src/ripple/shamap/impl/SHAMapDelta.cpp src/ripple/shamap/impl/SHAMapItem.cpp - src/ripple/shamap/impl/SHAMapMissingNode.cpp src/ripple/shamap/impl/SHAMapNodeID.cpp src/ripple/shamap/impl/SHAMapSync.cpp src/ripple/shamap/impl/SHAMapTreeNode.cpp diff --git a/src/ripple/app/consensus/RCLConsensus.cpp b/src/ripple/app/consensus/RCLConsensus.cpp index 50143d5044..862be4cfc7 100644 --- a/src/ripple/app/consensus/RCLConsensus.cpp +++ b/src/ripple/app/consensus/RCLConsensus.cpp @@ -827,7 +827,7 @@ RCLConsensus::timerEntry(NetClock::time_point const& now) catch (SHAMapMissingNode const& mn) { // This should never happen - JLOG(j_.error()) << "Missing node during consensus process " << mn; + JLOG(j_.error()) << "During consensus timerEntry: " << mn.what(); Rethrow(); } } @@ -843,7 +843,7 @@ RCLConsensus::gotTxSet(NetClock::time_point const& now, RCLTxSet const& txSet) catch (SHAMapMissingNode const& mn) { // This should never happen - JLOG(j_.error()) << "Missing node during consensus process " << mn; + JLOG(j_.error()) << "During consensus gotTxSet: " << mn.what(); Rethrow(); } } diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index f72d6d7347..0c5cc4cf1d 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -596,7 +596,7 @@ Ledger::setup (Config const& config) fees_.increment = sle->getFieldU32 (sfReserveIncrement); } } - catch (SHAMapMissingNode &) + catch (SHAMapMissingNode const&) { ret = false; } @@ -609,7 +609,7 @@ Ledger::setup (Config const& config) { rules_ = Rules(*this, config.features); } - catch (SHAMapMissingNode &) + catch (SHAMapMissingNode const&) { ret = false; } @@ -657,7 +657,7 @@ bool Ledger::walkLedger (beast::Journal j) const if (auto stream = j.info()) { stream << missingNodes1.size () << " missing account node(s)"; - stream << "First: " << missingNodes1[0]; + stream << "First: " << missingNodes1[0].what(); } } @@ -677,7 +677,7 @@ bool Ledger::walkLedger (beast::Journal j) const if (auto stream = j.info()) { stream << missingNodes2.size () << " missing transaction node(s)"; - stream << "First: " << missingNodes2[0]; + stream << "First: " << missingNodes2[0].what(); } } return missingNodes1.empty () && missingNodes2.empty (); diff --git a/src/ripple/app/ledger/OrderBookDB.cpp b/src/ripple/app/ledger/OrderBookDB.cpp index 02ebbcca50..c050bb317c 100644 --- a/src/ripple/app/ledger/OrderBookDB.cpp +++ b/src/ripple/app/ledger/OrderBookDB.cpp @@ -132,10 +132,10 @@ void OrderBookDB::update( } } } - catch (const SHAMapMissingNode&) + catch (SHAMapMissingNode const& mn) { JLOG (j_.info()) - << "OrderBookDB::update encountered a missing node"; + << "OrderBookDB::update: " << mn.what(); std::lock_guard sl (mLock); mSeq = 0; return; diff --git a/src/ripple/app/ledger/impl/LedgerCleaner.cpp b/src/ripple/app/ledger/impl/LedgerCleaner.cpp index 41c07faaed..382aca3778 100644 --- a/src/ripple/app/ledger/impl/LedgerCleaner.cpp +++ b/src/ripple/app/ledger/impl/LedgerCleaner.cpp @@ -277,10 +277,10 @@ private: { hash = hashOfSeq(*ledger, index, j_); } - catch (SHAMapMissingNode &) + catch (SHAMapMissingNode const& mn) { JLOG (j_.warn()) << - "Node missing from ledger " << ledger->info().seq; + "Ledger #" << ledger->info().seq << ": " << mn.what(); app_.getInboundLedgers().acquire ( ledger->info().hash, ledger->info().seq, InboundLedger::Reason::GENERIC); diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 3b64f8b38d..8762ed0844 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -1421,10 +1421,10 @@ LedgerMaster::updatePaths (Job& job) app_.getPathRequests().updateAll( lastLedger, job.getCancelCallback()); } - catch (SHAMapMissingNode&) + catch (SHAMapMissingNode const& mn) { JLOG (m_journal.info()) - << "Missing node detected during pathfinding"; + << "During pathfinding: " << mn.what(); if (lastLedger->open()) { // our parent is the problem @@ -1617,7 +1617,7 @@ LedgerMaster::walkHashBySeq ( { ledgerHash = hashOfSeq(*ledger, index, m_journal); } - catch(SHAMapMissingNode&) + catch(SHAMapMissingNode const&) { ledger.reset(); } diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index d8f223d2e1..61b4cc0ca5 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -1806,10 +1806,10 @@ ApplicationImp::getLastFullLedger() return {}; } - catch (SHAMapMissingNode& sn) + catch (SHAMapMissingNode const& mn) { JLOG (j.warn()) << - "Ledger with missing nodes in database: " << sn; + "Ledger in database: " << mn.what(); return {}; } } @@ -2117,10 +2117,10 @@ bool ApplicationImp::loadOldLedger ( m_ledgerMaster->takeReplay (std::move (replayData)); } } - catch (SHAMapMissingNode&) + catch (SHAMapMissingNode const& mn) { JLOG(m_journal.fatal()) << - "Data is missing for selected ledger"; + "While loading specified ledger: " << mn.what(); return false; } catch (boost::bad_lexical_cast&) diff --git a/src/ripple/rpc/impl/RPCHelpers.cpp b/src/ripple/rpc/impl/RPCHelpers.cpp index fcc77fb90e..4fd4eb2d4b 100644 --- a/src/ripple/rpc/impl/RPCHelpers.cpp +++ b/src/ripple/rpc/impl/RPCHelpers.cpp @@ -448,11 +448,10 @@ isValidated(LedgerMaster& ledgerMaster, ReadView const& ledger, return false; } } - catch (SHAMapMissingNode const&) + catch (SHAMapMissingNode const& mn) { auto stream = app.journal ("RPCHandler").warn(); - JLOG (stream) - << "Missing SHANode " << std::to_string (seq); + JLOG (stream) << "Ledger #" << seq << ": " << mn.what(); return false; } diff --git a/src/ripple/shamap/SHAMapMissingNode.h b/src/ripple/shamap/SHAMapMissingNode.h index e38471e296..2a38de64c0 100644 --- a/src/ripple/shamap/SHAMapMissingNode.h +++ b/src/ripple/shamap/SHAMapMissingNode.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include namespace ripple { @@ -34,31 +36,38 @@ enum class SHAMapType FREE = 3, // A tree not part of a ledger }; +inline +std::string +to_string(SHAMapType t) +{ + switch (t) + { + case SHAMapType::TRANSACTION: + return "Transaction Tree"; + case SHAMapType::STATE: + return "State Tree"; + case SHAMapType::FREE: + return "Free Tree"; + default: + return std::to_string(safe_cast>(t)); + } +} + class SHAMapMissingNode : public std::runtime_error { -private: - SHAMapType mType; - SHAMapHash mNodeHash; - uint256 mNodeID; public: - SHAMapMissingNode (SHAMapType t, - SHAMapHash const& nodeHash) - : std::runtime_error ("SHAMapMissingNode") - , mType (t) - , mNodeHash (nodeHash) + SHAMapMissingNode (SHAMapType t, SHAMapHash const& hash) + : std::runtime_error("Missing Node: " + + to_string(t) + ": hash " + to_string(hash)) { } - SHAMapMissingNode (SHAMapType t, - uint256 const& nodeID) - : std::runtime_error ("SHAMapMissingNode") - , mType (t) - , mNodeID (nodeID) + SHAMapMissingNode (SHAMapType t, uint256 const& id) + : std::runtime_error ("Missing Node: " + + to_string(t) + ": id " + to_string(id)) { } - - friend std::ostream& operator<< (std::ostream&, SHAMapMissingNode const&); }; } // ripple diff --git a/src/ripple/shamap/impl/SHAMapMissingNode.cpp b/src/ripple/shamap/impl/SHAMapMissingNode.cpp deleted file mode 100644 index d87a1eab11..0000000000 --- a/src/ripple/shamap/impl/SHAMapMissingNode.cpp +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include - -namespace ripple { - -std::ostream& -operator<< (std::ostream& out, const SHAMapMissingNode& mn) -{ - switch (mn.mType) - { - case SHAMapType::TRANSACTION: - out << "Missing/TXN("; - break; - - case SHAMapType::STATE: - out << "Missing/STA("; - break; - - case SHAMapType::FREE: - default: - out << "Missing/("; - break; - }; - - if (mn.mNodeHash == beast::zero) - out << "id : " << mn.mNodeID; - else - out << "hash : " << mn.mNodeHash; - out << ")"; - return out; -} - -} // ripple