From 3b1d7e03fcc1caa8898ced33e127f6ba09d66df8 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 29 Jan 2016 15:09:17 +0000 Subject: Fix V1/V2 use of hard fork related parameters Some of it uses hardcoded height, which will need some thinking for next (voted upon) fork. --- src/cryptonote_core/tx_pool.cpp | 50 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 1be44172d..2c607fa88 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -54,7 +54,8 @@ namespace cryptonote { namespace { - size_t const TRANSACTION_SIZE_LIMIT = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); + size_t const TRANSACTION_SIZE_LIMIT_V1 = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); + size_t const TRANSACTION_SIZE_LIMIT_V2 = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE); time_t const MIN_RELAY_TIME = (60 * 5); // only start re-relaying transactions after that many seconds time_t const MAX_RELAY_TIME = (60 * 60 * 4); // at most that many seconds between resends @@ -81,7 +82,7 @@ namespace cryptonote } #endif //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed) + bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version) { @@ -118,9 +119,10 @@ namespace cryptonote return false; } - if (!kept_by_block && blob_size >= TRANSACTION_SIZE_LIMIT) + size_t tx_size_limit = (version < 2 ? TRANSACTION_SIZE_LIMIT_V1 : TRANSACTION_SIZE_LIMIT_V2); + if (!kept_by_block && blob_size >= tx_size_limit) { - LOG_PRINT_L1("transaction is too big: " << blob_size << " bytes, maximum size: " << TRANSACTION_SIZE_LIMIT); + LOG_PRINT_L1("transaction is too big: " << blob_size << " bytes, maximum size: " << tx_size_limit); tvc.m_verifivation_failed = true; return false; } @@ -217,12 +219,12 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed) + bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version) { crypto::hash h = null_hash; size_t blob_size = 0; get_transaction_hash(tx, h, blob_size); - return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed); + return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, version); } //--------------------------------------------------------------------------------- bool tx_memory_pool::remove_transaction_keyimages(const transaction& tx) @@ -607,6 +609,33 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- + size_t tx_memory_pool::validate(uint8_t version) + { + size_t n_removed = 0; + size_t tx_size_limit = (version < 2 ? TRANSACTION_SIZE_LIMIT_V1 : TRANSACTION_SIZE_LIMIT_V2); + for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { + if (it->second.blob_size >= tx_size_limit) { + LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); + remove_transaction_keyimages(it->second.tx); + auto sorted_it = find_tx_in_sorted_container(it->first); + if (sorted_it == m_txs_by_fee.end()) + { + LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!"); + } + else + { + m_txs_by_fee.erase(sorted_it); + } + auto pit = it++; + m_transactions.erase(pit); + ++n_removed; + continue; + } + it++; + } + return n_removed; + } + //--------------------------------------------------------------------------------- bool tx_memory_pool::init(const std::string& config_folder) { CRITICAL_REGION_LOCAL(m_transactions_lock); @@ -629,15 +658,6 @@ namespace cryptonote m_spent_key_images.clear(); } - for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { - if (it->second.blob_size >= TRANSACTION_SIZE_LIMIT) { - LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); - remove_transaction_keyimages(it->second.tx); - m_transactions.erase(it); - } - it++; - } - // no need to store queue of sorted transactions, as it's easy to generate. for (const auto& tx : m_transactions) { -- cgit v1.2.3 From eadbdf354a3a3135fd235ce3cce47d8b89f7b279 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 29 Jan 2016 16:49:53 +0000 Subject: tx_pool: fix use of invalidated iterator --- src/cryptonote_core/tx_pool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 2c607fa88..2cef68a85 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -315,7 +315,8 @@ namespace cryptonote { m_txs_by_fee.erase(sorted_it); } - m_transactions.erase(it++); + auto pit = it++; + m_transactions.erase(pit); }else ++it; } -- cgit v1.2.3 From 94b98fb5fa98ca317664b96d6a564159945de95e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Fri, 29 Jan 2016 17:15:09 +0000 Subject: tx_pool: do not accept txes not in a block if they timed out before This is intended to avoid cases where a timed out tx will be re-relayed by another peer for which it has not timed out yet, which would cause the tx to stay in the network's pool for a long time (until all peers time it out before another one tries to relay it again). --- src/cryptonote_core/tx_pool.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 2cef68a85..5d67acdd2 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -84,7 +84,15 @@ namespace cryptonote //--------------------------------------------------------------------------------- bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version) { - + // we do not accept transactions that timed out before, unless they're + // kept_by_block + if (!kept_by_block && m_timed_out_transactions.find(id) != m_timed_out_transactions.end()) + { + // not clear if we should set that, since verifivation (sic) did not fail before, since + // the tx was accepted before timing out. + tvc.m_verifivation_failed = true; + return false; + } if(!check_inputs_types_supported(tx)) { @@ -315,6 +323,7 @@ namespace cryptonote { m_txs_by_fee.erase(sorted_it); } + m_timed_out_transactions.insert(it->first); auto pit = it++; m_transactions.erase(pit); }else -- cgit v1.2.3