From 13f524defbb530da0c176ba9edd3448e831c0bbe Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 6 Dec 2024 05:39:18 +0100 Subject: [PATCH 1/9] tx hardfork id: wip (basic structures, miner tx creation adapted, tests adapted almost all + hard_fork_5_tx_version) --- src/connectivity_tool/conn_tool.cpp | 2 +- src/currency_core/blockchain_storage.cpp | 11 +++++-- src/currency_core/currency_basic.h | 3 ++ src/currency_core/currency_config.h | 5 ++-- src/currency_core/currency_format_utils.cpp | 16 ++++++++++- src/currency_core/currency_format_utils.h | 2 ++ tests/core_tests/chaingen.cpp | 9 ++++-- tests/core_tests/chaingen.h | 4 ++- tests/core_tests/chaingen_main.cpp | 3 ++ tests/core_tests/chaingen_tests_list.h | 1 + tests/core_tests/hard_fork_5.cpp | 32 +++++++++++++++++++++ tests/core_tests/hard_fork_5.h | 12 ++++++++ tests/core_tests/pos_block_builder.cpp | 6 ++-- tests/core_tests/transaction_tests.cpp | 14 ++++----- tests/unit_tests/test_format_utils.cpp | 5 ++-- 15 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 tests/core_tests/hard_fork_5.cpp create mode 100644 tests/core_tests/hard_fork_5.h diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index a7c32892..d1f37b0a 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -414,7 +414,7 @@ bool generate_genesis(const std::string& path_config, uint64_t premine_split_amo std::cout << ENDL << "PROOF PHRASE: " << gcp.proof_string << ENDL; uint64_t block_reward_without_fee = 0; uint64_t block_reward = 0; - construct_miner_tx(0, 0, 0, 0, 0, dummy_address, dummy_address, bl.miner_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, gcp.proof_string, CURRENCY_MINER_TX_MAX_OUTS, false, pos_entry(), nullptr, nullptr, destinations); + construct_miner_tx(0, 0, 0, 0, 0, dummy_address, dummy_address, bl.miner_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0, gcp.proof_string, CURRENCY_MINER_TX_MAX_OUTS, false, pos_entry(), nullptr, nullptr, destinations); currency::blobdata txb = tx_to_blob(bl.miner_tx); //self validate block diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 0d6d41f8..b36e218c 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1589,6 +1589,9 @@ bool blockchain_storage::create_block_template(const create_block_template_param resp.txs_fee = fee; + size_t tx_hardfork_id = 0; + size_t tx_version = get_tx_version_and_hardfork_id(height, m_core_runtime_config.hard_forks, tx_hardfork_id); + /* instead of complicated two-phase template construction and adjustment of cumulative size with block reward we use CURRENCY_COINBASE_BLOB_RESERVED_SIZE as penalty-free coinbase transaction reservation. @@ -1601,7 +1604,8 @@ bool blockchain_storage::create_block_template(const create_block_template_param b.miner_tx, resp.block_reward_without_fee, resp.block_reward, - get_tx_version(height, m_core_runtime_config.hard_forks), + tx_version, + tx_hardfork_id, ex_nonce, CURRENCY_MINER_TX_MAX_OUTS, pos, @@ -6080,6 +6084,7 @@ struct visitor_proxy : public boost::static_visitor bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transaction& tx, const crypto::hash& tx_id, uint64_t block_height) const { + size_t most_recent_hardfork_id_for_height = m_core_runtime_config.hard_forks.get_the_most_recent_hardfork_id_for_height(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); @@ -6218,7 +6223,9 @@ bool blockchain_storage::validate_tx_for_hardfork_specific_terms(const transacti if (var_is_after_hardfork_5_zone) { - // additional checks here + CHECK_AND_ASSERT_MES(tx.version >= TRANSACTION_VERSION_POST_HF5, false, "HF5: tx with version " << tx.version << " is not allowed"); + // starting from HF5 each tx must have hardfork_id corresponding to the current active hardfork + CHECK_AND_ASSERT_MES(tx.hardfork_id == most_recent_hardfork_id_for_height, false, "tx's hardfork_id is " << (int)tx.hardfork_id << ", but the current hardfork is " << most_recent_hardfork_id_for_height << ", rejected"); } else { diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index d0630089..5b0bfcc2 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -1032,6 +1032,7 @@ namespace currency { public: uint64_t version = 0; + uint8_t hardfork_id = 0; std::vector vin; std::vector extra; std::vector vout; @@ -1044,6 +1045,8 @@ namespace currency FIELD(vin) FIELD(extra) FIELD(vout) + if(version < TRANSACTION_VERSION_POST_HF5) return true; + FIELD(hardfork_id) END_SERIALIZE() }; diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 1d6edf20..cd796b74 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -28,10 +28,11 @@ #define CURRENCY_PUBLIC_AUDITABLE_ADDRESS_BASE58_PREFIX 0x98c8 // auditable addresses start with 'aZx' #define CURRENCY_PUBLIC_AUDITABLE_INTEG_ADDRESS_BASE58_PREFIX 0x8a49 // auditable integrated addresses start with 'aiZX' #define CURRENCY_MINED_MONEY_UNLOCK_WINDOW 10 -#define CURRENT_TRANSACTION_VERSION 2 +#define CURRENT_TRANSACTION_VERSION 3 #define TRANSACTION_VERSION_INITAL 0 #define TRANSACTION_VERSION_PRE_HF4 1 -#define TRANSACTION_VERSION_POST_HF4 2 +#define TRANSACTION_VERSION_POST_HF4 2 +#define TRANSACTION_VERSION_POST_HF5 3 #define HF1_BLOCK_MAJOR_VERSION 1 #define HF3_BLOCK_MAJOR_VERSION 2 #define HF3_BLOCK_MINOR_VERSION 0 diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 96d55b46..ea309bdd 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -393,6 +393,7 @@ namespace currency uint64_t& block_reward_without_fee, uint64_t& block_reward, uint64_t tx_version, + size_t tx_hadrfork_id, const blobdata& extra_nonce /* = blobdata() */, size_t max_outs /* = CURRENCY_MINER_TX_MAX_OUTS */, bool pos /* = false */, @@ -476,6 +477,8 @@ namespace currency CHECK_AND_ASSERT_MES(destinations.size() <= CURRENCY_TX_MAX_ALLOWED_OUTS || height == 0, false, "Too many outs (" << destinations.size() << ")! Miner tx can't be constructed."); // tx is not cleared intentionally to allow passing additional args in the extra/attachments tx.version = tx_version; + if (tx.version >= TRANSACTION_VERSION_POST_HF5) + tx.hardfork_id = tx_hadrfork_id; tx_generation_context tx_gen_context{}; tx_gen_context.set_tx_key(tx_one_time_key_to_use ? *tx_one_time_key_to_use : keypair::generate()); @@ -2819,15 +2822,26 @@ namespace currency //--------------------------------------------------------------- - uint64_t get_tx_version(uint64_t tx_expected_block_height, const hard_forks_descriptor& hfd) + uint64_t get_tx_version_and_hardfork_id(uint64_t tx_expected_block_height, const hard_forks_descriptor& hfd, size_t& tx_hardfork_id) { + tx_hardfork_id = hfd.get_the_most_recent_hardfork_id_for_height(tx_expected_block_height); if (!hfd.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, tx_expected_block_height)) { return TRANSACTION_VERSION_PRE_HF4; } + if (!hfd.is_hardfork_active_for_height(ZANO_HARDFORK_05, tx_expected_block_height)) + { + return TRANSACTION_VERSION_POST_HF4; + } return CURRENT_TRANSACTION_VERSION; } //--------------------------------------------------------------- + uint64_t get_tx_version(uint64_t tx_expected_block_height, const hard_forks_descriptor& hfd) + { + [[maybe_unused]] size_t tx_hardfork_id{}; + return get_tx_version_and_hardfork_id(tx_expected_block_height, hfd, tx_hardfork_id); + } + //--------------------------------------------------------------- // TODO @#@# this function is obsolete and needs to be re-written uint64_t get_reward_from_miner_tx(const transaction& tx) { diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 399a6d90..3f9152cd 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -295,6 +295,7 @@ namespace currency uint64_t& block_reward_without_fee, uint64_t& block_reward, uint64_t tx_version, + size_t tx_hadrfork_id, const blobdata& extra_nonce = blobdata(), size_t max_outs = CURRENCY_MINER_TX_MAX_OUTS, bool pos = false, @@ -348,6 +349,7 @@ namespace currency bool shuffle = true, uint64_t flags = 0); + uint64_t get_tx_version_and_hardfork_id(uint64_t tx_expected_block_height, const hard_forks_descriptor& hfd, size_t& tx_hardfork_id); // returns tx version and tx hardfork id based on the height of the block where the transaction is expected to be uint64_t get_tx_version(uint64_t tx_expected_block_height, const hard_forks_descriptor& hfd); // returns tx version based on the height of the block where the transaction is expected to be bool construct_tx(const account_keys& sender_account_keys, const finalize_tx_param& param, finalized_tx& result); bool get_or_calculate_asset_id(const asset_descriptor_operation& ado, crypto::point_t* p_result_point, crypto::public_key* p_result_pub_key); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 2679dd39..dd4dffab 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -299,6 +299,8 @@ bool test_generator::construct_block(currency::block& blk, tx_generation_context miner_tx_tgc{}; uint64_t block_reward_without_fee = 0; uint64_t block_reward = 0; + size_t tx_hardfork_id = 0; + uint64_t tx_version = get_tx_version_and_hardfork_id(height, m_hardforks, tx_hardfork_id); while (true) { r = construct_miner_tx(height, misc_utils::median(block_sizes), @@ -310,7 +312,8 @@ bool test_generator::construct_block(currency::block& blk, blk.miner_tx, block_reward_without_fee, block_reward, - get_tx_version(height, m_hardforks), + tx_version, + tx_hardfork_id, blobdata(), test_generator::get_test_gentime_settings().miner_tx_max_outs, static_cast(coin_stake_sources.size()), @@ -956,10 +959,12 @@ bool test_generator::construct_block(int64_t manual_timestamp_adjustment, { uint64_t base_block_reward = 0; uint64_t block_reward = 0; + size_t tx_hardfork_id = 0; + uint64_t tx_version = get_tx_version_and_hardfork_id(height, m_hardforks, tx_hardfork_id); size_t current_block_size = txs_sizes + get_object_blobsize(blk.miner_tx); // TODO: This will work, until size of constructed block is less then CURRENCY_BLOCK_GRANTED_FULL_REWARD_ZONE if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, current_block_size, 0, - miner_acc.get_public_address(), miner_acc.get_public_address(), blk.miner_tx, base_block_reward, block_reward, get_tx_version(height, m_hardforks), blobdata(), 1)) + miner_acc.get_public_address(), miner_acc.get_public_address(), blk.miner_tx, base_block_reward, block_reward, tx_version, tx_hardfork_id, blobdata(), 1)) return false; } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 1ff60a9a..962d9b95 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -994,10 +994,12 @@ bool test_generator::construct_block_gentime_with_coinbase_cb(const currency::bl uint64_t block_reward_without_fee = 0; uint64_t block_reward = 0; + size_t tx_hardfork_id = 0; + uint64_t tx_version = get_tx_version_and_hardfork_id(height, m_hardforks, tx_hardfork_id); currency::keypair tx_sec_key = currency::keypair::generate(); r = construct_miner_tx(height, epee::misc_utils::median(block_sizes), already_generated_coins, 0 /* current_block_size !HACK! */, 0, - acc.get_public_address(), acc.get_public_address(), miner_tx, block_reward_without_fee, block_reward, get_tx_version(height, m_hardforks), currency::blobdata(), /* max outs: */ 1, + acc.get_public_address(), acc.get_public_address(), miner_tx, block_reward_without_fee, block_reward, tx_version, tx_hardfork_id, currency::blobdata(), /* max outs: */ 1, /* pos: */ false, currency::pos_entry(), /* ogc_ptr: */ nullptr, &tx_sec_key); CHECK_AND_ASSERT_MES(r, false, "construct_miner_tx failed"); diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index d1a217c6..ec8ba6a2 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1271,6 +1271,9 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(hardfork_4_wallet_sweep_bare_outs); GENERATE_AND_PLAY_HF(hardfork_4_pop_tx_from_global_index, "4-*"); + // HF5 + GENERATE_AND_PLAY_HF(hard_fork_5_tx_version, "5-*"); + // atomics GENERATE_AND_PLAY(atomic_simple_test); GENERATE_AND_PLAY(atomic_test_wrong_redeem_wrong_refund); diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h index abac7b00..8c128250 100644 --- a/tests/core_tests/chaingen_tests_list.h +++ b/tests/core_tests/chaingen_tests_list.h @@ -39,6 +39,7 @@ #include "hard_fork_1.h" #include "hard_fork_2.h" #include "hard_fork_4.h" +#include "hard_fork_5.h" #include "atomic_tests.h" #include "isolate_auditable_and_proof.h" #include "zarcanum_test.h" diff --git a/tests/core_tests/hard_fork_5.cpp b/tests/core_tests/hard_fork_5.cpp new file mode 100644 index 00000000..8a88658a --- /dev/null +++ b/tests/core_tests/hard_fork_5.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2024 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include "chaingen.h" +#include "hard_fork_5.h" +#include "random_helper.h" + +using namespace currency; + +bool hard_fork_5_tx_version::generate(std::vector& events) const +{ + // + // Test idea: + // + uint64_t ts = test_core_time::get_time(); + GENERATE_ACCOUNT(miner_acc); + GENERATE_ACCOUNT(alice_acc); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); + //// rebuild genesis miner tx + //std::vector destinations; + //destinations.emplace_back(MK_TEST_COINS(1), alice_acc.get_public_address()); + //destinations.emplace_back(MK_TEST_COINS(1), alice_acc.get_public_address()); + //CHECK_AND_ASSERT_MES(replace_coinbase_in_genesis_block(destinations, generator, events, blk_0), false, ""); // leftover amount will be also send to miner + + DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks + REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + + MAKE_TX(events, tx_1, miner_acc, alice_acc, MK_TEST_COINS(1), blk_0r); + + return true; +} diff --git a/tests/core_tests/hard_fork_5.h b/tests/core_tests/hard_fork_5.h new file mode 100644 index 00000000..692d3348 --- /dev/null +++ b/tests/core_tests/hard_fork_5.h @@ -0,0 +1,12 @@ +// Copyright (c) 2024 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#pragma once +#include "chaingen.h" +#include "wallet_tests_basic.h" + + +struct hard_fork_5_tx_version : public test_chain_unit_enchanced +{ + bool generate(std::vector& events) const; +}; diff --git a/tests/core_tests/pos_block_builder.cpp b/tests/core_tests/pos_block_builder.cpp index da3e08c1..6ebd50ab 100644 --- a/tests/core_tests/pos_block_builder.cpp +++ b/tests/core_tests/pos_block_builder.cpp @@ -161,6 +161,8 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, CHECK_AND_ASSERT_THROW_MES(m_step == 3, "pos_block_builder: incorrect step sequence"); uint64_t tx_version = m_context.zarcanum ? TRANSACTION_VERSION_POST_HF4 : TRANSACTION_VERSION_PRE_HF4; + // TODO @#@# tx_hardfork_id + pos_entry pe{}; pe.stake_unlock_time = 0; // TODO pe.amount = m_context.stake_amount; @@ -171,7 +173,7 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, size_t estimated_block_size = m_txs_total_size; m_block.miner_tx = transaction{}; bool r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee, - reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); + reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, 0, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); CHECK_AND_ASSERT_THROW_MES(r, "construct_miner_tx failed"); estimated_block_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx); @@ -180,7 +182,7 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, { m_block.miner_tx = transaction{}; r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee, - reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); + reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, 0, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); CHECK_AND_ASSERT_THROW_MES(r, "construct_homemade_pos_miner_tx failed"); cumulative_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index 206a5596..d884c17e 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -42,17 +42,17 @@ bool test_transaction_generation_and_ring_signature() account_base rv_acc2; rv_acc2.generate(); transaction tx_mine_1; - construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().account_address, miner_acc1.get_keys().account_address, tx_mine_1, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().account_address, miner_acc1.get_keys().account_address, tx_mine_1, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); transaction tx_mine_2; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().account_address, miner_acc2.get_keys().account_address, tx_mine_2, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().account_address, miner_acc2.get_keys().account_address, tx_mine_2, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); transaction tx_mine_3; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().account_address, miner_acc3.get_keys().account_address, tx_mine_3, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().account_address, miner_acc3.get_keys().account_address, tx_mine_3, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); transaction tx_mine_4; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().account_address, miner_acc4.get_keys().account_address, tx_mine_4, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().account_address, miner_acc4.get_keys().account_address, tx_mine_4, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); transaction tx_mine_5; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().account_address, miner_acc5.get_keys().account_address, tx_mine_5, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().account_address, miner_acc5.get_keys().account_address, tx_mine_5, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); transaction tx_mine_6; - construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().account_address, miner_acc6.get_keys().account_address, tx_mine_6, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().account_address, miner_acc6.get_keys().account_address, tx_mine_6, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); //fill inputs entry typedef tx_source_entry::output_entry tx_output_entry; @@ -139,7 +139,7 @@ bool test_block_creation() uint64_t block_reward_without_fee = 0; uint64_t block_reward = 0; block b; - r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, adr, adr, b.miner_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4); + r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, adr, adr, b.miner_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0); return r; } diff --git a/tests/unit_tests/test_format_utils.cpp b/tests/unit_tests/test_format_utils.cpp index f12c149f..b42a45f3 100644 --- a/tests/unit_tests/test_format_utils.cpp +++ b/tests/unit_tests/test_format_utils.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2014-2024 Zano Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -16,7 +17,7 @@ TEST(parse_and_validate_tx_extra, is_correct_parse_and_validate_tx_extra) currency::blobdata b = "dsdsdfsdfsf"; uint64_t block_reward_without_fee = 0, block_reward = 0; bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().account_address, acc.get_keys().account_address, tx, - block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, b, 1); + block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0, b, 1); ASSERT_TRUE(r); crypto::public_key tx_pub_key; r = currency::parse_and_validate_tx_extra(tx, tx_pub_key); @@ -30,7 +31,7 @@ TEST(parse_and_validate_tx_extra, is_correct_extranonce_too_big) currency::blobdata b(260, 0); uint64_t block_reward_without_fee = 0, block_reward = 0; bool r = currency::construct_miner_tx(0, 0, 10000000000000, 1000, TESTS_DEFAULT_FEE, acc.get_keys().account_address, acc.get_keys().account_address, tx, - block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, b, 1); + block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0, b, 1); ASSERT_FALSE(r); } From b9557dd70efa8ee2f6211dfdcfbafa0a705c0a0d Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 9 Dec 2024 23:31:39 +0100 Subject: [PATCH 2/9] chaingen: run-single-test made more specific (exact match is now required) --- tests/core_tests/chaingen_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index ec8ba6a2..b557b642 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -387,7 +387,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ #define GENERATE_AND_PLAY(genclass) \ - if (!skip_all_till_the_end && ((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string::npos != std::string(#genclass).find(run_single_test)))) \ + if (!skip_all_till_the_end && ((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string(#genclass) == run_single_test))) \ { \ TIME_MEASURE_START_MS(t); \ ++tests_count; \ @@ -422,7 +422,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ } #define GENERATE_AND_PLAY_HF(genclass, hardfork_str_mask) \ - if (!skip_all_till_the_end && ((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string::npos != std::string(#genclass).find(run_single_test)))) \ + if (!skip_all_till_the_end && ((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string(#genclass) == run_single_test))) \ { \ std::vector hardforks = parse_hardfork_str_mask(hardfork_str_mask); \ CHECK_AND_ASSERT_MES(!hardforks.empty(), false, "invalid hardforks mask: " << hardfork_str_mask); \ From 8dd8a6ac1c1e55d4e01671804e585cda6d7c722a Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 27 Dec 2024 07:27:43 +0100 Subject: [PATCH 3/9] tx hf id: WIP --- src/currency_core/currency_format_utils.cpp | 17 ++- src/currency_core/currency_format_utils.h | 6 + tests/core_tests/alias_tests.cpp | 19 +-- tests/core_tests/block_validation.cpp | 6 +- tests/core_tests/chain_switch_1.cpp | 34 ++--- tests/core_tests/chaingen.cpp | 133 ++++++++++++++++++-- tests/core_tests/chaingen.h | 36 ++++++ tests/core_tests/chaingen_helpers.h | 5 +- tests/core_tests/checkpoints_tests.cpp | 4 +- tests/core_tests/double_spend.inl | 4 +- tests/core_tests/emission_test.cpp | 5 +- tests/core_tests/escrow_wallet_common.h | 25 ++-- tests/core_tests/escrow_wallet_tests.cpp | 81 ++++++------ tests/core_tests/get_random_outs.cpp | 5 +- tests/core_tests/hard_fork_1.cpp | 4 +- tests/core_tests/integer_overflow.cpp | 7 +- tests/core_tests/misc_tests.cpp | 22 ++-- tests/core_tests/multiassets_test.cpp | 36 +++--- tests/core_tests/multisig_wallet_tests.cpp | 36 +++--- tests/core_tests/offers_test.cpp | 2 +- tests/core_tests/pos_basic_tests.cpp | 3 +- tests/core_tests/transaction_tests.cpp | 2 +- tests/core_tests/tx_validation.cpp | 29 +++-- tests/core_tests/wallet_tests.cpp | 2 +- tests/core_tests/zarcanum_test.cpp | 9 +- 25 files changed, 355 insertions(+), 177 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index ea309bdd..7ec3400d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1442,12 +1442,13 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, uint64_t unlock_time, uint8_t tx_outs_attr, bool shuffle) { - crypto::secret_key one_time_secret_key = AUTO_VAL_INIT(one_time_secret_key); - return construct_tx(sender_account_keys, sources, destinations, std::vector(), attachments, tx, tx_version, one_time_secret_key, unlock_time, tx_outs_attr, shuffle); + crypto::secret_key one_time_secret_key{}; + return construct_tx(sender_account_keys, sources, destinations, std::vector(), attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, unlock_time, tx_outs_attr, shuffle); } //--------------------------------------------------------------- @@ -1967,6 +1968,7 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, crypto::secret_key& one_time_secret_key, uint64_t unlock_time, uint8_t tx_outs_attr, @@ -1979,7 +1981,7 @@ namespace currency //in case if there is no real targets we use sender credentials to encrypt attachments account_public_address crypt_destination_addr = get_crypt_address_from_destinations(sender_account_keys, destinations); - return construct_tx(sender_account_keys, sources, destinations, extra, attachments, tx, tx_version, one_time_secret_key, unlock_time, + return construct_tx(sender_account_keys, sources, destinations, extra, attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, unlock_time, crypt_destination_addr, 0, tx_outs_attr, @@ -1993,6 +1995,7 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, crypto::secret_key& one_time_secret_key, uint64_t unlock_time, const account_public_address& crypt_destination_addr, @@ -2002,8 +2005,9 @@ namespace currency uint64_t flags) { //extra copy operation, but creating transaction is not sensitive to this - finalize_tx_param ftp = AUTO_VAL_INIT(ftp); + finalize_tx_param ftp{}; ftp.tx_version = tx_version; + ftp.tx_hardfork_id = tx_hardfork_id; ftp.sources = sources; ftp.prepared_destinations = destinations; ftp.extra = extra; @@ -2015,7 +2019,7 @@ namespace currency ftp.shuffle = shuffle; ftp.flags = flags; - finalized_tx ft = AUTO_VAL_INIT(ft); + finalized_tx ft{}; ft.tx = tx; ft.one_time_key = one_time_secret_key; bool r = construct_tx(sender_account_keys, ftp, ft); @@ -2405,6 +2409,9 @@ namespace currency tx.signatures.clear(); tx.version = ftp.tx_version; + if (tx.version >= TRANSACTION_VERSION_POST_HF5) + tx.hardfork_id = ftp.tx_hardfork_id; + if (unlock_time != 0) set_tx_unlock_time(tx, unlock_time); diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 3f9152cd..1503baee 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -163,6 +163,7 @@ namespace currency uint64_t expiration_time; crypto::public_key spend_pub_key; // only for validations uint64_t tx_version; + uint8_t tx_hardfork_id = 0; uint64_t mode_separate_fee = 0; epee::misc_utils::events_dispatcher* pevents_dispatcher = nullptr; @@ -187,6 +188,7 @@ namespace currency FIELD(expiration_time) FIELD(spend_pub_key) FIELD(tx_version) + FIELD(tx_hardfork_id) FIELD(mode_separate_fee) if (flags & TX_FLAG_SIGNATURE_MODE_SEPARATE) { @@ -318,9 +320,11 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED, bool shuffle = true); + bool construct_tx(const account_keys& sender_account_keys, const std::vector& sources, const std::vector& destinations, @@ -328,6 +332,7 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, crypto::secret_key& one_time_secret_key, uint64_t unlock_time, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED, @@ -341,6 +346,7 @@ namespace currency const std::vector& attachments, transaction& tx, uint64_t tx_version, + size_t tx_hardfork_id, crypto::secret_key& one_time_secret_key, uint64_t unlock_time, const account_public_address& crypt_account, diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index b8a1e4fd..1e5b1de5 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -975,7 +975,9 @@ bool gen_alias_too_much_reward::generate(std::vector& events) d.flags |= tx_destination_entry_flags::tdef_explicit_native_asset_id | tx_destination_entry_flags::tdef_zero_amount_blinding_mask; transaction tx_0{}; crypto::secret_key sk{}; - r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx_0, get_tx_version_from_events(events), sk, 0); + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx_0, tx_version, tx_hardfork_id, sk, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); if (tx_0.version <= TRANSACTION_VERSION_PRE_HF4) @@ -1166,8 +1168,9 @@ bool gen_alias_too_small_reward::make_tx_reg_alias(std::vector destinations.push_back(tx_destination_entry(sources_amount - (alias_reward + TESTS_DEFAULT_FEE), miner_acc.get_public_address())); // change crypto::secret_key stub = AUTO_VAL_INIT(stub); - uint64_t tx_version = get_tx_version(get_block_height(prev_block), m_hardforks); - r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx, tx_version, stub, uint64_t(0)); + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_hardfork_id(get_block_height(prev_block), m_hardforks, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx, tx_version, tx_hardfork_id, stub, uint64_t(0)); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); PRINT_EVENT_N_TEXT(events, "make_tx_reg_alias -> construct_tx()"); events.push_back(tx); @@ -1382,8 +1385,9 @@ bool gen_alias_too_many_regs_in_block_template::generate(std::vector& events) } transaction tx{}; - uint64_t tx_version = currency::get_tx_version(get_block_height(blk_0r) + 1, generator.get_hardforks()); + size_t tx_hardfork_id{}; + uint64_t tx_version = currency::get_tx_version_and_hardfork_id(get_block_height(blk_0r) + 1, generator.get_hardforks(), tx_hardfork_id); crypto::secret_key sk{}; - r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx, tx_version, sk, 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx, tx_version, tx_hardfork_id, sk, 0); /*tx_builder tb; tb.step1_init(); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index c5a911a7..26045224 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -321,10 +321,9 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector& events destinations.push_back(de); transaction tmp_tx; - std::vector attachments; uint64_t tx_version = get_tx_version(get_block_height(blk_0r), m_hardforks); - if (!construct_tx(miner_account.get_keys(), sources, destinations, attachments, tmp_tx, tx_version, 0)) + if (!construct_tx(miner_account.get_keys(), sources, destinations, empty_extra, empty_attachment, tmp_tx, tx_version)) return false; MAKE_MINER_TX_MANUALLY(miner_tx, blk_0); @@ -369,9 +368,8 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector destinations.push_back(de); transaction tmp_tx = AUTO_VAL_INIT(tmp_tx); - std::vector attachments; uint64_t tx_version = get_tx_version(get_block_height(blk_1r), m_hardforks); - if (!construct_tx(miner_account.get_keys(), sources, destinations, attachments, tmp_tx, tx_version, 0)) + if (!construct_tx(miner_account.get_keys(), sources, destinations, empty_extra, empty_attachment, tmp_tx, tx_version)) return false; MAKE_MINER_TX_MANUALLY(miner_tx, blk_1); diff --git a/tests/core_tests/chain_switch_1.cpp b/tests/core_tests/chain_switch_1.cpp index 69ad2a28..b607e852 100644 --- a/tests/core_tests/chain_switch_1.cpp +++ b/tests/core_tests/chain_switch_1.cpp @@ -532,9 +532,10 @@ bool alt_blocks_validation_and_same_new_amount_in_two_txs::generate(std::vector< std::vector destinations; destinations.push_back(tx_destination_entry(new_amount, miner_acc.get_public_address())); destinations.push_back(tx_destination_entry(TESTS_DEFAULT_FEE, miner_acc.get_public_address())); //just to make two outputs (to please HF4 rules) - transaction tx_1 = AUTO_VAL_INIT(tx_1); - uint64_t tx_version = get_tx_version(get_block_height(blk_3), m_hardforks); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, tx_version, 0); + transaction tx_1{}; + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_3), m_hardforks, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, tx_version, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_1); @@ -544,8 +545,8 @@ bool alt_blocks_validation_and_same_new_amount_in_two_txs::generate(std::vector< CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); transaction tx_2 = AUTO_VAL_INIT(tx_2); // use the same destinations - tx_version = get_tx_version(get_block_height(blk_3), m_hardforks); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_2, tx_version, 0); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_3), m_hardforks, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_2, tx_version, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_2); @@ -913,16 +914,10 @@ bool alt_chain_and_block_tx_fee_median::generate( CHECK_AND_ASSERT_MES(success, false, "fail to fill sources, destinations"); - tx_version = get_tx_version(get_block_height(blk_1r), - m_hardforks); + size_t tx_hardfork_id{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1r), m_hardforks, tx_hardfork_id); - success = construct_tx(miner.get_keys(), - sources, - destinations, - empty_attachment, - tx_0, - tx_version, - 0); + success = construct_tx(miner.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(success, false, "fail to construct tx_0"); @@ -934,8 +929,7 @@ bool alt_chain_and_block_tx_fee_median::generate( // Transaction tx_1 is constructed and placed in block blk_2a. - tx_version = get_tx_version(get_block_height(blk_1r), - m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1r), m_hardforks, tx_hardfork_id); success = fill_tx_sources_and_destinations( events, @@ -950,13 +944,7 @@ bool alt_chain_and_block_tx_fee_median::generate( CHECK_AND_ASSERT_MES(success, false, "fail to fill sources, destinations"); - success = construct_tx(miner.get_keys(), - sources, - destinations, - empty_attachment, - tx_1, - tx_version, - 0); + success = construct_tx(miner.get_keys(), sources, destinations, empty_attachment, tx_1, tx_version, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(success, false, "fail to construct tx_1"); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index dd4dffab..91fbe462 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1750,8 +1750,9 @@ bool construct_tx_to_key(const currency::hard_forks_descriptor& hf, std::vector destinations; if (!fill_tx_sources_and_destinations(events, blk_head, from.get_keys(), to.get_public_address(), amount, fee, nmix, sources, destinations, check_for_spends, check_for_unlocktime)) return false; - uint64_t tx_version = currency::get_tx_version(get_block_height(blk_head) + 1, hf); // assuming the tx will be in the next block (blk_head + 1) - return construct_tx(from.get_keys(), sources, destinations, extr, att, tx, tx_version, sk, 0, mix_attr); + size_t tx_hardfork_id = 0; + uint64_t tx_version = currency::get_tx_version_and_hardfork_id(get_block_height(blk_head) + 1, hf, tx_hardfork_id); // assuming the tx will be in the next block (blk_head + 1) + return construct_tx(from.get_keys(), sources, destinations, extr, att, tx, tx_version, tx_hardfork_id, sk, 0, mix_attr); } bool construct_tx_to_key(const currency::hard_forks_descriptor& hf, @@ -1779,16 +1780,17 @@ bool construct_tx_to_key(const currency::hard_forks_descriptor& hf, return false; uint64_t tx_expected_block_height = get_block_height(blk_head) + 1; - uint64_t tx_version = currency::get_tx_version(tx_expected_block_height, hf); + size_t tx_hardfork_id = 0; + uint64_t tx_version = currency::get_tx_version_and_hardfork_id(tx_expected_block_height, hf, tx_hardfork_id); boost::multiprecision::int128_t change = get_sources_total_amount(sources); change -= spending_amount; if (change < 0) return false; // should never happen if fill_tx_sources succeded if (change == 0) - return construct_tx(from.get_keys(), sources, destinations, extr, att, tx, tx_version, sk, 0, mix_attr); + return construct_tx(from.get_keys(), sources, destinations, extr, att, tx, tx_version, tx_hardfork_id, sk, 0, mix_attr); std::vector local_dst = destinations; local_dst.push_back(tx_destination_entry(change.convert_to(), from.get_public_address())); - return construct_tx(from.get_keys(), sources, local_dst, extr, att, tx, tx_version, sk, 0, mix_attr); + return construct_tx(from.get_keys(), sources, local_dst, extr, att, tx, tx_version, tx_hardfork_id, sk, 0, mix_attr); } @@ -1817,8 +1819,53 @@ bool construct_tx_with_many_outputs(const currency::hard_forks_descriptor& hf, s uint64_t sources_amount = get_sources_total_amount(sources); if (sources_amount > total_amount + fee) destinations.push_back(tx_destination_entry(sources_amount - (total_amount + fee), keys_from.account_address)); // change - uint64_t tx_version = currency::get_tx_version(currency::get_block_height(blk_head), hf); - return construct_tx(keys_from, sources, destinations, empty_attachment, tx, tx_version, 0); + size_t tx_hardfork_id = 0; + uint64_t tx_version = currency::get_tx_version_and_hardfork_id(currency::get_block_height(blk_head), hf, tx_hardfork_id); + return construct_tx(keys_from, sources, destinations, empty_attachment, tx, tx_version, tx_hardfork_id, 0); +} + +bool construct_tx(const account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + transaction& tx, + uint64_t tx_version, + size_t tx_hardfork_id, + crypto::secret_key& one_time_secret_key, + uint64_t unlock_time, + uint64_t expiration_time, + uint8_t tx_outs_attr, + bool shuffle, + uint64_t flags, + uint64_t explicit_consolidated_tx_fee, + tx_generation_context& gen_context) +{ + // extra copy operation, but creating transaction is not sensitive to this + finalize_tx_param ftp {}; + ftp.tx_version = tx_version; + ftp.tx_hardfork_id = tx_hardfork_id; + ftp.sources = sources; + ftp.prepared_destinations = destinations; + ftp.extra = extra; + ftp.attachments = attachments; + ftp.unlock_time = unlock_time; + // ftp.crypt_address = crypt_destination_addr; + ftp.expiration_time = expiration_time; + ftp.tx_outs_attr = tx_outs_attr; + ftp.shuffle = shuffle; + ftp.flags = flags; + ftp.mode_separate_fee = explicit_consolidated_tx_fee; + + finalized_tx ft{}; + ft.tx = tx; + ft.one_time_key = one_time_secret_key; + ftp.gen_context = gen_context; // ftp, not ft here, this is UGLY -- sowle + bool r = construct_tx(sender_account_keys, ftp, ft); + tx = ft.tx; + one_time_secret_key = ft.one_time_key; + gen_context = ft.ftp.gen_context; + return r; } bool construct_tx(const account_keys& sender_account_keys, @@ -1840,6 +1887,9 @@ bool construct_tx(const account_keys& sender_account_keys, // extra copy operation, but creating transaction is not sensitive to this finalize_tx_param ftp {}; ftp.tx_version = tx_version; + if (tx_version >= TRANSACTION_VERSION_POST_HF5) + LOG_PRINT_YELLOW("warning: tx_hardfork_id not set for tx, while it seems to be HF5", LOG_LEVEL_0); + ftp.tx_hardfork_id = 0; ftp.sources = sources; ftp.prepared_destinations = destinations; ftp.extra = extra; @@ -1852,7 +1902,7 @@ bool construct_tx(const account_keys& sender_account_keys, ftp.flags = flags; ftp.mode_separate_fee = explicit_consolidated_tx_fee; - finalized_tx ft = AUTO_VAL_INIT(ft); + finalized_tx ft{}; ft.tx = tx; ft.one_time_key = one_time_secret_key; ftp.gen_context = gen_context; // ftp, not ft here, this is UGLY -- sowle @@ -1863,6 +1913,60 @@ bool construct_tx(const account_keys& sender_account_keys, return r; } +bool construct_tx(const currency::account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + currency::transaction& tx, + uint64_t tx_version, + crypto::secret_key& one_time_secret_key, + uint64_t unlock_time) +{ + return construct_tx(sender_account_keys, + sources, + destinations, + extra, + attachments, + tx, + tx_version, + one_time_secret_key, + unlock_time, + 0, /* expiration_time */ + CURRENCY_TO_KEY_OUT_RELAXED, /* tx_outs_attr */ + true, /* shuffle */ + 0, /* flags */ + 0, /* explicit_consolidated_tx_fee */ + tx_generation_context{} + ); +} + +bool construct_tx(const currency::account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + currency::transaction& tx, + uint64_t tx_version) +{ + return construct_tx(sender_account_keys, + sources, + destinations, + extra, + attachments, + tx, + tx_version, + crypto::secret_key{}, /* one_time_secret_key */ + 0, /* unlock_time */ + 0, /* expiration_time */ + CURRENCY_TO_KEY_OUT_RELAXED, /* tx_outs_attr */ + true, /* shuffle */ + 0, /* flags */ + 0, /* explicit_consolidated_tx_fee */ + tx_generation_context{} + ); +} + uint64_t get_balance(const currency::account_keys& addr, const std::vector& blockchain, const map_hash2tx_t& mtx, bool dbg_log) { uint64_t res = 0; @@ -2565,19 +2669,26 @@ void test_chain_unit_base::register_callback(const std::string& cb_name, verify_ m_callbacks[cb_name] = cb; } -uint64_t test_chain_unit_base::get_tx_version_from_events(const std::vector &events)const +uint64_t test_chain_unit_base::get_tx_version_from_events(const std::vector &events) const +{ + [[maybe_unused]] size_t tx_hardfork_id{}; + return get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id); +} + +uint64_t test_chain_unit_base::get_tx_version_and_harfork_id_from_events(const std::vector &events, size_t& tx_hardfork_id) const { for (auto it = events.rbegin(); it!= events.rend(); it++) { if(it->type() == typeid(currency::block)) { const currency::block& b = boost::get(*it); - return currency::get_tx_version(get_block_height(b), m_hardforks); + return currency::get_tx_version_and_hardfork_id(get_block_height(b), m_hardforks, tx_hardfork_id); } } - return currency::get_tx_version(0, m_hardforks); + return currency::get_tx_version_and_hardfork_id(0, m_hardforks, tx_hardfork_id); } + bool test_chain_unit_base::verify(const std::string& cb_name, currency::core& c, size_t ev_index, const std::vector &events) { auto cb_it = m_callbacks.find(cb_name); diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 962d9b95..f81efb4f 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -257,6 +257,7 @@ 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; + uint64_t get_tx_version_and_harfork_id_from_events(const std::vector &events, size_t& tx_hardfork_id) const; virtual void on_test_constructed() {} // called right after test class is constructed by the chaingen void on_test_generator_created(test_generator& generator) const; // tests can override this for special initialization @@ -691,6 +692,41 @@ bool construct_tx(const currency::account_keys& sender_account_keys, uint64_t explicit_consolidated_tx_fee, currency::tx_generation_context& gen_context); +bool construct_tx(const currency::account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + currency::transaction& tx, + uint64_t tx_version, + size_t tx_hardfork_id, + crypto::secret_key& one_time_secret_key, + uint64_t unlock_time, + uint64_t expiration_time, + uint8_t tx_outs_attr, + bool shuffle, + uint64_t flags, + uint64_t explicit_consolidated_tx_fee, + currency::tx_generation_context& gen_context); + +bool construct_tx(const currency::account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + currency::transaction& tx, + uint64_t tx_version, + crypto::secret_key& one_time_secret_key, + uint64_t unlock_time); + +bool construct_tx(const currency::account_keys& sender_account_keys, + const std::vector& sources, + const std::vector& destinations, + const std::vector& extra, + const std::vector& attachments, + currency::transaction& tx, + uint64_t tx_version); + void get_confirmed_txs(const std::vector& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs); bool find_block_chain(const std::vector& events, std::vector& blockchain, map_hash2tx_t& mtx, const crypto::hash& head); bool fill_tx_sources(std::vector& sources, const std::vector& events, diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 703aec6f..1ae461b5 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -313,9 +313,10 @@ inline bool put_alias_via_tx_to_list(const currency::hard_forks_descriptor& hf, el.flags |= currency::tx_destination_entry_flags::tdef_explicit_native_asset_id | currency::tx_destination_entry_flags::tdef_zero_amount_blinding_mask; // all alias-burn outputs must have explicit native asset id and zero amount mask } - uint64_t tx_version = currency::get_tx_version(get_block_height(head_block) + 1, generator.get_hardforks()); // assuming the tx will be in the next block (head_block + 1) + size_t tx_hardfork_id{}; + uint64_t tx_version = currency::get_tx_version_and_hardfork_id(get_block_height(head_block) + 1, generator.get_hardforks(), tx_hardfork_id); // assuming the tx will be in the next block (head_block + 1) tx_set.emplace_back(); - r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_set.back(), tx_version, generator.last_tx_generated_secret_key, 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_set.back(), tx_version, tx_hardfork_id, generator.last_tx_generated_secret_key, 0); PRINT_EVENT_N_TEXT(events, "put_alias_via_tx_to_list()"); events.push_back(tx_set.back()); diff --git a/tests/core_tests/checkpoints_tests.cpp b/tests/core_tests/checkpoints_tests.cpp index d0b88650..50668524 100644 --- a/tests/core_tests/checkpoints_tests.cpp +++ b/tests/core_tests/checkpoints_tests.cpp @@ -930,8 +930,8 @@ bool gen_checkpoints_and_invalid_tx_to_pool::generate(std::vector::generate(std::vector attachments; - if (!construct_tx(bob_account.get_keys(), sources, destinations, attachments, tx_1, this->get_tx_version_from_events(events), uint64_t(0))) + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_from_events(events); + if (!construct_tx(bob_account.get_keys(), sources, destinations, attachments, tx_1, tx_version, tx_hardfork_id, uint64_t(0))) return false; SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_kept_by_block, txs_kept_by_block); diff --git a/tests/core_tests/emission_test.cpp b/tests/core_tests/emission_test.cpp index 035726ca..3f2a1127 100644 --- a/tests/core_tests/emission_test.cpp +++ b/tests/core_tests/emission_test.cpp @@ -181,8 +181,9 @@ bool pos_emission_test::generate(std::vector &events) for (size_t i = 0; i < m_pos_entries_to_generate; ++i) destinations.push_back(tx_destination_entry(pos_entry_amount, alice_acc.get_public_address())); - transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(preminer_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + transaction tx_1{}; + size_t tx_hardfork_id{}; + r = construct_tx(preminer_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_1); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); diff --git a/tests/core_tests/escrow_wallet_common.h b/tests/core_tests/escrow_wallet_common.h index f084809c..83cb9585 100644 --- a/tests/core_tests/escrow_wallet_common.h +++ b/tests/core_tests/escrow_wallet_common.h @@ -167,6 +167,7 @@ inline bool build_custom_escrow_template(const std::vector& ev bc_services::contract_private_details& cpd, uint64_t unlock_time, uint64_t expiration_time, size_t nmix, uint64_t b_fee_release, uint64_t custom_config_mask, uint64_t tx_version, + size_t tx_hardfork_id, transaction& escrow_template_tx, /* OUT */ crypto::secret_key& tx_key_sec, /* OUT */ std::vector& used_sources /* IN/OUT */) @@ -231,7 +232,7 @@ inline bool build_custom_escrow_template(const std::vector& ev if (custom_config_mask & eccf_template_additional_attach) attachments.push_back(tx_comment({ get_random_text(1024) })); - r = construct_tx(a_keys, sources, destinations, extra, attachments, escrow_template_tx, tx_version, tx_key_sec, unlock_time, crypt_addr, expiration_time, CURRENCY_TO_KEY_OUT_RELAXED, true, flags); + r = construct_tx(a_keys, sources, destinations, extra, attachments, escrow_template_tx, tx_version, tx_hardfork_id, tx_key_sec, unlock_time, crypt_addr, expiration_time, CURRENCY_TO_KEY_OUT_RELAXED, true, flags); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); if (custom_config_mask & eccf_template_no_tx_flags) @@ -266,6 +267,7 @@ inline bool build_custom_escrow_proposal(const std::vector& ev uint64_t a_fee_proposal, uint64_t b_fee_release, uint64_t custom_config_mask, uint64_t tx_version, + size_t tx_hardfork_id, transaction& escrow_proposal_tx, /* OUT */ std::vector& used_sources,/* IN/OUT */ bc_services::proposal_body* p_pb = nullptr /* OUT */ ) @@ -283,7 +285,7 @@ inline bool build_custom_escrow_proposal(const std::vector& ev p_pb = &local_pb; if (~custom_config_mask & eccf_proposal_sa_empty_body) { - r = build_custom_escrow_template(events, head, a_keys, cpd, template_unlock_time, template_expiration_time, nmix, b_fee_release, custom_config_mask, tx_version, p_pb->tx_template, p_pb->tx_onetime_secret_key, used_sources); + r = build_custom_escrow_template(events, head, a_keys, cpd, template_unlock_time, template_expiration_time, nmix, b_fee_release, custom_config_mask, tx_version, tx_hardfork_id, p_pb->tx_template, p_pb->tx_onetime_secret_key, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_template failed"); } @@ -309,7 +311,7 @@ inline bool build_custom_escrow_proposal(const std::vector& ev account_public_address crypt_addr = cpd.b_addr; crypto::secret_key tx_key_sec; // stub, not used - r = construct_tx(a_keys, sources, destinations, empty_extra, attachments, escrow_proposal_tx, tx_version, tx_key_sec, unlock_time, crypt_addr, expiration_time, 0, true, (~custom_config_mask & eccf_proposal_inv_flags) ? 0 : TX_FLAG_SIGNATURE_MODE_SEPARATE); + r = construct_tx(a_keys, sources, destinations, empty_extra, attachments, escrow_proposal_tx, tx_version, tx_hardfork_id, tx_key_sec, unlock_time, crypt_addr, expiration_time, 0, true, (~custom_config_mask & eccf_proposal_inv_flags) ? 0 : TX_FLAG_SIGNATURE_MODE_SEPARATE); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); append_vector_by_another_vector(used_sources, sources); @@ -321,7 +323,8 @@ inline bool build_custom_escrow_release_template( const account_keys& b_keys, const bc_services::contract_private_details& cpd, uint64_t unlock_time, uint64_t expiration_time, - uint64_t tx_version, + uint64_t tx_version, + size_t tx_hardfork_id, const transaction& escrow_template_tx, /* IN (needed for ms output, tx pub key) */ uint64_t custom_config_mask, /* IN */ transaction& tx /* OUT */ @@ -420,7 +423,7 @@ inline bool build_custom_escrow_release_template( crypto::secret_key one_time_secret_key = AUTO_VAL_INIT(one_time_secret_key); account_public_address crypt_address = AUTO_VAL_INIT(crypt_address); - bool r = construct_tx(b_keys, sources, destinations, extra, attachments, tx, tx_version, one_time_secret_key, unlock_time, crypt_address, expiration_time, 0, true, tx_flags); + bool r = construct_tx(b_keys, sources, destinations, extra, attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, unlock_time, crypt_address, expiration_time, 0, true, tx_flags); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); bool tx_fully_signed = false; r = sign_multisig_input_in_tx(tx, 0, b_keys, escrow_template_tx, &tx_fully_signed); @@ -470,6 +473,7 @@ inline bool build_custom_escrow_accept_proposal( uint64_t custom_config_mask, /* IN */ crypto::secret_key one_time_secret_key, /* IN */ uint64_t tx_version, /* IN */ + size_t tx_hardfork_id, /* IN */ transaction& tx, /* IN (escrow template), OUT */ std::vector& used_sources /* IN/OUT */ ) @@ -496,9 +500,9 @@ inline bool build_custom_escrow_accept_proposal( // generate release templates bc_services::escrow_relese_templates_body rtb = AUTO_VAL_INIT(rtb); - r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_NORMAL, b_keys, cpd, release_unlock_time, release_expiration_time, tx_version, tx, custom_config_mask, rtb.tx_normal_template); + r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_NORMAL, b_keys, cpd, release_unlock_time, release_expiration_time, tx_version, tx_hardfork_id, tx, custom_config_mask, rtb.tx_normal_template); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_release_template(normal) failed"); - r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_BURN, b_keys, cpd, release_unlock_time, release_expiration_time, tx_version, tx, custom_config_mask, rtb.tx_burn_template); + r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_BURN, b_keys, cpd, release_unlock_time, release_expiration_time, tx_version, tx_hardfork_id, tx, custom_config_mask, rtb.tx_burn_template); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_release_template(burn) failed"); // put release templates into the extra @@ -529,7 +533,7 @@ inline bool build_custom_escrow_accept_proposal( sources.back().separately_signed_tx_complete = true; account_public_address crypt_address = AUTO_VAL_INIT(crypt_address); - r = construct_tx(b_keys, sources, destinations, extra, attachments, tx, tx_version, one_time_secret_key, 0, crypt_address, 0, 0, true, tx_flags); // see comment above regarding unlock_time and expiration_time + r = construct_tx(b_keys, sources, destinations, extra, attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, 0, crypt_address, 0, 0, true, tx_flags); // see comment above regarding unlock_time and expiration_time CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); return true; @@ -545,6 +549,7 @@ inline bool build_custom_escrow_cancel_proposal( uint64_t custom_config_mask, /* IN */ const transaction& escrow_template_tx, /* IN */ uint64_t tx_version, /* IN */ + size_t tx_hardfork_id, /* IN */ transaction& tx, /* OUT */ std::vector& used_sources /* IN/OUT */ ) @@ -568,7 +573,7 @@ inline bool build_custom_escrow_cancel_proposal( // generate cancel release template bc_services::escrow_cancel_templates_body ctb = AUTO_VAL_INIT(ctb); - r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_CANCEL, a_keys, cpd, release_unlock_time, release_expiration_time, tx_version, escrow_template_tx, custom_config_mask, ctb.tx_cancel_template); + r = build_custom_escrow_release_template(BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_CANCEL, a_keys, cpd, release_unlock_time, release_expiration_time, tx_version, tx_hardfork_id, escrow_template_tx, custom_config_mask, ctb.tx_cancel_template); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_release_template(cancel) failed"); // put release templates into the extra @@ -593,7 +598,7 @@ inline bool build_custom_escrow_cancel_proposal( if (~custom_config_mask & eccf_cancellation_inv_crypt_address) crypt_address = cpd.b_addr; crypto::secret_key one_time_secret_key = AUTO_VAL_INIT(one_time_secret_key); - r = construct_tx(a_keys, sources, destinations, extra, attachments, tx, tx_version, one_time_secret_key, unlock_time, crypt_address, expiration_time, 0, true, tx_flags); + r = construct_tx(a_keys, sources, destinations, extra, attachments, tx, tx_version, tx_hardfork_id, one_time_secret_key, unlock_time, crypt_address, expiration_time, 0, true, tx_flags); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); return true; diff --git a/tests/core_tests/escrow_wallet_tests.cpp b/tests/core_tests/escrow_wallet_tests.cpp index b511aaab..6c805d29 100644 --- a/tests/core_tests/escrow_wallet_tests.cpp +++ b/tests/core_tests/escrow_wallet_tests.cpp @@ -503,10 +503,11 @@ bool escrow_incorrect_proposal::generate(std::vector& events) // 1. create normal proposal and make sure it goes correctly through out the whole mechanism (test self-check) // if it fails, it means build_custom_escrow_proposal() produced incorrect proposal - uint64_t tx_version = get_tx_version(get_block_height(blk_1r), m_hardforks); + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1r), m_hardforks, tx_hardfork_id); uint64_t normal_escrow_mask = eccf_proposal_additional_attach | eccf_template_additional_extra | eccf_template_additional_attach; transaction normal_escrow_proposal_tx = AUTO_VAL_INIT(normal_escrow_proposal_tx); - r = build_custom_escrow_proposal(events, blk_1r, miner_acc.get_keys(), cpd, 0, 0, 0, blk_1r.timestamp + 3600, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, normal_escrow_mask, tx_version, normal_escrow_proposal_tx, used_sources); + r = build_custom_escrow_proposal(events, blk_1r, miner_acc.get_keys(), cpd, 0, 0, 0, blk_1r.timestamp + 3600, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, normal_escrow_mask, tx_version, tx_hardfork_id, normal_escrow_proposal_tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); events.push_back(normal_escrow_proposal_tx); @@ -550,9 +551,9 @@ bool escrow_incorrect_proposal::generate(std::vector& events) uint64_t config_mask = custom_config_masks[i].mask; cpd.comment = "#" + std::to_string(i) + " " + custom_config_masks[i].name; - tx_version = get_tx_version(get_block_height(top_block), m_hardforks); - transaction escrow_proposal_tx = AUTO_VAL_INIT(escrow_proposal_tx); - r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, 0, 0, top_block.timestamp + 3600, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, config_mask, tx_version, escrow_proposal_tx, used_sources); + tx_version = get_tx_version_and_hardfork_id(get_block_height(top_block), m_hardforks, tx_hardfork_id); + transaction escrow_proposal_tx{}; + r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, 0, 0, top_block.timestamp + 3600, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, config_mask, tx_version, tx_hardfork_id, escrow_proposal_tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); LOG_PRINT_YELLOW("proposal tx: " << get_transaction_hash(escrow_proposal_tx) << " is built for mask: " << cpd.comment, LOG_LEVEL_0); @@ -579,10 +580,10 @@ bool escrow_incorrect_proposal::generate(std::vector& events) { cpd.comment = "incorrect unlock time (past)"; - transaction tx = AUTO_VAL_INIT(tx); - tx_version = get_tx_version(get_block_height(top_block), m_hardforks); + transaction tx{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(top_block), m_hardforks, tx_hardfork_id); // set unlock time to the past (suppose it's incorrect for escrow proposals) - r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, top_block.timestamp, 0, top_block.timestamp, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx, used_sources); + r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, top_block.timestamp, 0, top_block.timestamp, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx_hardfork_id, tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); LOG_PRINT_YELLOW("proposal tx: " << get_transaction_hash(tx) << " is built for " << cpd.comment, LOG_LEVEL_0); events.push_back(tx); @@ -592,11 +593,11 @@ bool escrow_incorrect_proposal::generate(std::vector& events) { cpd.comment = "incorrect unlock time (future)"; - transaction tx = AUTO_VAL_INIT(tx); - tx_version = get_tx_version(get_block_height(top_block), m_hardforks); + transaction tx{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(top_block), m_hardforks, tx_hardfork_id); // set unlock time to the future (suppose it's incorrect for escrow proposals) uint64_t unlock_time = top_block.timestamp + 365 * 24 * 60 * 60; - r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, unlock_time, 0, unlock_time, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx, used_sources); + r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, unlock_time, 0, unlock_time, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx_hardfork_id, tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); LOG_PRINT_YELLOW("proposal tx: " << get_transaction_hash(tx) << " is built for " << cpd.comment, LOG_LEVEL_0); events.push_back(tx); @@ -606,9 +607,9 @@ bool escrow_incorrect_proposal::generate(std::vector& events) { cpd.comment = "template zero expiration time"; - transaction tx = AUTO_VAL_INIT(tx); - tx_version = get_tx_version(get_block_height(top_block), m_hardforks); - r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, 0, 0, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx, used_sources); + transaction tx{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(top_block), m_hardforks, tx_hardfork_id); + r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, 0, 0, 0, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx_hardfork_id, tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); LOG_PRINT_YELLOW("proposal tx: " << get_transaction_hash(tx) << " is built for " << cpd.comment, LOG_LEVEL_0); events.push_back(tx); @@ -618,11 +619,11 @@ bool escrow_incorrect_proposal::generate(std::vector& events) { cpd.comment = "proposal non-zero expiration time"; - transaction tx = AUTO_VAL_INIT(tx); - tx_version = get_tx_version(get_block_height(top_block), m_hardforks); + transaction tx{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(top_block), m_hardforks, tx_hardfork_id); uint64_t proposal_expiration_time = top_block.timestamp + 12 * 60 * 60; uint64_t template_expiration_time = top_block.timestamp + 12 * 60 * 60; - r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, proposal_expiration_time, 0, template_expiration_time, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx, used_sources); + r = build_custom_escrow_proposal(events, top_block, miner_acc.get_keys(), cpd, 0, proposal_expiration_time, 0, template_expiration_time, 0, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, eccf_normal, tx_version, tx_hardfork_id, tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); LOG_PRINT_YELLOW("proposal tx: " << get_transaction_hash(tx) << " is built for " << cpd.comment, LOG_LEVEL_0); events.push_back(tx); @@ -1149,17 +1150,18 @@ bool escrow_incorrect_proposal_acceptance::generate(std::vector& events) const destinations.push_back(tx_destination_entry(chunk_amount, bob_acc.get_public_address())); } // no change back to the miner - it will become a fee - transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + transaction tx_1{}; + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_1); @@ -1949,7 +1952,8 @@ bool escrow_incorrect_cancel_proposal::generate(std::vector& e } // no change back to the miner - it will become a fee transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_1); @@ -1969,27 +1973,27 @@ bool escrow_incorrect_cancel_proposal::generate(std::vector& e // create normal escrow proposal bc_services::proposal_body prop = AUTO_VAL_INIT(prop); - uint64_t tx_version = get_tx_version(get_block_height(blk_1r), m_hardforks); + uint64_t tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1r), m_hardforks, tx_hardfork_id); transaction escrow_proposal_tx = AUTO_VAL_INIT(escrow_proposal_tx); - r = build_custom_escrow_proposal(events, blk_1r, alice_acc.get_keys(), m_cpd, 0, 0, 0, blk_1r.timestamp + 36000, 0, TESTS_DEFAULT_FEE, m_bob_fee_release, eccf_normal, tx_version, escrow_proposal_tx, used_sources, &prop); + r = build_custom_escrow_proposal(events, blk_1r, alice_acc.get_keys(), m_cpd, 0, 0, 0, blk_1r.timestamp + 36000, 0, TESTS_DEFAULT_FEE, m_bob_fee_release, eccf_normal, tx_version, tx_hardfork_id, escrow_proposal_tx, used_sources, &prop); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_proposal failed"); events.push_back(escrow_proposal_tx); MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner_acc, escrow_proposal_tx); // create normal escrow proposal acceptance transaction escrow_normal_acceptance_tx = prop.tx_template; - tx_version = get_tx_version(get_block_height(blk_2), m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_2), m_hardforks, tx_hardfork_id); uint64_t normal_acceptance_mask = eccf_acceptance_no_tsa_compression; - r = build_custom_escrow_accept_proposal(events, blk_2, 0, bob_acc.get_keys(), m_cpd, 0, 0, 0, 0, TESTS_DEFAULT_FEE, m_bob_fee_release, normal_acceptance_mask, prop.tx_onetime_secret_key, tx_version, escrow_normal_acceptance_tx, used_sources); + r = build_custom_escrow_accept_proposal(events, blk_2, 0, bob_acc.get_keys(), m_cpd, 0, 0, 0, 0, TESTS_DEFAULT_FEE, m_bob_fee_release, normal_acceptance_mask, prop.tx_onetime_secret_key, tx_version, tx_hardfork_id, escrow_normal_acceptance_tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_accept_proposal failed"); events.push_back(escrow_normal_acceptance_tx); MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, escrow_normal_acceptance_tx); // create normal cancel proposal - tx_version = get_tx_version(get_block_height(blk_3), m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_3), m_hardforks, tx_hardfork_id); transaction escrow_normal_cancel_proposal_tx = AUTO_VAL_INIT(escrow_normal_cancel_proposal_tx); - r = build_custom_escrow_cancel_proposal(events, blk_3, 0, alice_acc.get_keys(), m_cpd, 0, 0, 0, blk_3.timestamp + 3600, TESTS_DEFAULT_FEE, eccf_normal, prop.tx_template, tx_version, escrow_normal_cancel_proposal_tx, used_sources); + r = build_custom_escrow_cancel_proposal(events, blk_3, 0, alice_acc.get_keys(), m_cpd, 0, 0, 0, blk_3.timestamp + 3600, TESTS_DEFAULT_FEE, eccf_normal, prop.tx_template, tx_version, tx_hardfork_id, escrow_normal_cancel_proposal_tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_cancel_proposal failed"); events.push_back(escrow_normal_cancel_proposal_tx); @@ -2057,9 +2061,9 @@ bool escrow_incorrect_cancel_proposal::generate(std::vector& e uint64_t mask = ccm_el.mask; transaction incorrect_cancellation_proposal_tx = prop.tx_template; - uint64_t tx_version = get_tx_version(get_block_height(blk_3), m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_3), m_hardforks, tx_hardfork_id); r = build_custom_escrow_cancel_proposal(events, prev_block, 0, alice_acc.get_keys(), m_cpd, ccm_el.unlock_time, ccm_el.expiration_time, ccm_el.release_unlock_time, ccm_el.release_expiration_time, - TESTS_DEFAULT_FEE, mask, prop.tx_template, tx_version, incorrect_cancellation_proposal_tx, used_sources); + TESTS_DEFAULT_FEE, mask, prop.tx_template, tx_version, tx_hardfork_id, incorrect_cancellation_proposal_tx, used_sources); CHECK_AND_ASSERT_MES(r, false, "build_custom_escrow_cancel_proposal failed"); // In order to use the same escrow proposal to test different invalid cancellations we need to switch chains after each try @@ -2985,9 +2989,10 @@ bool escrow_proposal_acceptance_in_alt_chain::generate(std::vector& events r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), m_amount * m_fake_amounts_count + TESTS_DEFAULT_FEE, 0); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); - transaction tx_0 = AUTO_VAL_INIT(tx_0); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + transaction tx_0{}; + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); uint64_t burned_tx_amount_total = get_burned_amount(tx_0); diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index 861b29aa..ff9d0381 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -437,7 +437,7 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector& CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); transaction tx_1 = AUTO_VAL_INIT(tx_1); r = construct_tx(alice_acc.get_keys(), sources, std::vector{ tx_destination_entry(MK_TEST_COINS(90) - TESTS_DEFAULT_FEE, miner_acc.get_public_address()) }, - empty_attachment, tx_1, get_tx_version_from_events(events), stake_lock_time /* try to use stake unlock time -- should not work as it is not a coinbase */); + empty_attachment, tx_1, get_tx_version_from_events(events), 0, stake_lock_time /* try to use stake unlock time -- should not work as it is not a coinbase */); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); DO_CALLBACK(events, "mark_invalid_tx"); @@ -882,7 +882,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector{ tx_destination_entry(stake_amount / 2, miner_acc.get_public_address()) }, - empty_attachment, tx_1, get_tx_version_from_events(events), stake_unlock_time /* try to use stake unlock time -- should not work as it is not a coinbase */); + empty_attachment, tx_1, get_tx_version_from_events(events), 0, stake_unlock_time /* try to use stake unlock time -- should not work as it is not a coinbase */); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); DO_CALLBACK(events, "mark_invalid_tx"); diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp index e73c6cef..33361093 100644 --- a/tests/core_tests/integer_overflow.cpp +++ b/tests/core_tests/integer_overflow.cpp @@ -157,9 +157,10 @@ bool gen_uint_overflow_2::generate(std::vector& events) const // sources.front().amount = destinations[0].amount + destinations[2].amount + destinations[3].amount + TESTS_DEFAULT_FEE destinations.push_back(tx_destination_entry(sources.front().amount - TX_MAX_TRANSFER_AMOUNT - TX_MAX_TRANSFER_AMOUNT + 1 - TESTS_DEFAULT_FEE, bob_addr)); - currency::transaction tx_1; + currency::transaction tx_1{}; std::vector attachments; - if (!construct_tx(miner_account.get_keys(), sources, destinations, attachments, tx_1, get_tx_version_from_events(events), 0)) + size_t tx_hardfork_id{}; + if (!construct_tx(miner_account.get_keys(), sources, destinations, attachments, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0)) return false; events.push_back(tx_1); @@ -186,7 +187,7 @@ bool gen_uint_overflow_2::generate(std::vector& events) const currency::transaction tx_2; std::vector attachments2; - if (!construct_tx(bob_account.get_keys(), sources, destinations, attachments2, tx_2, get_tx_version_from_events(events), 0)) + if (!construct_tx(bob_account.get_keys(), sources, destinations, attachments2, tx_2, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0)) return false; events.push_back(tx_2); diff --git a/tests/core_tests/misc_tests.cpp b/tests/core_tests/misc_tests.cpp index b9ccab13..c7b738ed 100644 --- a/tests/core_tests/misc_tests.cpp +++ b/tests/core_tests/misc_tests.cpp @@ -237,8 +237,9 @@ bool block_template_vs_invalid_txs_from_pool::generate(std::vector sources; r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), de.amount + TESTS_DEFAULT_FEE, 0); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); - transaction tx_1m = AUTO_VAL_INIT(tx_1m); - r = construct_tx(miner_acc.get_keys(), sources, std::vector({ de }), empty_attachment, tx_1m, get_tx_version_from_events(events), 0); + transaction tx_1m; + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, std::vector({ de }), empty_attachment, tx_1m, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_1m); @@ -269,18 +270,18 @@ bool block_template_vs_invalid_txs_from_pool::generate(std::vector(boost::get(tx_1m.vout[se.real_output_in_tx_index]).target).keys.size(); se.ms_sigs_count = 1; - transaction tx_2m = AUTO_VAL_INIT(tx_2m); + transaction tx_2m{}; r = construct_tx(bob_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address()) }), - empty_attachment, tx_2m, get_tx_version_from_events(events), 0); + empty_attachment, tx_2m, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); bool input_fully_signed = false; r = sign_multisig_input_in_tx(tx_2m, 0, bob_acc.get_keys(), tx_1m, &input_fully_signed); CHECK_AND_ASSERT_MES(r && input_fully_signed, false, "sign_multisig_input_in_tx failed, input_fully_signed=" << input_fully_signed); events.push_back(tx_2m); - transaction tx_2ma = AUTO_VAL_INIT(tx_2ma); + transaction tx_2ma{}; r = construct_tx(bob_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, miner_acc.get_public_address()) }), - empty_attachment, tx_2ma, get_tx_version_from_events(events), 0); + empty_attachment, tx_2ma, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); input_fully_signed = false; r = sign_multisig_input_in_tx(tx_2ma, 0, bob_acc.get_keys(), tx_1m, &input_fully_signed); @@ -436,8 +437,9 @@ bool test_blockchain_vs_spent_multisig_outs::generate(std::vector destinations; r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc, alice_acc, m_alice_initial_balance, TESTS_DEFAULT_FEE, 0, sources, destinations, true /* spends */, false /* unlock time */); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_0); @@ -701,7 +702,8 @@ bool asset_depoyment_and_few_zc_utxos::generate(std::vector& e m_alice_initial_balance = TESTS_DEFAULT_FEE * 100; r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), m_alice_initial_balance + TESTS_DEFAULT_FEE, 0); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_0); @@ -1017,16 +1019,10 @@ bool asset_operation_and_hardfork_checks::generate( CHECK_AND_ASSERT_MES(success, false, "fail to fill sources, destinations"); - tx_version = get_tx_version(get_block_height(blk_0r), - m_hardforks); + size_t tx_hardfork_id{}; + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_0r), m_hardforks, tx_hardfork_id); - success = construct_tx(miner.get_keys(), - sources, - destinations, - empty_attachment, - tx_0, - tx_version, - 0); + success = construct_tx(miner.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(success, false, "fail to construct tx_0"); @@ -1058,7 +1054,7 @@ bool asset_operation_and_hardfork_checks::generate( /* to = */ alice.get_public_address(), /* asset_id = */ currency::null_pkey); - tx_version = get_tx_version(get_block_height(blk_1r), m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1r), m_hardforks, tx_hardfork_id); size_t hf_n = m_hardforks.get_the_most_recent_hardfork_id_for_height(get_block_height(blk_1r)); fill_ado_version_based_onhardfork(m_ado_hello, hf_n); fill_adb_version_based_onhardfork(*m_ado_hello.opt_descriptor, hf_n); @@ -1069,6 +1065,7 @@ bool asset_operation_and_hardfork_checks::generate( empty_attachment, tx_1, tx_version, + tx_hardfork_id, stub, 0); @@ -1105,8 +1102,7 @@ bool asset_operation_and_hardfork_checks::generate( CHECK_AND_ASSERT_MES(success, false, "fail to fill sources, destinations"); - tx_version = get_tx_version(get_block_height(blk_2r), - m_hardforks); + tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_2r), m_hardforks, tx_hardfork_id); hf_n = m_hardforks.get_the_most_recent_hardfork_id_for_height(get_block_height(blk_2r)); fill_ado_version_based_onhardfork(m_ado_hello, hf_n); @@ -1118,6 +1114,7 @@ bool asset_operation_and_hardfork_checks::generate( empty_attachment, tx_2, tx_version, + tx_hardfork_id, stub, 0); @@ -1159,6 +1156,7 @@ bool asset_operation_and_hardfork_checks::generate( /* attachments = */ {m_ado_bye}, tx_3, tx_version, + hf_n, 0); CHECK_AND_ASSERT_MES(success, false, "fail to construct tx_3"); @@ -1199,6 +1197,7 @@ bool asset_operation_and_hardfork_checks::generate( /* attachments = */ {m_ado_bye}, tx_4, tx_version, + hf_n, stub, 0); @@ -2068,6 +2067,7 @@ bool asset_current_and_total_supplies_comparative_constraints::generate(std::vec GENERATE_ACCOUNT(miner); GENERATE_ACCOUNT(alice); transaction tx_0{}, tx_1{}, tx_2{}, tx_3{}, tx_4{}; + size_t tx_hardfork_id{}; m_accounts.push_back(miner); m_accounts.push_back(alice); @@ -2091,7 +2091,7 @@ bool asset_current_and_total_supplies_comparative_constraints::generate(std::vec success = fill_tx_sources_and_destinations(events, top, miner.get_keys(), alice.get_public_address(), MK_TEST_COINS(8), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_EQ(success, true); - success = construct_tx(miner.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version(get_block_height(top), m_hardforks), 0); + success = construct_tx(miner.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_hardfork_id(get_block_height(top), m_hardforks, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_EQ(success, true); } @@ -2115,7 +2115,7 @@ bool asset_current_and_total_supplies_comparative_constraints::generate(std::vec destinations.emplace_back(ado.opt_descriptor->current_supply, alice.get_public_address(), null_pkey); CHECK_AND_ASSERT_EQ(ado.opt_descriptor->total_max_supply, 0); CHECK_AND_ASSERT_EQ(ado.opt_descriptor->total_max_supply, ado.opt_descriptor->current_supply); - success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_1, get_tx_version(get_block_height(top), m_hardforks), one_time, 0); + success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_1, get_tx_version_and_hardfork_id(get_block_height(top), m_hardforks, tx_hardfork_id), tx_hardfork_id, one_time, 0); CHECK_AND_ASSERT_EQ(success, true); } @@ -2140,7 +2140,7 @@ bool asset_current_and_total_supplies_comparative_constraints::generate(std::vec CHECK_AND_ASSERT_EQ(success, true); destinations.emplace_back(ado.opt_descriptor->current_supply, alice.get_public_address(), null_pkey); CHECK_AND_ASSERT_MES(ado.opt_descriptor->current_supply > ado.opt_descriptor->total_max_supply, false, "current_supply <= total_max_supply"); - success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_2, get_tx_version(get_block_height(top), m_hardforks), one_time, 0); + success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_2, get_tx_version_and_hardfork_id(get_block_height(top), m_hardforks, tx_hardfork_id), tx_hardfork_id, one_time, 0); CHECK_AND_ASSERT_EQ(success, true); } @@ -2165,7 +2165,7 @@ bool asset_current_and_total_supplies_comparative_constraints::generate(std::vec CHECK_AND_ASSERT_EQ(success, true); destinations.emplace_back(ado.opt_descriptor->current_supply, alice.get_public_address(), null_pkey); CHECK_AND_ASSERT(ado.opt_descriptor->current_supply <= ado.opt_descriptor->total_max_supply, false); - success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_3, get_tx_version(get_block_height(top), m_hardforks), one_time, 0); + success = construct_tx(alice.get_keys(), sources, destinations, {ado}, empty_attachment, tx_3, get_tx_version_and_hardfork_id(get_block_height(top), m_hardforks, tx_hardfork_id), tx_hardfork_id, one_time, 0); CHECK_AND_ASSERT_EQ(success, true); } diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index ef4f0c34..ed0978e6 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -880,7 +880,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), ms_addr_list, amount, TESTS_DEFAULT_FEE, 0, sources, destinations, true, true, 4); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx = AUTO_VAL_INIT(tx); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r == false, false, "construct_tx was expected to fail, but successed"); @@ -893,7 +893,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_1); @@ -917,7 +917,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons // Transaction should be successfully created, but rejected by the core transaction tx_2 = AUTO_VAL_INIT(tx_2); - r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ de }), empty_attachment, tx_2, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ de }), empty_attachment, tx_2, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); bool tx_fully_signed = false; r = sign_multisig_input_in_tx(tx_2, 0, bob_acc.get_keys(), tx_1, &tx_fully_signed); @@ -947,7 +947,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons se.ms_sigs_count = 2; transaction tx_3 = AUTO_VAL_INIT(tx_3); - r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, bob_acc.get_public_address()) }), empty_attachment, tx_3, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, bob_acc.get_public_address()) }), empty_attachment, tx_3, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); r = sign_multisig_input_in_tx(tx_3, 0, bob_acc.get_keys(), tx_1, &tx_fully_signed); CHECK_AND_ASSERT_MES(r && !tx_fully_signed, false, "sign_multisig_input_in_tx failed, tx_fully_signed : " << tx_fully_signed); @@ -966,7 +966,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_4 = AUTO_VAL_INIT(tx_4); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_4, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_4, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_4); @@ -984,7 +984,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons se.ms_sigs_count = 3; transaction tx_5 = AUTO_VAL_INIT(tx_5); - r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_5, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_5, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // use sign_multisig_input_in_tx_custom to create tx with more signatures (3) than minimum_sigs (1) @@ -1009,7 +1009,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_6 = AUTO_VAL_INIT(tx_6); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_6, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_6, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_6); @@ -1028,7 +1028,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons se.ms_sigs_count = 4; transaction tx_7 = AUTO_VAL_INIT(tx_7); - r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_7, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_7, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // use sign_multisig_input_in_tx_custom to create tx with more signatures (4) than minimum_sigs (1) @@ -1051,7 +1051,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_8 = AUTO_VAL_INIT(tx_8); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_8, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_8, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_8); @@ -1071,7 +1071,7 @@ bool multisig_minimum_sigs::generate(std::vector& events) cons se.ms_sigs_count = redundant_keys_count; transaction tx_9 = AUTO_VAL_INIT(tx_9); - r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_9, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), empty_attachment, tx_9, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); boost::get(tx_9.signatures[0]).s.resize(redundant_keys_count, invalid_signature); @@ -1256,7 +1256,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c r = fill_tx_sources_and_destinations(events, blk_2, alice_acc, bob_acc, amount - TESTS_DEFAULT_FEE * 2, TESTS_DEFAULT_FEE, 0 /*nmix*/, sources, destinations, true, false /* check_for_unlocktime */); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_3{}; - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_from_events(events), 0); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_3); @@ -1281,7 +1281,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c crypto::secret_key stub_key = AUTO_VAL_INIT(stub_key); etc_tx_details_expiration_time extra_expiration_time = AUTO_VAL_INIT(extra_expiration_time); extra_expiration_time.v = expiration_time; - r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ extra_expiration_time }), empty_attachment, tx_4, get_tx_version_from_events(events), stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ extra_expiration_time }), empty_attachment, tx_4, get_tx_version_from_events(events), 0, stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); CHECK_AND_ASSERT_MES(get_tx_expiration_time(tx_4) == expiration_time, false, "Expiration time was not correctly set"); DO_CALLBACK(events, "mark_invalid_tx"); @@ -1289,7 +1289,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c // add similar tx (same sources and destinations) with no expiration_time - should be accepted by the core transaction tx_5 = AUTO_VAL_INIT(tx_5); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_5, get_tx_version_from_events(events), stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_5, get_tx_version_from_events(events), 0, stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_5); @@ -1316,7 +1316,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c extra_expiration_time = AUTO_VAL_INIT(extra_expiration_time); extra_expiration_time.v = expiration_time; transaction tx_6 = AUTO_VAL_INIT(tx_6); - r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ extra_expiration_time }), empty_attachment, tx_6, get_tx_version_from_events(events), stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ extra_expiration_time }), empty_attachment, tx_6, get_tx_version_from_events(events), 0, stub_key, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); CHECK_AND_ASSERT_MES(get_tx_expiration_time(tx_6) == expiration_time, false, "Expiration time was not correctly set"); r = sign_multisig_input_in_tx(tx_6, tx_5_ms_out_idx, miner_acc.get_keys(), tx_5, &tx_fully_signed); @@ -1429,7 +1429,7 @@ bool multisig_and_coinbase::generate(std::vector& events) cons destinations.assign({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, bob_acc.get_public_address()) }); transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); bool fully_signed_tx = false; r = sign_multisig_input_in_tx(tx_1, 0, alice_acc.get_keys(), blk_1.miner_tx, &fully_signed_tx); @@ -1493,7 +1493,7 @@ bool multisig_and_coinbase::generate(std::vector& events) cons transaction tx_2 = AUTO_VAL_INIT(tx_2); r = construct_tx(alice_acc.get_keys(), std::vector({ se }), std::vector({ tx_destination_entry(se.amount - TESTS_DEFAULT_FEE, alice_acc.get_public_address()) }), - empty_attachment, tx_2, get_tx_version_from_events(events), 0); + empty_attachment, tx_2, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); r = sign_multisig_input_in_tx(tx_2, 0, alice_acc.get_keys(), blk_3.miner_tx, &fully_signed_tx); @@ -2259,7 +2259,7 @@ bool multisig_n_participants_seq_signing::generate(std::vector r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), ms_addr_list, ms_amount, TESTS_DEFAULT_FEE, 0, sources, destinations, true, true, m_minimum_signs_to_spend); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0, 0); events.push_back(tx_1); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); @@ -2289,7 +2289,7 @@ bool multisig_n_participants_seq_signing::generate(std::vector // construct a transaction (no participants keys are provided, thus no signs for ms input are created) transaction tx = AUTO_VAL_INIT(tx); - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx, get_tx_version_from_events(events), 0); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // sign the transaction by (m_minimum_signs_to_spend) participants in random order diff --git a/tests/core_tests/offers_test.cpp b/tests/core_tests/offers_test.cpp index e9be6c2c..39c115ae 100644 --- a/tests/core_tests/offers_test.cpp +++ b/tests/core_tests/offers_test.cpp @@ -633,7 +633,7 @@ bool offer_removing_and_selected_output::generate(std::vector& std::vector sources; r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), destinations_amount + TESTS_DEFAULT_FEE, 0); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_0); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); diff --git a/tests/core_tests/pos_basic_tests.cpp b/tests/core_tests/pos_basic_tests.cpp index 06fbf71a..c07a2850 100644 --- a/tests/core_tests/pos_basic_tests.cpp +++ b/tests/core_tests/pos_basic_tests.cpp @@ -174,7 +174,8 @@ bool pos_mining_with_decoys::generate(std::vector& events) con destinations.emplace_back(COIN, carol_acc.get_public_address()); transaction tx_0{}; - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_0); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp index d884c17e..9bff9d9b 100644 --- a/tests/core_tests/transaction_tests.cpp +++ b/tests/core_tests/transaction_tests.cpp @@ -101,7 +101,7 @@ bool test_transaction_generation_and_ring_signature() transaction tx_rc1; std::vector attachments; - bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, attachments, tx_rc1, get_tx_version(0, hf), 0); + bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, attachments, tx_rc1, get_tx_version(0, hf), 0, 0); CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction"); crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1); diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index dea895ea..a0527f4a 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -1239,8 +1239,9 @@ bool tx_expiration_time::generate(std::vector& events) const std::vector destinations; r = fill_tx_sources_and_destinations(events, blk_2, alice_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); - transaction tx_2 = AUTO_VAL_INIT(tx_2); - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_2, get_tx_version_from_events(events), 0); + transaction tx_2{}; + size_t tx_hardfork_id{}; + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_2, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); set_tx_expiration_time(tx_2, ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 1); // one second greather than minimum allowed r = resign_tx(alice_acc.get_keys(), sources, tx_2); @@ -1258,7 +1259,7 @@ bool tx_expiration_time::generate(std::vector& events) const r = fill_tx_sources_and_destinations(events, blk_3, alice_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_3 = AUTO_VAL_INIT(tx_3); - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_from_events(events), 0); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); set_tx_expiration_time(tx_3, ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 0); // exact expiration time, should not pass (see core condition above) r = resign_tx(alice_acc.get_keys(), sources, tx_3); @@ -1322,8 +1323,9 @@ bool tx_expiration_time_and_block_template::generate(std::vector destinations; bool r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); - transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0); + transaction tx_1{}; + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); uint64_t tx_1_expiration_time = ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 1; // one second greather than minimum allowed set_tx_expiration_time(tx_1, tx_1_expiration_time); @@ -1394,8 +1396,9 @@ bool tx_expiration_time_and_chain_switching::generate(std::vector destinations; r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); - transaction tx_0 = AUTO_VAL_INIT(tx_0); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + transaction tx_0{}; + size_t tx_hardfork_id{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); uint64_t tx_0_expiration_time = ts_median + TX_EXPIRATION_MEDIAN_SHIFT + 0; // one second less than minimum allowed (see condition above) set_tx_expiration_time(tx_0, tx_0_expiration_time); @@ -1515,8 +1518,9 @@ bool tx_key_image_pool_conflict::generate(std::vector& events) std::vector destinations; r = fill_tx_sources_and_destinations(events, blk_0r, m_miner_acc.get_keys(), bob_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); - transaction tx_0 = AUTO_VAL_INIT(tx_0); - r = construct_tx(m_miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_from_events(events), 0); + transaction tx_0{}; + size_t tx_hardfork_id{}; + r = construct_tx(m_miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id), tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); LOG_PRINT_YELLOW("tx_0 = " << get_transaction_hash(tx_0), LOG_LEVEL_0); // do not push tx_0 into events yet @@ -1643,15 +1647,18 @@ bool tx_version_against_hardfork::generate(std::vector& events // tx_1 tx_1 is accepted uint64_t tx_version_good = 0, tx_version_bad = 0; + size_t tx_hardfork_id = 0; // select good and bad tx versions based on active hardfork size_t most_recent_hardfork_id = m_hardforks.get_the_most_recent_hardfork_id_for_height(get_block_height(blk_0r)); switch(most_recent_hardfork_id) { case ZANO_HARDFORK_04_ZARCANUM: + tx_hardfork_id = 0; case ZANO_HARDFORK_05: tx_version_good = TRANSACTION_VERSION_POST_HF4; tx_version_bad = TRANSACTION_VERSION_PRE_HF4; + tx_hardfork_id = ZANO_HARDFORK_05; break; default: LOG_ERROR("hardfork " << most_recent_hardfork_id << " is not supported by this test"); @@ -1667,7 +1674,7 @@ bool tx_version_against_hardfork::generate(std::vector& events r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_0{}; - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_good, 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_good, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); events.push_back(tx_0); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); @@ -1681,7 +1688,7 @@ bool tx_version_against_hardfork::generate(std::vector& events r = fill_tx_sources_and_destinations(events, blk_0, miner_acc.get_keys(), miner_acc.get_public_address(), MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_1{}; - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_bad, 0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, tx_version_bad, tx_hardfork_id, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // check tx pool rejection DO_CALLBACK(events, "mark_invalid_tx"); diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 79eb631d..3e38e3ee 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -2306,7 +2306,7 @@ bool generate_oversized_offer(size_t min_size, size_t max_size, bc_services::off // construct fake tx to estimate it's size transaction tx = AUTO_VAL_INIT(tx); crypto::secret_key one_time_secret_key; - if (!construct_tx(account_keys(), std::vector(), std::vector(), empty_extra, att_container, tx, tx_version, one_time_secret_key, 0, 0, true, 0)) + if (!construct_tx(account_keys(), std::vector(), std::vector(), empty_extra, att_container, tx, tx_version, 0, one_time_secret_key, 0, 0, true, 0)) return false; size_t sz = get_object_blobsize(tx); diff --git a/tests/core_tests/zarcanum_test.cpp b/tests/core_tests/zarcanum_test.cpp index 72dea5b4..472d3315 100644 --- a/tests/core_tests/zarcanum_test.cpp +++ b/tests/core_tests/zarcanum_test.cpp @@ -520,7 +520,8 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector Date: Fri, 27 Dec 2024 19:37:39 +0100 Subject: [PATCH 4/9] tests: fixes for performance_tests and functional_tests --- tests/functional_tests/core_concurrency_test.cpp | 3 ++- tests/performance_tests/single_tx_test_base.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 3fcbc00c..1d791dcc 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -77,7 +77,8 @@ bool create_block_template_manually(const currency::block& prev_block, boost::mu result.miner_tx, block_reward_without_fee, block_reward, - TRANSACTION_VERSION_PRE_HF4); + TRANSACTION_VERSION_PRE_HF4, + 0); CHECK_AND_ASSERT_MES(r, false, "construct_miner_tx failed"); size_t coinbase_size = get_object_blobsize(result.miner_tx); diff --git a/tests/performance_tests/single_tx_test_base.h b/tests/performance_tests/single_tx_test_base.h index a605d624..a3aff814 100644 --- a/tests/performance_tests/single_tx_test_base.h +++ b/tests/performance_tests/single_tx_test_base.h @@ -20,7 +20,7 @@ public: uint64_t block_reward_without_fee = 0; uint64_t block_reward = 0; - if(!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().account_address, m_bob.get_keys().account_address, m_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, blobdata(), CURRENCY_MINER_TX_MAX_OUTS)) + if(!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().account_address, m_bob.get_keys().account_address, m_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, 0, blobdata(), CURRENCY_MINER_TX_MAX_OUTS)) return false; m_tx_pub_key = get_tx_pub_key_from_extra(m_tx); return true; From 653b05298b22a9a3a9e200cd73314bd97bf4f43a Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 28 Dec 2024 00:27:16 +0100 Subject: [PATCH 5/9] coretests: hard_fork_5_tx_version implemented --- tests/core_tests/hard_fork_5.cpp | 79 ++++++++++++++++++++++++++++---- tests/core_tests/hard_fork_5.h | 4 +- 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/tests/core_tests/hard_fork_5.cpp b/tests/core_tests/hard_fork_5.cpp index 8a88658a..bd0cd4df 100644 --- a/tests/core_tests/hard_fork_5.cpp +++ b/tests/core_tests/hard_fork_5.cpp @@ -7,26 +7,87 @@ using namespace currency; +hard_fork_5_tx_version::hard_fork_5_tx_version() +{ + REGISTER_CALLBACK_METHOD(hard_fork_5_tx_version, c1); +} + bool hard_fork_5_tx_version::generate(std::vector& events) const { // - // Test idea: + // Test idea: ensure that the correct tx.hardfork_id is required after HF5. // + bool r = false; uint64_t ts = test_core_time::get_time(); - GENERATE_ACCOUNT(miner_acc); - GENERATE_ACCOUNT(alice_acc); + m_accounts.resize(TOTAL_ACCS_COUNT); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); + account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); - //// rebuild genesis miner tx - //std::vector destinations; - //destinations.emplace_back(MK_TEST_COINS(1), alice_acc.get_public_address()); - //destinations.emplace_back(MK_TEST_COINS(1), alice_acc.get_public_address()); - //CHECK_AND_ASSERT_MES(replace_coinbase_in_genesis_block(destinations, generator, events, blk_0), false, ""); // leftover amount will be also send to miner - DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + // make a simple tx just to check HF5 tx.hardfork_id rule basic validity MAKE_TX(events, tx_1, miner_acc, alice_acc, MK_TEST_COINS(1), blk_0r); + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); + + // + // construct a tx with an incorrect hardfork_id and make sure it won't be accepted by either the tx pool or the core + // + std::vector sources; + std::vector destinations; + + r = fill_tx_sources_and_destinations(events, blk_1, miner_acc, alice_acc, MK_TEST_COINS(7), TX_DEFAULT_FEE, 4, sources, destinations); + CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); + + transaction tx_2{}; + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_hardfork_id(get_block_height(blk_1) + 1, m_hardforks, tx_hardfork_id); + size_t incorrect_tx_hardfork_id = 0; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_2, tx_version, incorrect_tx_hardfork_id, 0); // note using incorrect hardfork id here + CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + // mark as invalid, shouldn't be accepted by the tx pool + DO_CALLBACK(events, "mark_invalid_tx"); + ADD_CUSTOM_EVENT(events, tx_2); + + // now add tx_2 as 'kept_by_block', with tx pool checks turned off + ADD_CUSTOM_EVENT(events, event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); + events.push_back(tx_2); // now tx should be accepted by the pool + ADD_CUSTOM_EVENT(events, event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); + // the block shouldn't be accepted, because of invalid tx_2 + DO_CALLBACK(events, "mark_invalid_block"); + MAKE_NEXT_BLOCK_TX1(events, blk_2_bad, blk_1, miner_acc, tx_2); + + + // + // reconstruct the same tx, now using the correct tx_hardfork_id, and make sure it will be accepted + // + tx_2 = transaction{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_2, tx_version, tx_hardfork_id, 0); + CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + ADD_CUSTOM_EVENT(events, tx_2); + MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1, miner_acc, tx_2); + + REWIND_BLOCKS_N_WITH_TIME(events, blk_2r, blk_2, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + // epilogue + + DO_CALLBACK(events, "c1"); + + return true; +} + +bool hard_fork_5_tx_version::c1(currency::core& c, size_t ev_index, const std::vector &events) +{ + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); + + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); + + size_t blocks_fetched = 0; + alice_wlt->refresh(blocks_fetched); + CHECK_AND_ASSERT_EQ(blocks_fetched, 2 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5); + + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", MK_TEST_COINS(8)), false, ""); return true; } diff --git a/tests/core_tests/hard_fork_5.h b/tests/core_tests/hard_fork_5.h index 692d3348..61c79c48 100644 --- a/tests/core_tests/hard_fork_5.h +++ b/tests/core_tests/hard_fork_5.h @@ -6,7 +6,9 @@ #include "wallet_tests_basic.h" -struct hard_fork_5_tx_version : public test_chain_unit_enchanced +struct hard_fork_5_tx_version : public wallet_test { + hard_fork_5_tx_version(); bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector &events); }; From 059a71fd97e3c879847eff9f1a2a2cdbba61e928 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 28 Dec 2024 04:20:50 +0100 Subject: [PATCH 6/9] tx hf id: wallet adaptation --- src/currency_core/currency_format_utils.h | 2 +- src/wallet/wallet2.cpp | 28 +++++++++++------------ src/wallet/wallet2.h | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 1503baee..b3cfbeed 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -163,7 +163,7 @@ namespace currency uint64_t expiration_time; crypto::public_key spend_pub_key; // only for validations uint64_t tx_version; - uint8_t tx_hardfork_id = 0; + size_t tx_hardfork_id = 0; uint64_t mode_separate_fee = 0; epee::misc_utils::events_dispatcher* pevents_dispatcher = nullptr; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ac486389..6dc46bc7 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1162,7 +1162,7 @@ void wallet2::accept_proposal(const crypto::hash& contract_id, uint64_t b_accept //build transaction currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(construct_param, ftp, msc); mark_transfers_as_spent(ftp.selected_transfers, std::string("contract <") + epee::string_tools::pod_to_hex(contract_id) + "> has been accepted with tx <" + epee::string_tools::pod_to_hex(get_transaction_hash(tx)) + ">"); @@ -1182,10 +1182,10 @@ void wallet2::accept_proposal(const crypto::hash& contract_id, uint64_t b_accept *p_acceptance_tx = tx; } //--------------------------------------------------------------------------------- -uint64_t wallet2::get_current_tx_version() +uint64_t wallet2::get_current_tx_version_and_hardfork_id(size_t& tx_hardfork_id) { uint64_t tx_expected_block_height = get_top_block_height() + 1; - return currency::get_tx_version(tx_expected_block_height, this->m_core_runtime_config.hard_forks); + return currency::get_tx_version_and_hardfork_id(tx_expected_block_height, this->m_core_runtime_config.hard_forks, tx_hardfork_id); } //--------------------------------------------------------------------------------- void wallet2::finish_contract(const crypto::hash& contract_id, const std::string& release_type, currency::transaction* p_release_tx /* = nullptr */) @@ -1299,7 +1299,7 @@ void wallet2::request_cancel_contract(const crypto::hash& contract_id, uint64_t construct_param.split_strategy_id = get_current_split_strategy(); currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(construct_param, ftp); currency::transaction tx = AUTO_VAL_INIT(tx); crypto::secret_key sk = AUTO_VAL_INIT(sk); @@ -2393,7 +2393,7 @@ bool wallet2::sweep_bare_unspent_outputs(const currency::account_public_address& currency::finalized_tx ftx{}; currency::finalize_tx_param ftp{}; ftp.pevents_dispatcher = &m_debug_events_dispatcher; - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); if (!prepare_tx_sources(decoys_count, /*use_all_decoys_if_found_less_than_required*/ true, ftp.sources, group.tids)) { @@ -5924,7 +5924,7 @@ void wallet2::build_escrow_release_templates(crypto::hash multisig_id, construct_params.extra.push_back(tsa); { currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(construct_params, ftp); crypto::secret_key sk = AUTO_VAL_INIT(sk); finalize_transaction(ftp, tx_release_template, sk, false); @@ -5941,7 +5941,7 @@ void wallet2::build_escrow_release_templates(crypto::hash multisig_id, construct_params.extra.push_back(tsa); { currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(construct_params, ftp); crypto::secret_key sk = AUTO_VAL_INIT(sk); finalize_transaction(ftp, tx_burn_template, sk, false); @@ -5962,7 +5962,7 @@ void wallet2::build_escrow_cancel_template(crypto::hash multisig_id, construct_tx_param construct_params = AUTO_VAL_INIT(construct_params); currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); construct_params.fee = it->second.amount() - (ecrow_details.amount_a_pledge + ecrow_details.amount_to_pay + ecrow_details.amount_b_pledge); construct_params.multisig_id = multisig_id; construct_params.split_strategy_id = get_current_split_strategy(); @@ -6045,7 +6045,7 @@ void wallet2::build_escrow_template(const bc_services::contract_private_details& } currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(ctp, ftp); selected_transfers = ftp.selected_transfers; @@ -6181,7 +6181,7 @@ void wallet2::send_escrow_proposal(const bc_services::contract_private_details& ctp.unlock_time = unlock_time; currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); try { prepare_transaction(ctp, ftp); @@ -6355,7 +6355,7 @@ bool wallet2::build_ionic_swap_template(const wallet_public::ionic_swap_proposal currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); ftp.mode_separate_fee = ctp.fee; - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); prepare_transaction(ctp, ftp); selected_transfers = ftp.selected_transfers; @@ -6584,7 +6584,7 @@ bool wallet2::accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposa //build transaction currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); ftp.gen_context = ionic_context.gen_context; prepare_transaction(construct_param, ftp, msc); @@ -8153,7 +8153,7 @@ void wallet2::transfer(construct_tx_param& ctp, TIME_MEASURE_START(prepare_transaction_time); currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); ftp.pevents_dispatcher = &m_debug_events_dispatcher; - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); if (!prepare_transaction(ctp, ftp)) { result.was_not_prepared = true; @@ -8280,7 +8280,7 @@ void wallet2::sweep_below(size_t fake_outs_count, const currency::account_public } currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp); - ftp.tx_version = this->get_current_tx_version(); + ftp.tx_version = get_current_tx_version_and_hardfork_id(ftp.tx_hardfork_id); bool is_hf4 = this->is_in_hardfork_zone(ZANO_HARDFORK_04_ZARCANUM); if (!payment_id.empty()) set_payment_id_to_tx(ftp.attachments, payment_id, is_hf4); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 8fcced41..cc4d8f53 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -857,7 +857,7 @@ private: bool handle_cancel_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector& decrypted_attach); bool handle_expiration_list(uint64_t tx_expiration_ts_median); void handle_contract_expirations(uint64_t tx_expiration_ts_median); - uint64_t get_current_tx_version(); + uint64_t get_current_tx_version_and_hardfork_id(size_t& tx_hardfork_id); void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const; void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const; void load_votes_config(); From 6ab3d465294b34032b10b758c8f8279a9889d796 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 28 Dec 2024 18:20:14 +0100 Subject: [PATCH 7/9] gcc compilation fix --- tests/core_tests/chaingen.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 91fbe462..4203f616 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1923,6 +1923,7 @@ bool construct_tx(const currency::account_keys& sender_account_keys, crypto::secret_key& one_time_secret_key, uint64_t unlock_time) { + [[maybe_unused]] tx_generation_context gen_context{}; return construct_tx(sender_account_keys, sources, destinations, @@ -1937,7 +1938,7 @@ bool construct_tx(const currency::account_keys& sender_account_keys, true, /* shuffle */ 0, /* flags */ 0, /* explicit_consolidated_tx_fee */ - tx_generation_context{} + gen_context /* tx_generation_context */ ); } @@ -1949,6 +1950,8 @@ bool construct_tx(const currency::account_keys& sender_account_keys, currency::transaction& tx, uint64_t tx_version) { + [[maybe_unused]] tx_generation_context gen_context{}; + [[maybe_unused]] crypto::secret_key tx_sec_key{}; return construct_tx(sender_account_keys, sources, destinations, @@ -1956,14 +1959,14 @@ bool construct_tx(const currency::account_keys& sender_account_keys, attachments, tx, tx_version, - crypto::secret_key{}, /* one_time_secret_key */ + tx_sec_key, /* one_time_secret_key */ 0, /* unlock_time */ 0, /* expiration_time */ CURRENCY_TO_KEY_OUT_RELAXED, /* tx_outs_attr */ true, /* shuffle */ 0, /* flags */ 0, /* explicit_consolidated_tx_fee */ - tx_generation_context{} + gen_context /* tx_generation_context */ ); } From ad2b10116dccc409ca817d2ed6b47642b3d7337a Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 30 Dec 2024 15:37:14 +0100 Subject: [PATCH 8/9] coretests: presumably all tests fixed: multisig_and_unlock_time, multisig_and_coinbase, pos_altblocks_validation@5, gen_wallet_alias_and_unconfirmed_txs@5, hard_fork_4_consolidated_txs@5, multisig_and_checkpoints@0 --- tests/core_tests/hard_fork_4.cpp | 8 ++++++-- tests/core_tests/multisig_wallet_tests.cpp | 12 ++++++------ tests/core_tests/pos_block_builder.cpp | 10 +++++----- tests/core_tests/pos_block_builder.h | 2 ++ tests/core_tests/wallet_tests.cpp | 4 +++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/core_tests/hard_fork_4.cpp b/tests/core_tests/hard_fork_4.cpp index a87a1479..dc5fc492 100644 --- a/tests/core_tests/hard_fork_4.cpp +++ b/tests/core_tests/hard_fork_4.cpp @@ -82,7 +82,9 @@ bool hard_fork_4_consolidated_txs::generate(std::vector& event destinations.push_back(tx_destination_entry(m_bob_amount, bob_acc.get_public_address())); add_flags_to_all_destination_entries(tx_destination_entry_flags::tdef_explicit_native_asset_id, destinations); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_1, get_tx_version_from_events(events), one_time_secret_key, + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_1, tx_version, tx_hardfork_id, one_time_secret_key, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, TX_DEFAULT_FEE, gen_context); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); @@ -119,7 +121,9 @@ bool hard_fork_4_consolidated_txs::generate(std::vector& event std::vector destinations; - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_1, get_tx_version_from_events(events), one_time_secret_key, + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_1, tx_version, tx_hardfork_id, one_time_secret_key, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, 0 /* note zero fee here */, gen_context); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index ed0978e6..4c2dc2dc 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1202,7 +1202,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c uint64_t unlock_time_2 = blk_0r.timestamp + DIFFICULTY_TOTAL_TARGET * 6 + CURRENCY_LOCKED_TX_ALLOWED_DELTA_SECONDS; transaction tx_1 = AUTO_VAL_INIT(tx_1); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), unlock_time, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, get_tx_version_from_events(events), 0, unlock_time, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); CHECK_AND_ASSERT_MES(get_tx_max_unlock_time(tx_1) == unlock_time, false, "Unlock time was not correctly set"); events.push_back(tx_1); @@ -1232,7 +1232,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c // tx_2 should be created ok, but rejected by the core, as one of input refers to a locked tx // Note: tx_2 has unlock_time_2 specified transaction tx_2 = AUTO_VAL_INIT(tx_2); - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_2, get_tx_version_from_events(events), unlock_time_2, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_2, get_tx_version_from_events(events), 0, unlock_time_2, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); bool tx_fully_signed = false; @@ -1256,7 +1256,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c r = fill_tx_sources_and_destinations(events, blk_2, alice_acc, bob_acc, amount - TESTS_DEFAULT_FEE * 2, TESTS_DEFAULT_FEE, 0 /*nmix*/, sources, destinations, true, false /* check_for_unlocktime */); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction tx_3{}; - r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_from_events(events), 0, 0); + r = construct_tx(alice_acc.get_keys(), sources, destinations, empty_attachment, tx_3, get_tx_version_from_events(events), 0, 0 /* unlock time */, 0 /* mix attib */); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_3); @@ -1459,7 +1459,7 @@ bool multisig_and_coinbase::generate(std::vector& events) cons r = fill_tx_sources_and_destinations(events, prev_block, miner_acc.get_keys(), ms_addr_list, blk_2_reward, TESTS_DEFAULT_FEE, 0, sources, destinations, false, false, 1); CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); transaction miner_tx = AUTO_VAL_INIT(miner_tx); - r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, miner_tx, get_tx_version_from_events(events), height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW, CURRENCY_TO_KEY_OUT_RELAXED, true); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, miner_tx, get_tx_version_from_events(events), 0, height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // replace vin with coinbase input @@ -1477,7 +1477,7 @@ bool multisig_and_coinbase::generate(std::vector& events) cons r = generator.construct_block_manually(b, prev_block, miner_acc, test_generator::bf_miner_tx, 0, 0, 0, null_hash, 1, miner_tx); CHECK_AND_ASSERT_MES(r, false, "construct_block_manually failed"); } - events.push_back(blk_3); + ADD_CUSTOM_EVENT(events, blk_3); // rewind blocks to be able to spend mined money REWIND_BLOCKS_N(events, blk_3r, blk_3, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -1638,7 +1638,7 @@ multisig_and_checkpoints::multisig_and_checkpoints() bool multisig_and_checkpoints::set_cp(currency::core& c, size_t ev_index, const std::vector& events) { currency::checkpoints checkpoints; - checkpoints.add_checkpoint(15, "fda3e645fbfd0f4852aa68e6ad021c9005c9faf2d7ba6b1b3c8e24efb9c0e8d0"); + checkpoints.add_checkpoint(15, "a78fa870608991aa773d5d5aaf684ac77fea30c3e103b00d3c05c15912215c31"); c.set_checkpoints(std::move(checkpoints)); return true; diff --git a/tests/core_tests/pos_block_builder.cpp b/tests/core_tests/pos_block_builder.cpp index 6ebd50ab..a6e4cd4e 100644 --- a/tests/core_tests/pos_block_builder.cpp +++ b/tests/core_tests/pos_block_builder.cpp @@ -28,6 +28,7 @@ void pos_block_builder::step1_init_header(const hard_forks_descriptor& hardforks m_height = block_height; m_context.zarcanum = hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, m_height); + m_miner_tx_version = get_tx_version_and_hardfork_id(m_height, hardforks, m_miner_tx_hardfork_id); m_step = 1; } @@ -160,9 +161,6 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, { CHECK_AND_ASSERT_THROW_MES(m_step == 3, "pos_block_builder: incorrect step sequence"); - uint64_t tx_version = m_context.zarcanum ? TRANSACTION_VERSION_POST_HF4 : TRANSACTION_VERSION_PRE_HF4; - // TODO @#@# tx_hardfork_id - pos_entry pe{}; pe.stake_unlock_time = 0; // TODO pe.amount = m_context.stake_amount; @@ -173,7 +171,8 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, size_t estimated_block_size = m_txs_total_size; m_block.miner_tx = transaction{}; bool r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee, - reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, 0, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); + reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, m_miner_tx_version, m_miner_tx_hardfork_id, + extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); CHECK_AND_ASSERT_THROW_MES(r, "construct_miner_tx failed"); estimated_block_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx); @@ -182,7 +181,8 @@ void pos_block_builder::step4_generate_coinbase_tx(size_t median_size, { m_block.miner_tx = transaction{}; r = construct_miner_tx(m_height, median_size, already_generated_coins, estimated_block_size, m_total_fee, - reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, tx_version, 0, extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); + reward_receiver_address, stakeholder_address, m_block.miner_tx, block_reward_without_fee, m_block_reward, m_miner_tx_version, m_miner_tx_hardfork_id, + extra_nonce, max_outs, true, pe, &m_miner_tx_tgc, tx_one_time_key_to_use); CHECK_AND_ASSERT_THROW_MES(r, "construct_homemade_pos_miner_tx failed"); cumulative_size = m_txs_total_size + get_object_blobsize(m_block.miner_tx); diff --git a/tests/core_tests/pos_block_builder.h b/tests/core_tests/pos_block_builder.h index fdf7a297..a0014f1e 100644 --- a/tests/core_tests/pos_block_builder.h +++ b/tests/core_tests/pos_block_builder.h @@ -76,6 +76,8 @@ struct pos_block_builder uint64_t m_total_fee = 0; //currency::stake_kernel m_stake_kernel {}; size_t m_height = 0; + size_t m_miner_tx_hardfork_id = 0; + uint64_t m_miner_tx_version = 0; size_t m_pos_stake_output_gindex = 0; uint64_t m_block_reward = 0; currency::tx_generation_context m_miner_tx_tgc {}; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 3e38e3ee..e3039a06 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1661,7 +1661,9 @@ bool gen_wallet_alias_and_unconfirmed_txs::generate(std::vector({ ai }), empty_attachment, tx_alice_alias, get_tx_version_from_events(events), sk, 0); + size_t tx_hardfork_id{}; + uint64_t tx_version = get_tx_version_and_harfork_id_from_events(events, tx_hardfork_id); + r = construct_tx(miner_acc.get_keys(), sources, destinations, std::vector({ ai }), empty_attachment, tx_alice_alias, tx_version, tx_hardfork_id, sk, 0); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); ADD_CUSTOM_EVENT(events, tx_alice_alias); From a101a676b0f777b5805f3f470a9992c36b077e60 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 3 Feb 2025 19:40:10 +0100 Subject: [PATCH 9/9] minor compilation fix --- tests/functional_tests/sha3.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional_tests/sha3.cpp b/tests/functional_tests/sha3.cpp index 537bb5ea..427c1e82 100644 --- a/tests/functional_tests/sha3.cpp +++ b/tests/functional_tests/sha3.cpp @@ -23,6 +23,7 @@ // SOFTWARE. #include #include +#include using namespace std; #ifndef KECCAKF_ROUNDS