Skip to content

Commit

Permalink
Review fixes: catch exception in a sensible place.
Browse files Browse the repository at this point in the history
No need to overload SHAMapMissingNode, instead use std::runtime_error.
  • Loading branch information
mtrippled committed Mar 14, 2023
1 parent 746579f commit fddd14c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
10 changes: 0 additions & 10 deletions src/ripple/shamap/SHAMapMissingNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ enum class SHAMapType {
TRANSACTION = 1, // A tree of transactions
STATE = 2, // A tree of state nodes
FREE = 3, // A tree not part of a ledger
UNKNOWN = 4 // Could be any type, but it's not there nonetheless
};

inline std::string
Expand All @@ -47,8 +46,6 @@ to_string(SHAMapType t)
return "State Tree";
case SHAMapType::FREE:
return "Free Tree";
case SHAMapType::UNKNOWN:
return "Unknown Tree";
default:
return std::to_string(
safe_cast<std::underlying_type_t<SHAMapType>>(t));
Expand All @@ -69,13 +66,6 @@ class SHAMapMissingNode : public std::runtime_error
"Missing Node: " + to_string(t) + ": id " + to_string(id))
{
}

SHAMapMissingNode(uint256 const& id)
: std::runtime_error(
"Missing Node: " + to_string(SHAMapType::UNKNOWN) + ": hash " +
to_string(id))
{
}
};

} // namespace ripple
Expand Down
10 changes: 7 additions & 3 deletions src/ripple/shamap/impl/NodeFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/main/Tuning.h>
#include <ripple/basics/contract.h>
#include <ripple/shamap/NodeFamily.h>
#include <ripple/shamap/SHAMapMissingNode.h>
#include <sstream>

namespace ripple {

Expand Down Expand Up @@ -71,7 +70,12 @@ NodeFamily::missingNodeAcquireBySeq(std::uint32_t seq, uint256 const& nodeHash)
{
JLOG(j_.error()) << "Missing node in " << seq;
if (app_.config().reporting())
Throw<SHAMapMissingNode>(nodeHash);
{
std::stringstream ss;
ss << "Node not read, likely a Cassandra error in ledger seq " << seq
<< " object hash " << nodeHash;
Throw<std::runtime_error>(ss.str());
}

std::unique_lock<std::mutex> lock(maxSeqMutex_);
if (maxSeq_ == 0)
Expand Down
32 changes: 21 additions & 11 deletions src/ripple/shamap/impl/SHAMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,40 @@ SHAMap::finishFetch(
std::shared_ptr<NodeObject> const& object) const
{
assert(backed_);
if (!object)
{
if (full_)
{
full_ = false;
f_.missingNodeAcquireBySeq(ledgerSeq_, hash.as_uint256());
}
return {};
}

std::shared_ptr<SHAMapTreeNode> node;
try
{
if (!object)
{
if (full_)
{
full_ = false;
f_.missingNodeAcquireBySeq(ledgerSeq_, hash.as_uint256());
}
return {};
}

node =
SHAMapTreeNode::makeFromPrefix(makeSlice(object->getData()), hash);
if (node)
canonicalize(hash, node);
return node;
}
catch (std::exception const&)
catch (SHAMapMissingNode const& e)
{
JLOG(journal_.warn()) << "Missing node: " << hash << " : " << e.what();
}
catch (std::runtime_error const& e)
{
JLOG(journal_.warn()) << e.what();
}
catch (...)
{
JLOG(journal_.warn()) << "Invalid DB node " << hash;
return std::shared_ptr<SHAMapTreeNode>();
}

return std::shared_ptr<SHAMapTreeNode>();
}

// See if a sync filter has a node
Expand Down

0 comments on commit fddd14c

Please sign in to comment.