From 456588ddc3455c8811d0c5deb1d2e9554451f792 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 26 May 2022 16:53:40 +0200 Subject: [PATCH] hardfork-related structures global refactoring --- src/currency_core/blockchain_storage.cpp | 91 +++++++------------ src/currency_core/blockchain_storage.h | 11 +-- src/currency_core/core_runtime_config.h | 67 ++++++++++---- src/currency_core/currency_core.cpp | 15 ++- src/currency_core/currency_format_utils.cpp | 2 +- src/currency_core/currency_format_utils.h | 4 +- src/wallet/wallet2.cpp | 4 +- tests/core_tests/alias_tests.cpp | 4 +- tests/core_tests/atomic_tests.cpp | 19 ++-- tests/core_tests/block_validation.cpp | 18 ++-- tests/core_tests/block_validation.h | 5 +- tests/core_tests/chaingen.cpp | 40 +++----- tests/core_tests/chaingen.h | 9 +- tests/core_tests/chaingen_helpers.h | 3 +- tests/core_tests/checkpoints_tests.cpp | 2 - tests/core_tests/hard_fork_1.cpp | 2 +- .../core_tests/hard_fork_1_bad_pos_source.cpp | 2 +- .../core_tests/hard_fork_1_consensus_test.cpp | 2 +- .../hard_fork_1_locked_pos_test.cpp | 2 +- tests/core_tests/hard_fork_2.cpp | 6 +- tests/core_tests/tx_validation.cpp | 8 +- tests/core_tests/wallet_rpc_tests.cpp | 6 +- tests/core_tests/wallet_tests.cpp | 12 +-- 23 files changed, 160 insertions(+), 174 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 81c3a0e2..a3e2e736 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1147,7 +1147,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con wide_difficulty_type& dif = pos ? m_cached_next_pos_difficulty : m_cached_next_pow_difficulty; TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks); TIME_MEASURE_START_PD(target_calculating_calc); - if (m_db_blocks.size() > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (m_core_runtime_config.is_hardfork_active_for_height(1, m_db_blocks.size())) { dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); } @@ -1186,7 +1186,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co enum_blockchain(cb, alt_chain, split_height); wide_difficulty_type diff = 0; - if(abei.height > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if(m_core_runtime_config.is_hardfork_active_for_height(1, abei.height)) diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); else diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET); @@ -1266,7 +1266,7 @@ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t CHECK_AND_ASSERT_MES(b.miner_tx.vin[1].type() == typeid(txin_to_key), false, "coinstake transaction in the block has the wrong type"); } - if (height > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (m_core_runtime_config.is_hardfork_active_for_height(1, height)) { // new rules that allow different unlock time in coinbase outputs uint64_t max_unlock_time = 0; @@ -1286,7 +1286,8 @@ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t bool r = get_tx_max_min_unlock_time(b.miner_tx, max_unlock_time, min_unlock_time); CHECK_AND_ASSERT_MES(r && max_unlock_time == min_unlock_time && min_unlock_time == height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW, false, - "coinbase transaction has wrong min_unlock_time: " << min_unlock_time << ", expected: " << height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + "coinbase transaction has wrong min_unlock_time: " << min_unlock_time << " or max_unlock_time: " << max_unlock_time << + ", expected: " << height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW); } @@ -1437,9 +1438,9 @@ bool blockchain_storage::create_block_template(const create_block_template_param boost::multiprecision::uint128_t already_generated_coins; CRITICAL_REGION_BEGIN(m_read_lock); height = m_db_blocks.size(); - if(height <= m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if(!m_core_runtime_config.is_hardfork_active_for_height(1, height)) b.major_version = BLOCK_MAJOR_VERSION_INITIAL; - else if(height <= m_core_runtime_config.hard_forks.hard_fork_03_starts_after_height) + else if(!m_core_runtime_config.is_hardfork_active_for_height(3, height)) b.major_version = HF1_BLOCK_MAJOR_VERSION; else b.major_version = CURRENT_BLOCK_MAJOR_VERSION; @@ -1836,7 +1837,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: if (abei.height >= m_core_runtime_config.pos_minimum_heigh) cumulative_diff_delta = correct_difficulty_with_sequence_factor(sequence_factor, cumulative_diff_delta); - if (abei.height > BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION && abei.height <= m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height && pos_block && sequence_factor > BLOCK_POS_STRICT_SEQUENCE_LIMIT) + if (abei.height > BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION && !m_core_runtime_config.is_hardfork_active_for_height(1, abei.height) && pos_block && sequence_factor > BLOCK_POS_STRICT_SEQUENCE_LIMIT) { LOG_PRINT_RED_L0("Alternative block " << id << " @ " << abei.height << " has too big sequence factor: " << sequence_factor << ", rejected"); bvc.m_verification_failed = true; @@ -1961,9 +1962,9 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ const block_extended_info& alt_chain_bei = alt_chain.back()->second; const block_extended_info& connection_point = alt_chain.front()->second; - if (connection_point.height <= m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (!m_core_runtime_config.is_hardfork_active_for_height(1, connection_point.height)) { - //use pre-hard fork, old-style comparing + //use pre-hard fork #1, old-style comparing if (main_chain_bei.cumulative_diff_adjusted < alt_chain_bei.cumulative_diff_adjusted) return true; else if (main_chain_bei.cumulative_diff_adjusted > alt_chain_bei.cumulative_diff_adjusted) @@ -1982,7 +1983,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ return true; } } - else if (alt_chain_bei.height > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + else if (m_core_runtime_config.is_hardfork_active_for_height(1, alt_chain_bei.height)) { //new rules, applied after HARD_FORK_1 //to learn this algo please read https://github.com/hyle-team/docs/blob/master/zano/PoS_Analysis_and_improvements_proposal.pdf @@ -3335,9 +3336,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_3_zone()) + if (ot.target.type() == typeid(txout_htlc) && !is_hardfork_active(3)) { - LOG_ERROR("Error: Transaction with txout_htlc before is_after_hardfork_3_zone(before height " << m_core_runtime_config.hard_forks.hard_fork_03_starts_after_height <<")"); + LOG_ERROR("Error: Transaction with txout_htlc before hardfork 3 (before height " << m_core_runtime_config.hard_forks.get_str_height_the_hardfork_active_after(3) <<")"); return false; } } @@ -3856,9 +3857,9 @@ namespace currency } bool operator()(const txin_htlc& in) const { - if (!m_bcs.is_after_hardfork_3_zone()) + if (!m_bcs.is_hardfork_active(3)) { - LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_3_zone(before height " << m_bcs.get_core_runtime_config().hard_forks.hard_fork_03_starts_after_height << ")"); + LOG_ERROR("Error: Transaction with txin_htlc before hardfork 3 (before height " << m_bcs.get_core_runtime_config().hard_forks.get_str_height_the_hardfork_active_after(3) << ")"); return false; } return this->operator()(static_cast(in)); @@ -4286,9 +4287,9 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha } else if (txin.type() == typeid(txin_htlc)) { - if (!is_after_hardfork_3_zone()) + if (!is_hardfork_active(3)) { - LOG_ERROR("Error: Transaction with txin_htlc before is_after_hardfork_3_zone(before height " << m_core_runtime_config.hard_forks.hard_fork_03_starts_after_height << ")"); + LOG_ERROR("Error: Transaction with txin_htlc before hardfork 3 (before height " << m_core_runtime_config.hard_forks.get_str_height_the_hardfork_active_after(3) << ")"); return false; } @@ -4955,9 +4956,9 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti return true; }; - 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); + bool var_is_after_hardfork_1_zone = m_core_runtime_config.is_hardfork_active_for_height(1, block_height); + bool var_is_after_hardfork_2_zone = m_core_runtime_config.is_hardfork_active_for_height(2, block_height); + bool var_is_after_hardfork_3_zone = m_core_runtime_config.is_hardfork_active_for_height(3, block_height); //inputs for (const auto in : tx.vin) @@ -5010,11 +5011,13 @@ bool blockchain_storage::validate_pos_coinbase_outs_unlock_time(const transactio return true; } - CHECK_AND_ASSERT_MES(get_block_height(miner_tx) > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height, false, "error in block [" << get_block_height(miner_tx) << "] etc_tx_details_unlock_time2 can exist only after hard fork point : " << m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height); + uint64_t block_height = get_block_height(miner_tx); + CHECK_AND_ASSERT_MES(m_core_runtime_config.is_hardfork_active_for_height(1, block_height), false, "error in block [" << block_height << "]: etc_tx_details_unlock_time was not found but etc_tx_details_unlock_time2 can exist only after hard fork 1 at height " << m_core_runtime_config.hard_forks.get_str_height_the_hardfork_active_after(1)); //etc_tx_details_unlock_time2 can be kept only after hard_fork_1 point etc_tx_details_unlock_time2 ut2 = AUTO_VAL_INIT(ut2); - get_type_in_variant_container(miner_tx.extra, ut2); + bool found = get_type_in_variant_container(miner_tx.extra, ut2); + CHECK_AND_ASSERT_MES(found, false, "etc_tx_details_unlock_time2 was not found in tx extra"); CHECK_AND_ASSERT_MES(ut2.unlock_time_array.size() == miner_tx.vout.size(), false, "ut2.unlock_time_array.size()<" << ut2.unlock_time_array.size() << "> != miner_tx.vout.size()<" << miner_tx.vout.size() << ">"); @@ -5116,7 +5119,7 @@ bool blockchain_storage::validate_pos_block(const block& b, r = check_tx_input(b.miner_tx, 1, coinstake_in, id, b.miner_tx.signatures[0], max_related_block_height, source_max_unlock_time_for_pos_coinbase); CHECK_AND_ASSERT_MES(r, false, "Failed to validate coinstake input in miner tx, block_id = " << get_block_hash(b)); - if (get_block_height(b) > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (m_core_runtime_config.is_hardfork_active_for_height(1, get_block_height(b))) { uint64_t last_pow_h = get_last_x_block_height(false); CHECK_AND_ASSERT_MES(max_related_block_height <= last_pow_h, false, "Failed to validate coinbase in PoS block, condition failed: max_related_block_height(" << max_related_block_height << ") <= last_pow_h(" << last_pow_h << ")"); @@ -5744,53 +5747,23 @@ bool blockchain_storage::update_next_comulative_size_limit() return true; } //------------------------------------------------------------------ -bool blockchain_storage::is_after_hardfork_1_zone()const +bool blockchain_storage::is_hardfork_active(size_t hardfork_id) const { - return is_after_hardfork_1_zone(m_db_blocks.size()); -} -//------------------------------------------------------------------ -bool blockchain_storage::is_after_hardfork_1_zone(uint64_t height)const -{ - if (height > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) - return true; - return false; -} -//------------------------------------------------------------------ -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_forks.hard_fork_02_starts_after_height) - return true; - return false; -} -//------------------------------------------------------------------ -bool blockchain_storage::is_after_hardfork_3_zone(uint64_t height)const -{ - if (height > m_core_runtime_config.hard_forks.hard_fork_03_starts_after_height) - return true; - return false; + return m_core_runtime_config.is_hardfork_active_for_height(hardfork_id, m_db_blocks.size()); // note using m_db_blocks.size() ( == top_block_height + 1 ) } //------------------------------------------------------------------ bool blockchain_storage::prevalidate_block(const block& bl) { + uint64_t block_height = get_block_height(bl); + //before hard_fork1 - if (bl.major_version == BLOCK_MAJOR_VERSION_INITIAL && get_block_height(bl) <= m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (bl.major_version == BLOCK_MAJOR_VERSION_INITIAL && !m_core_runtime_config.is_hardfork_active_for_height(1, block_height)) return true; //after hard_fork1 and before hard_fork3 - if ( get_block_height(bl) > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height && - get_block_height(bl) <= m_core_runtime_config.hard_forks.hard_fork_03_starts_after_height - ) + if ( m_core_runtime_config.is_hardfork_active_for_height(1, block_height) && + !m_core_runtime_config.is_hardfork_active_for_height(3, block_height)) { if (bl.major_version <= HF1_BLOCK_MAJOR_VERSION ) return true; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 67a649a0..5f7dcffd 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -661,14 +661,9 @@ namespace currency bool is_output_allowed_for_input(const output_key_or_htlc_v& out_v, const txin_v& in_v, uint64_t top_minus_source_height)const; bool is_output_allowed_for_input(const txout_to_key& out_v, const txin_v& in_v)const; bool is_output_allowed_for_input(const txout_htlc& out_v, const txin_v& in_v, uint64_t top_minus_source_height)const; - bool is_after_hardfork_1_zone()const; - 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; -// bool is_after_hardfork_4_zone()const; -// bool is_after_hardfork_4_zone(uint64_t height)const; + + // returns true as soon as the hardfork is active for the NEXT upcoming block (not for the top block in the blockchain storage) + bool is_hardfork_active(size_t hardfork_id) const; diff --git a/src/currency_core/core_runtime_config.h b/src/currency_core/core_runtime_config.h index 214a1590..310f697f 100644 --- a/src/currency_core/core_runtime_config.h +++ b/src/currency_core/core_runtime_config.h @@ -10,16 +10,52 @@ namespace currency { - typedef uint64_t (*core_time_func_t)(); - struct hard_forks_descriptor { - uint64_t hard_fork_01_starts_after_height = 0; - uint64_t hard_fork_02_starts_after_height = 0; - uint64_t hard_fork_03_starts_after_height = 0; - uint64_t hard_fork_04_starts_after_height = UINT64_MAX; + constexpr static size_t m_total_count = 5; + std::array m_height_the_hardfork_n_active_after; + + hard_forks_descriptor() + { + m_height_the_hardfork_n_active_after.fill(CURRENCY_MAX_BLOCK_NUMBER); + } + + void set_hardfork_height(size_t hardfork_id, uint64_t height_the_hardfork_is_active_after) + { + CHECK_AND_ASSERT_THROW_MES(hardfork_id < m_total_count, "invalid hardfork id: " << hardfork_id); + m_height_the_hardfork_n_active_after[hardfork_id] = height_the_hardfork_is_active_after; + } + + bool is_hardfork_active_for_height(size_t hardfork_id, uint64_t height) const + { + if (hardfork_id == 0) + return true; // hardfork #0 is a special case that is considered always active + CHECK_AND_ASSERT_THROW_MES(hardfork_id < m_total_count, "invalid hardfork id: " << hardfork_id); + return height > m_height_the_hardfork_n_active_after[hardfork_id]; + } + + std::string get_str_height_the_hardfork_active_after(size_t hardfork_id) const + { + if (hardfork_id == 0) + return "0"; // hardfork #0 is a special case that is considered always active + CHECK_AND_ASSERT_THROW_MES(hardfork_id < m_total_count, "invalid hardfork id: " << hardfork_id); + return epee::string_tools::num_to_string_fast(m_height_the_hardfork_n_active_after[hardfork_id]); + } + + size_t get_the_most_recent_hardfork_id_for_height(uint64_t height) const + { + for(size_t hid = m_total_count - 1; hid != 0; --hid) // 0 is not including + { + if(is_hardfork_active_for_height(hid, height)) + return hid; + } + return 0; + } }; + + typedef uint64_t (*core_time_func_t)(); + struct core_runtime_config { uint64_t min_coinstake_age; @@ -34,15 +70,7 @@ namespace currency bool is_hardfork_active_for_height(size_t hardfork_id, uint64_t height) const { - switch (hardfork_id) - { - case 0: return true; - case 1: return height > hard_forks.hard_fork_01_starts_after_height; - case 2: return height > hard_forks.hard_fork_02_starts_after_height; - case 3: return height > hard_forks.hard_fork_03_starts_after_height; - case 4: return height > hard_forks.hard_fork_04_starts_after_height; - default: return false; - } + return hard_forks.is_hardfork_active_for_height(hardfork_id, height); } static uint64_t _default_core_time_function() @@ -60,10 +88,11 @@ namespace currency pc.tx_default_fee = TX_DEFAULT_FEE; pc.max_alt_blocks = CURRENCY_ALT_BLOCK_MAX_COUNT; - pc.hard_forks.hard_fork_01_starts_after_height = ZANO_HARDFORK_01_AFTER_HEIGHT; - pc.hard_forks.hard_fork_02_starts_after_height = ZANO_HARDFORK_02_AFTER_HEIGHT; - pc.hard_forks.hard_fork_03_starts_after_height = ZANO_HARDFORK_03_AFTER_HEIGHT; - pc.hard_forks.hard_fork_04_starts_after_height = ZANO_HARDFORK_04_AFTER_HEIGHT; + // TODO: refactor the following + pc.hard_forks.set_hardfork_height(1, ZANO_HARDFORK_01_AFTER_HEIGHT); + pc.hard_forks.set_hardfork_height(2, ZANO_HARDFORK_02_AFTER_HEIGHT); + 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.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_core.cpp b/src/currency_core/currency_core.cpp index 0f526c7a..b4c3d25c 100644 --- a/src/currency_core/currency_core.cpp +++ b/src/currency_core/currency_core.cpp @@ -508,11 +508,16 @@ namespace currency if (r && bvc.m_added_to_main_chain) { uint64_t h = get_block_height(b); - auto& crc = m_blockchain_storage.get_core_runtime_config(); - if (h == crc.hard_forks.hard_fork_01_starts_after_height + 1) - { LOG_PRINT_GREEN("Hardfork 1 activated at height " << h, LOG_LEVEL_0); } - else if (h == crc.hard_forks.hard_fork_02_starts_after_height + 1) - { LOG_PRINT_GREEN("Hardfork 2 activated at height " << h, LOG_LEVEL_0); } + if (h > 0) + { + auto& crc = m_blockchain_storage.get_core_runtime_config(); + size_t hardfork_id_for_prev_block = crc.hard_forks.get_the_most_recent_hardfork_id_for_height(h - 1); + size_t hardfork_id_for_curr_block = crc.hard_forks.get_the_most_recent_hardfork_id_for_height(h); + if (hardfork_id_for_prev_block != hardfork_id_for_curr_block) + { + LOG_PRINT_GREEN("Hardfork " << hardfork_id_for_curr_block << " activated at height " << h, LOG_LEVEL_0); + } + } if (h == m_stop_after_height) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index fabca75d..588d4013 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1573,7 +1573,7 @@ namespace currency //--------------------------------------------------------------- uint64_t get_tx_version(uint64_t h, const hard_forks_descriptor& hfd) { - if (h <= hfd.hard_fork_04_starts_after_height) + if (!hfd.is_hardfork_active_for_height(4, h)) { return TRANSACTION_VERSION_PRE_HF4; } diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index ee86735d..31e4075d 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -707,7 +707,7 @@ namespace currency template void create_and_add_tx_payer_to_container_from_address(container_t& container, const account_public_address& addr, uint64_t top_block_height, const core_runtime_config& crc) { - if (top_block_height > crc.hard_forks.hard_fork_02_starts_after_height) + if (crc.is_hardfork_active_for_height(2, top_block_height)) { // after hardfork 2 tx_payer result = AUTO_VAL_INIT(result); @@ -729,7 +729,7 @@ namespace currency template void create_and_add_tx_receiver_to_container_from_address(container_t& container, const account_public_address& addr, uint64_t top_block_height, const core_runtime_config& crc) { - if (top_block_height > crc.hard_forks.hard_fork_02_starts_after_height) + if (crc.is_hardfork_active_for_height(2, top_block_height)) { // after hardfork 2 tx_receiver result = AUTO_VAL_INIT(result); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d0f7d98e..ac0bc306 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3703,7 +3703,7 @@ bool wallet2::is_transfer_unlocked(const transfer_details& td, bool for_pos_mini uint64_t unlock_time = get_tx_unlock_time(td.m_ptx_wallet_info->m_tx, td.m_internal_output_index); - if (for_pos_mining && get_blockchain_current_size() > m_core_runtime_config.hard_forks.hard_fork_01_starts_after_height) + if (for_pos_mining && m_core_runtime_config.is_hardfork_active_for_height(1, get_blockchain_current_size())) { //allowed of staking locked coins with stake_lock_time = unlock_time; @@ -3789,7 +3789,7 @@ void wallet2::update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, con //---------------------------------------------------------------------------------------------------- void wallet2::push_alias_info_to_extra_according_to_hf_status(const currency::extra_alias_entry& ai, std::vector& extra) { - if (get_top_block_height() > m_core_runtime_config.hard_forks.hard_fork_02_starts_after_height) + if (m_core_runtime_config.is_hardfork_active_for_height(2, get_top_block_height())) { // after HF2 extra.push_back(ai); diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index a3d79bc8..64c4d9d0 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -96,8 +96,8 @@ gen_alias_tests::gen_alias_tests() REGISTER_CALLBACK_METHOD(gen_alias_tests, check_height_changed); REGISTER_CALLBACK_METHOD(gen_alias_tests, check_too_many_aliases_registration); - m_hardforks.hard_fork_01_starts_after_height = 0; - m_hardforks.hard_fork_02_starts_after_height = 0; + m_hardforks.set_hardfork_height(1, 0); + m_hardforks.set_hardfork_height(2, 0); } bool gen_alias_tests::generate(std::vector& events) const diff --git a/tests/core_tests/atomic_tests.cpp b/tests/core_tests/atomic_tests.cpp index 05d54d3e..bf852eda 100644 --- a/tests/core_tests/atomic_tests.cpp +++ b/tests/core_tests/atomic_tests.cpp @@ -72,9 +72,10 @@ bool atomic_base_test::configure_core(currency::core& c, size_t ev_index, const currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = 10; - pc.hard_forks.hard_fork_02_starts_after_height = 11; - pc.hard_forks.hard_fork_03_starts_after_height = 12; + + pc.hard_forks.set_hardfork_height(1, 10); + pc.hard_forks.set_hardfork_height(2, 11); + pc.hard_forks.set_hardfork_height(3, 12); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } @@ -635,9 +636,9 @@ bool atomic_test_check_hardfork_rules::configure_core(currency::core& c, size_t currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = 10; - pc.hard_forks.hard_fork_02_starts_after_height = 10; - pc.hard_forks.hard_fork_03_starts_after_height = 10; + pc.hard_forks.set_hardfork_height(1, 10); + pc.hard_forks.set_hardfork_height(2, 10); + pc.hard_forks.set_hardfork_height(3, 10); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } @@ -668,9 +669,9 @@ bool atomic_test_check_hardfork_rules::c1(currency::core& c, size_t ev_index, co currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = 10; - pc.hard_forks.hard_fork_02_starts_after_height = 10; - pc.hard_forks.hard_fork_03_starts_after_height = 30; + pc.hard_forks.set_hardfork_height(1, 10); + pc.hard_forks.set_hardfork_height(2, 10); + pc.hard_forks.set_hardfork_height(3, 30); c.get_blockchain_storage().set_core_runtime_config(pc); bool r = mine_next_pow_block_in_playtime(m_mining_accunt.get_public_address(), c); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index 2653e67a..e104ec80 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -626,9 +626,9 @@ bool gen_block_wrong_version_agains_hardfork::c1(currency::core& c, size_t ev_in currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = 10; - pc.hard_forks.hard_fork_02_starts_after_height = 10; - pc.hard_forks.hard_fork_03_starts_after_height = 10; + pc.hard_forks.set_hardfork_height(1, 10); + pc.hard_forks.set_hardfork_height(2, 10); + pc.hard_forks.set_hardfork_height(3, 10); c.get_blockchain_storage().set_core_runtime_config(pc); currency::account_base mining_accunt; @@ -645,9 +645,9 @@ bool gen_block_wrong_version_agains_hardfork::c1(currency::core& c, size_t ev_in }; //between 1 and 2 hardforks - pc.hard_forks.hard_fork_01_starts_after_height = 1; - pc.hard_forks.hard_fork_02_starts_after_height = 10; - pc.hard_forks.hard_fork_03_starts_after_height = 20; + pc.hard_forks.set_hardfork_height(1, 1); + pc.hard_forks.set_hardfork_height(2, 10); + pc.hard_forks.set_hardfork_height(3, 20); c.get_blockchain_storage().set_core_runtime_config(pc); //major unknown @@ -663,9 +663,9 @@ bool gen_block_wrong_version_agains_hardfork::c1(currency::core& c, size_t ev_in CHECK_TEST_CONDITION(r); //between 1 and 2 hardforks - pc.hard_forks.hard_fork_01_starts_after_height = 1; - pc.hard_forks.hard_fork_02_starts_after_height = 1; - pc.hard_forks.hard_fork_03_starts_after_height = 1; + pc.hard_forks.set_hardfork_height(1, 1); + pc.hard_forks.set_hardfork_height(2, 1); + pc.hard_forks.set_hardfork_height(3, 1); c.get_blockchain_storage().set_core_runtime_config(pc); diff --git a/tests/core_tests/block_validation.h b/tests/core_tests/block_validation.h index 95f9cef4..0ce700ba 100644 --- a/tests/core_tests/block_validation.h +++ b/tests/core_tests/block_validation.h @@ -13,10 +13,7 @@ class gen_block_verification_base : public test_chain_unit_base public: gen_block_verification_base() { - m_hardforks.hard_fork_01_starts_after_height = 0; - m_hardforks.hard_fork_02_starts_after_height = 0; - m_hardforks.hard_fork_03_starts_after_height = 0; - m_hardforks.hard_fork_04_starts_after_height = 0; + m_hardforks.m_height_the_hardfork_n_active_after.fill(0); REGISTER_CALLBACK("check_block_purged", gen_block_verification_base::check_block_purged); } diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 31bc4f25..f7b12740 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -53,10 +53,6 @@ test_generator::test_generator() , m_ignore_last_pow_in_wallets(false) , m_last_found_timestamp(0) { - m_hardforks.hard_fork_01_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_02_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_03_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_04_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; } @@ -67,14 +63,7 @@ void test_generator::set_hardforks(const currency::hard_forks_descriptor& hardfo void test_generator::set_hardfork_height(size_t hardfork_id, uint64_t h) { - switch (hardfork_id) - { - case 1: m_hardforks.hard_fork_01_starts_after_height = h; break; - case 2: m_hardforks.hard_fork_02_starts_after_height = h; break; - case 3: m_hardforks.hard_fork_03_starts_after_height = h; break; - case 4: m_hardforks.hard_fork_04_starts_after_height = h; break; - default: CHECK_AND_ASSERT_THROW_MES(false, "invalid hardfork id: " << hardfork_id) - } + m_hardforks.set_hardfork_height(hardfork_id, h); } void test_generator::get_block_chain(std::vector& blockchain, const crypto::hash& head, size_t n) const @@ -168,7 +157,8 @@ void test_generator::add_block(const currency::block& blk, uint64_t block_reward; get_block_reward(is_pos_block(blk), misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward, currency::get_block_height(blk)); - m_blocks_info[get_block_hash(blk)] = block_info(blk, already_generated_coins + block_reward, block_size, cum_diff, tx_list, ks_hash); + crypto::hash block_hash = get_block_hash(blk); + m_blocks_info[block_hash] = block_info(blk, already_generated_coins + block_reward, block_size, cum_diff, tx_list, ks_hash); std::stringstream ss_tx_hashes; @@ -177,7 +167,7 @@ void test_generator::add_block(const currency::block& blk, ss_tx_hashes << " [tx]: " << h << ENDL; } - LOG_PRINT_MAGENTA("ADDED_BLOCK[" << get_block_hash(blk) << "][" << (is_pos_block(blk)? "PoS":"PoW") <<"][" << get_block_height(blk) << "][cumul_diff:" << cum_diff << "]" << ENDL << ss_tx_hashes.str(), LOG_LEVEL_0); + LOG_PRINT_MAGENTA("ADDED_BLOCK[" << block_hash << "][" << (is_pos_block(blk)? "PoS":"PoW") <<"][" << get_block_height(blk) << "][cumul_diff:" << cum_diff << "]" << ENDL << ss_tx_hashes.str(), LOG_LEVEL_0); } void test_generator::add_block_info(const block_info& bi) @@ -232,9 +222,9 @@ bool test_generator::construct_block(currency::block& blk, // else // blk.major_version = BLOCK_MAJOR_VERSION_INITIAL; - if (height <= m_hardforks.hard_fork_01_starts_after_height) + if (!m_hardforks.is_hardfork_active_for_height(1, height)) blk.major_version = BLOCK_MAJOR_VERSION_INITIAL; - else if (height <= m_hardforks.hard_fork_03_starts_after_height) + else if (!m_hardforks.is_hardfork_active_for_height(3, height)) blk.major_version = HF1_BLOCK_MAJOR_VERSION; else blk.major_version = CURRENT_BLOCK_MAJOR_VERSION; @@ -523,7 +513,7 @@ bool test_generator::find_kernel(const std::list& accs, uint64_t& found_timestamp, crypto::hash& found_kh) { - bool is_after_hardfork_01 = blck_chain.size() > m_hardforks.hard_fork_01_starts_after_height ? true : false; + //bool is_after_hardfork_01 = m_hardforks.is_hardfork_active_for_height(1, blck_chain.size()); uint64_t median_timestamp = get_timestamps_median(blck_chain); wide_difficulty_type basic_diff = 0; @@ -845,7 +835,7 @@ bool test_generator::construct_block(int64_t manual_timestamp_adjustment, std::vector blockchain; map_hash2tx_t mtx; bool r = find_block_chain(events, blockchain, mtx, get_block_hash(blk_prev)); - CHECK_AND_ASSERT_MES(r, false, "can't find a blockchain up from given blk_prev"); + CHECK_AND_ASSERT_MES(r, false, "can't find a blockchain up from given blk_prev with hash " << get_block_hash(blk_prev) << " @ height " << get_block_height(blk_prev)); bool pos_bl = coin_stake_sources.size(); bool adjust_timestamp_finished = have_n_blocks_of_type(blockchain, pos_bl); uint64_t diff_up_timestamp_delta = POW_DIFF_UP_TIMESTAMP_DELTA; @@ -1647,14 +1637,17 @@ void get_confirmed_txs(const std::vector& blockchain, const map } } -bool find_block_chain(const std::vector& events, std::vector& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) { +bool find_block_chain(const std::vector& events, std::vector& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) +{ std::unordered_map block_index; - BOOST_FOREACH(const test_event_entry& ev, events) + for(size_t i = 0, sz = events.size(); i < sz; ++i) { + const test_event_entry& ev = events[i]; if (typeid(currency::block) == ev.type()) { const block* blk = &boost::get(ev); - block_index[get_block_hash(*blk)] = blk; + crypto::hash h = get_block_hash(*blk); + block_index[h] = blk; } else if (typeid(event_special_block) == ev.type()) { @@ -2125,11 +2118,6 @@ test_chain_unit_enchanced::test_chain_unit_enchanced() , m_invalid_tx_index(std::numeric_limits::max()) , m_unverifiable_tx_index(std::numeric_limits::max()) { - m_hardforks.hard_fork_01_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_01_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_01_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - m_hardforks.hard_fork_01_starts_after_height = CURRENCY_MAX_BLOCK_NUMBER; - REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, configure_core); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_tx); diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 364d07e2..c1dbdd2e 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -235,8 +235,10 @@ public: bool need_core_proxy() const { return false; } // tests can override this in order to obtain core proxy (e.g. for wallet) void set_core_proxy(std::shared_ptr) { /* do nothing */ } uint64_t get_tx_version_from_events(const std::vector &events) const; + private: callbacks_map m_callbacks; + protected: currency::hard_forks_descriptor m_hardforks; }; @@ -326,9 +328,6 @@ protected: size_t m_invalid_tx_index; size_t m_unverifiable_tx_index; size_t m_orphan_block_index; - - // the following members is intended to be set by coretests with specific HF-related needs - //currency::hard_forks_descriptor m_hardforks; }; struct wallet_test_core_proxy; @@ -533,6 +532,8 @@ public: void set_ignore_last_pow_in_wallets(bool ignore_last_pow_in_wallets) { m_ignore_last_pow_in_wallets = ignore_last_pow_in_wallets; } void set_hardfork_height(size_t hardfork_id, uint64_t h); void set_hardforks(const currency::hard_forks_descriptor& hardforks); + const currency::hard_forks_descriptor& get_hardforks() const { return m_hardforks; } + private: bool m_do_pos_to_low_timestamp; @@ -544,7 +545,7 @@ private: std::unordered_map m_blocks_info; static test_gentime_settings m_test_gentime_settings; static test_gentime_settings m_test_gentime_settings_default; -}; +}; // class class test_generator extern const crypto::signature invalid_signature; // invalid non-null signature for test purpose static const std::vector empty_extra; diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 2f5921f9..88c8e4a9 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -281,7 +281,7 @@ inline std::string gen_random_alias(size_t len) } template -inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, +inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, // <-- TODO: remove this std::vector& events, std::list& tx_set, const currency::block& head_block, @@ -289,7 +289,6 @@ inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, const alias_entry_t& ae, test_generator& generator) { - const currency::hard_forks_descriptor& m_hardforks = hf; //a name to feed macro MAKE_TX_MIX_LIST_EXTRA_MIX_ATTR std::vector ex; ex.push_back(ae); currency::account_base reward_acc; diff --git a/tests/core_tests/checkpoints_tests.cpp b/tests/core_tests/checkpoints_tests.cpp index 1e50d5c0..8a19c518 100644 --- a/tests/core_tests/checkpoints_tests.cpp +++ b/tests/core_tests/checkpoints_tests.cpp @@ -628,8 +628,6 @@ gen_no_attchments_in_coinbase::gen_no_attchments_in_coinbase() REGISTER_CALLBACK_METHOD(gen_no_attchments_in_coinbase, c1); REGISTER_CALLBACK_METHOD(gen_no_attchments_in_coinbase, init_config_set_cp); - - m_hardforks.hard_fork_04_starts_after_height = UINT64_MAX; } bool gen_no_attchments_in_coinbase::generate(std::vector& events) const diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index 688e20a5..a3c7d845 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -35,7 +35,7 @@ bool hard_fork_1_base_test::configure_core(currency::core& c, size_t ev_index, c currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; - pc.hard_forks.hard_fork_01_starts_after_height = m_hardfork_height; + pc.hard_forks.set_hardfork_height(1, m_hardfork_height); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/hard_fork_1_bad_pos_source.cpp b/tests/core_tests/hard_fork_1_bad_pos_source.cpp index 5c78a33d..b60a1d08 100644 --- a/tests/core_tests/hard_fork_1_bad_pos_source.cpp +++ b/tests/core_tests/hard_fork_1_bad_pos_source.cpp @@ -72,7 +72,7 @@ bool hard_fork_1_bad_pos_source::configure_core(currency::core& c, size_t ev_ind currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = get_hardfork_height(); + pc.hard_forks.set_hardfork_height(1, get_hardfork_height()); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/hard_fork_1_consensus_test.cpp b/tests/core_tests/hard_fork_1_consensus_test.cpp index 744b99db..09753840 100644 --- a/tests/core_tests/hard_fork_1_consensus_test.cpp +++ b/tests/core_tests/hard_fork_1_consensus_test.cpp @@ -62,7 +62,7 @@ bool hard_fork_1_cumulative_difficulty_base::configure_core(currency::core& c, s currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = get_hardfork_height(); + pc.hard_forks.set_hardfork_height(1, get_hardfork_height()); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/hard_fork_1_locked_pos_test.cpp b/tests/core_tests/hard_fork_1_locked_pos_test.cpp index 9175d469..ef525c5e 100644 --- a/tests/core_tests/hard_fork_1_locked_pos_test.cpp +++ b/tests/core_tests/hard_fork_1_locked_pos_test.cpp @@ -103,7 +103,7 @@ bool hard_fork_1_locked_mining_test::configure_core(currency::core& c, size_t ev currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); 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_forks.hard_fork_01_starts_after_height = get_hardfork_height(); + pc.hard_forks.set_hardfork_height(1, get_hardfork_height()); c.get_blockchain_storage().set_core_runtime_config(pc); return true; diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index 497a21cf..decf46e4 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -29,9 +29,9 @@ bool hard_fork_2_base_test::configure_core(currency::core& c, size_t ev_index, c currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; - pc.hard_forks.hard_fork_01_starts_after_height = m_hardfork_01_height; - pc.hard_forks.hard_fork_02_starts_after_height = m_hardfork_02_height; - pc.hard_forks.hard_fork_03_starts_after_height = m_hardfork_03_height; + pc.hard_forks.set_hardfork_height(1, m_hardfork_01_height); + pc.hard_forks.set_hardfork_height(2, m_hardfork_02_height); + pc.hard_forks.set_hardfork_height(3, m_hardfork_03_height); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index a57426fd..ff5f5557 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -775,8 +775,8 @@ gen_crypted_attachments::gen_crypted_attachments() REGISTER_CALLBACK("check_offers_count_befor_cancel", gen_crypted_attachments::check_offers_count_befor_cancel); REGISTER_CALLBACK("check_offers_count_after_cancel", gen_crypted_attachments::check_offers_count_after_cancel); - m_hardforks.hard_fork_01_starts_after_height = 0; - m_hardforks.hard_fork_02_starts_after_height = 0; // tx_payer is allowed only after HF2 + m_hardforks.set_hardfork_height(1, 0); + m_hardforks.set_hardfork_height(2, 0); // tx_payer is allowed only after HF2 } bool gen_crypted_attachments::generate(std::vector& events) const @@ -989,8 +989,8 @@ bool gen_tx_extra_double_entry::configure_core(currency::core& c, size_t ev_inde currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; - pc.hard_forks.hard_fork_01_starts_after_height = 0; - pc.hard_forks.hard_fork_02_starts_after_height = 0; + pc.hard_forks.set_hardfork_height(1, 0); + pc.hard_forks.set_hardfork_height(2, 0); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/wallet_rpc_tests.cpp b/tests/core_tests/wallet_rpc_tests.cpp index 31a7018e..a953576a 100644 --- a/tests/core_tests/wallet_rpc_tests.cpp +++ b/tests/core_tests/wallet_rpc_tests.cpp @@ -216,9 +216,9 @@ bool wallet_rpc_transfer::generate(std::vector& events) const bool wallet_rpc_transfer::configure_core(currency::core& c, size_t ev_index, const std::vector& events) { currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); - pc.hard_forks.hard_fork_01_starts_after_height = 1; - pc.hard_forks.hard_fork_02_starts_after_height = 1; - pc.hard_forks.hard_fork_03_starts_after_height = 1; + pc.hard_forks.set_hardfork_height(1, 1); + pc.hard_forks.set_hardfork_height(2, 1); + pc.hard_forks.set_hardfork_height(3, 1); c.get_blockchain_storage().set_core_runtime_config(pc); return true; } diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 142a020a..e1ead036 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1381,8 +1381,8 @@ bool gen_wallet_transfers_and_chain_switch::generate(std::vector& events) const @@ -1562,8 +1562,8 @@ void gen_wallet_decrypted_attachments::on_transfer2(const tools::wallet_public:: gen_wallet_alias_and_unconfirmed_txs::gen_wallet_alias_and_unconfirmed_txs() { - m_hardforks.hard_fork_01_starts_after_height = 0; - m_hardforks.hard_fork_02_starts_after_height = 0; + m_hardforks.set_hardfork_height(1, 0); + m_hardforks.set_hardfork_height(2, 0); REGISTER_CALLBACK_METHOD(gen_wallet_alias_and_unconfirmed_txs, c1); REGISTER_CALLBACK_METHOD(gen_wallet_alias_and_unconfirmed_txs, c2); @@ -1711,8 +1711,8 @@ bool gen_wallet_alias_and_unconfirmed_txs::c3(currency::core& c, size_t ev_index gen_wallet_alias_via_special_wallet_funcs::gen_wallet_alias_via_special_wallet_funcs() { // start hardfork from block 0 in order to use extra_alias_entry (allowed only since HF2) - m_hardforks.hard_fork_01_starts_after_height = 0; - m_hardforks.hard_fork_02_starts_after_height = 0; + m_hardforks.set_hardfork_height(1, 0); + m_hardforks.set_hardfork_height(2, 0); REGISTER_CALLBACK_METHOD(gen_wallet_alias_via_special_wallet_funcs, c1); }