aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortobtoht <tob@featherwallet.org>2026-06-30 10:00:47 +0000
committertobtoht <tob@featherwallet.org>2026-06-30 10:00:47 +0000
commitc4746233fc3a8efa58f71d1b795d588f94e5239f (patch)
tree82ef78e55a028be79008fd68259014e5ff8470c0 /src
parentde95c4f993bfd0fc4df07ee7fb6fccbdbe0493ac (diff)
parentfc6e4af01c5fde4d232d16e61ae4b26d51f82987 (diff)
downloadmonzero-core-c4746233fc3a8efa58f71d1b795d588f94e5239f.tar.gz
monzero-core-c4746233fc3a8efa58f71d1b795d588f94e5239f.tar.xz
monzero-core-c4746233fc3a8efa58f71d1b795d588f94e5239f.zip
Merge pull request #10836
fc6e4af 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) (SChernykh) ACKs: selsta, j-berman
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index aaa93f21d..3ad26a3de 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -883,17 +883,23 @@ namespace cryptonote
int t_cryptonote_protocol_handler<t_core>::handle_notify_new_transactions(int command, NOTIFY_NEW_TRANSACTIONS::request& arg, cryptonote_connection_context& context)
{
MLOG_P2P_MESSAGE("Received NOTIFY_NEW_TRANSACTIONS (" << arg.txs.size() << " txes)");
- std::unordered_set<blobdata> seen;
+ std::unordered_set<crypto::hash> 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<const uint8_t*>(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(context.m_state != cryptonote_connection_context::state_normal)