From 921b447b0279b2a70124e891fa64ca3ff1679f1a Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 21 Mar 2024 10:48:11 +0100 Subject: [PATCH 1/3] p2p: block old clients (<2.x) on in and out conn + build version bump to 280 --- src/common/util.cpp | 8 ++------ src/p2p/net_node.inl | 2 +- src/version.h.in | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/common/util.cpp b/src/common/util.cpp index f5d4baa9..1fdbe537 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -684,12 +684,8 @@ std::string get_nix_version_display_string() // got v_major, v_minor, v_revision - // allow 1.1.x and greater - - if (v_major < 1) - return false; - - if (v_major == 1 && v_minor < 1) + // allow 2.x and greater + if (v_major < 2) return false; return true; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 22c2e457..46a39ee5 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -525,7 +525,7 @@ namespace nodetool if (!tools::check_remote_client_version(rsp.payload_data.client_version)) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong client version: " << rsp.payload_data.client_version << ", closing connection."); + LOG_PRINT_CC_YELLOW(context, "COMMAND_HANDSHAKE Failed, wrong client version: " << rsp.payload_data.client_version << ", closing connection.", LOG_LEVEL_1); return; } diff --git a/src/version.h.in b/src/version.h.in index 997c9452..c6196432 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 272 +#define PROJECT_VERSION_BUILD_NO 280 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From e11ee0fa073c28027c1575193800e0cb29b5f5fb Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 21 Mar 2024 19:52:18 +0100 Subject: [PATCH 2/3] tx_pool: remove HF4-incompatible txs on load --- src/currency_core/currency_core.cpp | 2 ++ src/currency_core/tx_pool.cpp | 21 +++++++++++++++++++++ src/currency_core/tx_pool.h | 2 ++ src/version.h.in | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/currency_core/currency_core.cpp b/src/currency_core/currency_core.cpp index 876c2d17..7658f4da 100644 --- a/src/currency_core/currency_core.cpp +++ b/src/currency_core/currency_core.cpp @@ -163,6 +163,8 @@ namespace currency r = m_blockchain_storage.init(m_config_folder, vm); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); + m_mempool.remove_incompatible_txs(); + r = m_miner.init(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize miner"); diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 94a69124..3acf108c 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -1293,6 +1293,27 @@ namespace currency return true; } //--------------------------------------------------------------------------------- + void tx_memory_pool::remove_incompatible_txs() + { + std::vector invalid_tx_ids; + + m_db_transactions.enumerate_items([&](uint64_t i, const crypto::hash& h, const tx_details &tx_entry) + { + if (!m_blockchain.validate_tx_for_hardfork_specific_terms(tx_entry.tx, h)) + invalid_tx_ids.push_back(h); + return true; + }); + + for(const auto& id : invalid_tx_ids) + { + transaction tx{}; + size_t blob_size = 0; + uint64_t fee = 0; + take_tx(id, tx, blob_size, fee); + LOG_PRINT_L0("tx " << id << " was incompatible with the hardfork rules and removed"); + } + } + //--------------------------------------------------------------------------------- bool tx_memory_pool::load_keyimages_cache() { CRITICAL_REGION_LOCAL(m_key_images_lock); diff --git a/src/currency_core/tx_pool.h b/src/currency_core/tx_pool.h index 4ede52a2..92d60604 100644 --- a/src/currency_core/tx_pool.h +++ b/src/currency_core/tx_pool.h @@ -138,6 +138,8 @@ namespace currency bool remove_stuck_transactions(); // made public to be called from coretests + void remove_incompatible_txs(); // made public to be called after the BCS is loaded and hardfork info is ready + private: bool on_tx_add(crypto::hash tx_id, const transaction& tx, bool kept_by_block); bool on_tx_remove(const crypto::hash &tx_id, const transaction& tx, bool kept_by_block); diff --git a/src/version.h.in b/src/version.h.in index c6196432..6bfc64f8 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 280 +#define PROJECT_VERSION_BUILD_NO 282 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 09d08baeccce2d6c00cbaf4c29d3c45ef0dccd58 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 21 Mar 2024 23:01:33 +0100 Subject: [PATCH 3/3] fixed consensus bug related to miners motivations to include transactions --- src/currency_core/blockchain_storage.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 17ed1fbd..ec98bea6 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2089,7 +2089,14 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ main_chain_bei.this_block_tx_fee_median * main_chain_bei.bl.tx_hashes.size()) { //with the rest equal, alt block has more fees in it, prefer it + LOG_PRINT_L1("[is_reorganize_required]:TRUE, \"by order of tx_hashes.size()\" main_stake_hash:" << &main_chain_bei.stake_hash << ", alt_stake_hash" << proof_alt); return true; + }else if (alt_chain_bei.this_block_tx_fee_median * alt_chain_bei.bl.tx_hashes.size() < + main_chain_bei.this_block_tx_fee_median * main_chain_bei.bl.tx_hashes.size()) + { + //with the rest equal, alt block has more fees in it, prefer it + LOG_PRINT_L1("[is_reorganize_required]:FALSE, \"by order of tx_hashes.size()\" main_stake_hash:" << &main_chain_bei.stake_hash << ", alt_stake_hash" << proof_alt); + return false; } } if (!is_pos_block(main_chain_bei.bl))