From 209e2356f54c5f93b8f6d6cf7810693e60b45a9e Mon Sep 17 00:00:00 2001 From: Antonio Juarez Date: Sun, 29 Jun 2014 03:39:24 +0400 Subject: [PATCH] Add proper big transaction handling --- src/cryptonote_core/tx_pool.cpp | 18 ++++++++++++++++++ src/wallet/wallet2.h | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 7fab0d2e..4f209ec4 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -20,6 +20,8 @@ DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated +#define TRANSACTION_SIZE_LIMIT (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE) + namespace cryptonote { //--------------------------------------------------------------------------------- tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs) { @@ -52,6 +54,12 @@ namespace cryptonote { return false; } + if (!kept_by_block && blob_size >= TRANSACTION_SIZE_LIMIT) { + LOG_ERROR("transaction is too big: " << blob_size << " bytes, maximum size: " << TRANSACTION_SIZE_LIMIT); + tvc.m_verifivation_failed = true; + return false; + } + //check key images for transaction if it is not kept by block if (!kept_by_block) { if (have_tx_keyimges_as_spent(tx)) { @@ -340,6 +348,16 @@ namespace cryptonote { m_transactions.clear(); m_spent_key_images.clear(); } + + for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { + auto it2 = it++; + if (it2->second.blob_size >= TRANSACTION_SIZE_LIMIT) { + LOG_PRINT_L0("Transaction " << get_transaction_hash(it2->second.tx) << " is too big (" << it2->second.blob_size << " bytes), removing it from pool"); + remove_transaction_keyimages(it2->second.tx); + m_transactions.erase(it2); + } + } + // Ignore deserialization error return true; } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index a2c961e8..6342e8c7 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -102,7 +102,7 @@ namespace tools void store(); cryptonote::account_base& get_account(){return m_account;} - void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE*2 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); + void init(const std::string& daemon_address = "http://localhost:8080", uint64_t upper_transaction_size_limit = ((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); bool deinit(); void stop() { m_run.store(false, std::memory_order_relaxed); }