diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 15bca16d..ac95a829 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1718,7 +1718,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ const block_extended_info& alt_chain_bei = alt_chain.back()->second; const block_extended_info& connection_point = alt_chain.front()->second; - if (alt_chain_bei.bl.major_version == BLOCK_MAJOR_VERSION_INITAL || connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height) + if (connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height) { //use pre-hard fork, old-style comparing if (main_chain_bei.cumulative_diff_adjusted < alt_chain_bei.cumulative_diff_adjusted) @@ -1739,7 +1739,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_ return true; } } - else if (alt_chain_bei.bl.major_version == CURRENT_BLOCK_MAJOR_VERSION) + else if (alt_chain_bei.height > m_core_runtime_config.hard_fork1_starts_after_height) { //new rules, applied after HARD_FORK_1 //to learn this algo please read https://github.com/hyle-team/docs/blob/master/zano/PoS_Analysis_and_improvements_proposal.pdf @@ -4819,7 +4819,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt ////////////////////////////////////////////////////////////////////////// // rebuild cumulative_diff_precise_adjusted for whole period wide_difficulty_type diff_precise_adj = correct_difficulty_with_sequence_factor(sequence_factor, current_diffic); - bei.cumulative_diff_precise_adjusted = m_db_blocks[last_x_h]->cumulative_diff_precise_adjusted + diff_precise_adj; + bei.cumulative_diff_precise_adjusted = last_x_h ? m_db_blocks[last_x_h]->cumulative_diff_precise_adjusted + diff_precise_adj : diff_precise_adj; ////////////////////////////////////////////////////////////////////////// @@ -5028,7 +5028,7 @@ bool blockchain_storage::add_new_block(const block& bl, block_verification_conte return false; } - if (prevalidate_block(bl)) + if (!prevalidate_block(bl)) { LOG_PRINT_RED_L0("block with id = " << id << " failed to prevalidate"); bvc.m_added_to_main_chain = false; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 662a8d4a..d584512d 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -222,6 +222,9 @@ namespace currency bool have_tx_keyimg_as_spent(const crypto::key_image &key_im, uint64_t before_height = UINT64_MAX) const; std::shared_ptr get_tx(const crypto::hash &id) const; + + template + bool scan_outputkeys_for_indexes(const transaction &validated_tx, const txin_to_key& tx_in_to_key, visitor_t& vis) { uint64_t stub = 0; return scan_outputkeys_for_indexes(validated_tx, tx_in_to_key, vis, stub); } template bool scan_outputkeys_for_indexes(const transaction &validated_tx, const txin_to_key& tx_in_to_key, visitor_t& vis, uint64_t& max_related_block_height) const ; @@ -708,7 +711,7 @@ namespace currency CHECK_AND_ASSERT_MES(mixattr_ok, false, "tx output #" << output_index << " violates mixin restrictions: mix_attr = " << static_cast(outtk.mix_attr) << ", key_offsets.size = " << tx_in_to_key.key_offsets.size()); TIME_MEASURE_START_PD(tx_check_inputs_loop_scan_outputkeys_loop_handle_output); - if (!vis.handle_output(tx_ptr->tx, validated_tx, tx_ptr->tx.vout[n], output_index)) + if (!vis.handle_output(tx_ptr->tx, validated_tx, tx_ptr->tx.vout[n], n)) { LOG_PRINT_L0("Failed to handle_output for output id = " << tx_id << ", no " << n); return false; diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 347f3fc0..b1f3b9cc 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -390,7 +390,7 @@ namespace currency END_SERIALIZE() }; - typedef boost::mpl::vector all_payload_types; + typedef boost::mpl::vector all_payload_types; typedef boost::make_variant_over::type attachment_v; typedef boost::make_variant_over::type extra_v; typedef boost::make_variant_over::type payload_items_v; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 4b8d1a3a..8a3d2087 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -165,6 +165,10 @@ namespace currency if (!add_tx_extra_userdata(tx, extra_nonce)) return false; + //at this moment we do apply_unlock_time only for coin_base transactions + apply_unlock_time(destinations, tx); + //we always add extra_padding with 2 bytes length to make possible for get_block_template to adjust cumulative size + tx.extra.push_back(extra_padding()); txin_gen in; @@ -191,12 +195,7 @@ namespace currency CHECK_AND_ASSERT_MES(r, false, "Failed to contruct miner tx out"); no++; } - - //at this moment we do apply_unlock_time only for coin_base transactions - apply_unlock_time(destinations, tx); - - //we always add extra_padding with 2 bytes length to make possible for get_block_template to adjust cumulative size - tx.extra.push_back(extra_padding()); + tx.version = CURRENT_TRANSACTION_VERSION; set_tx_unlock_time(tx, height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index 22973321..9e65c8ec 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -193,7 +193,7 @@ bool gen_block_unlock_time_is_low::generate(std::vector& event BLOCK_VALIDATION_INIT_GENERATE(); MAKE_MINER_TX_MANUALLY(miner_tx, blk_0); - currency::set_tx_unlock_time(miner_tx, currency::get_tx_unlock_time(miner_tx) - 1); + currency::set_tx_unlock_time(miner_tx, currency::get_tx_max_unlock_time(miner_tx) - 1); block blk_1; generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_miner_tx, 0, 0, 0, crypto::hash(), 0, miner_tx); @@ -209,7 +209,7 @@ bool gen_block_unlock_time_is_high::generate(std::vector& even BLOCK_VALIDATION_INIT_GENERATE(); MAKE_MINER_TX_MANUALLY(miner_tx, blk_0); - set_tx_unlock_time(miner_tx, get_tx_unlock_time(miner_tx) + 1); + set_tx_unlock_time(miner_tx, get_tx_max_unlock_time(miner_tx) + 1); block blk_1; generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_miner_tx, 0, 0, 0, crypto::hash(), 0, miner_tx); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index e28afd2d..3a404ffe 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -191,7 +191,7 @@ bool test_generator::construct_block(currency::block& blk, const std::list& tx_list, const std::list& coin_stake_sources)//in case of PoS block { - blk.major_version = CURRENT_BLOCK_MAJOR_VERSION; + blk.major_version = BLOCK_MAJOR_VERSION_INITAL; blk.minor_version = CURRENT_BLOCK_MINOR_VERSION; blk.timestamp = timestamp; blk.prev_id = prev_id; @@ -786,7 +786,7 @@ bool test_generator::construct_block(const std::vector& events size_t txs_sizes/* = 0*/) { size_t height = get_block_height(prev_block) + 1; - blk.major_version = actual_params & bf_major_ver ? major_ver : CURRENT_BLOCK_MAJOR_VERSION; + blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITAL; blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION; blk.timestamp = actual_params & bf_timestamp ? timestamp : (height > 10 ? prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN: prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN-POW_DIFF_UP_TIMESTAMP_DELTA); // Keep difficulty unchanged blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block); @@ -1197,10 +1197,10 @@ bool fill_tx_sources(std::vector& sources, const std: continue; if (check_for_unlocktime) { - if (currency::get_tx_unlock_time(*oi.p_tx) < CURRENCY_MAX_BLOCK_NUMBER) + if (currency::get_tx_max_unlock_time(*oi.p_tx) < CURRENCY_MAX_BLOCK_NUMBER) { //interpret as block index - if (currency::get_tx_unlock_time(*oi.p_tx) > blockchain.size()) + if (currency::get_tx_max_unlock_time(*oi.p_tx) > blockchain.size()) continue; } else diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 3bd63fd5..1b677ecf 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1194,7 +1194,7 @@ bool multisig_and_unlock_time::generate(std::vector& events) c transaction tx_1 = AUTO_VAL_INIT(tx_1); r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, unlock_time, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); - CHECK_AND_ASSERT_MES(get_tx_unlock_time(tx_1) == unlock_time, false, "Unlock time was not correctly set"); + 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); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); diff --git a/tests/core_tests/pos_block_builder.cpp b/tests/core_tests/pos_block_builder.cpp index 95b281a9..71819a64 100644 --- a/tests/core_tests/pos_block_builder.cpp +++ b/tests/core_tests/pos_block_builder.cpp @@ -24,7 +24,7 @@ void pos_block_builder::step1_init_header(size_t block_height, crypto::hash& pre { CHECK_AND_ASSERT_THROW_MES(m_step == 0, "pos_block_builder: incorrect step sequence"); m_block.minor_version = CURRENT_BLOCK_MINOR_VERSION; - m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION; + m_block.major_version = BLOCK_MAJOR_VERSION_INITAL; m_block.timestamp = 0; // to be set at step 3 m_block.prev_id = prev_block_hash; m_block.flags = CURRENCY_BLOCK_FLAG_POS_BLOCK; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index fc2817e5..e665fbee 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -48,15 +48,15 @@ bool determine_tx_real_inputs(currency::core& c, const currency::transaction& tx , m_found(false) {} - bool handle_output(const currency::transaction& tx, const currency::tx_out& out) + bool handle_output(const transaction& source_tx, const transaction& validated_tx, const tx_out& out, uint64_t out_i) { CHECK_AND_ASSERT_MES(!m_found, false, "Internal error: m_found is true but the visitor is still being applied"); - auto it = std::find(tx.vout.begin(), tx.vout.end(), out); - if (it == tx.vout.end()) + auto it = std::find(validated_tx.vout.begin(), validated_tx.vout.end(), out); + if (it == validated_tx.vout.end()) return false; - size_t output_tx_index = it - tx.vout.begin(); + size_t output_tx_index = it - validated_tx.vout.begin(); - crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx); + crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(validated_tx); crypto::key_derivation derivation; bool r = generate_key_derivation(tx_pub_key, m_keys.m_view_secret_key, derivation); CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed"); @@ -96,7 +96,7 @@ bool determine_tx_real_inputs(currency::core& c, const currency::transaction& tx continue; } local_visitor vis(keys, in.k_image); - bool r = c.get_blockchain_storage().scan_outputkeys_for_indexes(in, vis); + bool r = c.get_blockchain_storage().scan_outputkeys_for_indexes(tx, in, vis); CHECK_AND_ASSERT_MES(r || vis.m_found, false, "scan_outputkeys_for_indexes failed"); if (!vis.m_found) return false; diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 810c135e..6da67324 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -46,7 +46,7 @@ static const std::vector empty_attachment; bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector& txs, const currency::account_public_address& miner_addr, currency::block& result) { result.flags = 0; - result.major_version = CURRENT_BLOCK_MAJOR_VERSION; + result.major_version = BLOCK_MAJOR_VERSION_INITAL; result.minor_version = CURRENT_BLOCK_MINOR_VERSION; result.nonce = 0; result.prev_id = get_block_hash(prev_block);