Skip to content

Commit

Permalink
Do not attempt to acquire missing data from peer network in
Browse files Browse the repository at this point in the history
reporting mode.
  • Loading branch information
Mark Travis committed Mar 9, 2023
1 parent 8687b5c commit a5a2f6b
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ripple/shamap/Family.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/shamap/NodeFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 112 additions & 0 deletions src/ripple/shamap/NodeFamily.h.orig
Original file line number Diff line number Diff line change
@@ -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 <ripple/app/main/CollectorManager.h>
#include <ripple/shamap/Family.h>

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<FullBelowCache> getFullBelowCache(std::uint32_t) override
{
return fbCache_;
}

std::shared_ptr<TreeNodeCache> 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<FullBelowCache> fbCache_;
std::shared_ptr<TreeNodeCache> tnCache_;

// Missing node handler
LedgerIndex maxSeq_{0};
std::mutex maxSeqMutex_;

void
acquire(uint256 const& hash, std::uint32_t seq);
};

} // namespace ripple

#endif
19 changes: 19 additions & 0 deletions src/ripple/shamap/NodeFamily.h.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- common.h
+++ common.h
@@ -81,14 +81,12 @@ public:
return j_;
}

- std::shared_ptr<FullBelowCache>
- getFullBelowCache(std::uint32_t) override
+ std::shared_ptr<FullBelowCache> getFullBelowCache(std::uint32_t) override
{
return fbCache_;
}

- std::shared_ptr<TreeNodeCache>
- getTreeNodeCache(std::uint32_t) override
+ std::shared_ptr<TreeNodeCache> getTreeNodeCache(std::uint32_t) override
{
return tnCache_;
}
10 changes: 10 additions & 0 deletions src/ripple/shamap/SHAMapMissingNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<std::underlying_type_t<SHAMapType>>(t));
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/shamap/ShardFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/ripple/shamap/impl/NodeFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#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>

namespace ripple {

Expand Down Expand Up @@ -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<SHAMapMissingNode>(nodeHash);

std::unique_lock<std::mutex> lock(maxSeqMutex_);
if (maxSeq_ == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/shamap/impl/SHAMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ SHAMap::finishFetch(
if (full_)
{
full_ = false;
f_.missingNode(ledgerSeq_);
f_.missingNode(ledgerSeq_, hash.as_uint256());
}
return {};
}
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/shamap/impl/ShardFamily.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ripple/app/main/Tuning.h>
#include <ripple/nodestore/DatabaseShard.h>
#include <ripple/shamap/ShardFamily.h>
#include <tuple>

namespace ripple {

Expand Down Expand Up @@ -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<std::mutex> lock(maxSeqMutex_);
Expand Down
2 changes: 1 addition & 1 deletion src/test/shamap/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::runtime_error>("missing node");
}
Expand Down

0 comments on commit a5a2f6b

Please sign in to comment.