diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 0b511f6b..86a8083e 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3331,9 +3331,9 @@ bool blockchain_storage::push_transaction_to_global_outs_index(const transaction { m_db_outputs.push_back_item(ot.amount, global_output_entry::construct(tx_id, i)); global_indexes.push_back(m_db_outputs.get_item_size(ot.amount) - 1); - if (ot.target.type() == typeid(txout_htlc) && !is_after_hardfork_2_zone()) + if (ot.target.type() == typeid(txout_htlc) && !is_after_hardfork_3_zone()) { - LOG_ERROR("Error: Transaction with txout_htlc before is_after_hardfork_2_zone(before height " << m_core_runtime_config.hard_fork_02_starts_after_height <<")"); + LOG_ERROR("Error: Transaction with txout_htlc before is_after_hardfork_3_zone(before height " << m_core_runtime_config.hard_fork_03_starts_after_height <<")"); return false; } } @@ -3849,9 +3849,9 @@ namespace currency } bool operator()(const txin_htlc& in) const { - if (!m_bcs.is_after_hardfork_2_zone()) + if (!m_bcs.is_after_hardfork_3_zone()) { - LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_2_zone(before height " << m_bcs.get_core_runtime_config().hard_fork_02_starts_after_height << ")"); + LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_3_zone(before height " << m_bcs.get_core_runtime_config().hard_fork_03_starts_after_height << ")"); return false; } return this->operator()(static_cast(in)); @@ -4272,9 +4272,9 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha } else if (txin.type() == typeid(txin_htlc)) { - if (!is_after_hardfork_2_zone()) + if (!is_after_hardfork_3_zone()) { - LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_2_zone(before height " << m_core_runtime_config.hard_fork_02_starts_after_height << ")"); + LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_3_zone(before height " << m_core_runtime_config.hard_fork_03_starts_after_height << ")"); return false; } @@ -4919,34 +4919,6 @@ void blockchain_storage::get_pos_mining_estimate(uint64_t amount_coins, estimate_result = current_amount; } //------------------------------------------------------------------ -// bool check_tx_fit_hardfork(const transaction& tx); - -/* -//------------------------------------------------------------------ -bool blockchain_storage::check_tx_fit_hardfork(const transaction& tx) -{ - //inputs - for (const auto in : tx.vin) - { - if (in.type() == typeid(txin_htlc)) - { - if (!is_after_hardfork_2_zone()) - return false; - } - } - //outputs - for (const auto out : tx.vout) - { - if (out.target.type() == typeid(txout_htlc)) - { - if (!is_after_hardfork_2_zone()) - return false; - } - } - return true; -} -*/ -//------------------------------------------------------------------ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id) const { uint64_t block_height = m_db_blocks.size(); @@ -4955,38 +4927,6 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti //------------------------------------------------------------------ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id, uint64_t block_height) const { -// if (block_height <= m_core_runtime_config.hard_fork_01_starts_after_height) -// { -// // before hardfork 1 -// -// for (const auto& el : tx.extra) -// { -// // etc_tx_details_unlock_time2 is not allowed in txs in blocks prior to hardfork 1 -// CHECK_AND_ASSERT_MES(el.type() != typeid(etc_tx_details_unlock_time2), false, "tx " << tx_id << " contains etc_tx_details_unlock_time2 which is not allowed on height " << block_height); -// } -// return true; -// } -// -// if (block_height <= m_core_runtime_config.hard_fork_02_starts_after_height) -// { -// // before hardfork 2 -// -// auto check_lambda = [&](const std::vector& container) -> bool -// { -// for (const auto& el : container) -// { -// const auto& type = el.type(); -// CHECK_AND_ASSERT_MES(type != typeid(tx_payer), false, "tx " << tx_id << " contains tx_payer which is not allowed on height " << block_height); -// CHECK_AND_ASSERT_MES(type != typeid(tx_receiver), false, "tx " << tx_id << " contains tx_receiver which is not allowed on height " << block_height); -// CHECK_AND_ASSERT_MES(type != typeid(extra_alias_entry), false, "tx " << tx_id << " contains extra_alias_entry which is not allowed on height " << block_height); -// } -// return true; -// }; -// -// return check_lambda(tx.extra) && check_lambda(tx.attachment); -// } - - auto is_allowed_before_hardfork2 = [&](const payload_items_v& el) -> bool { CHECK_AND_ASSERT_MES(el.type() != typeid(tx_payer), false, "tx " << tx_id << " contains tx_payer which is not allowed on height " << block_height); @@ -5003,13 +4943,14 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti bool var_is_after_hardfork_1_zone = is_after_hardfork_1_zone(block_height); bool var_is_after_hardfork_2_zone = is_after_hardfork_2_zone(block_height); + bool var_is_after_hardfork_3_zone = is_after_hardfork_3_zone(block_height); //inputs for (const auto in : tx.vin) { if (in.type() == typeid(txin_htlc)) { - if (!var_is_after_hardfork_2_zone) + if (!var_is_after_hardfork_3_zone) return false; } } @@ -5018,7 +4959,7 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti { if (out.target.type() == typeid(txout_htlc)) { - if (!var_is_after_hardfork_2_zone) + if (!var_is_after_hardfork_3_zone) return false; } } @@ -5805,6 +5746,11 @@ bool blockchain_storage::is_after_hardfork_2_zone()const return is_after_hardfork_2_zone(m_db_blocks.size()); } //------------------------------------------------------------------ +bool blockchain_storage::is_after_hardfork_3_zone()const +{ + return is_after_hardfork_3_zone(m_db_blocks.size()); +} +//------------------------------------------------------------------ bool blockchain_storage::is_after_hardfork_2_zone(uint64_t height)const { if (height > m_core_runtime_config.hard_fork_02_starts_after_height) @@ -5812,6 +5758,13 @@ bool blockchain_storage::is_after_hardfork_2_zone(uint64_t height)const return false; } //------------------------------------------------------------------ +bool blockchain_storage::is_after_hardfork_3_zone(uint64_t height)const +{ + if (height > m_core_runtime_config.hard_fork_03_starts_after_height) + return true; + return false; +} +//------------------------------------------------------------------ bool blockchain_storage::prevalidate_block(const block& bl) { if (bl.major_version == BLOCK_MAJOR_VERSION_INITAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height) @@ -5819,7 +5772,7 @@ bool blockchain_storage::prevalidate_block(const block& bl) if (bl.major_version == HF1_BLOCK_MAJOR_VERSION && get_block_height(bl) > m_core_runtime_config.hard_fork_01_starts_after_height - && get_block_height(bl) <= m_core_runtime_config.hard_fork_02_starts_after_height + && get_block_height(bl) <= m_core_runtime_config.hard_fork_03_starts_after_height ) { return true; @@ -5832,7 +5785,7 @@ bool blockchain_storage::prevalidate_block(const block& bl) return false; } - if (is_after_hardfork_2_zone() && bl.minor_version > CURRENT_BLOCK_MINOR_VERSION) + if (is_after_hardfork_3_zone() && bl.minor_version > CURRENT_BLOCK_MINOR_VERSION) { //this means that binary block is compatible, but semantics got changed due to hardfork, daemon should be updated LOG_PRINT_MAGENTA("Block's MINOR_VERSION is: " << bl.minor_version diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index d750fe59..5c3b995f 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -663,6 +663,8 @@ namespace currency bool is_after_hardfork_1_zone(uint64_t height)const; bool is_after_hardfork_2_zone()const; bool is_after_hardfork_2_zone(uint64_t height)const; + bool is_after_hardfork_3_zone()const; + bool is_after_hardfork_3_zone(uint64_t height)const; diff --git a/src/currency_core/core_runtime_config.h b/src/currency_core/core_runtime_config.h index 283d3efb..1f8302a5 100644 --- a/src/currency_core/core_runtime_config.h +++ b/src/currency_core/core_runtime_config.h @@ -24,6 +24,7 @@ namespace currency uint64_t hard_fork_01_starts_after_height; uint64_t hard_fork_02_starts_after_height; + uint64_t hard_fork_03_starts_after_height; static uint64_t _default_core_time_function() { @@ -42,6 +43,7 @@ namespace currency pc.hard_fork_01_starts_after_height = ZANO_HARDFORK_01_AFTER_HEIGHT; pc.hard_fork_02_starts_after_height = ZANO_HARDFORK_02_AFTER_HEIGHT; + pc.hard_fork_03_starts_after_height = ZANO_HARDFORK_03_AFTER_HEIGHT; 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 e7b9f2f6..28438f71 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -236,9 +236,11 @@ #ifndef TESTNET #define ZANO_HARDFORK_01_AFTER_HEIGHT 194624 #define ZANO_HARDFORK_02_AFTER_HEIGHT 999999 +#define ZANO_HARDFORK_03_AFTER_HEIGHT 100000000 #else #define ZANO_HARDFORK_01_AFTER_HEIGHT 1440 #define ZANO_HARDFORK_02_AFTER_HEIGHT 1800 +#define ZANO_HARDFORK_03_AFTER_HEIGHT 1801 #endif diff --git a/tests/core_tests/atomic_tests.cpp b/tests/core_tests/atomic_tests.cpp index 5fd46d84..3768cce7 100644 --- a/tests/core_tests/atomic_tests.cpp +++ b/tests/core_tests/atomic_tests.cpp @@ -73,7 +73,8 @@ bool atomic_base_test::configure_core(currency::core& c, size_t ev_index, const pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; //four blocks pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; //four blocks pc.hard_fork_01_starts_after_height = 10; - pc.hard_fork_02_starts_after_height = 12; + pc.hard_fork_02_starts_after_height = 11; + pc.hard_fork_03_starts_after_height = 12; c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 111b7f03..ff7b9762 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -54,6 +54,7 @@ test_generator::test_generator() , m_last_found_timestamp(0) , m_hardfork_01_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) , m_hardfork_02_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) + , m_hardfork_03_after_heigh(CURRENCY_MAX_BLOCK_NUMBER) { } @@ -63,6 +64,7 @@ void test_generator::set_hardfork_height(size_t hardfork_id, uint64_t h) { case 1: m_hardfork_01_after_heigh = h; break; case 2: m_hardfork_02_after_heigh = h; break; + case 3: m_hardfork_03_after_heigh = h; break; default: CHECK_AND_ASSERT_THROW_MES(false, "invalid hardfork id: " << hardfork_id) } } @@ -422,6 +424,7 @@ bool test_generator::build_wallets(const blockchain_vector& blocks, pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; pc.hard_fork_01_starts_after_height = m_hardfork_01_after_heigh; pc.hard_fork_02_starts_after_height = m_hardfork_02_after_heigh; + pc.hard_fork_03_starts_after_height = m_hardfork_03_after_heigh; wallets.back()->set_core_runtime_config(pc); } @@ -2075,6 +2078,7 @@ test_chain_unit_enchanced::test_chain_unit_enchanced() , m_unverifiable_tx_index(std::numeric_limits::max()) , m_hardfork_01_height(CURRENCY_MAX_BLOCK_NUMBER) , m_hardfork_02_height(CURRENCY_MAX_BLOCK_NUMBER) + , m_hardfork_03_height(CURRENCY_MAX_BLOCK_NUMBER) { REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, configure_core); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_tx); @@ -2097,6 +2101,7 @@ bool test_chain_unit_enchanced::configure_core(currency::core& c, size_t ev_inde pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; pc.hard_fork_01_starts_after_height = m_hardfork_01_height; pc.hard_fork_02_starts_after_height = m_hardfork_02_height; + pc.hard_fork_03_starts_after_height = m_hardfork_03_height; c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index f6b8385b..bcb04550 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -324,6 +324,7 @@ protected: uint64_t m_hardfork_01_height; uint64_t m_hardfork_02_height; + uint64_t m_hardfork_03_height; }; struct wallet_test_core_proxy; @@ -536,6 +537,7 @@ private: uint64_t m_hardfork_01_after_heigh; uint64_t m_hardfork_02_after_heigh; + uint64_t m_hardfork_03_after_heigh; std::unordered_map m_blocks_info; static test_gentime_settings m_test_gentime_settings; diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index 2b58530e..fcff78a2 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -18,6 +18,7 @@ hard_fork_2_base_test::hard_fork_2_base_test(size_t hardfork_02_height) hard_fork_2_base_test::hard_fork_2_base_test(size_t hardfork_01_height, size_t hardfork_02_height) : m_hardfork_01_height(hardfork_01_height) , m_hardfork_02_height(hardfork_02_height) + , m_hardfork_03_height(CURRENCY_MAX_BLOCK_NUMBER) { REGISTER_CALLBACK_METHOD(hard_fork_2_base_test, configure_core); } @@ -29,6 +30,7 @@ bool hard_fork_2_base_test::configure_core(currency::core& c, size_t ev_index, c pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; pc.hard_fork_01_starts_after_height = m_hardfork_01_height; pc.hard_fork_02_starts_after_height = m_hardfork_02_height; + pc.hard_fork_03_starts_after_height = m_hardfork_03_height; c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/hard_fork_2.h b/tests/core_tests/hard_fork_2.h index 54721651..bcca582e 100644 --- a/tests/core_tests/hard_fork_2.h +++ b/tests/core_tests/hard_fork_2.h @@ -17,6 +17,7 @@ struct hard_fork_2_base_test : virtual public test_chain_unit_enchanced size_t m_hardfork_01_height; size_t m_hardfork_02_height; + size_t m_hardfork_03_height; }; struct hard_fork_2_tx_payer_in_wallet : public wallet_test, public hard_fork_2_base_test