mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 17:27:00 +00:00
Compare commits
36 Commits
copilot/re
...
ximinez/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb109eccf7 | ||
|
|
5bbc553acd | ||
|
|
2bc15d9838 | ||
|
|
77fd2c3cf7 | ||
|
|
518bd4ec46 | ||
|
|
b551562db9 | ||
|
|
98604be7a2 | ||
|
|
edbb9daa36 | ||
|
|
2bcbef1b63 | ||
|
|
59189e6234 | ||
|
|
9f0ca26875 | ||
|
|
2aa493e0e4 | ||
|
|
6074510d47 | ||
|
|
3d39d9e10e | ||
|
|
2ec1276b5f | ||
|
|
61049d9ef8 | ||
|
|
d52851eecb | ||
|
|
e2a7a51e78 | ||
|
|
3e38ee2997 | ||
|
|
25d246fc92 | ||
|
|
2881c08d2e | ||
|
|
ddbe7e87fb | ||
|
|
f1ea5233a8 | ||
|
|
85342554b7 | ||
|
|
cb9b5f0399 | ||
|
|
2f79477190 | ||
|
|
55e5374f56 | ||
|
|
846f29e8ad | ||
|
|
d236569282 | ||
|
|
58170b5ece | ||
|
|
8bb87e9ca9 | ||
|
|
9545e1f7ce | ||
|
|
22b3cbbada | ||
|
|
cbc2288bdc | ||
|
|
5fa9fc55bb | ||
|
|
4ab2950410 |
134
include/xrpl/basics/CanProcess.h
Normal file
134
include/xrpl/basics/CanProcess.h
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of rippled: https://github.com/ripple/rippled
|
||||||
|
Copyright (c) 2024 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_BASICS_CANPROCESS_H_INCLUDED
|
||||||
|
#define RIPPLE_BASICS_CANPROCESS_H_INCLUDED
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
/** RAII class to check if an Item is already being processed on another thread,
|
||||||
|
* as indicated by it's presence in a Collection.
|
||||||
|
*
|
||||||
|
* If the Item is not in the Collection, it will be added under lock in the
|
||||||
|
* ctor, and removed under lock in the dtor. The object will be considered
|
||||||
|
* "usable" and evaluate to `true`.
|
||||||
|
*
|
||||||
|
* If the Item is in the Collection, no changes will be made to the collection,
|
||||||
|
* and the CanProcess object will be considered "unusable".
|
||||||
|
*
|
||||||
|
* It's up to the caller to decide what "usable" and "unusable" mean. (e.g.
|
||||||
|
* Process or skip a block of code, or set a flag.)
|
||||||
|
*
|
||||||
|
* The current use is to avoid lock contention that would be involved in
|
||||||
|
* processing something associated with the Item.
|
||||||
|
*
|
||||||
|
* Examples:
|
||||||
|
*
|
||||||
|
* void IncomingLedgers::acquireAsync(LedgerHash const& hash, ...)
|
||||||
|
* {
|
||||||
|
* if (CanProcess check{acquiresMutex_, pendingAcquires_, hash})
|
||||||
|
* {
|
||||||
|
* acquire(hash, ...);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* bool
|
||||||
|
* NetworkOPsImp::recvValidation(
|
||||||
|
* std::shared_ptr<STValidation> const& val,
|
||||||
|
* std::string const& source)
|
||||||
|
* {
|
||||||
|
* CanProcess check(
|
||||||
|
* validationsMutex_, pendingValidations_, val->getLedgerHash());
|
||||||
|
* BypassAccept bypassAccept =
|
||||||
|
* check ? BypassAccept::no : BypassAccept::yes;
|
||||||
|
* handleNewValidation(app_, val, source, bypassAccept, m_journal);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CanProcess
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <class Mutex, class Collection, class Item>
|
||||||
|
CanProcess(Mutex& mtx, Collection& collection, Item const& item)
|
||||||
|
: cleanup_(insert(mtx, collection, item))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~CanProcess()
|
||||||
|
{
|
||||||
|
if (cleanup_)
|
||||||
|
cleanup_();
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
operator bool() const
|
||||||
|
{
|
||||||
|
return static_cast<bool>(cleanup_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template <bool useIterator, class Mutex, class Collection, class Item>
|
||||||
|
std::function<void()>
|
||||||
|
doInsert(Mutex& mtx, Collection& collection, Item const& item)
|
||||||
|
{
|
||||||
|
std::unique_lock<Mutex> lock(mtx);
|
||||||
|
// TODO: Use structured binding once LLVM 16 is the minimum supported
|
||||||
|
// version. See also: https://github.com/llvm/llvm-project/issues/48582
|
||||||
|
// https://github.com/llvm/llvm-project/commit/127bf44385424891eb04cff8e52d3f157fc2cb7c
|
||||||
|
auto const insertResult = collection.insert(item);
|
||||||
|
auto const it = insertResult.first;
|
||||||
|
if (!insertResult.second)
|
||||||
|
return {};
|
||||||
|
if constexpr (useIterator)
|
||||||
|
return [&, it]() {
|
||||||
|
std::unique_lock<Mutex> lock(mtx);
|
||||||
|
collection.erase(it);
|
||||||
|
};
|
||||||
|
else
|
||||||
|
return [&]() {
|
||||||
|
std::unique_lock<Mutex> lock(mtx);
|
||||||
|
collection.erase(item);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generic insert() function doesn't use iterators because they may get
|
||||||
|
// invalidated
|
||||||
|
template <class Mutex, class Collection, class Item>
|
||||||
|
std::function<void()>
|
||||||
|
insert(Mutex& mtx, Collection& collection, Item const& item)
|
||||||
|
{
|
||||||
|
return doInsert<false>(mtx, collection, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specialize insert() for std::set, which does not invalidate iterators for
|
||||||
|
// insert and erase
|
||||||
|
template <class Mutex, class Item>
|
||||||
|
std::function<void()>
|
||||||
|
insert(Mutex& mtx, std::set<Item>& collection, Item const& item)
|
||||||
|
{
|
||||||
|
return doInsert<true>(mtx, collection, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If set, then the item is "usable"
|
||||||
|
std::function<void()> cleanup_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -44,7 +44,7 @@ template <class T>
|
|||||||
inline void
|
inline void
|
||||||
maybeReverseBytes(T& t, std::true_type)
|
maybeReverseBytes(T& t, std::true_type)
|
||||||
{
|
{
|
||||||
reverse_bytes(t);
|
reverseBytes(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class Hasher>
|
template <class T, class Hasher>
|
||||||
|
|||||||
@@ -137,6 +137,13 @@ private:
|
|||||||
return std::move(peers_);
|
return std::move(peers_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return set of peers waiting for reply. Leaves list unchanged. */
|
||||||
|
std::set<PeerShortID> const&
|
||||||
|
peekPeerSet()
|
||||||
|
{
|
||||||
|
return peers_;
|
||||||
|
}
|
||||||
|
|
||||||
/** Return seated relay time point if the message has been relayed */
|
/** Return seated relay time point if the message has been relayed */
|
||||||
[[nodiscard]] std::optional<Stopwatch::time_point>
|
[[nodiscard]] std::optional<Stopwatch::time_point>
|
||||||
relayed() const
|
relayed() const
|
||||||
@@ -168,6 +175,20 @@ private:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
shouldProcessForPeer(
|
||||||
|
PeerShortID peer,
|
||||||
|
Stopwatch::time_point now,
|
||||||
|
std::chrono::seconds interval)
|
||||||
|
{
|
||||||
|
if (peerProcessed_.contains(peer) && ((peerProcessed_[peer] + interval) > now))
|
||||||
|
return false;
|
||||||
|
// Peer may already be in the list, but adding it again doesn't hurt
|
||||||
|
addPeer(peer);
|
||||||
|
peerProcessed_[peer] = now;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HashRouterFlags flags_ = HashRouterFlags::UNDEFINED;
|
HashRouterFlags flags_ = HashRouterFlags::UNDEFINED;
|
||||||
std::set<PeerShortID> peers_;
|
std::set<PeerShortID> peers_;
|
||||||
@@ -175,6 +196,7 @@ private:
|
|||||||
// than one flag needs to expire independently.
|
// than one flag needs to expire independently.
|
||||||
std::optional<Stopwatch::time_point> relayed_;
|
std::optional<Stopwatch::time_point> relayed_;
|
||||||
std::optional<Stopwatch::time_point> processed_;
|
std::optional<Stopwatch::time_point> processed_;
|
||||||
|
std::map<PeerShortID, Stopwatch::time_point> peerProcessed_;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -197,7 +219,7 @@ public:
|
|||||||
|
|
||||||
/** Add a suppression peer and get message's relay status.
|
/** Add a suppression peer and get message's relay status.
|
||||||
* Return pair:
|
* Return pair:
|
||||||
* element 1: true if the peer is added.
|
* element 1: true if the key is added.
|
||||||
* element 2: optional is seated to the relay time point or
|
* element 2: optional is seated to the relay time point or
|
||||||
* is unseated if has not relayed yet. */
|
* is unseated if has not relayed yet. */
|
||||||
std::pair<bool, std::optional<Stopwatch::time_point>>
|
std::pair<bool, std::optional<Stopwatch::time_point>>
|
||||||
@@ -214,6 +236,15 @@ public:
|
|||||||
HashRouterFlags& flags,
|
HashRouterFlags& flags,
|
||||||
std::chrono::seconds txInterval);
|
std::chrono::seconds txInterval);
|
||||||
|
|
||||||
|
/** Determines whether the hashed item should be processed for the given
|
||||||
|
peer. Could be an incoming or outgoing message.
|
||||||
|
|
||||||
|
Items filtered with this function should only be processed for the given
|
||||||
|
peer once. Unlike shouldProcess, it can be processed for other peers.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
shouldProcessForPeer(uint256 const& key, PeerShortID peer, std::chrono::seconds interval);
|
||||||
|
|
||||||
/** Set the flags on a hash.
|
/** Set the flags on a hash.
|
||||||
|
|
||||||
@return `true` if the flags were changed. `false` if unchanged.
|
@return `true` if the flags were changed. `false` if unchanged.
|
||||||
@@ -239,6 +270,11 @@ public:
|
|||||||
std::optional<std::set<PeerShortID>>
|
std::optional<std::set<PeerShortID>>
|
||||||
shouldRelay(uint256 const& key);
|
shouldRelay(uint256 const& key);
|
||||||
|
|
||||||
|
/** Returns a copy of the set of peers in the Entry for the key
|
||||||
|
*/
|
||||||
|
std::set<PeerShortID>
|
||||||
|
getPeers(uint256 const& key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// pair.second indicates whether the entry was created
|
// pair.second indicates whether the entry was created
|
||||||
std::pair<Entry&, bool>
|
std::pair<Entry&, bool>
|
||||||
|
|||||||
@@ -288,8 +288,18 @@ message TMLedgerData {
|
|||||||
required uint32 ledgerSeq = 2;
|
required uint32 ledgerSeq = 2;
|
||||||
required TMLedgerInfoType type = 3;
|
required TMLedgerInfoType type = 3;
|
||||||
repeated TMLedgerNode nodes = 4;
|
repeated TMLedgerNode nodes = 4;
|
||||||
|
// If the peer supports "responseCookies", this field will
|
||||||
|
// never be populated.
|
||||||
optional uint32 requestCookie = 5;
|
optional uint32 requestCookie = 5;
|
||||||
optional TMReplyError error = 6;
|
optional TMReplyError error = 6;
|
||||||
|
// The old field is called "requestCookie", but this is
|
||||||
|
// a response, so this name makes more sense
|
||||||
|
repeated uint32 responseCookies = 7;
|
||||||
|
// If a TMGetLedger request was received without a "requestCookie",
|
||||||
|
// and the peer supports it, this flag will be set to true to
|
||||||
|
// indicate that the receiver should process the result in addition
|
||||||
|
// to forwarding it to its "responseCookies" peers.
|
||||||
|
optional bool directResponse = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TMPing {
|
message TMPing {
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ struct LedgerHeader
|
|||||||
|
|
||||||
// If validated is false, it means "not yet validated."
|
// If validated is false, it means "not yet validated."
|
||||||
// Once validated is true, it will never be set false at a later time.
|
// Once validated is true, it will never be set false at a later time.
|
||||||
|
// NOTE: If you are accessing this directly, you are probably doing it
|
||||||
|
// wrong. Use LedgerMaster::isValidated().
|
||||||
// VFALCO TODO Make this not mutable
|
// VFALCO TODO Make this not mutable
|
||||||
bool mutable validated = false;
|
bool mutable validated = false;
|
||||||
bool accepted = false;
|
bool accepted = false;
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ public:
|
|||||||
virtual bool
|
virtual bool
|
||||||
isFull() = 0;
|
isFull() = 0;
|
||||||
virtual void
|
virtual void
|
||||||
setMode(OperatingMode om) = 0;
|
setMode(OperatingMode om, char const* reason) = 0;
|
||||||
virtual bool
|
virtual bool
|
||||||
isBlocked() = 0;
|
isBlocked() = 0;
|
||||||
virtual bool
|
virtual bool
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ HashRouter::shouldProcess(
|
|||||||
return s.shouldProcess(suppressionMap_.clock().now(), txInterval);
|
return s.shouldProcess(suppressionMap_.clock().now(), txInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
HashRouter::shouldProcessForPeer(
|
||||||
|
uint256 const& key,
|
||||||
|
PeerShortID peer,
|
||||||
|
std::chrono::seconds interval)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex_);
|
||||||
|
|
||||||
|
auto& entry = emplace(key).first;
|
||||||
|
|
||||||
|
return entry.shouldProcessForPeer(peer, suppressionMap_.clock().now(), interval);
|
||||||
|
}
|
||||||
|
|
||||||
HashRouterFlags
|
HashRouterFlags
|
||||||
HashRouter::getFlags(uint256 const& key)
|
HashRouter::getFlags(uint256 const& key)
|
||||||
{
|
{
|
||||||
@@ -119,4 +132,13 @@ HashRouter::shouldRelay(uint256 const& key) -> std::optional<std::set<PeerShortI
|
|||||||
return s.releasePeerSet();
|
return s.releasePeerSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto
|
||||||
|
HashRouter::getPeers(uint256 const& key) -> std::set<PeerShortID>
|
||||||
|
{
|
||||||
|
std::lock_guard lock(mutex_);
|
||||||
|
|
||||||
|
auto& s = emplace(key).first;
|
||||||
|
return s.peekPeerSet();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xrpl
|
} // namespace xrpl
|
||||||
|
|||||||
@@ -394,6 +394,33 @@ class HashRouter_test : public beast::unit_test::Suite
|
|||||||
BEAST_EXPECT(!any(HF::UNDEFINED));
|
BEAST_EXPECT(!any(HF::UNDEFINED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testProcessPeer()
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
TestStopwatch stopwatch;
|
||||||
|
HashRouter router(getSetup(5s, 5s), stopwatch);
|
||||||
|
uint256 const key(1);
|
||||||
|
HashRouter::PeerShortID peer1 = 1;
|
||||||
|
HashRouter::PeerShortID peer2 = 2;
|
||||||
|
auto const timeout = 2s;
|
||||||
|
|
||||||
|
BEAST_EXPECT(router.shouldProcessForPeer(key, peer1, timeout));
|
||||||
|
BEAST_EXPECT(!router.shouldProcessForPeer(key, peer1, timeout));
|
||||||
|
++stopwatch;
|
||||||
|
BEAST_EXPECT(!router.shouldProcessForPeer(key, peer1, timeout));
|
||||||
|
BEAST_EXPECT(router.shouldProcessForPeer(key, peer2, timeout));
|
||||||
|
BEAST_EXPECT(!router.shouldProcessForPeer(key, peer2, timeout));
|
||||||
|
++stopwatch;
|
||||||
|
BEAST_EXPECT(router.shouldProcessForPeer(key, peer1, timeout));
|
||||||
|
BEAST_EXPECT(!router.shouldProcessForPeer(key, peer2, timeout));
|
||||||
|
++stopwatch;
|
||||||
|
BEAST_EXPECT(router.shouldProcessForPeer(key, peer2, timeout));
|
||||||
|
++stopwatch;
|
||||||
|
BEAST_EXPECT(router.shouldProcessForPeer(key, peer1, timeout));
|
||||||
|
BEAST_EXPECT(!router.shouldProcessForPeer(key, peer2, timeout));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
run() override
|
run() override
|
||||||
@@ -406,6 +433,7 @@ public:
|
|||||||
testProcess();
|
testProcess();
|
||||||
testSetup();
|
testSetup();
|
||||||
testFlagsOps();
|
testFlagsOps();
|
||||||
|
testProcessPeer();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -339,6 +339,11 @@ public:
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::set<std::optional<uint64_t>>
|
||||||
|
releaseRequestCookies(uint256 const& requestHash) override
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::string const&
|
[[nodiscard]] std::string const&
|
||||||
fingerprint() const override
|
fingerprint() const override
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ public:
|
|||||||
negotiateProtocolVersion("RTXP/1.2, XRPL/2.0, XRPL/2.1") == makeProtocol(2, 1));
|
negotiateProtocolVersion("RTXP/1.2, XRPL/2.0, XRPL/2.1") == makeProtocol(2, 1));
|
||||||
BEAST_EXPECT(negotiateProtocolVersion("XRPL/2.2") == makeProtocol(2, 2));
|
BEAST_EXPECT(negotiateProtocolVersion("XRPL/2.2") == makeProtocol(2, 2));
|
||||||
BEAST_EXPECT(
|
BEAST_EXPECT(
|
||||||
negotiateProtocolVersion("RTXP/1.2, XRPL/2.2, XRPL/2.3, XRPL/999.999") ==
|
negotiateProtocolVersion("RTXP/1.2, XRPL/2.2, XRPL/2.3, XRPL/2.4, XRPL/999.999") ==
|
||||||
makeProtocol(2, 2));
|
makeProtocol(2, 3));
|
||||||
BEAST_EXPECT(negotiateProtocolVersion("XRPL/999.999, WebSocket/1.0") == std::nullopt);
|
BEAST_EXPECT(negotiateProtocolVersion("XRPL/999.999, WebSocket/1.0") == std::nullopt);
|
||||||
BEAST_EXPECT(negotiateProtocolVersion("") == std::nullopt);
|
BEAST_EXPECT(negotiateProtocolVersion("") == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,6 +190,11 @@ public:
|
|||||||
removeTxQueue(uint256 const&) override
|
removeTxQueue(uint256 const&) override
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
std::set<std::optional<uint64_t>>
|
||||||
|
releaseRequestCookies(uint256 const& requestHash) override
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Manually advanced clock. */
|
/** Manually advanced clock. */
|
||||||
|
|||||||
@@ -1052,7 +1052,7 @@ void
|
|||||||
RCLConsensus::Adaptor::updateOperatingMode(std::size_t const positions) const
|
RCLConsensus::Adaptor::updateOperatingMode(std::size_t const positions) const
|
||||||
{
|
{
|
||||||
if ((positions == 0u) && app_.getOPs().isFull())
|
if ((positions == 0u) && app_.getOPs().isFull())
|
||||||
app_.getOPs().setMode(OperatingMode::CONNECTED);
|
app_.getOPs().setMode(OperatingMode::CONNECTED, "updateOperatingMode: no positions");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -172,4 +172,22 @@ private:
|
|||||||
std::unique_ptr<PeerSet> peerSet_;
|
std::unique_ptr<PeerSet> peerSet_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::string
|
||||||
|
to_string(InboundLedger::Reason reason)
|
||||||
|
{
|
||||||
|
using enum InboundLedger::Reason;
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case HISTORY:
|
||||||
|
return "HISTORY";
|
||||||
|
case GENERIC:
|
||||||
|
return "GENERIC";
|
||||||
|
case CONSENSUS:
|
||||||
|
return "CONSENSUS";
|
||||||
|
default:
|
||||||
|
UNREACHABLE("ripple::to_string(InboundLedger::Reason) : unknown value");
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace xrpl
|
} // namespace xrpl
|
||||||
|
|||||||
@@ -367,7 +367,14 @@ InboundLedger::onTimer(bool wasProgress, ScopedLockType&)
|
|||||||
|
|
||||||
if (!wasProgress)
|
if (!wasProgress)
|
||||||
{
|
{
|
||||||
checkLocal();
|
if (checkLocal())
|
||||||
|
{
|
||||||
|
// Done. Something else (probably consensus) built the ledger
|
||||||
|
// locally while waiting for data (or possibly before requesting)
|
||||||
|
XRPL_ASSERT(isDone(), "ripple::InboundLedger::onTimer : done");
|
||||||
|
JLOG(journal_.info()) << "Finished while waiting " << hash_;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
byHash_ = true;
|
byHash_ = true;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <xrpld/overlay/PeerSet.h>
|
#include <xrpld/overlay/PeerSet.h>
|
||||||
|
|
||||||
#include <xrpl/basics/Blob.h>
|
#include <xrpl/basics/Blob.h>
|
||||||
|
#include <xrpl/basics/CanProcess.h>
|
||||||
#include <xrpl/basics/DecayingSample.h>
|
#include <xrpl/basics/DecayingSample.h>
|
||||||
#include <xrpl/basics/Log.h>
|
#include <xrpl/basics/Log.h>
|
||||||
#include <xrpl/basics/Slice.h>
|
#include <xrpl/basics/Slice.h>
|
||||||
@@ -78,10 +79,78 @@ public:
|
|||||||
XRPL_ASSERT(
|
XRPL_ASSERT(
|
||||||
hash.isNonZero(), "xrpl::InboundLedgersImp::acquire::doAcquire : nonzero hash");
|
hash.isNonZero(), "xrpl::InboundLedgersImp::acquire::doAcquire : nonzero hash");
|
||||||
|
|
||||||
// probably not the right rule
|
bool const needNetworkLedger = app_.getOPs().isNeedNetworkLedger();
|
||||||
if (app_.getOPs().isNeedNetworkLedger() && (reason != InboundLedger::Reason::GENERIC) &&
|
bool const shouldAcquire = [&]() {
|
||||||
(reason != InboundLedger::Reason::CONSENSUS))
|
if (!needNetworkLedger)
|
||||||
|
return true;
|
||||||
|
if (reason == InboundLedger::Reason::GENERIC)
|
||||||
|
return true;
|
||||||
|
if (reason == InboundLedger::Reason::CONSENSUS)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "InboundLedger::acquire: "
|
||||||
|
<< "Request: " << to_string(hash) << ", " << seq
|
||||||
|
<< " NeedNetworkLedger: " << (needNetworkLedger ? "yes" : "no")
|
||||||
|
<< " Reason: " << to_string(reason)
|
||||||
|
<< " Should acquire: " << (shouldAcquire ? "true." : "false.");
|
||||||
|
|
||||||
|
/* Acquiring ledgers is somewhat expensive. It requires lots of
|
||||||
|
* computation and network communication. Avoid it when it's not
|
||||||
|
* appropriate. Every validation from a peer for a ledger that
|
||||||
|
* we do not have locally results in a call to this function: even
|
||||||
|
* if we are moments away from validating the same ledger.
|
||||||
|
*/
|
||||||
|
bool const shouldBroadcast = [&]() {
|
||||||
|
// If the node is not in "full" state, it needs to sync to
|
||||||
|
// the network, and doesn't have the necessary tx's and
|
||||||
|
// ledger entries to build the ledger.
|
||||||
|
bool const isFull = app_.getOPs().isFull();
|
||||||
|
// If everything else is ok, don't try to acquire the ledger
|
||||||
|
// if the requested seq is in the near future relative to
|
||||||
|
// the validated ledger. If the requested ledger is between
|
||||||
|
// 1 and 19 inclusive ledgers ahead of the valid ledger this
|
||||||
|
// node has not built it yet, but it's possible/likely it
|
||||||
|
// has the tx's necessary to build it and get caught up.
|
||||||
|
// Plus it might not become validated. On the other hand, if
|
||||||
|
// it's more than 20 in the future, this node should request
|
||||||
|
// it so that it can jump ahead and get caught up.
|
||||||
|
LedgerIndex const validSeq = app_.getLedgerMaster().getValidLedgerIndex();
|
||||||
|
constexpr std::size_t lagLeeway = 20;
|
||||||
|
bool const nearFuture = (seq > validSeq) && (seq < validSeq + lagLeeway);
|
||||||
|
// If everything else is ok, don't try to acquire the ledger
|
||||||
|
// if the request is related to consensus. (Note that
|
||||||
|
// consensus calls usually pass a seq of 0, so nearFuture
|
||||||
|
// will be false other than on a brand new network.)
|
||||||
|
bool const consensus = reason == InboundLedger::Reason::CONSENSUS;
|
||||||
|
ss << " Evaluating whether to broadcast requests to peers"
|
||||||
|
<< ". full: " << (isFull ? "true" : "false") << ". ledger sequence " << seq
|
||||||
|
<< ". Valid sequence: " << validSeq << ". Lag leeway: " << lagLeeway
|
||||||
|
<< ". request for near future ledger: " << (nearFuture ? "true" : "false")
|
||||||
|
<< ". Consensus: " << (consensus ? "true" : "false");
|
||||||
|
|
||||||
|
// If the node is not synced, send requests.
|
||||||
|
if (!isFull)
|
||||||
|
return true;
|
||||||
|
// If the ledger is in the near future, do NOT send requests.
|
||||||
|
// This node is probably about to build it.
|
||||||
|
if (nearFuture)
|
||||||
|
return false;
|
||||||
|
// If the request is because of consensus, do NOT send requests.
|
||||||
|
// This node is probably about to build it.
|
||||||
|
if (consensus)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
ss << ". Would broadcast to peers? " << (shouldBroadcast ? "true." : "false.");
|
||||||
|
|
||||||
|
if (!shouldAcquire)
|
||||||
|
{
|
||||||
|
JLOG(j_.debug()) << "Abort(rule): " << ss.str();
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool isNew = true;
|
bool isNew = true;
|
||||||
std::shared_ptr<InboundLedger> inbound;
|
std::shared_ptr<InboundLedger> inbound;
|
||||||
@@ -89,6 +158,7 @@ public:
|
|||||||
ScopedLockType sl(lock_);
|
ScopedLockType sl(lock_);
|
||||||
if (stopping_)
|
if (stopping_)
|
||||||
{
|
{
|
||||||
|
JLOG(j_.debug()) << "Abort(stopping): " << ss.str();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,47 +177,51 @@ public:
|
|||||||
++counter_;
|
++counter_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ss << " IsNew: " << (isNew ? "true" : "false");
|
||||||
|
|
||||||
if (inbound->isFailed())
|
if (inbound->isFailed())
|
||||||
|
{
|
||||||
|
JLOG(j_.debug()) << "Abort(failed): " << ss.str();
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (!isNew)
|
if (!isNew)
|
||||||
inbound->update(seq);
|
inbound->update(seq);
|
||||||
|
|
||||||
if (!inbound->isComplete())
|
if (!inbound->isComplete())
|
||||||
|
{
|
||||||
|
JLOG(j_.debug()) << "InProgress: " << ss.str();
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
JLOG(j_.debug()) << "Complete: " << ss.str();
|
||||||
return inbound->getLedger();
|
return inbound->getLedger();
|
||||||
};
|
};
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
std::shared_ptr<Ledger const> ledger =
|
return perf::measureDurationAndLog(doAcquire, "InboundLedgersImp::acquire", 500ms, j_);
|
||||||
perf::measureDurationAndLog(doAcquire, "InboundLedgersImp::acquire", 500ms, j_);
|
|
||||||
|
|
||||||
return ledger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
acquireAsync(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason reason) override
|
acquireAsync(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason reason) override
|
||||||
{
|
{
|
||||||
std::unique_lock lock(acquiresMutex_);
|
if (CanProcess const check{acquiresMutex_, pendingAcquires_, hash})
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (pendingAcquires_.contains(hash))
|
try
|
||||||
return;
|
{
|
||||||
pendingAcquires_.insert(hash);
|
acquire(hash, seq, reason);
|
||||||
ScopeUnlock const unlock(lock);
|
}
|
||||||
acquire(hash, seq, reason);
|
catch (std::exception const& e)
|
||||||
|
{
|
||||||
|
JLOG(j_.warn()) << "Exception thrown for acquiring new inbound ledger " << hash
|
||||||
|
<< ": " << e.what();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
JLOG(j_.warn()) << "Unknown exception thrown for acquiring new "
|
||||||
|
"inbound ledger "
|
||||||
|
<< hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception const& e)
|
|
||||||
{
|
|
||||||
JLOG(j_.warn()) << "Exception thrown for acquiring new inbound ledger " << hash << ": "
|
|
||||||
<< e.what();
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
JLOG(j_.warn()) << "Unknown exception thrown for acquiring new inbound ledger " << hash;
|
|
||||||
}
|
|
||||||
pendingAcquires_.erase(hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<InboundLedger>
|
std::shared_ptr<InboundLedger>
|
||||||
|
|||||||
@@ -965,8 +965,9 @@ LedgerMaster::checkAccept(std::shared_ptr<Ledger const> const& ledger)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JLOG(journal_.info()) << "Advancing accepted ledger to " << ledger->header().seq
|
JLOG(journal_.info()) << "Advancing accepted ledger to " << ledger->header().seq << " ("
|
||||||
<< " with >= " << minVal << " validations";
|
<< toShortString(ledger->header().hash) << ") with >= " << minVal
|
||||||
|
<< " validations";
|
||||||
|
|
||||||
ledger->setValidated();
|
ledger->setValidated();
|
||||||
ledger->setFull();
|
ledger->setFull();
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ TimeoutCounter::TimeoutCounter(
|
|||||||
QueueJobParameter&& jobParameter,
|
QueueJobParameter&& jobParameter,
|
||||||
beast::Journal journal)
|
beast::Journal journal)
|
||||||
: app_(app)
|
: app_(app)
|
||||||
, journal_(journal)
|
, sink_(journal, toShortString(hash) + " ")
|
||||||
|
, journal_(sink_)
|
||||||
, hash_(hash)
|
, hash_(hash)
|
||||||
, timerInterval_(interval)
|
, timerInterval_(interval)
|
||||||
, queueJobParameter_(std::move(jobParameter))
|
, queueJobParameter_(std::move(jobParameter))
|
||||||
@@ -41,6 +42,7 @@ TimeoutCounter::setTimer(ScopedLockType& sl)
|
|||||||
{
|
{
|
||||||
if (isDone())
|
if (isDone())
|
||||||
return;
|
return;
|
||||||
|
JLOG(journal_.debug()) << "Setting timer for " << timerInterval_.count() << "ms";
|
||||||
timer_.expires_after(timerInterval_);
|
timer_.expires_after(timerInterval_);
|
||||||
timer_.async_wait([wptr = pmDowncast()](boost::system::error_code const& ec) {
|
timer_.async_wait([wptr = pmDowncast()](boost::system::error_code const& ec) {
|
||||||
if (ec == boost::asio::error::operation_aborted)
|
if (ec == boost::asio::error::operation_aborted)
|
||||||
@@ -48,6 +50,10 @@ TimeoutCounter::setTimer(ScopedLockType& sl)
|
|||||||
|
|
||||||
if (auto ptr = wptr.lock())
|
if (auto ptr = wptr.lock())
|
||||||
{
|
{
|
||||||
|
JLOG(ptr->journal_.debug())
|
||||||
|
<< "timer: ec: " << ec
|
||||||
|
<< " (operation_aborted: " << boost::asio::error::operation_aborted << " - "
|
||||||
|
<< (ec == boost::asio::error::operation_aborted ? "aborted" : "other") << ")";
|
||||||
ScopedLockType sl(ptr->mtx_);
|
ScopedLockType sl(ptr->mtx_);
|
||||||
ptr->queueJob(sl);
|
ptr->queueJob(sl);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <xrpld/app/main/Application.h>
|
#include <xrpld/app/main/Application.h>
|
||||||
|
|
||||||
#include <xrpl/beast/utility/Journal.h>
|
#include <xrpl/beast/utility/Journal.h>
|
||||||
|
#include <xrpl/beast/utility/WrappedSink.h>
|
||||||
#include <xrpl/core/Job.h>
|
#include <xrpl/core/Job.h>
|
||||||
|
|
||||||
#include <boost/asio/basic_waitable_timer.hpp>
|
#include <boost/asio/basic_waitable_timer.hpp>
|
||||||
@@ -103,6 +104,7 @@ protected:
|
|||||||
// Used in this class for access to boost::asio::io_context and
|
// Used in this class for access to boost::asio::io_context and
|
||||||
// xrpl::Overlay. Used in subtypes for the kitchen sink.
|
// xrpl::Overlay. Used in subtypes for the kitchen sink.
|
||||||
Application& app_;
|
Application& app_;
|
||||||
|
beast::WrappedSink sink_;
|
||||||
beast::Journal journal_;
|
beast::Journal journal_;
|
||||||
mutable std::recursive_mutex mtx_;
|
mutable std::recursive_mutex mtx_;
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
#include <xrpld/rpc/MPTokenIssuanceID.h>
|
||||||
#include <xrpld/rpc/ServerHandler.h>
|
#include <xrpld/rpc/ServerHandler.h>
|
||||||
|
|
||||||
|
#include <xrpl/basics/CanProcess.h>
|
||||||
#include <xrpl/basics/Log.h>
|
#include <xrpl/basics/Log.h>
|
||||||
#include <xrpl/basics/ToString.h>
|
#include <xrpl/basics/ToString.h>
|
||||||
#include <xrpl/basics/UnorderedContainers.h>
|
#include <xrpl/basics/UnorderedContainers.h>
|
||||||
@@ -485,7 +486,7 @@ public:
|
|||||||
isFull() override;
|
isFull() override;
|
||||||
|
|
||||||
void
|
void
|
||||||
setMode(OperatingMode om) override;
|
setMode(OperatingMode om, char const* reason) override;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
isBlocked() override;
|
isBlocked() override;
|
||||||
@@ -924,7 +925,7 @@ NetworkOPsImp::strOperatingMode(bool const admin /* = false */) const
|
|||||||
inline void
|
inline void
|
||||||
NetworkOPsImp::setStandAlone()
|
NetworkOPsImp::setStandAlone()
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::FULL);
|
setMode(OperatingMode::FULL, "setStandAlone");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -1067,7 +1068,7 @@ NetworkOPsImp::processHeartbeatTimer()
|
|||||||
{
|
{
|
||||||
if (mode_ != OperatingMode::DISCONNECTED)
|
if (mode_ != OperatingMode::DISCONNECTED)
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::DISCONNECTED);
|
setMode(OperatingMode::DISCONNECTED, "Heartbeat: insufficient peers");
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Node count (" << numPeers << ") has fallen "
|
ss << "Node count (" << numPeers << ") has fallen "
|
||||||
<< "below required minimum (" << minPeerCount_ << ").";
|
<< "below required minimum (" << minPeerCount_ << ").";
|
||||||
@@ -1091,7 +1092,7 @@ NetworkOPsImp::processHeartbeatTimer()
|
|||||||
|
|
||||||
if (mode_ == OperatingMode::DISCONNECTED)
|
if (mode_ == OperatingMode::DISCONNECTED)
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "Heartbeat: sufficient peers");
|
||||||
JLOG(journal_.info()) << "Node count (" << numPeers << ") is sufficient.";
|
JLOG(journal_.info()) << "Node count (" << numPeers << ") is sufficient.";
|
||||||
CLOG(clog.ss()) << "setting mode to CONNECTED based on " << numPeers << " peers. ";
|
CLOG(clog.ss()) << "setting mode to CONNECTED based on " << numPeers << " peers. ";
|
||||||
}
|
}
|
||||||
@@ -1102,11 +1103,11 @@ NetworkOPsImp::processHeartbeatTimer()
|
|||||||
CLOG(clog.ss()) << "mode: " << strOperatingMode(origMode, true);
|
CLOG(clog.ss()) << "mode: " << strOperatingMode(origMode, true);
|
||||||
if (mode_ == OperatingMode::SYNCING)
|
if (mode_ == OperatingMode::SYNCING)
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::SYNCING);
|
setMode(OperatingMode::SYNCING, "Heartbeat: check syncing");
|
||||||
}
|
}
|
||||||
else if (mode_ == OperatingMode::CONNECTED)
|
else if (mode_ == OperatingMode::CONNECTED)
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "Heartbeat: check connected");
|
||||||
}
|
}
|
||||||
auto newMode = mode_.load();
|
auto newMode = mode_.load();
|
||||||
if (origMode != newMode)
|
if (origMode != newMode)
|
||||||
@@ -1811,7 +1812,7 @@ void
|
|||||||
NetworkOPsImp::setAmendmentBlocked()
|
NetworkOPsImp::setAmendmentBlocked()
|
||||||
{
|
{
|
||||||
amendmentBlocked_ = true;
|
amendmentBlocked_ = true;
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "setAmendmentBlocked");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
@@ -1842,7 +1843,7 @@ void
|
|||||||
NetworkOPsImp::setUNLBlocked()
|
NetworkOPsImp::setUNLBlocked()
|
||||||
{
|
{
|
||||||
unlBlocked_ = true;
|
unlBlocked_ = true;
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "setUNLBlocked");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@@ -1942,7 +1943,7 @@ NetworkOPsImp::checkLastClosedLedger(Overlay::PeerSequence const& peerList, uint
|
|||||||
|
|
||||||
if ((mode_ == OperatingMode::TRACKING) || (mode_ == OperatingMode::FULL))
|
if ((mode_ == OperatingMode::TRACKING) || (mode_ == OperatingMode::FULL))
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "check LCL: not on consensus ledger");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consensus)
|
if (consensus)
|
||||||
@@ -2030,8 +2031,8 @@ NetworkOPsImp::beginConsensus(
|
|||||||
// this shouldn't happen unless we jump ledgers
|
// this shouldn't happen unless we jump ledgers
|
||||||
if (mode_ == OperatingMode::FULL)
|
if (mode_ == OperatingMode::FULL)
|
||||||
{
|
{
|
||||||
JLOG(journal_.warn()) << "Don't have LCL, going to tracking";
|
JLOG(journal_.warn()) << "beginConsensus Don't have LCL, going to tracking";
|
||||||
setMode(OperatingMode::TRACKING);
|
setMode(OperatingMode::TRACKING, "beginConsensus: No LCL");
|
||||||
CLOG(clog) << "beginConsensus Don't have LCL, going to tracking. ";
|
CLOG(clog) << "beginConsensus Don't have LCL, going to tracking. ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2159,7 +2160,7 @@ NetworkOPsImp::endConsensus(std::unique_ptr<std::stringstream> const& clog)
|
|||||||
// validations we have for LCL. If the ledger is good enough, go to
|
// validations we have for LCL. If the ledger is good enough, go to
|
||||||
// TRACKING - TODO
|
// TRACKING - TODO
|
||||||
if (!needNetworkLedger_)
|
if (!needNetworkLedger_)
|
||||||
setMode(OperatingMode::TRACKING);
|
setMode(OperatingMode::TRACKING, "endConsensus: check tracking");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((mode_ == OperatingMode::CONNECTED) || (mode_ == OperatingMode::TRACKING)) &&
|
if (((mode_ == OperatingMode::CONNECTED) || (mode_ == OperatingMode::TRACKING)) &&
|
||||||
@@ -2172,7 +2173,7 @@ NetworkOPsImp::endConsensus(std::unique_ptr<std::stringstream> const& clog)
|
|||||||
if (registry_.get().getTimeKeeper().now() <
|
if (registry_.get().getTimeKeeper().now() <
|
||||||
(current->header().parentCloseTime + 2 * current->header().closeTimeResolution))
|
(current->header().parentCloseTime + 2 * current->header().closeTimeResolution))
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::FULL);
|
setMode(OperatingMode::FULL, "endConsensus: check full");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2184,7 +2185,7 @@ NetworkOPsImp::consensusViewChange()
|
|||||||
{
|
{
|
||||||
if ((mode_ == OperatingMode::FULL) || (mode_ == OperatingMode::TRACKING))
|
if ((mode_ == OperatingMode::FULL) || (mode_ == OperatingMode::TRACKING))
|
||||||
{
|
{
|
||||||
setMode(OperatingMode::CONNECTED);
|
setMode(OperatingMode::CONNECTED, "consensusViewChange");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2488,7 +2489,7 @@ NetworkOPsImp::pubPeerStatus(std::function<json::Value(void)> const& func)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkOPsImp::setMode(OperatingMode om)
|
NetworkOPsImp::setMode(OperatingMode om, char const* reason)
|
||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
if (om == OperatingMode::CONNECTED)
|
if (om == OperatingMode::CONNECTED)
|
||||||
@@ -2508,11 +2509,12 @@ NetworkOPsImp::setMode(OperatingMode om)
|
|||||||
if (mode_ == om)
|
if (mode_ == om)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto const sink = om < mode_ ? journal_.warn() : journal_.info();
|
||||||
mode_ = om;
|
mode_ = om;
|
||||||
|
|
||||||
accounting_.mode(om);
|
accounting_.mode(om);
|
||||||
|
|
||||||
JLOG(journal_.info()) << "STATE->" << strOperatingMode();
|
JLOG(sink) << "STATE->" << strOperatingMode() << " - " << reason;
|
||||||
pubServer();
|
pubServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2521,36 +2523,24 @@ NetworkOPsImp::recvValidation(std::shared_ptr<STValidation> const& val, std::str
|
|||||||
{
|
{
|
||||||
JLOG(journal_.trace()) << "recvValidation " << val->getLedgerHash() << " from " << source;
|
JLOG(journal_.trace()) << "recvValidation " << val->getLedgerHash() << " from " << source;
|
||||||
|
|
||||||
std::unique_lock lock(validationsMutex_);
|
|
||||||
BypassAccept bypassAccept = BypassAccept::No;
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (pendingValidations_.contains(val->getLedgerHash()))
|
CanProcess const check(validationsMutex_, pendingValidations_, val->getLedgerHash());
|
||||||
|
try
|
||||||
{
|
{
|
||||||
bypassAccept = BypassAccept::Yes;
|
BypassAccept bypassAccept = check ? BypassAccept::No : BypassAccept::Yes;
|
||||||
|
handleNewValidation(registry_.get().getApp(), val, source, bypassAccept, journal_);
|
||||||
}
|
}
|
||||||
else
|
catch (std::exception const& e)
|
||||||
{
|
{
|
||||||
pendingValidations_.insert(val->getLedgerHash());
|
JLOG(journal_.warn()) << "Exception thrown for handling new validation "
|
||||||
|
<< val->getLedgerHash() << ": " << e.what();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
JLOG(journal_.warn()) << "Unknown exception thrown for handling new validation "
|
||||||
|
<< val->getLedgerHash();
|
||||||
}
|
}
|
||||||
ScopeUnlock const unlock(lock);
|
|
||||||
handleNewValidation(registry_.get().getApp(), val, source, bypassAccept, journal_);
|
|
||||||
}
|
}
|
||||||
catch (std::exception const& e)
|
|
||||||
{
|
|
||||||
JLOG(journal_.warn()) << "Exception thrown for handling new validation "
|
|
||||||
<< val->getLedgerHash() << ": " << e.what();
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
JLOG(journal_.warn()) << "Unknown exception thrown for handling new validation "
|
|
||||||
<< val->getLedgerHash();
|
|
||||||
}
|
|
||||||
if (bypassAccept == BypassAccept::No)
|
|
||||||
{
|
|
||||||
pendingValidations_.erase(val->getLedgerHash());
|
|
||||||
}
|
|
||||||
lock.unlock();
|
|
||||||
|
|
||||||
pubValidation(val);
|
pubValidation(val);
|
||||||
|
|
||||||
|
|||||||
@@ -200,11 +200,11 @@ public:
|
|||||||
iter->second.upVotes |
|
iter->second.upVotes |
|
||||||
boost::adaptors::transformed(to_string<256, void>),
|
boost::adaptors::transformed(to_string<256, void>),
|
||||||
", ");
|
", ");
|
||||||
// TODO: Maybe transform using to_short_string once #5126 is
|
// TODO: Maybe transform using toShortString once #5126 is
|
||||||
// merged
|
// merged
|
||||||
//
|
//
|
||||||
// iter->second.upVotes |
|
// iter->second.upVotes |
|
||||||
// boost::adaptors::transformed(to_short_string<256, void>)
|
// boost::adaptors::transformed(toShortString<256, void>)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ enum class ProtocolFeature {
|
|||||||
ValidatorListPropagation,
|
ValidatorListPropagation,
|
||||||
ValidatorList2Propagation,
|
ValidatorList2Propagation,
|
||||||
LedgerReplay,
|
LedgerReplay,
|
||||||
|
LedgerDataCookies
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Represents a peer connection in the overlay. */
|
/** Represents a peer connection in the overlay. */
|
||||||
@@ -116,6 +117,13 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] virtual bool
|
[[nodiscard]] virtual bool
|
||||||
txReduceRelayEnabled() const = 0;
|
txReduceRelayEnabled() const = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Messages
|
||||||
|
//
|
||||||
|
|
||||||
|
virtual std::set<std::optional<uint64_t>>
|
||||||
|
releaseRequestCookies(uint256 const& requestHash) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace xrpl
|
} // namespace xrpl
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ constexpr std::chrono::milliseconds kPeerHighLatency{300};
|
|||||||
/** How often we PING the peer to check for latency and sendq probe */
|
/** How often we PING the peer to check for latency and sendq probe */
|
||||||
constexpr std::chrono::seconds kPeerTimerInterval{60};
|
constexpr std::chrono::seconds kPeerTimerInterval{60};
|
||||||
|
|
||||||
|
/** How often we process duplicate incoming TMGetLedger messages */
|
||||||
|
std::chrono::seconds constexpr kGetLedgerInterval{15};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// TODO: Remove this exclusion once unit tests are added after the hotfix
|
// TODO: Remove this exclusion once unit tests are added after the hotfix
|
||||||
@@ -551,6 +554,8 @@ PeerImp::supportsFeature(ProtocolFeature f) const
|
|||||||
return protocol_ >= makeProtocol(2, 2);
|
return protocol_ >= makeProtocol(2, 2);
|
||||||
case ProtocolFeature::LedgerReplay:
|
case ProtocolFeature::LedgerReplay:
|
||||||
return ledgerReplayEnabled_;
|
return ledgerReplayEnabled_;
|
||||||
|
case ProtocolFeature::LedgerDataCookies:
|
||||||
|
return protocol_ >= makeProtocol(2, 3);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1430,8 +1435,9 @@ PeerImp::handleTransaction(
|
|||||||
void
|
void
|
||||||
PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
||||||
{
|
{
|
||||||
auto badData = [&](std::string const& msg) {
|
auto badData = [&](std::string const& msg, bool chargefee = true) {
|
||||||
fee_.update(Resource::kFeeInvalidData, "get_ledger " + msg);
|
if (chargefee)
|
||||||
|
fee_.update(Resource::kFeeInvalidData, "get_ledger " + msg);
|
||||||
JLOG(pJournal_.warn()) << "TMGetLedger: " << msg;
|
JLOG(pJournal_.warn()) << "TMGetLedger: " << msg;
|
||||||
};
|
};
|
||||||
auto const itype{m->itype()};
|
auto const itype{m->itype()};
|
||||||
@@ -1529,11 +1535,68 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop duplicate requests from the same peer for at least
|
||||||
|
// `kGetLedgerInterval` seconds.
|
||||||
|
// Append a little junk to prevent the hash of an incoming messsage
|
||||||
|
// from matching the hash of the same outgoing message.
|
||||||
|
// `shouldProcessForPeer` does not distingish between incoming and
|
||||||
|
// outgoing, and some of the message relay logic checks the hash to see
|
||||||
|
// if the message has been relayed already. If the hashes are the same,
|
||||||
|
// a duplicate will be detected when sending the message is attempted,
|
||||||
|
// so it will fail.
|
||||||
|
auto const messageHash = sha512Half(*m, nullptr);
|
||||||
|
// Request cookies are not included in the hash. Track them here.
|
||||||
|
auto const requestCookie = [&m]() -> std::optional<uint64_t> {
|
||||||
|
if (m->has_requestcookie())
|
||||||
|
return m->requestcookie();
|
||||||
|
return std::nullopt;
|
||||||
|
}();
|
||||||
|
auto const [inserted, pending] = [&] {
|
||||||
|
std::lock_guard lock{cookieLock_};
|
||||||
|
auto& cookies = messageRequestCookies_[messageHash];
|
||||||
|
bool const pending = !cookies.empty();
|
||||||
|
return std::pair{cookies.emplace(requestCookie).second, pending};
|
||||||
|
}();
|
||||||
|
// Check if the request has been seen from this peer.
|
||||||
|
if (!app_.getHashRouter().shouldProcessForPeer(messageHash, id_, kGetLedgerInterval))
|
||||||
|
{
|
||||||
|
// This request has already been seen from this peer.
|
||||||
|
// Has it been seen with this request cookie (or lack thereof)?
|
||||||
|
|
||||||
|
if (inserted)
|
||||||
|
{
|
||||||
|
// This is a duplicate request, but with a new cookie. When a
|
||||||
|
// response is ready, one will be sent for each request cookie.
|
||||||
|
JLOG(pJournal_.debug())
|
||||||
|
<< "TMGetLedger: duplicate request with new request cookie: "
|
||||||
|
<< requestCookie.value_or(0) << ". Job pending: " << (pending ? "yes" : "no")
|
||||||
|
<< ": " << messageHash;
|
||||||
|
if (pending)
|
||||||
|
{
|
||||||
|
// Don't bother queueing up a new job if other requests are
|
||||||
|
// already pending. This should limit entries in the job queue
|
||||||
|
// to one per peer per unique request.
|
||||||
|
JLOG(pJournal_.debug()) << "TMGetLedger: Suppressing recvGetLedger job, since one "
|
||||||
|
"is pending: "
|
||||||
|
<< messageHash;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Don't punish nodes that don't know any better
|
||||||
|
return badData(
|
||||||
|
"duplicate request: " + to_string(messageHash),
|
||||||
|
supportsFeature(ProtocolFeature::LedgerDataCookies));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Queue a job to process the request
|
// Queue a job to process the request
|
||||||
|
JLOG(pJournal_.debug()) << "TMGetLedger: Adding recvGetLedger job: " << messageHash;
|
||||||
std::weak_ptr<PeerImp> const weak = shared_from_this();
|
std::weak_ptr<PeerImp> const weak = shared_from_this();
|
||||||
app_.getJobQueue().addJob(JtLedgerReq, "RcvGetLedger", [weak, m]() {
|
app_.getJobQueue().addJob(JtLedgerReq, "RcvGetLedger", [weak, m, messageHash]() {
|
||||||
if (auto peer = weak.lock())
|
if (auto peer = weak.lock())
|
||||||
peer->processLedgerRequest(m);
|
peer->processLedgerRequest(m, messageHash);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1640,8 +1703,9 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMReplayDeltaResponse> const& m)
|
|||||||
void
|
void
|
||||||
PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
|
PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
|
||||||
{
|
{
|
||||||
auto badData = [&](std::string const& msg) {
|
auto badData = [&](std::string const& msg, bool charge = true) {
|
||||||
fee_.update(Resource::kFeeInvalidData, msg);
|
if (charge)
|
||||||
|
fee_.update(Resource::kFeeInvalidData, msg);
|
||||||
JLOG(pJournal_.warn()) << "TMLedgerData: " << msg;
|
JLOG(pJournal_.warn()) << "TMLedgerData: " << msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1698,19 +1762,93 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a request cookie, attempt to relay the message
|
auto const messageHash = sha512Half(*m);
|
||||||
if (m->has_requestcookie())
|
if (!app_.getHashRouter().addSuppressionPeer(messageHash, id_))
|
||||||
{
|
{
|
||||||
if (auto peer = overlay_.findPeerByShortID(m->requestcookie()))
|
// Don't punish nodes that don't know any better
|
||||||
|
return badData(
|
||||||
|
"Duplicate message: " + to_string(messageHash),
|
||||||
|
supportsFeature(ProtocolFeature::LedgerDataCookies));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool const routed =
|
||||||
|
m->has_directresponse() || m->responsecookies_size() || m->has_requestcookie();
|
||||||
|
|
||||||
|
{
|
||||||
|
// Check if this message needs to be forwarded to one or more peers.
|
||||||
|
// Maximum of one of the relevant fields should be populated.
|
||||||
|
XRPL_ASSERT(
|
||||||
|
!m->has_requestcookie() || !m->responsecookies_size(),
|
||||||
|
"ripple::PeerImp::onMessage(TMLedgerData) : valid cookie fields");
|
||||||
|
|
||||||
|
// Make a copy of the response cookies, then wipe the list so it can be
|
||||||
|
// forwarded cleanly
|
||||||
|
auto const responseCookies = m->responsecookies();
|
||||||
|
m->clear_responsecookies();
|
||||||
|
// Flag indicating if this response should be processed locally,
|
||||||
|
// possibly in addition to being forwarded.
|
||||||
|
bool const directResponse = m->has_directresponse() && m->directresponse();
|
||||||
|
m->clear_directresponse();
|
||||||
|
|
||||||
|
auto const relay = [this, m, &messageHash](auto const cookie) {
|
||||||
|
if (auto peer = overlay_.findPeerByShortID(cookie))
|
||||||
|
{
|
||||||
|
XRPL_ASSERT(
|
||||||
|
!m->has_requestcookie() && !m->responsecookies_size(),
|
||||||
|
"ripple::PeerImp::onMessage(TMLedgerData) relay : no "
|
||||||
|
"cookies");
|
||||||
|
if (peer->supportsFeature(ProtocolFeature::LedgerDataCookies))
|
||||||
|
// Setting this flag is not _strictly_ necessary for peers
|
||||||
|
// that support it if there are no cookies included in the
|
||||||
|
// message, but it is more accurate.
|
||||||
|
m->set_directresponse(true);
|
||||||
|
else
|
||||||
|
m->clear_directresponse();
|
||||||
|
peer->send(std::make_shared<Message>(*m, protocol::mtLEDGER_DATA));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
JLOG(pJournal_.info()) << "Unable to route TX/ledger data reply to peer [" << cookie
|
||||||
|
<< "]: " << messageHash;
|
||||||
|
};
|
||||||
|
// If there is a request cookie, attempt to relay the message
|
||||||
|
if (m->has_requestcookie())
|
||||||
{
|
{
|
||||||
|
XRPL_ASSERT(
|
||||||
|
responseCookies.empty(),
|
||||||
|
"ripple::PeerImp::onMessage(TMLedgerData) : no response "
|
||||||
|
"cookies");
|
||||||
m->clear_requestcookie();
|
m->clear_requestcookie();
|
||||||
peer->send(std::make_shared<Message>(*m, protocol::mtLEDGER_DATA));
|
relay(m->requestcookie());
|
||||||
|
if (!directResponse && responseCookies.empty())
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
// If there's a list of request cookies, attempt to relay the message to
|
||||||
|
// all of them.
|
||||||
|
if (responseCookies.size())
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.info()) << "Unable to route TX/ledger data reply";
|
for (auto const cookie : responseCookies)
|
||||||
|
relay(cookie);
|
||||||
|
if (!directResponse)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now that any forwarding is done check the base message (data only, no
|
||||||
|
// routing info for duplicates)
|
||||||
|
if (routed)
|
||||||
|
{
|
||||||
|
m->clear_directresponse();
|
||||||
|
XRPL_ASSERT(
|
||||||
|
!m->has_requestcookie() && !m->responsecookies_size(),
|
||||||
|
"ripple::PeerImp::onMessage(TMLedgerData) : no cookies");
|
||||||
|
auto const baseMessageHash = sha512Half(*m);
|
||||||
|
if (!app_.getHashRouter().addSuppressionPeer(baseMessageHash, id_))
|
||||||
|
{
|
||||||
|
// Don't punish nodes that don't know any better
|
||||||
|
return badData(
|
||||||
|
"Duplicate message: " + to_string(baseMessageHash),
|
||||||
|
supportsFeature(ProtocolFeature::LedgerDataCookies));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 const ledgerHash = uint256::fromRaw(m->ledgerhash());
|
uint256 const ledgerHash = uint256::fromRaw(m->ledgerhash());
|
||||||
@@ -3040,16 +3178,21 @@ PeerImp::checkValidation(
|
|||||||
// the TX tree with the specified root hash.
|
// the TX tree with the specified root hash.
|
||||||
//
|
//
|
||||||
static std::shared_ptr<PeerImp>
|
static std::shared_ptr<PeerImp>
|
||||||
getPeerWithTree(OverlayImpl& ov, uint256 const& rootHash, PeerImp const* skip)
|
getPeerWithTree(
|
||||||
|
OverlayImpl& ov,
|
||||||
|
uint256 const& rootHash,
|
||||||
|
PeerImp const* skip,
|
||||||
|
std::function<bool(Peer::id_t)> shouldProcessCallback)
|
||||||
{
|
{
|
||||||
std::shared_ptr<PeerImp> ret;
|
std::shared_ptr<PeerImp> ret;
|
||||||
int retScore = 0;
|
int retScore = 0;
|
||||||
|
|
||||||
|
XRPL_ASSERT(shouldProcessCallback, "ripple::getPeerWithTree : callback provided");
|
||||||
ov.forEach([&](std::shared_ptr<PeerImp>&& p) {
|
ov.forEach([&](std::shared_ptr<PeerImp>&& p) {
|
||||||
if (p->hasTxSet(rootHash) && p.get() != skip)
|
if (p->hasTxSet(rootHash) && p.get() != skip)
|
||||||
{
|
{
|
||||||
auto score = p->getScore(true);
|
auto score = p->getScore(true);
|
||||||
if (!ret || (score > retScore))
|
if (!ret || (score > retScore && shouldProcessCallback(p->id())))
|
||||||
{
|
{
|
||||||
ret = std::move(p);
|
ret = std::move(p);
|
||||||
retScore = score;
|
retScore = score;
|
||||||
@@ -3068,16 +3211,18 @@ getPeerWithLedger(
|
|||||||
OverlayImpl& ov,
|
OverlayImpl& ov,
|
||||||
uint256 const& ledgerHash,
|
uint256 const& ledgerHash,
|
||||||
LedgerIndex ledger,
|
LedgerIndex ledger,
|
||||||
PeerImp const* skip)
|
PeerImp const* skip,
|
||||||
|
std::function<bool(Peer::id_t)> shouldProcessCallback)
|
||||||
{
|
{
|
||||||
std::shared_ptr<PeerImp> ret;
|
std::shared_ptr<PeerImp> ret;
|
||||||
int retScore = 0;
|
int retScore = 0;
|
||||||
|
|
||||||
|
XRPL_ASSERT(shouldProcessCallback, "ripple::getPeerWithLedger : callback provided");
|
||||||
ov.forEach([&](std::shared_ptr<PeerImp>&& p) {
|
ov.forEach([&](std::shared_ptr<PeerImp>&& p) {
|
||||||
if (p->hasLedger(ledgerHash, ledger) && p.get() != skip)
|
if (p->hasLedger(ledgerHash, ledger) && p.get() != skip)
|
||||||
{
|
{
|
||||||
auto score = p->getScore(true);
|
auto score = p->getScore(true);
|
||||||
if (!ret || (score > retScore))
|
if (!ret || (score > retScore && shouldProcessCallback(p->id())))
|
||||||
{
|
{
|
||||||
ret = std::move(p);
|
ret = std::move(p);
|
||||||
retScore = score;
|
retScore = score;
|
||||||
@@ -3091,7 +3236,8 @@ getPeerWithLedger(
|
|||||||
void
|
void
|
||||||
PeerImp::sendLedgerBase(
|
PeerImp::sendLedgerBase(
|
||||||
std::shared_ptr<Ledger const> const& ledger,
|
std::shared_ptr<Ledger const> const& ledger,
|
||||||
protocol::TMLedgerData& ledgerData)
|
protocol::TMLedgerData& ledgerData,
|
||||||
|
PeerCookieMap const& destinations)
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.trace()) << "sendLedgerBase: Base data";
|
JLOG(pJournal_.trace()) << "sendLedgerBase: Base data";
|
||||||
|
|
||||||
@@ -3121,14 +3267,92 @@ PeerImp::sendLedgerBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto message{std::make_shared<Message>(ledgerData, protocol::mtLEDGER_DATA)};
|
sendToMultiple(ledgerData, destinations);
|
||||||
send(message);
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PeerImp::sendToMultiple(protocol::TMLedgerData& ledgerData, PeerCookieMap const& destinations)
|
||||||
|
{
|
||||||
|
bool foundSelf = false;
|
||||||
|
for (auto const& [peer, cookies] : destinations)
|
||||||
|
{
|
||||||
|
if (peer.get() == this)
|
||||||
|
foundSelf = true;
|
||||||
|
bool const multipleCookies = peer->supportsFeature(ProtocolFeature::LedgerDataCookies);
|
||||||
|
std::vector<std::uint64_t> sendCookies;
|
||||||
|
|
||||||
|
bool directResponse = false;
|
||||||
|
if (!multipleCookies)
|
||||||
|
{
|
||||||
|
JLOG(pJournal_.debug()) << "sendToMultiple: Sending " << cookies.size()
|
||||||
|
<< " TMLedgerData messages to peer [" << peer->id()
|
||||||
|
<< "]: " << sha512Half(ledgerData);
|
||||||
|
}
|
||||||
|
for (auto const& cookie : cookies)
|
||||||
|
{
|
||||||
|
// Unfortunately, need a separate Message object for every
|
||||||
|
// combination
|
||||||
|
if (cookie)
|
||||||
|
{
|
||||||
|
if (multipleCookies)
|
||||||
|
{
|
||||||
|
// Save this one for later to send a single message
|
||||||
|
sendCookies.emplace_back(*cookie);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Feature not supported, so send a single message with a
|
||||||
|
// single cookie
|
||||||
|
ledgerData.set_requestcookie(*cookie);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (multipleCookies)
|
||||||
|
{
|
||||||
|
// Set this flag later on the single message
|
||||||
|
directResponse = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ledgerData.clear_requestcookie();
|
||||||
|
}
|
||||||
|
XRPL_ASSERT(
|
||||||
|
!multipleCookies,
|
||||||
|
"ripple::PeerImp::sendToMultiple : ledger data cookies "
|
||||||
|
"unsupported");
|
||||||
|
auto message{std::make_shared<Message>(ledgerData, protocol::mtLEDGER_DATA)};
|
||||||
|
peer->send(message);
|
||||||
|
}
|
||||||
|
if (multipleCookies)
|
||||||
|
{
|
||||||
|
// Send a single message with all the cookies and/or the direct
|
||||||
|
// response flag, so the receiver can farm out the single message to
|
||||||
|
// multiple peers and/or itself
|
||||||
|
XRPL_ASSERT(
|
||||||
|
sendCookies.size() || directResponse,
|
||||||
|
"ripple::PeerImp::sendToMultiple : valid response options");
|
||||||
|
ledgerData.clear_requestcookie();
|
||||||
|
ledgerData.clear_responsecookies();
|
||||||
|
ledgerData.set_directresponse(directResponse);
|
||||||
|
for (auto const& cookie : sendCookies)
|
||||||
|
ledgerData.add_responsecookies(cookie);
|
||||||
|
auto message{std::make_shared<Message>(ledgerData, protocol::mtLEDGER_DATA)};
|
||||||
|
peer->send(message);
|
||||||
|
|
||||||
|
JLOG(pJournal_.debug())
|
||||||
|
<< "sendToMultiple: Sent 1 TMLedgerData message to peer [" << peer->id()
|
||||||
|
<< "]: including " << (directResponse ? "the direct response flag and " : "")
|
||||||
|
<< sendCookies.size() << " response cookies. "
|
||||||
|
<< ": " << sha512Half(ledgerData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XRPL_ASSERT(foundSelf, "ripple::PeerImp::sendToMultiple : current peer included");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Ledger const>
|
std::shared_ptr<Ledger const>
|
||||||
PeerImp::getLedger(std::shared_ptr<protocol::TMGetLedger> const& m)
|
PeerImp::getLedger(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash)
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.trace()) << "getLedger: Ledger";
|
JLOG(pJournal_.trace()) << "getLedger: Ledger " << mHash;
|
||||||
|
|
||||||
std::shared_ptr<Ledger const> ledger;
|
std::shared_ptr<Ledger const> ledger;
|
||||||
|
|
||||||
@@ -3144,16 +3368,30 @@ PeerImp::getLedger(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
if (m->has_querytype() && !m->has_requestcookie())
|
if (m->has_querytype() && !m->has_requestcookie())
|
||||||
{
|
{
|
||||||
// Attempt to relay the request to a peer
|
// Attempt to relay the request to a peer
|
||||||
|
// Note repeated messages will not relay to the same peer
|
||||||
|
// before `kGetLedgerInterval` seconds. This prevents one
|
||||||
|
// peer from getting flooded, and distributes the request
|
||||||
|
// load. If a request has been relayed to all eligible
|
||||||
|
// peers, then this message will not be relayed.
|
||||||
if (auto const peer = getPeerWithLedger(
|
if (auto const peer = getPeerWithLedger(
|
||||||
overlay_, ledgerHash, m->has_ledgerseq() ? m->ledgerseq() : 0, this))
|
overlay_,
|
||||||
|
ledgerHash,
|
||||||
|
m->has_ledgerseq() ? m->ledgerseq() : 0,
|
||||||
|
this,
|
||||||
|
[&](Peer::id_t id) {
|
||||||
|
return app_.getHashRouter().shouldProcessForPeer(
|
||||||
|
mHash, id, kGetLedgerInterval);
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
m->set_requestcookie(id());
|
m->set_requestcookie(id());
|
||||||
peer->send(std::make_shared<Message>(*m, protocol::mtGET_LEDGER));
|
peer->send(std::make_shared<Message>(*m, protocol::mtGET_LEDGER));
|
||||||
JLOG(pJournal_.debug()) << "getLedger: Request relayed to peer";
|
JLOG(pJournal_.debug())
|
||||||
|
<< "getLedger: Request relayed to peer [" << peer->id() << "]: " << mHash;
|
||||||
return ledger;
|
return ledger;
|
||||||
}
|
}
|
||||||
|
|
||||||
JLOG(pJournal_.trace()) << "getLedger: Failed to find peer to relay request";
|
JLOG(pJournal_.trace())
|
||||||
|
<< "getLedger: Don't have ledger with hash " << ledgerHash << ": " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3162,15 +3400,15 @@ PeerImp::getLedger(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
// Attempt to find ledger by sequence
|
// Attempt to find ledger by sequence
|
||||||
if (m->ledgerseq() < app_.getLedgerMaster().getEarliestFetch())
|
if (m->ledgerseq() < app_.getLedgerMaster().getEarliestFetch())
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.debug()) << "getLedger: Early ledger sequence request";
|
JLOG(pJournal_.debug()) << "getLedger: Early ledger sequence request " << mHash;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ledger = app_.getLedgerMaster().getLedgerBySeq(m->ledgerseq());
|
ledger = app_.getLedgerMaster().getLedgerBySeq(m->ledgerseq());
|
||||||
if (!ledger)
|
if (!ledger)
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.debug())
|
JLOG(pJournal_.debug()) << "getLedger: Don't have ledger with sequence "
|
||||||
<< "getLedger: Don't have ledger with sequence " << m->ledgerseq();
|
<< m->ledgerseq() << ": " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3192,27 +3430,29 @@ PeerImp::getLedger(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
charge(Resource::kFeeMalformedRequest, "get_ledger ledgerSeq");
|
charge(Resource::kFeeMalformedRequest, "get_ledger ledgerSeq");
|
||||||
|
|
||||||
ledger.reset();
|
ledger.reset();
|
||||||
JLOG(pJournal_.warn()) << "getLedger: Invalid ledger sequence " << ledgerSeq;
|
JLOG(pJournal_.warn())
|
||||||
|
<< "getLedger: Invalid ledger sequence " << ledgerSeq << ": " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ledgerSeq < app_.getLedgerMaster().getEarliestFetch())
|
else if (ledgerSeq < app_.getLedgerMaster().getEarliestFetch())
|
||||||
{
|
{
|
||||||
ledger.reset();
|
ledger.reset();
|
||||||
JLOG(pJournal_.debug()) << "getLedger: Early ledger sequence request " << ledgerSeq;
|
JLOG(pJournal_.debug())
|
||||||
|
<< "getLedger: Early ledger sequence request " << ledgerSeq << ": " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.debug()) << "getLedger: Unable to find ledger";
|
JLOG(pJournal_.debug()) << "getLedger: Unable to find ledger " << mHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ledger;
|
return ledger;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<SHAMap const>
|
std::shared_ptr<SHAMap const>
|
||||||
PeerImp::getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m) const
|
PeerImp::getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash) const
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.trace()) << "getTxSet: TX set";
|
JLOG(pJournal_.trace()) << "getTxSet: TX set " << mHash;
|
||||||
|
|
||||||
uint256 const txSetHash = uint256::fromRaw(m->ledgerhash());
|
uint256 const txSetHash = uint256::fromRaw(m->ledgerhash());
|
||||||
std::shared_ptr<SHAMap> shaMap{app_.getInboundTransactions().getSet(txSetHash, false)};
|
std::shared_ptr<SHAMap> shaMap{app_.getInboundTransactions().getSet(txSetHash, false)};
|
||||||
@@ -3221,20 +3461,28 @@ PeerImp::getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m) const
|
|||||||
if (m->has_querytype() && !m->has_requestcookie())
|
if (m->has_querytype() && !m->has_requestcookie())
|
||||||
{
|
{
|
||||||
// Attempt to relay the request to a peer
|
// Attempt to relay the request to a peer
|
||||||
if (auto const peer = getPeerWithTree(overlay_, txSetHash, this))
|
// Note repeated messages will not relay to the same peer
|
||||||
|
// before `kGetLedgerInterval` seconds. This prevents one
|
||||||
|
// peer from getting flooded, and distributes the request
|
||||||
|
// load. If a request has been relayed to all eligible
|
||||||
|
// peers, then this message will not be relayed.
|
||||||
|
if (auto const peer = getPeerWithTree(overlay_, txSetHash, this, [&](Peer::id_t id) {
|
||||||
|
return app_.getHashRouter().shouldProcessForPeer(mHash, id, kGetLedgerInterval);
|
||||||
|
}))
|
||||||
{
|
{
|
||||||
m->set_requestcookie(id());
|
m->set_requestcookie(id());
|
||||||
peer->send(std::make_shared<Message>(*m, protocol::mtGET_LEDGER));
|
peer->send(std::make_shared<Message>(*m, protocol::mtGET_LEDGER));
|
||||||
JLOG(pJournal_.debug()) << "getTxSet: Request relayed";
|
JLOG(pJournal_.debug())
|
||||||
|
<< "getTxSet: Request relayed to peer [" << peer->id() << "]: " << mHash;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.debug()) << "getTxSet: Failed to find relay peer";
|
JLOG(pJournal_.debug()) << "getTxSet: Failed to find relay peer: " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JLOG(pJournal_.debug()) << "getTxSet: Failed to find TX set";
|
JLOG(pJournal_.debug()) << "getTxSet: Failed to find TX set " << mHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3242,7 +3490,7 @@ PeerImp::getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash)
|
||||||
{
|
{
|
||||||
// Do not resource charge a peer responding to a relay
|
// Do not resource charge a peer responding to a relay
|
||||||
if (!m->has_requestcookie())
|
if (!m->has_requestcookie())
|
||||||
@@ -3255,9 +3503,72 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
bool fatLeaves{true};
|
bool fatLeaves{true};
|
||||||
auto const itype{m->itype()};
|
auto const itype{m->itype()};
|
||||||
|
|
||||||
|
auto getDestinations = [&] {
|
||||||
|
// If a ledger data message is generated, it's going to be sent to every
|
||||||
|
// peer that is waiting for it.
|
||||||
|
|
||||||
|
PeerCookieMap result;
|
||||||
|
|
||||||
|
std::size_t numCookies = 0;
|
||||||
|
{
|
||||||
|
// Don't do the work under this peer if this peer is not waiting for
|
||||||
|
// any replies
|
||||||
|
auto myCookies = releaseRequestCookies(mHash);
|
||||||
|
if (myCookies.empty())
|
||||||
|
{
|
||||||
|
JLOG(pJournal_.debug()) << "TMGetLedger: peer is no longer "
|
||||||
|
"waiting for response to request: "
|
||||||
|
<< mHash;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
numCookies += myCookies.size();
|
||||||
|
result[shared_from_this()] = myCookies;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<HashRouter::PeerShortID> const peers = app_.getHashRouter().getPeers(mHash);
|
||||||
|
for (auto const peerID : peers)
|
||||||
|
{
|
||||||
|
// This loop does not need to be done under the HashRouter
|
||||||
|
// lock because findPeerByShortID and releaseRequestCookies
|
||||||
|
// are thread safe, and everything else is local
|
||||||
|
if (auto p = overlay_.findPeerByShortID(peerID))
|
||||||
|
{
|
||||||
|
auto cookies = p->releaseRequestCookies(mHash);
|
||||||
|
numCookies += cookies.size();
|
||||||
|
if (result.contains(p))
|
||||||
|
{
|
||||||
|
// Unlikely, but if a request came in to this peer while
|
||||||
|
// iterating, add the items instead of copying /
|
||||||
|
// overwriting.
|
||||||
|
XRPL_ASSERT(
|
||||||
|
p.get() == this,
|
||||||
|
"ripple::PeerImp::processLedgerRequest : found self in "
|
||||||
|
"map");
|
||||||
|
for (auto const& cookie : cookies)
|
||||||
|
result[p].emplace(cookie);
|
||||||
|
}
|
||||||
|
else if (cookies.size())
|
||||||
|
result[p] = cookies;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JLOG(pJournal_.debug()) << "TMGetLedger: Processing request for " << result.size()
|
||||||
|
<< " peers. Will send " << numCookies
|
||||||
|
<< " messages if successful: " << mHash;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
// Will only populate this if we're going to do work.
|
||||||
|
PeerCookieMap destinations;
|
||||||
|
|
||||||
if (itype == protocol::liTS_CANDIDATE)
|
if (itype == protocol::liTS_CANDIDATE)
|
||||||
{
|
{
|
||||||
if (sharedMap = getTxSet(m); !sharedMap)
|
destinations = getDestinations();
|
||||||
|
if (destinations.empty())
|
||||||
|
// Nowhere to send the response!
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (sharedMap = getTxSet(m, mHash); !sharedMap)
|
||||||
return;
|
return;
|
||||||
map = sharedMap.get();
|
map = sharedMap.get();
|
||||||
|
|
||||||
@@ -3265,8 +3576,6 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
ledgerData.set_ledgerseq(0);
|
ledgerData.set_ledgerseq(0);
|
||||||
ledgerData.set_ledgerhash(m->ledgerhash());
|
ledgerData.set_ledgerhash(m->ledgerhash());
|
||||||
ledgerData.set_type(protocol::liTS_CANDIDATE);
|
ledgerData.set_type(protocol::liTS_CANDIDATE);
|
||||||
if (m->has_requestcookie())
|
|
||||||
ledgerData.set_requestcookie(m->requestcookie());
|
|
||||||
|
|
||||||
// We'll already have most transactions
|
// We'll already have most transactions
|
||||||
fatLeaves = false;
|
fatLeaves = false;
|
||||||
@@ -3284,7 +3593,12 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ledger = getLedger(m); !ledger)
|
destinations = getDestinations();
|
||||||
|
if (destinations.empty())
|
||||||
|
// Nowhere to send the response!
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ledger = getLedger(m, mHash); !ledger)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Fill out the reply
|
// Fill out the reply
|
||||||
@@ -3292,13 +3606,11 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
ledgerData.set_ledgerhash(ledgerHash.begin(), ledgerHash.size());
|
ledgerData.set_ledgerhash(ledgerHash.begin(), ledgerHash.size());
|
||||||
ledgerData.set_ledgerseq(ledger->header().seq);
|
ledgerData.set_ledgerseq(ledger->header().seq);
|
||||||
ledgerData.set_type(itype);
|
ledgerData.set_type(itype);
|
||||||
if (m->has_requestcookie())
|
|
||||||
ledgerData.set_requestcookie(m->requestcookie());
|
|
||||||
|
|
||||||
switch (itype)
|
switch (itype)
|
||||||
{
|
{
|
||||||
case protocol::liBASE:
|
case protocol::liBASE:
|
||||||
sendLedgerBase(ledger, ledgerData);
|
sendLedgerBase(ledger, ledgerData, destinations);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case protocol::liTX_NODE:
|
case protocol::liTX_NODE:
|
||||||
@@ -3409,7 +3721,7 @@ PeerImp::processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
if (ledgerData.nodes_size() == 0)
|
if (ledgerData.nodes_size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
send(std::make_shared<Message>(ledgerData, protocol::mtLEDGER_DATA));
|
sendToMultiple(ledgerData, destinations);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -3461,6 +3773,19 @@ PeerImp::isHighLatency() const
|
|||||||
return latency_ >= kPeerHighLatency;
|
return latency_ >= kPeerHighLatency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<std::optional<uint64_t>>
|
||||||
|
PeerImp::releaseRequestCookies(uint256 const& requestHash)
|
||||||
|
{
|
||||||
|
std::set<std::optional<uint64_t>> result;
|
||||||
|
std::lock_guard lock(cookieLock_);
|
||||||
|
if (messageRequestCookies_.contains(requestHash))
|
||||||
|
{
|
||||||
|
std::swap(result, messageRequestCookies_[requestHash]);
|
||||||
|
messageRequestCookies_.erase(requestHash);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
PeerImp::Metrics::addMessage(std::uint64_t bytes)
|
PeerImp::Metrics::addMessage(std::uint64_t bytes)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -172,6 +172,13 @@ private:
|
|||||||
bool ledgerReplayEnabled_ = false;
|
bool ledgerReplayEnabled_ = false;
|
||||||
LedgerReplayMsgHandler ledgerReplayMsgHandler_;
|
LedgerReplayMsgHandler ledgerReplayMsgHandler_;
|
||||||
|
|
||||||
|
// Track message requests and responses
|
||||||
|
// TODO: Use an expiring cache or something
|
||||||
|
using MessageCookieMap = std::map<uint256, std::set<std::optional<uint64_t>>>;
|
||||||
|
using PeerCookieMap = std::map<std::shared_ptr<Peer>, std::set<std::optional<uint64_t>>>;
|
||||||
|
std::mutex mutable cookieLock_;
|
||||||
|
MessageCookieMap messageRequestCookies_;
|
||||||
|
|
||||||
friend class OverlayImpl;
|
friend class OverlayImpl;
|
||||||
|
|
||||||
class Metrics
|
class Metrics
|
||||||
@@ -416,6 +423,13 @@ public:
|
|||||||
return txReduceRelayEnabled_;
|
return txReduceRelayEnabled_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Messages
|
||||||
|
//
|
||||||
|
|
||||||
|
std::set<std::optional<uint64_t>>
|
||||||
|
releaseRequestCookies(uint256 const& requestHash) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void
|
void
|
||||||
close();
|
close();
|
||||||
@@ -614,16 +628,22 @@ private:
|
|||||||
std::shared_ptr<protocol::TMValidation> const& packet);
|
std::shared_ptr<protocol::TMValidation> const& packet);
|
||||||
|
|
||||||
void
|
void
|
||||||
sendLedgerBase(std::shared_ptr<Ledger const> const& ledger, protocol::TMLedgerData& ledgerData);
|
sendLedgerBase(
|
||||||
|
std::shared_ptr<Ledger const> const& ledger,
|
||||||
std::shared_ptr<Ledger const>
|
protocol::TMLedgerData& ledgerData,
|
||||||
getLedger(std::shared_ptr<protocol::TMGetLedger> const& m);
|
PeerCookieMap const& destinations);
|
||||||
|
|
||||||
std::shared_ptr<SHAMap const>
|
|
||||||
getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m) const;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m);
|
sendToMultiple(protocol::TMLedgerData& ledgerData, PeerCookieMap const& destinations);
|
||||||
|
|
||||||
|
std::shared_ptr<Ledger const>
|
||||||
|
getLedger(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash);
|
||||||
|
|
||||||
|
std::shared_ptr<SHAMap const>
|
||||||
|
getTxSet(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash) const;
|
||||||
|
|
||||||
|
void
|
||||||
|
processLedgerRequest(std::shared_ptr<protocol::TMGetLedger> const& m, uint256 const& mHash);
|
||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include <xrpl/basics/Log.h>
|
#include <xrpl/basics/Log.h>
|
||||||
#include <xrpl/beast/utility/Journal.h>
|
#include <xrpl/beast/utility/Journal.h>
|
||||||
|
#include <xrpl/core/HashRouter.h>
|
||||||
|
#include <xrpl/core/JobQueue.h>
|
||||||
|
#include <xrpl/protocol/digest.h>
|
||||||
|
|
||||||
#include <google/protobuf/message.h>
|
#include <google/protobuf/message.h>
|
||||||
|
|
||||||
@@ -97,16 +100,45 @@ PeerSetImpl::sendRequest(
|
|||||||
std::shared_ptr<Peer> const& peer)
|
std::shared_ptr<Peer> const& peer)
|
||||||
{
|
{
|
||||||
auto packet = std::make_shared<Message>(message, type);
|
auto packet = std::make_shared<Message>(message, type);
|
||||||
|
|
||||||
|
auto const messageHash = [&]() {
|
||||||
|
auto const packetBuffer = packet->getBuffer(compression::Compressed::Off);
|
||||||
|
return sha512Half(Slice(packetBuffer.data(), packetBuffer.size()));
|
||||||
|
}();
|
||||||
|
|
||||||
|
// Allow messages to be re-sent to the same peer after a delay
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
constexpr std::chrono::seconds interval = 30s;
|
||||||
|
|
||||||
if (peer)
|
if (peer)
|
||||||
{
|
{
|
||||||
peer->send(packet);
|
if (app_.getHashRouter().shouldProcessForPeer(messageHash, peer->id(), interval))
|
||||||
|
{
|
||||||
|
JLOG(journal_.trace()) << "Sending " << protocolMessageName(type) << " message to ["
|
||||||
|
<< peer->id() << "]: " << messageHash;
|
||||||
|
peer->send(packet);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
JLOG(journal_.debug()) << "Suppressing sending duplicate " << protocolMessageName(type)
|
||||||
|
<< " message to [" << peer->id() << "]: " << messageHash;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto id : peers_)
|
for (auto id : peers_)
|
||||||
{
|
{
|
||||||
if (auto p = app_.getOverlay().findPeerByShortID(id))
|
if (auto p = app_.getOverlay().findPeerByShortID(id))
|
||||||
p->send(packet);
|
{
|
||||||
|
if (app_.getHashRouter().shouldProcessForPeer(messageHash, p->id(), interval))
|
||||||
|
{
|
||||||
|
JLOG(journal_.trace()) << "Sending " << protocolMessageName(type) << " message to ["
|
||||||
|
<< p->id() << "]: " << messageHash;
|
||||||
|
p->send(packet);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
JLOG(journal_.debug())
|
||||||
|
<< "Suppressing sending duplicate " << protocolMessageName(type)
|
||||||
|
<< " message to [" << p->id() << "]: " << messageHash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ protocolMessageType(protocol::TMGetLedger const&)
|
|||||||
return protocol::mtGET_LEDGER;
|
return protocol::mtGET_LEDGER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline protocol::MessageType
|
||||||
|
protocolMessageType(protocol::TMLedgerData const&)
|
||||||
|
{
|
||||||
|
return protocol::mtLEDGER_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
inline protocol::MessageType
|
inline protocol::MessageType
|
||||||
protocolMessageType(protocol::TMReplayDeltaRequest const&)
|
protocolMessageType(protocol::TMReplayDeltaRequest const&)
|
||||||
{
|
{
|
||||||
@@ -434,3 +440,63 @@ invokeProtocolMessage(Buffers const& buffers, Handler& handler, std::size_t& hin
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace xrpl
|
} // namespace xrpl
|
||||||
|
|
||||||
|
namespace protocol {
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
void
|
||||||
|
hash_append(Hasher& h, TMGetLedger const& msg)
|
||||||
|
{
|
||||||
|
using beast::hash_append;
|
||||||
|
using namespace xrpl;
|
||||||
|
hash_append(h, safeCast<int>(protocolMessageType(msg)));
|
||||||
|
hash_append(h, safeCast<int>(msg.itype()));
|
||||||
|
if (msg.has_ltype())
|
||||||
|
hash_append(h, safeCast<int>(msg.ltype()));
|
||||||
|
|
||||||
|
if (msg.has_ledgerhash())
|
||||||
|
hash_append(h, msg.ledgerhash());
|
||||||
|
|
||||||
|
if (msg.has_ledgerseq())
|
||||||
|
hash_append(h, msg.ledgerseq());
|
||||||
|
|
||||||
|
for (auto const& nodeId : msg.nodeids())
|
||||||
|
hash_append(h, nodeId);
|
||||||
|
hash_append(h, msg.nodeids_size());
|
||||||
|
|
||||||
|
// Do NOT include the request cookie. It does not affect the content of the
|
||||||
|
// request, but only where to route the results.
|
||||||
|
// if (msg.has_requestcookie())
|
||||||
|
// hash_append(h, msg.requestcookie());
|
||||||
|
|
||||||
|
if (msg.has_querytype())
|
||||||
|
hash_append(h, safeCast<int>(msg.querytype()));
|
||||||
|
|
||||||
|
if (msg.has_querydepth())
|
||||||
|
hash_append(h, msg.querydepth());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
void
|
||||||
|
hash_append(Hasher& h, TMLedgerData const& msg)
|
||||||
|
{
|
||||||
|
using beast::hash_append;
|
||||||
|
using namespace xrpl;
|
||||||
|
hash_append(h, safeCast<int>(protocolMessageType(msg)));
|
||||||
|
hash_append(h, msg.ledgerhash());
|
||||||
|
hash_append(h, msg.ledgerseq());
|
||||||
|
hash_append(h, safeCast<int>(msg.type()));
|
||||||
|
for (auto const& node : msg.nodes())
|
||||||
|
{
|
||||||
|
hash_append(h, node.nodedata());
|
||||||
|
if (node.has_nodeid())
|
||||||
|
hash_append(h, node.nodeid());
|
||||||
|
}
|
||||||
|
hash_append(h, msg.nodes_size());
|
||||||
|
if (msg.has_requestcookie())
|
||||||
|
hash_append(h, msg.requestcookie());
|
||||||
|
if (msg.has_error())
|
||||||
|
hash_append(h, safeCast<int>(msg.error()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace protocol
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ namespace xrpl {
|
|||||||
constexpr ProtocolVersion const kSupportedProtocolList[]{
|
constexpr ProtocolVersion const kSupportedProtocolList[]{
|
||||||
{2, 1},
|
{2, 1},
|
||||||
{2, 2},
|
{2, 2},
|
||||||
|
// Adds TMLedgerData::responseCookies and directResponse
|
||||||
|
{2, 3},
|
||||||
};
|
};
|
||||||
|
|
||||||
// This ugly construct ensures that supportedProtocolList is sorted in strictly
|
// This ugly construct ensures that supportedProtocolList is sorted in strictly
|
||||||
|
|||||||
Reference in New Issue
Block a user