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 Aug 17, 2024
1 parent c378d0e commit 0b30d71
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ripple/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
10 changes: 9 additions & 1 deletion src/ripple/overlay/impl/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <ripple/nodestore/DatabaseShard.h>
#include <ripple/overlay/Cluster.h>
#include <ripple/overlay/impl/PeerImp.h>
#include <ripple/overlay/impl/ProtocolMessage.h>
#include <ripple/overlay/impl/Tuning.h>
#include <ripple/overlay/predicates.h>
#include <ripple/protocol/digest.h>
Expand Down Expand Up @@ -1944,8 +1945,15 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
return;
}

uint256 const ledgerHash{m->ledgerhash()};
auto const peerId = shared_from_this()->id();
auto const messageHash = sha512Half(*m);
if (!app_.getHashRouter().addSuppressionPeer(messageHash, peerId))
{
auto const shortHash = to_string(messageHash).substr(0, 6);
return badData("Duplicate message: " + shortHash);
}

uint256 const ledgerHash{m->ledgerhash()};
// Otherwise check if received data for a candidate transaction set
if (m->type() == protocol::liTS_CANDIDATE)
{
Expand Down
29 changes: 29 additions & 0 deletions src/ripple/overlay/impl/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 @@ -543,6 +549,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 0b30d71

Please sign in to comment.