Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ripd 1869 tm ledger data duplicates #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ripple/app/misc/HashRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,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
29 changes: 28 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 @@ -1890,8 +1891,34 @@ 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 = [&]() {
sha512_half_hasher h;
using beast::hash_append;
hash_append(h, safe_cast<int>(protocolMessageType(*m)));
hash_append(h, m->ledgerhash());
hash_append(h, m->ledgerseq());
hash_append(h, safe_cast<int>(m->type()));
for (auto const& node : m->nodes())
{
hash_append(h, node.nodedata());
if (node.has_nodeid())
hash_append(h, node.nodeid());
}
hash_append(h, m->nodes_size());
if (m->has_requestcookie())
hash_append(h, m->requestcookie());
if (m->has_error())
hash_append(h, safe_cast<int>(m->error()));
return static_cast<typename sha512_half_hasher::result_type>(h);
}();
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
6 changes: 6 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
Loading