Improve reporting of missing node exceptions

This commit is contained in:
Nik Bougalis
2020-04-12 01:53:32 -07:00
parent b7631d2a28
commit bdd22e4d51
10 changed files with 44 additions and 90 deletions

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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 ();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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&)

View File

@@ -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;
}

View File

@@ -24,6 +24,8 @@
#include <ripple/shamap/SHAMapTreeNode.h>
#include <iosfwd>
#include <stdexcept>
#include <string>
#include <type_traits>
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<std::underlying_type_t<SHAMapType>>(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

View File

@@ -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 <ripple/shamap/SHAMapMissingNode.h>
#include <ripple/beast/utility/Zero.h>
#include <ostream>
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