From 0d882868c8a8cf84febe52e37c6dec412b8bf7b3 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 14 Sep 2022 22:48:42 +0200 Subject: [PATCH 1/5] chaingen: postponed test can be run with --run-single-test, also print 'em all --- tests/core_tests/chaingen_main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 221cc9e8..fb1dc8e8 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -251,7 +251,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ #define GENERATE_AND_PLAY(genclass) \ - if(!postponed_tests.count(#genclass) && (run_single_test.empty() || std::string::npos != std::string(#genclass).find(run_single_test))) \ + if((!postponed_tests.count(#genclass) && run_single_test.empty()) || std::string::npos != std::string(#genclass).find(run_single_test)) \ { \ TIME_MEASURE_START_MS(t); \ ++tests_count; \ @@ -1073,6 +1073,13 @@ int main(int argc, char* argv[]) } serious_failures_count = failed_tests.size() - failed_postponed_tests_count; + + if (!postponed_tests.empty()) + { + std::cout << concolor::yellow << std::endl << postponed_tests.size() << " POSTPONED TESTS:" << std::endl; + for(auto& el : postponed_tests) + std::cout << " " << el << std::endl; + } std::cout << (serious_failures_count == 0 ? concolor::green : concolor::magenta); std::cout << "\nREPORT:\n"; From ece5038130d79d9490dc38f3f233b2934fe0e291 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 14 Sep 2022 22:50:43 +0200 Subject: [PATCH 2/5] wallet: build_minted_block adoptation (zarcanum wip) --- src/wallet/wallet2.cpp | 155 +++++++++++++++++++++-------------------- src/wallet/wallet2.h | 3 +- 2 files changed, 81 insertions(+), 77 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index aeaea8cc..baf920e8 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3784,101 +3784,106 @@ bool wallet2::build_minted_block(const mining_context& cxt, const currency::account_public_address& miner_address, uint64_t new_block_expected_height /* UINT64_MAX */) { - //found a block, construct it, sign and push to daemon - WLT_LOG_GREEN("Found kernel, constructing block", LOG_LEVEL_0); + //found a block, construct it, sign and push to daemon + WLT_LOG_GREEN("Found kernel, constructing block", LOG_LEVEL_0); - //CHECK_AND_NO_ASSERT_MES(cxt.index < cxt.sp.pos_entries.size(), false, "call_COMMAND_RPC_SCAN_POS returned wrong index: " << cxt.index << ", expected less then " << cxt.sp.pos_entries.size()); + WLT_CHECK_AND_ASSERT_MES(cxt.index < m_transfers.size(), false, "cxt.index = " << cxt.index << " is out of bounds"); + const transfer_details& td = m_transfers[cxt.index]; - pos_entry pe = AUTO_VAL_INIT(pe); + pos_entry pe = AUTO_VAL_INIT(pe); + currency::COMMAND_RPC_GETBLOCKTEMPLATE::request tmpl_req = AUTO_VAL_INIT(tmpl_req); + currency::COMMAND_RPC_GETBLOCKTEMPLATE::response tmpl_rsp = AUTO_VAL_INIT(tmpl_rsp); + tmpl_req.wallet_address = get_account_address_as_str(miner_address); + tmpl_req.stakeholder_address = get_account_address_as_str(m_account.get_public_address()); + tmpl_req.pos_block = true; + pe.g_index = tmpl_req.pos_g_index = td.m_global_output_index; + pe.amount = tmpl_req.pos_amount = td.amount();// pe.amount; + pe.keyimage = td.m_key_image; + pe.block_timestamp = td.m_ptx_wallet_info->m_block_timestamp; + pe.stake_unlock_time = tmpl_req.stake_unlock_time = cxt.stake_unlock_time; + pe.tx_id = tmpl_req.tx_id = td.tx_hash(); + pe.tx_out_index = tmpl_req.tx_out_index = td.m_internal_output_index; + pe.wallet_index = cxt.index; - currency::COMMAND_RPC_GETBLOCKTEMPLATE::request tmpl_req = AUTO_VAL_INIT(tmpl_req); - currency::COMMAND_RPC_GETBLOCKTEMPLATE::response tmpl_rsp = AUTO_VAL_INIT(tmpl_rsp); - tmpl_req.wallet_address = get_account_address_as_str(miner_address); - tmpl_req.stakeholder_address = get_account_address_as_str(m_account.get_public_address()); - tmpl_req.pos_block = true; - pe.g_index = tmpl_req.pos_g_index = m_transfers[cxt.index].m_global_output_index; - pe.amount = tmpl_req.pos_amount = m_transfers[cxt.index].amount();// pe.amount; - pe.keyimage = m_transfers[cxt.index].m_key_image; - pe.block_timestamp = m_transfers[cxt.index].m_ptx_wallet_info->m_block_timestamp; - pe.stake_unlock_time = tmpl_req.stake_unlock_time = cxt.stake_unlock_time; - pe.tx_id = tmpl_req.tx_id = m_transfers[cxt.index].tx_hash(); - pe.tx_out_index = tmpl_req.tx_out_index = m_transfers[cxt.index].m_internal_output_index; - pe.wallet_index = cxt.index; + //tmpl_req.pos_index = pe.index; // gindex <--- this should be removed as soon as pos_entry::index is replaced with tx_id and tx_out_index + // TODO: also fill out tx_id and tx_out_index for mining tx creation + tmpl_req.extra_text = m_miner_text_info; + //generate packing tx + transaction pack_tx = AUTO_VAL_INIT(pack_tx); + if (generate_packing_transaction_if_needed(pack_tx, 0)) + { + tx_to_blob(pack_tx, tmpl_req.explicit_transaction); + WLT_LOG_GREEN("Packing inputs: " << pack_tx.vin.size() << " inputs consolidated in tx " << get_transaction_hash(pack_tx), LOG_LEVEL_0); + } + m_core_proxy->call_COMMAND_RPC_GETBLOCKTEMPLATE(tmpl_req, tmpl_rsp); + WLT_CHECK_AND_ASSERT_MES(tmpl_rsp.status == API_RETURN_CODE_OK, false, "Failed to create block template after kernel hash found!"); - //tmpl_req.pos_index = pe.index; // gindex <--- this should be removed as soon as pos_entry::index is replaced with tx_id and tx_out_index - // TODO: also fill out tx_id and tx_out_index for mining tx creation - tmpl_req.extra_text = m_miner_text_info; - //generate packing tx - transaction pack_tx = AUTO_VAL_INIT(pack_tx); - if (generate_packing_transaction_if_needed(pack_tx, 0)) - { - tx_to_blob(pack_tx, tmpl_req.explicit_transaction); - WLT_LOG_GREEN("Packing inputs: " << pack_tx.vin.size() << " inputs consolidated in tx " << get_transaction_hash(pack_tx), LOG_LEVEL_0); - } - m_core_proxy->call_COMMAND_RPC_GETBLOCKTEMPLATE(tmpl_req, tmpl_rsp); - WLT_CHECK_AND_ASSERT_MES(tmpl_rsp.status == API_RETURN_CODE_OK, false, "Failed to create block template after kernel hash found!"); + currency::block b = AUTO_VAL_INIT(b); + currency::blobdata block_blob; + bool res = epee::string_tools::parse_hexstr_to_binbuff(tmpl_rsp.blocktemplate_blob, block_blob); + WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to create block template after kernel hash found!"); + res = parse_and_validate_block_from_blob(block_blob, b); + WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to create block template after kernel hash found!"); - currency::block b = AUTO_VAL_INIT(b); - currency::blobdata block_blob; - bool res = epee::string_tools::parse_hexstr_to_binbuff(tmpl_rsp.blocktemplate_blob, block_blob); - WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to create block template after kernel hash found!"); - res = parse_and_validate_block_from_blob(block_blob, b); - WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to create block template after kernel hash found!"); + if (cxt.last_block_hash != b.prev_id) + { + WLT_LOG_YELLOW("Kernel was found but block is behindhand, b.prev_id=" << b.prev_id << ", last_block_hash=" << cxt.last_block_hash, LOG_LEVEL_0); + return false; + } - if (cxt.last_block_hash != b.prev_id) - { - WLT_LOG_YELLOW("Kernel was found but block is behindhand, b.prev_id=" << b.prev_id << ", last_block_hash=" << cxt.last_block_hash, LOG_LEVEL_0); - return false; - } + // set the timestamp from stake kernel + b.timestamp = cxt.sk.block_timestamp; + uint64_t current_timestamp = m_core_runtime_config.get_core_time(); + set_block_datetime(current_timestamp, b); + WLT_LOG_MAGENTA("Applying actual timestamp: " << current_timestamp, LOG_LEVEL_0); - std::vector keys_ptrs; - WLT_CHECK_AND_ASSERT_MES(cxt.index < m_transfers.size(), - false, "Wrong wallet_index at generating coinbase transacton"); + const currency::tx_out_v& stake_out_v = td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]; + if (cxt.zarcanum && td.is_zc()) + { + // Zarcanum + WLT_CHECK_AND_ASSERT_MES(stake_out_v.type() == typeid(tx_out_zarcanum), false, "unexpected stake output type: " << stake_out_v.type().name() << ", expected: zarcanum"); - if (m_transfers[cxt.index].m_ptx_wallet_info->m_tx.vout[m_transfers[cxt.index].m_internal_output_index].type() != typeid(tx_out_bare)) - { - //@#@ review zarcanum here - return false; - } - const auto& target = boost::get(m_transfers[cxt.index].m_ptx_wallet_info->m_tx.vout[m_transfers[cxt.index].m_internal_output_index]).target; + return false; + } + else + { + // old fashioned non-hidden amount PoS scheme + const auto& target = boost::get(stake_out_v).target; WLT_CHECK_AND_ASSERT_MES(target.type() == typeid(currency::txout_to_key), false, "wrong type_id in source transaction in coinbase tx"); + const currency::txout_to_key& stake_out_to_key = boost::get(target); + std::vector keys_ptrs; + keys_ptrs.push_back(&stake_out_to_key.key); - const currency::txout_to_key& txtokey = boost::get(target); - keys_ptrs.push_back(&txtokey.key); - - // set the timestamp from stake kernel - b.timestamp = cxt.sk.block_timestamp; - uint64_t current_timestamp = m_core_runtime_config.get_core_time(); - set_block_datetime(current_timestamp, b); - WLT_LOG_MAGENTA("Applying actual timestamp: " << current_timestamp, LOG_LEVEL_0); //sign block res = prepare_and_sign_pos_block(b, pe, get_tx_pub_key_from_extra(m_transfers[pe.wallet_index].m_ptx_wallet_info->m_tx), - m_transfers[cxt.index].m_internal_output_index, + td.m_internal_output_index, keys_ptrs); WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to prepare_and_sign_pos_block"); - - WLT_LOG_GREEN("Block constructed <" << get_block_hash(b) << ">, sending to core...", LOG_LEVEL_0); + } - currency::COMMAND_RPC_SUBMITBLOCK2::request subm_req = AUTO_VAL_INIT(subm_req); - currency::COMMAND_RPC_SUBMITBLOCK2::response subm_rsp = AUTO_VAL_INIT(subm_rsp); - subm_req.b = t_serializable_object_to_blob(b); - if (tmpl_req.explicit_transaction.size()) - subm_req.explicit_txs.push_back(hexemizer{ tmpl_req.explicit_transaction }); - - m_core_proxy->call_COMMAND_RPC_SUBMITBLOCK2(subm_req, subm_rsp); - if (subm_rsp.status != API_RETURN_CODE_OK) - { - WLT_LOG_ERROR("Constructed block is not accepted by core, status: " << subm_rsp.status); - return false; - } - WLT_LOG_GREEN("POS block generated and accepted, congrats!", LOG_LEVEL_0); - m_wcallback->on_pos_block_found(b); + crypto::hash block_hash = get_block_hash(b); + WLT_LOG_GREEN("Block " << print16(block_hash) << " has been constructed, sending to core...", LOG_LEVEL_0); - return true; + currency::COMMAND_RPC_SUBMITBLOCK2::request subm_req = AUTO_VAL_INIT(subm_req); + currency::COMMAND_RPC_SUBMITBLOCK2::response subm_rsp = AUTO_VAL_INIT(subm_rsp); + subm_req.b = t_serializable_object_to_blob(b); + if (tmpl_req.explicit_transaction.size()) + subm_req.explicit_txs.push_back(hexemizer{ tmpl_req.explicit_transaction }); + + m_core_proxy->call_COMMAND_RPC_SUBMITBLOCK2(subm_req, subm_rsp); + if (subm_rsp.status != API_RETURN_CODE_OK) + { + WLT_LOG_ERROR("Constructed block " << print16(block_hash) << " was rejected by the core, status: " << subm_rsp.status); + return false; + } + WLT_LOG_GREEN("PoS block " << print16(block_hash) << " generated and accepted, congrats!", LOG_LEVEL_0); + m_wcallback->on_pos_block_found(b); + + return true; } //---------------------------------------------------------------------------------------------------- void wallet2::get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d78d092b..b0bb0bad 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -466,11 +466,10 @@ namespace tools crypto::scalar_t last_pow_block_id_hashed; // Zarcanum notation: f' crypto::scalar_t secret_q; // Zarcanum notation: q - boost::multiprecision::uint256_t z_l_div_z_D; // Zarcanum notation: z * floor( l / (z * D) ) (max possible value: 2^64 * 2^252 / (2^64 * 1) ~= 2^252, or 2^252 / (1 * 1) = 2^252) + boost::multiprecision::uint256_t z_l_div_z_D; // Zarcanum notation: z * floor( l / (z * D) ) (max possible value (assuming z=2^64) : z * 2^252 / (z * 1) ~= 2^252) currency::wide_difficulty_type basic_diff; currency::stake_kernel sk; - //currency::stake_modifier_type sm; uint64_t iterations_processed = 0; uint64_t total_items_checked = 0; From 2aa62f43bbded4e52b83e9c1cff2ef12ef5b8408 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 15 Sep 2022 19:41:46 +0200 Subject: [PATCH 3/5] coretests: getting rid of set_pos_to_low_timestamp; postponed tests not running --- tests/core_tests/chaingen.cpp | 15 --------------- tests/core_tests/chaingen.h | 2 -- tests/core_tests/chaingen_main.cpp | 2 +- tests/core_tests/hard_fork_1_bad_pos_source.cpp | 1 - tests/core_tests/hard_fork_1_consensus_test.cpp | 1 - 5 files changed, 1 insertion(+), 20 deletions(-) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index ddeef09d..41c149bc 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -49,7 +49,6 @@ const crypto::signature invalid_signature = create_invalid_signature(); test_generator::test_generator() : m_wallet_test_core_proxy(new wallet_test_core_proxy()) - , m_do_pos_to_low_timestamp(false) , m_ignore_last_pow_in_wallets(false) , m_last_found_timestamp(0) { @@ -533,8 +532,6 @@ bool test_generator::find_kernel(const std::list& accs, { starter_timestamp -= 90; } - if (m_do_pos_to_low_timestamp) - starter_timestamp += 60; //adjust timestamp starting from timestamp%POS_SCAN_STEP = 0 //starter_timestamp = starter_timestamp - POS_SCAN_WINDOW; @@ -570,18 +567,6 @@ bool test_generator::find_kernel(const std::list& accs, continue; else { - if (m_do_pos_to_low_timestamp) - { - if (!m_last_found_timestamp) - { - m_last_found_timestamp = ts; - continue; - } - - if(m_last_found_timestamp >= ts) - continue; - } - //found kernel LOG_PRINT_GREEN("Found kernel: amount=" << print_money(pos_entries[i].amount) << ", index=" << pos_entries[i].g_index diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 88019806..b7f4e97d 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -525,7 +525,6 @@ public: static const test_gentime_settings& get_test_gentime_settings() { return m_test_gentime_settings; } static void set_test_gentime_settings(const test_gentime_settings& s) { m_test_gentime_settings = s; } static void set_test_gentime_settings_default() { m_test_gentime_settings = m_test_gentime_settings_default; } - void set_pos_to_low_timestamp(bool do_pos_to_low_timestamp) { m_do_pos_to_low_timestamp = do_pos_to_low_timestamp; } void set_ignore_last_pow_in_wallets(bool ignore_last_pow_in_wallets) { m_ignore_last_pow_in_wallets = ignore_last_pow_in_wallets; } void set_hardfork_height(size_t hardfork_id, uint64_t h); void set_hardforks(const currency::hard_forks_descriptor& hardforks); @@ -533,7 +532,6 @@ public: private: - bool m_do_pos_to_low_timestamp; bool m_ignore_last_pow_in_wallets; uint64_t m_last_found_timestamp; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index fb1dc8e8..90fe3ff4 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -251,7 +251,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ #define GENERATE_AND_PLAY(genclass) \ - if((!postponed_tests.count(#genclass) && run_single_test.empty()) || std::string::npos != std::string(#genclass).find(run_single_test)) \ + if((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string::npos != std::string(#genclass).find(run_single_test)) \ { \ TIME_MEASURE_START_MS(t); \ ++tests_count; \ diff --git a/tests/core_tests/hard_fork_1_bad_pos_source.cpp b/tests/core_tests/hard_fork_1_bad_pos_source.cpp index b60a1d08..3c79512c 100644 --- a/tests/core_tests/hard_fork_1_bad_pos_source.cpp +++ b/tests/core_tests/hard_fork_1_bad_pos_source.cpp @@ -37,7 +37,6 @@ bool hard_fork_1_bad_pos_source::generate(std::vector& events) DO_CALLBACK(events, "configure_core"); REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5); - generator.set_pos_to_low_timestamp(true); MAKE_TX(events, tx_1, miner_acc, pos_miner_acc_before_pow, 1000000000000, blk_0r); MAKE_NEXT_BLOCK_TX1(events, blk_pow_tx1, blk_0r, miner_acc, tx_1); MAKE_TX(events, tx_2, preminer_acc, pos_miner_acc_after_pow, 1000000000000, blk_pow_tx1); diff --git a/tests/core_tests/hard_fork_1_consensus_test.cpp b/tests/core_tests/hard_fork_1_consensus_test.cpp index 09753840..dd672019 100644 --- a/tests/core_tests/hard_fork_1_consensus_test.cpp +++ b/tests/core_tests/hard_fork_1_consensus_test.cpp @@ -43,7 +43,6 @@ bool hard_fork_1_cumulative_difficulty_base::generate(std::vector Date: Thu, 15 Sep 2022 20:26:54 +0200 Subject: [PATCH 4/5] coretests: typo fixed --- tests/core_tests/chaingen_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 90fe3ff4..102b3116 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -251,7 +251,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ #define GENERATE_AND_PLAY(genclass) \ - if((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string::npos != std::string(#genclass).find(run_single_test)) \ + if((!postponed_tests.count(#genclass) && run_single_test.empty()) || (!run_single_test.empty() && std::string::npos != std::string(#genclass).find(run_single_test))) \ { \ TIME_MEASURE_START_MS(t); \ ++tests_count; \ From d01ab52c7c2e03d696901315a64862dff663b83a Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 15 Sep 2022 23:21:02 +0200 Subject: [PATCH 5/5] coretests: some HF1 tests marked as postponed --- tests/core_tests/chaingen_main.cpp | 5 +++++ tests/core_tests/hard_fork_1_consensus_test.cpp | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 102b3116..8c3dc903 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -747,6 +747,11 @@ int main(int argc, char* argv[]) MARK_TEST_AS_POSTPONED(gen_wallet_spending_coinstake_after_minting); MARK_TEST_AS_POSTPONED(gen_wallet_fake_outs_while_having_too_little_own_outs); MARK_TEST_AS_POSTPONED(gen_uint_overflow_1); + + MARK_TEST_AS_POSTPONED(after_hard_fork_1_cumulative_difficulty); // reason: set_pos_to_low_timestamp is not supported anymore + MARK_TEST_AS_POSTPONED(before_hard_fork_1_cumulative_difficulty); + MARK_TEST_AS_POSTPONED(inthe_middle_hard_fork_1_cumulative_difficulty); + MARK_TEST_AS_POSTPONED(zarcanum_basic_test); #undef MARK_TEST_AS_POSTPONED diff --git a/tests/core_tests/hard_fork_1_consensus_test.cpp b/tests/core_tests/hard_fork_1_consensus_test.cpp index dd672019..485f32c3 100644 --- a/tests/core_tests/hard_fork_1_consensus_test.cpp +++ b/tests/core_tests/hard_fork_1_consensus_test.cpp @@ -42,7 +42,8 @@ bool hard_fork_1_cumulative_difficulty_base::generate(std::vector