From 240054a7f8e42057e6912f5b399a08f8f63120a0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 23 Feb 2017 20:11:57 +0000 Subject: [PATCH 1/2] core: remove a couple unused/obsolete bits --- src/cryptonote_core/cryptonote_core.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 114e8393e..44b97fa93 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -818,7 +818,6 @@ namespace cryptonote epee::math_helper::once_a_time_seconds<60*2, false> m_txpool_auto_relayer; //!< interval for checking re-relaying txpool transactions epee::math_helper::once_a_time_seconds<60*60*12, true> m_check_updates_interval; //!< interval for checking for new versions - friend class tx_validate_inputs; std::atomic m_starter_message_showed; //!< has the "daemon will sync now" message been shown? uint64_t m_target_blockchain_height; //!< blockchain height target @@ -833,8 +832,6 @@ namespace cryptonote std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once - boost::interprocess::file_lock db_lock; //!< a lock object for a file lock in the db directory - size_t block_sync_size; time_t start_time; From 9effa55311a97aeb3f9bcbb8eeec4d8daac0d632 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 23 Feb 2017 20:15:52 +0000 Subject: [PATCH 2/2] core: bound the amount of entries in bad tx semantics cache This is to prevent unbounded memory use. Since I don't think there is a container that has quick insert, quick lookup, and automatic FIFO, I use two and swap every N, clearing the oldest one. --- src/cryptonote_core/cryptonote_core.cpp | 20 +++++++++++++++----- src/cryptonote_core/cryptonote_core.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 98c53890e..cfe3b5441 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -60,6 +60,8 @@ DISABLE_VS_WARNINGS(4355) #define MERROR_VER(x) MCERROR("verify", x) +#define BAD_SEMANTICS_TXES_MAX_SIZE 100 + namespace cryptonote { @@ -496,11 +498,14 @@ namespace cryptonote } //std::cout << "!"<< tx.vin.size() << std::endl; - if (bad_semantics_txes.find(tx_hash) != bad_semantics_txes.end()) + for (int idx = 0; idx < 2; ++idx) { - LOG_PRINT_L1("Transaction already seen with bad semantics, rejected"); - tvc.m_verifivation_failed = true; - return false; + if (bad_semantics_txes[idx].find(tx_hash) != bad_semantics_txes[idx].end()) + { + LOG_PRINT_L1("Transaction already seen with bad semantics, rejected"); + tvc.m_verifivation_failed = true; + return false; + } } uint8_t version = m_blockchain_storage.get_current_hard_fork_version(); @@ -551,8 +556,13 @@ namespace cryptonote if(!check_tx_semantic(tx, keeped_by_block)) { LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to check tx " << tx_hash << " semantic, rejected"); - bad_semantics_txes.insert(tx_hash); tvc.m_verifivation_failed = true; + bad_semantics_txes[0].insert(tx_hash); + if (bad_semantics_txes[0].size() >= BAD_SEMANTICS_TXES_MAX_SIZE) + { + std::swap(bad_semantics_txes[0], bad_semantics_txes[1]); + bad_semantics_txes[0].clear(); + } return false; } diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 44b97fa93..7323bef29 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -836,7 +836,7 @@ namespace cryptonote time_t start_time; - std::unordered_set bad_semantics_txes; + std::unordered_set bad_semantics_txes[2]; enum { UPDATES_DISABLED,