Skip to content

Commit

Permalink
Drop duplicate incoming TMLedgerData messages:
Browse files Browse the repository at this point in the history
* Addresses RIPD-1869

---------

Co-authored-by: Valentin Balaschenko <[email protected]>
Co-authored-by: Ed Hennis <[email protected]>
  • Loading branch information
vlntb and ximinez committed Sep 11, 2024
1 parent 5220567 commit 8848447
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/xrpld/app/misc/HashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class HashRouter

/** Add a suppression peer and get message's relay status.
* 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
* is unseated if has not relayed yet. */
std::pair<bool, std::optional<Stopwatch::time_point>>
Expand Down
12 changes: 9 additions & 3 deletions src/xrpld/overlay/detail/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <xrpld/overlay/detail/PeerImp.h>
#include <xrpld/overlay/detail/ProtocolMessage.h>
#include <xrpld/overlay/detail/Tuning.h>
#include <xrpld/overlay/detail/ProtocolMessage.h>
#include <xrpld/overlay/predicates.h>
#include <xrpld/perflog/PerfLog.h>
#include <xrpl/basics/UptimeClock.h>
Expand All @@ -40,7 +41,6 @@
#include <xrpl/basics/safe_cast.h>
#include <xrpl/beast/core/LexicalCast.h>
#include <xrpl/protocol/digest.h>
// #include <xrpl/beast/core/SemanticVersion.h>
#include <xrpl/protocol/digest.h>

#include <boost/algorithm/string/predicate.hpp>
Expand Down Expand Up @@ -1620,6 +1620,12 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
"Invalid Ledger/TXset nodes " + std::to_string(m->nodes_size()));
}

auto const messageHash = sha512Half(*m);
if (!app_.getHashRouter().addSuppressionPeer(messageHash, id_))
{
return badData("Duplicate message: " + to_string(messageHash));
}

// If there is a request cookie, attempt to relay the message
if (m->has_requestcookie())
{
Expand All @@ -1636,7 +1642,6 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
}

uint256 const ledgerHash{m->ledgerhash()};

// Otherwise check if received data for a candidate transaction set
if (m->type() == protocol::liTS_CANDIDATE)
{
Expand Down Expand Up @@ -3057,7 +3062,8 @@ PeerImp::sendToMultiple(
foundSelf = true;
JLOG(p_journal_.debug())
<< "sendToMultiple: Sending " << cookies.size()
<< " TMLedgerData messages to peer[" << peer->id() << "]";
<< " TMLedgerData messages to peer[" << peer->id()
<< "]: " << sha512Half(ledgerData);
for (auto const& cookie : cookies)
{
// Unfortunately, need a separate Message object for every
Expand Down
29 changes: 29 additions & 0 deletions src/xrpld/overlay/detail/ProtocolMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ protocolMessageType(protocol::TMGetLedger const&)
return protocol::mtGET_LEDGER;
}

inline protocol::MessageType
protocolMessageType(protocol::TMLedgerData const&)
{
return protocol::mtLEDGER_DATA;
}

inline protocol::MessageType
protocolMessageType(protocol::TMReplayDeltaRequest const&)
{
Expand Down Expand Up @@ -519,6 +525,29 @@ hash_append(Hasher& h, TMGetLedger const& msg)
hash_append(h, msg.querydepth());
}

template <class Hasher>
void
hash_append(Hasher& h, TMLedgerData const& msg)
{
using beast::hash_append;
using namespace ripple;
hash_append(h, safe_cast<int>(protocolMessageType(msg)));
hash_append(h, msg.ledgerhash());
hash_append(h, msg.ledgerseq());
hash_append(h, safe_cast<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, safe_cast<int>(msg.error()));
}

} // namespace protocol

#endif

0 comments on commit 8848447

Please sign in to comment.