From 330062a0041460950b316b140dbe544b84db6b11 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Mon, 29 Jun 2026 08:06:31 +0200 Subject: [PATCH] Optimized handle_notify_new_transactions's duplicate tx check - Check sha256 digests instead of full blobs (much less memory used) - Replace `find->insert` sequence with a single `insert` - 2x fewer hashset accesses - Preallocate the required size for the hashset (no full-table rehashes) --- .../cryptonote_protocol_handler.inl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index e4c30ad3a..d012b9193 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -915,17 +915,23 @@ namespace cryptonote return 1; } - std::unordered_set seen; + std::unordered_set seen; + seen.reserve(arg.txs.size()); + for (const auto &blob: arg.txs) { MLOGIF_P2P_MESSAGE(cryptonote::transaction tx; crypto::hash hash; bool ret = cryptonote::parse_and_validate_tx_from_blob(blob, tx, hash);, ret, "Including transaction " << hash); - if (seen.find(blob) != seen.end()) + + crypto::hash digest{}; + if (!blob.empty()) + tools::sha256sum(reinterpret_cast(blob.data()), blob.size(), digest); + + if (!seen.insert(digest).second) { LOG_PRINT_CCONTEXT_L1("Duplicate transaction in notification, dropping connection"); drop_connection(context, false, false); return 1; } - seen.insert(blob); } /* If the txes were received over i2p/tor, the default is to "forward"