From 4c860417f5eb3db2a6bb681881bff35396d06c86 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 14 Feb 2025 03:17:33 +0100 Subject: [PATCH] pre hardfork tx freeze period implemented (+HF6) --- src/currency_core/blockchain_storage.cpp | 17 +++++++++++++++++ src/currency_core/blockchain_storage.h | 1 + src/currency_core/core_runtime_config.h | 5 ++++- src/currency_core/currency_config.h | 16 ++++++++++++++-- src/currency_core/currency_core.h | 1 + 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 01074e2c..65c0bb1d 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1029,7 +1029,24 @@ bool blockchain_storage::is_tx_related_to_altblock(crypto::hash tx_id) const auto it = m_alternative_chains_txs.find(tx_id); return it != m_alternative_chains_txs.end(); } +//------------------------------------------------------------------ +bool blockchain_storage::is_pre_hardfork_tx_freeze_period_active() const +{ + CRITICAL_REGION_LOCAL(m_read_lock); + if (!is_hardfork_active(ZANO_HARDFORK_05)) + return false; + uint64_t next_block_height = m_db_blocks.size(); // top block height + 1 + size_t current_hardfork_id = m_core_runtime_config.hard_forks.get_the_most_recent_hardfork_id_for_height(next_block_height); + size_t next_hardfork_id = current_hardfork_id + 1; + if (next_hardfork_id >= ZANO_HARDFORKS_TOTAL) + return false; + + uint64_t next_hf_height_active_after = m_core_runtime_config.hard_forks.m_height_the_hardfork_n_active_after[next_hardfork_id]; + + bool result = (next_block_height + m_core_runtime_config.pre_hardfork_tx_freeze_period > next_hf_height_active_after); + return result; +} //------------------------------------------------------------------ bool blockchain_storage::get_block_extended_info_by_hash(const crypto::hash &h, block_extended_info &blk) const { diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 5ebc328c..c98e86eb 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -240,6 +240,7 @@ namespace currency bool get_block_by_height(uint64_t h, block &blk) const; bool is_tx_related_to_altblock(crypto::hash tx_id) const; //void get_all_known_block_ids(std::list &main, std::list &alt, std::list &invalid) const; + bool is_pre_hardfork_tx_freeze_period_active() const; bc_attachment_services_manager& get_attachment_services_manager(){ return m_services_mgr; } diff --git a/src/currency_core/core_runtime_config.h b/src/currency_core/core_runtime_config.h index 799ba0f9..0ed52890 100644 --- a/src/currency_core/core_runtime_config.h +++ b/src/currency_core/core_runtime_config.h @@ -107,6 +107,7 @@ namespace currency core_time_func_t get_core_time; uint64_t hf4_minimum_mixins; wide_difficulty_type max_pos_difficulty; + uint64_t pre_hardfork_tx_freeze_period; // number of blocks before the hardfork activatio when no new txs are accepted (effective from HF5); 0 means feature is switched off hard_forks_descriptor hard_forks; std::array min_build_numbers_for_hard_forks; @@ -137,6 +138,7 @@ namespace currency pc.max_alt_blocks = CURRENCY_ALT_BLOCK_MAX_COUNT; pc.hf4_minimum_mixins = CURRENCY_HF4_MANDATORY_DECOY_SET_SIZE; pc.max_pos_difficulty = wide_difficulty_type(POS_MAX_DIFFICULTY_ALLOWED); + pc.pre_hardfork_tx_freeze_period = CURRENCY_PRE_HARDFORK_TX_FREEZE_PERIOD; // TODO: refactor the following pc.hard_forks.set_hardfork_height(1, ZANO_HARDFORK_01_AFTER_HEIGHT); @@ -144,7 +146,8 @@ namespace currency pc.hard_forks.set_hardfork_height(3, ZANO_HARDFORK_03_AFTER_HEIGHT); pc.hard_forks.set_hardfork_height(4, ZANO_HARDFORK_04_AFTER_HEIGHT); pc.hard_forks.set_hardfork_height(5, ZANO_HARDFORK_05_AFTER_HEIGHT); pc.min_build_numbers_for_hard_forks[5] = ZANO_HARDFORK_05_MIN_BUILD_VER; - static_assert(5 + 1 == ZANO_HARDFORKS_TOTAL); + pc.hard_forks.set_hardfork_height(6, ZANO_HARDFORK_06_AFTER_HEIGHT); pc.min_build_numbers_for_hard_forks[6] = ZANO_HARDFORK_06_MIN_BUILD_VER; + static_assert(6 + 1 == ZANO_HARDFORKS_TOTAL); pc.get_core_time = &core_runtime_config::_default_core_time_function; bool r = epee::string_tools::hex_to_pod(ALIAS_SHORT_NAMES_VALIDATION_PUB_KEY, pc.alias_validation_pubkey); diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 06ce2813..6efa5517 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -41,6 +41,7 @@ #define CURRENCY_DEFAULT_DECOY_SET_SIZE 10 #define CURRENCY_HF4_MANDATORY_DECOY_SET_SIZE 15 #define CURRENCY_HF4_MANDATORY_MIN_COINAGE 10 +#define CURRENCY_PRE_HARDFORK_TX_FREEZE_PERIOD 60 // number of blocks before the hardfork activation when no new txs are accepted (effective from HF5) #define CURRENT_BLOCK_MINOR_VERSION 0 #define CURRENCY_BLOCK_FUTURE_TIME_LIMIT 60*60*2 @@ -269,19 +270,29 @@ #define ZANO_HARDFORK_01_AFTER_HEIGHT 194624 // 2019-09-21 20:25:16 #define ZANO_HARDFORK_02_AFTER_HEIGHT 999999 // 2021-04-05 09:11:45 #define ZANO_HARDFORK_03_AFTER_HEIGHT 1082577 // 2021-06-01 23:28:10 + #define ZANO_HARDFORK_04_AFTER_HEIGHT 2555000 // 2024-03-21 11:49:55 #define ZANO_HARDFORK_04_TIMESTAMP_ACTUAL 1711021795ull // block 2555000, 2024-03-21 11:49:55 UTC + #define ZANO_HARDFORK_05_AFTER_HEIGHT 999999999999999999 -#define ZANO_HARDFORK_05_MIN_BUILD_VER 354 +#define ZANO_HARDFORK_05_MIN_BUILD_VER 380 + +#define ZANO_HARDFORK_06_AFTER_HEIGHT 999999999999999999 +#define ZANO_HARDFORK_06_MIN_BUILD_VER 380 #else // Testnet #define ZANO_HARDFORK_01_AFTER_HEIGHT 0 #define ZANO_HARDFORK_02_AFTER_HEIGHT 0 #define ZANO_HARDFORK_03_AFTER_HEIGHT 0 + #define ZANO_HARDFORK_04_AFTER_HEIGHT 100 #define ZANO_HARDFORK_04_TIMESTAMP_ACTUAL 1738659600ull // block 100, 2025-00-00 00:00:00 UTC + #define ZANO_HARDFORK_05_AFTER_HEIGHT 200 #define ZANO_HARDFORK_05_MIN_BUILD_VER 379 + +#define ZANO_HARDFORK_06_AFTER_HEIGHT 999999999999999999 +#define ZANO_HARDFORK_06_MIN_BUILD_VER 379 #endif @@ -291,7 +302,8 @@ #define ZANO_HARDFORK_03 3 #define ZANO_HARDFORK_04_ZARCANUM 4 #define ZANO_HARDFORK_05 5 -#define ZANO_HARDFORKS_TOTAL 6 +#define ZANO_HARDFORK_06 6 +#define ZANO_HARDFORKS_TOTAL 7 diff --git a/src/currency_core/currency_core.h b/src/currency_core/currency_core.h index 637103b1..3da70452 100644 --- a/src/currency_core/currency_core.h +++ b/src/currency_core/currency_core.h @@ -107,6 +107,7 @@ namespace currency void resume_mine(); blockchain_storage& get_blockchain_storage() { return m_blockchain_storage; } const blockchain_storage& get_blockchain_storage() const { return m_blockchain_storage; } + const core_runtime_config& get_runtime_config() const { return m_blockchain_storage.get_core_runtime_config(); } //debug functions void print_blockchain(uint64_t start_index, uint64_t end_index); void print_blockchain_index();