From a5a2f6b3fc43e70b6e91d7b219b8f93d6462bfcb Mon Sep 17 00:00:00 2001 From: Mark Travis Date: Thu, 9 Mar 2023 14:18:45 -0800 Subject: [PATCH] Do not attempt to acquire missing data from peer network in reporting mode. --- src/ripple/shamap/Family.h | 2 +- src/ripple/shamap/NodeFamily.h | 2 +- src/ripple/shamap/NodeFamily.h.orig | 112 +++++++++++++++++++++++++ src/ripple/shamap/NodeFamily.h.rej | 19 +++++ src/ripple/shamap/SHAMapMissingNode.h | 10 +++ src/ripple/shamap/ShardFamily.h | 2 +- src/ripple/shamap/impl/NodeFamily.cpp | 6 +- src/ripple/shamap/impl/SHAMap.cpp | 2 +- src/ripple/shamap/impl/ShardFamily.cpp | 4 +- src/test/shamap/common.h | 2 +- 10 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 src/ripple/shamap/NodeFamily.h.orig create mode 100644 src/ripple/shamap/NodeFamily.h.rej diff --git a/src/ripple/shamap/Family.h b/src/ripple/shamap/Family.h index 72c9a6cb07a..cd3f9cdd001 100644 --- a/src/ripple/shamap/Family.h +++ b/src/ripple/shamap/Family.h @@ -76,7 +76,7 @@ class Family isShardBacked() const = 0; virtual void - missingNode(std::uint32_t refNum) = 0; + missingNode(std::uint32_t refNum, uint256 const& nodeHash) = 0; virtual void missingNode(uint256 const& refHash, std::uint32_t refNum) = 0; diff --git a/src/ripple/shamap/NodeFamily.h b/src/ripple/shamap/NodeFamily.h index 2d8236705b5..2c67622b33a 100644 --- a/src/ripple/shamap/NodeFamily.h +++ b/src/ripple/shamap/NodeFamily.h @@ -83,7 +83,7 @@ class NodeFamily : public Family reset() override; void - missingNode(std::uint32_t seq) override; + missingNode(std::uint32_t seq, uint256 const& hash) override; void missingNode(uint256 const& hash, std::uint32_t seq) override diff --git a/src/ripple/shamap/NodeFamily.h.orig b/src/ripple/shamap/NodeFamily.h.orig new file mode 100644 index 00000000000..2c67622b33a --- /dev/null +++ b/src/ripple/shamap/NodeFamily.h.orig @@ -0,0 +1,112 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2020 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. +*/ +//============================================================================== + +#ifndef RIPPLE_SHAMAP_NODEFAMILY_H_INCLUDED +#define RIPPLE_SHAMAP_NODEFAMILY_H_INCLUDED + +#include +#include + +namespace ripple { + +class Application; + +class NodeFamily : public Family +{ +public: + NodeFamily() = delete; + NodeFamily(NodeFamily const&) = delete; + NodeFamily(NodeFamily&&) = delete; + + NodeFamily& + operator=(NodeFamily const&) = delete; + + NodeFamily& + operator=(NodeFamily&&) = delete; + + NodeFamily(Application& app, CollectorManager& cm); + + NodeStore::Database& + db() override + { + return db_; + } + + NodeStore::Database const& + db() const override + { + return db_; + } + + beast::Journal const& + journal() override + { + return j_; + } + + bool + isShardBacked() const override + { + return false; + } + + std::shared_ptr getFullBelowCache(std::uint32_t) override + { + return fbCache_; + } + + std::shared_ptr getTreeNodeCache(std::uint32_t) override + { + return tnCache_; + } + + void + sweep() override; + + void + reset() override; + + void + missingNode(std::uint32_t seq, uint256 const& hash) override; + + void + missingNode(uint256 const& hash, std::uint32_t seq) override + { + acquire(hash, seq); + } + +private: + Application& app_; + NodeStore::Database& db_; + beast::Journal const j_; + + std::shared_ptr fbCache_; + std::shared_ptr tnCache_; + + // Missing node handler + LedgerIndex maxSeq_{0}; + std::mutex maxSeqMutex_; + + void + acquire(uint256 const& hash, std::uint32_t seq); +}; + +} // namespace ripple + +#endif diff --git a/src/ripple/shamap/NodeFamily.h.rej b/src/ripple/shamap/NodeFamily.h.rej new file mode 100644 index 00000000000..d3e2b38f619 --- /dev/null +++ b/src/ripple/shamap/NodeFamily.h.rej @@ -0,0 +1,19 @@ +--- common.h ++++ common.h +@@ -81,14 +81,12 @@ public: + return j_; + } + +- std::shared_ptr +- getFullBelowCache(std::uint32_t) override ++ std::shared_ptr getFullBelowCache(std::uint32_t) override + { + return fbCache_; + } + +- std::shared_ptr +- getTreeNodeCache(std::uint32_t) override ++ std::shared_ptr getTreeNodeCache(std::uint32_t) override + { + return tnCache_; + } diff --git a/src/ripple/shamap/SHAMapMissingNode.h b/src/ripple/shamap/SHAMapMissingNode.h index 811fe5f9615..07a521cd049 100644 --- a/src/ripple/shamap/SHAMapMissingNode.h +++ b/src/ripple/shamap/SHAMapMissingNode.h @@ -33,6 +33,7 @@ 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 @@ -46,6 +47,8 @@ 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>(t)); @@ -66,6 +69,13 @@ 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 diff --git a/src/ripple/shamap/ShardFamily.h b/src/ripple/shamap/ShardFamily.h index 550efeb5b81..c7cbb8d3d00 100644 --- a/src/ripple/shamap/ShardFamily.h +++ b/src/ripple/shamap/ShardFamily.h @@ -89,7 +89,7 @@ class ShardFamily : public Family reset() override; void - missingNode(std::uint32_t seq) override; + missingNode(std::uint32_t seq, uint256 const& nodeHash) override; void missingNode(uint256 const& hash, std::uint32_t seq) override diff --git a/src/ripple/shamap/impl/NodeFamily.cpp b/src/ripple/shamap/impl/NodeFamily.cpp index f9c6dedb265..0f851606e4a 100644 --- a/src/ripple/shamap/impl/NodeFamily.cpp +++ b/src/ripple/shamap/impl/NodeFamily.cpp @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include namespace ripple { @@ -65,9 +67,11 @@ NodeFamily::reset() } void -NodeFamily::missingNode(std::uint32_t seq) +NodeFamily::missingNode(std::uint32_t seq, uint256 const& nodeHash) { JLOG(j_.error()) << "Missing node in " << seq; + if (app_.config().reporting()) + Throw(nodeHash); std::unique_lock lock(maxSeqMutex_); if (maxSeq_ == 0) diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 1a5a283dd3c..cd9ba05736e 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -178,7 +178,7 @@ SHAMap::finishFetch( if (full_) { full_ = false; - f_.missingNode(ledgerSeq_); + f_.missingNode(ledgerSeq_, hash.as_uint256()); } return {}; } diff --git a/src/ripple/shamap/impl/ShardFamily.cpp b/src/ripple/shamap/impl/ShardFamily.cpp index eadfc42aa27..16423a65b7c 100644 --- a/src/ripple/shamap/impl/ShardFamily.cpp +++ b/src/ripple/shamap/impl/ShardFamily.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace ripple { @@ -152,8 +153,9 @@ ShardFamily::reset() } void -ShardFamily::missingNode(std::uint32_t seq) +ShardFamily::missingNode(std::uint32_t seq, uint256 const& nodeHash) { + std::ignore = nodeHash; JLOG(j_.error()) << "Missing node in ledger sequence " << seq; std::unique_lock lock(maxSeqMutex_); diff --git a/src/test/shamap/common.h b/src/test/shamap/common.h index c4238b2a65f..fd9da468348 100644 --- a/src/test/shamap/common.h +++ b/src/test/shamap/common.h @@ -105,7 +105,7 @@ class TestNodeFamily : public Family } void - missingNode(std::uint32_t refNum) override + missingNode(std::uint32_t refNum, uint256 const& nodeHash) override { Throw("missing node"); }