aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xFFFC0000 <0xFFFC0000@proton.me>2024-06-05 16:33:15 +0000
committer0xFFFC0000 <0xFFFC0000@proton.me>2024-06-05 16:33:15 +0000
commit32f32453f135104938668b1e59ea8835c0b0169b (patch)
treefe774c6e4522605810ae882541068d4fc089cf3b
parentMerge pull request #9202 (diff)
downloadmonero-32f32453f135104938668b1e59ea8835c0b0169b.tar.xz
cryptonote_protocol: prevent duplicate txs in fluff queue
1. Fix duplicate transaction #9335 2. Add test for cases where there are duplicate transaction in fluff Co-authored-by: Boog900 <boog900@tutanota.com>
-rw-r--r--src/cryptonote_protocol/levin_notify.cpp2
-rw-r--r--tests/unit_tests/levin.cpp57
2 files changed, 59 insertions, 0 deletions
diff --git a/src/cryptonote_protocol/levin_notify.cpp b/src/cryptonote_protocol/levin_notify.cpp
index 1c3a2901c..044fd49b5 100644
--- a/src/cryptonote_protocol/levin_notify.cpp
+++ b/src/cryptonote_protocol/levin_notify.cpp
@@ -396,6 +396,8 @@ namespace levin
for (auto& connection : connections)
{
std::sort(connection.first.begin(), connection.first.end()); // don't leak receive order
+ connection.first.erase(std::unique(connection.first.begin(), connection.first.end()),
+ connection.first.end());
make_payload_send_txs(*zone_->p2p, std::move(connection.first), connection.second, zone_->pad_txs, true);
}
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index d686df87d..65bfbdd43 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -2219,6 +2219,63 @@ TEST_F(levin_notify, fluff_multiple)
}
}
+TEST_F(levin_notify, fluff_with_duplicate)
+{
+ std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
+ auto &notifier = *notifier_ptr;
+
+ for (unsigned count = 0; count < 10; ++count)
+ add_connection(count % 2 == 0);
+
+ {
+ const auto status = notifier.get_status();
+ EXPECT_FALSE(status.has_noise);
+ EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
+ }
+ notifier.new_out_connection();
+ io_service_.poll();
+
+ std::vector<cryptonote::blobdata> txs(9);
+ txs[0].resize(100, 'e');
+ txs[1].resize(100, 'e');
+ txs[2].resize(100, 'e');
+ txs[3].resize(100, 'e');
+ txs[4].resize(200, 'f');
+ txs[5].resize(200, 'f');
+ txs[6].resize(200, 'f');
+ txs[7].resize(200, 'f');
+ txs[8].resize(200, 'f');
+
+ ASSERT_EQ(10u, contexts_.size());
+ {
+ auto context = contexts_.begin();
+ EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
+
+ io_service_.reset();
+ ASSERT_LT(0u, io_service_.poll());
+ notifier.run_fluff();
+ ASSERT_LT(0u, io_service_.poll());
+
+ EXPECT_EQ(0u, context->process_send_queue());
+ for (++context; context != contexts_.end(); ++context)
+ EXPECT_EQ(1u, context->process_send_queue());
+
+ EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
+ std::sort(txs.begin(), txs.end());
+ ASSERT_EQ(9u, receiver_.notified_size());
+ for (unsigned count = 0; count < 9; ++count)
+ {
+ auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
+ EXPECT_NE(txs, notification.txs);
+ EXPECT_EQ(notification.txs.size(), 2);
+ EXPECT_TRUE(notification._.empty());
+ EXPECT_TRUE(notification.dandelionpp_fluff);
+ }
+ }
+
+}
+
TEST_F(levin_notify, noise)
{
for (unsigned count = 0; count < 10; ++count)