Skip to content

Commit 78c4231

Browse files
vlntbximinez
andcommitted
Drop duplicate incoming TMLedgerData messages:
* Addresses RIPD-1869 --------- Co-authored-by: Valentin Balaschenko <13349202+vlntb@users.noreply.github.com> Co-authored-by: Ed Hennis <ed@ripple.com>
1 parent e9ebfcb commit 78c4231

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/ripple/app/misc/HashRouter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class HashRouter
186186

187187
/** Add a suppression peer and get message's relay status.
188188
* Return pair:
189-
* element 1: true if the peer is added.
189+
* element 1: true if the key is added.
190190
* element 2: optional is seated to the relay time point or
191191
* is unseated if has not relayed yet. */
192192
std::pair<bool, std::optional<Stopwatch::time_point>>

src/ripple/overlay/impl/PeerImp.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <ripple/nodestore/DatabaseShard.h>
3838
#include <ripple/overlay/Cluster.h>
3939
#include <ripple/overlay/impl/PeerImp.h>
40+
#include <ripple/overlay/impl/ProtocolMessage.h>
4041
#include <ripple/overlay/impl/Tuning.h>
4142
#include <ripple/overlay/predicates.h>
4243
#include <ripple/protocol/digest.h>
@@ -1944,8 +1945,15 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMLedgerData> const& m)
19441945
return;
19451946
}
19461947

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

1956+
uint256 const ledgerHash{m->ledgerhash()};
19491957
// Otherwise check if received data for a candidate transaction set
19501958
if (m->type() == protocol::liTS_CANDIDATE)
19511959
{

src/ripple/overlay/impl/ProtocolMessage.h

+29
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ protocolMessageType(protocol::TMGetLedger const&)
4343
return protocol::mtGET_LEDGER;
4444
}
4545

46+
inline protocol::MessageType
47+
protocolMessageType(protocol::TMLedgerData const&)
48+
{
49+
return protocol::mtLEDGER_DATA;
50+
}
51+
4652
inline protocol::MessageType
4753
protocolMessageType(protocol::TMReplayDeltaRequest const&)
4854
{
@@ -543,6 +549,29 @@ hash_append(Hasher& h, TMGetLedger const& msg)
543549
hash_append(h, msg.querydepth());
544550
}
545551

552+
template <class Hasher>
553+
void
554+
hash_append(Hasher& h, TMLedgerData const& msg)
555+
{
556+
using beast::hash_append;
557+
using namespace ripple;
558+
hash_append(h, safe_cast<int>(protocolMessageType(msg)));
559+
hash_append(h, msg.ledgerhash());
560+
hash_append(h, msg.ledgerseq());
561+
hash_append(h, safe_cast<int>(msg.type()));
562+
for (auto const& node : msg.nodes())
563+
{
564+
hash_append(h, node.nodedata());
565+
if (node.has_nodeid())
566+
hash_append(h, node.nodeid());
567+
}
568+
hash_append(h, msg.nodes_size());
569+
if (msg.has_requestcookie())
570+
hash_append(h, msg.requestcookie());
571+
if (msg.has_error())
572+
hash_append(h, safe_cast<int>(msg.error()));
573+
}
574+
546575
} // namespace protocol
547576

548577
#endif

0 commit comments

Comments
 (0)