From 9bfc9a04903458efc5db3810205883daf5c8f2a4 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 8 Oct 2021 08:01:59 +0300 Subject: [PATCH] get rid of coinday_weight --- src/currency_core/currency_format_utils.cpp | 5 ----- src/currency_core/currency_format_utils.h | 1 - src/wallet/wallet2.cpp | 5 +---- src/wallet/wallet2.h | 16 ++++++++-------- tests/core_tests/chaingen.cpp | 7 +------ tests/core_tests/chaingen.h | 1 - 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index f76bdd6e..e6a162de 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -64,11 +64,6 @@ namespace currency pos_entry()); }*/ //--------------------------------------------------------------- - uint64_t get_coinday_weight(uint64_t amount) - { - return amount; - } - //--------------------------------------------------------------- wide_difficulty_type correct_difficulty_with_sequence_factor(size_t sequence_factor, wide_difficulty_type diff) { //delta=delta*(0.75^n) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 9a108417..4b9e9030 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -346,7 +346,6 @@ namespace currency //PoS bool is_pos_block(const block& b); bool is_pos_block(const transaction& tx); - uint64_t get_coinday_weight(uint64_t amount); wide_difficulty_type correct_difficulty_with_sequence_factor(size_t sequence_factor, wide_difficulty_type diff); void print_currency_details(); std::string print_reward_change_first_blocks(size_t n_of_first_blocks); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f8cc2fb6..52f07402 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3377,16 +3377,13 @@ bool wallet2::prepare_and_sign_pos_block(currency::block& b, return true; } //------------------------------------------------------------------ -bool wallet2::build_kernel(const pos_entry& pe, const stake_modifier_type& stake_modifier, stake_kernel& kernel, uint64_t& coindays_weight, uint64_t timestamp) +bool wallet2::build_kernel(const pos_entry& pe, const stake_modifier_type& stake_modifier, const uint64_t timestamp, stake_kernel& kernel) { PROFILE_FUNC("build_kernel"); - coindays_weight = 0; kernel = stake_kernel(); kernel.kimage = pe.keyimage; kernel.stake_modifier = stake_modifier; kernel.block_timestamp = timestamp; - - coindays_weight = get_coinday_weight(pe.amount); return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index fd79042a..a67d6314 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -920,7 +920,7 @@ private: void handle_pulled_blocks(size_t& blocks_added, std::atomic& stop, currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& blocks); std::string get_alias_for_address(const std::string& addr); - static bool build_kernel(const currency::pos_entry& pe, const currency::stake_modifier_type& stake_modifier, currency::stake_kernel& kernel, uint64_t& coindays_weight, uint64_t timestamp); + static bool build_kernel(const currency::pos_entry& pe, const currency::stake_modifier_type& stake_modifier, const uint64_t timestamp, currency::stake_kernel& kernel); bool is_connected_to_net(); bool is_transfer_okay_for_pos(const transfer_details& tr, uint64_t& stake_unlock_time); bool scan_unconfirmed_outdate_tx(); @@ -1258,27 +1258,27 @@ namespace tools if (stop) return false; currency::stake_kernel sk = AUTO_VAL_INIT(sk); - uint64_t coindays_weight = 0; - build_kernel(cxt.sp.pos_entries[i], cxt.sm, sk, coindays_weight, ts); + const uint64_t& stake_amount = cxt.sp.pos_entries[i].amount; + build_kernel(cxt.sp.pos_entries[i], cxt.sm, ts, sk); crypto::hash kernel_hash; { PROFILE_FUNC("calc_hash"); kernel_hash = crypto::cn_fast_hash(&sk, sizeof(sk)); } - currency::wide_difficulty_type this_coin_diff = cxt.basic_diff / coindays_weight; + currency::wide_difficulty_type final_diff = cxt.basic_diff / stake_amount; bool check_hash_res; { PROFILE_FUNC("check_hash"); - check_hash_res = currency::check_hash(kernel_hash, this_coin_diff); + check_hash_res = currency::check_hash(kernel_hash, final_diff); ++cxt.rsp.iterations_processed; } if (check_hash_res) { //found kernel - LOG_PRINT_GREEN("Found kernel: amount=" << currency::print_money(cxt.sp.pos_entries[i].amount) << ENDL - << "difficulty_basic=" << cxt.basic_diff << ", diff for this coin: " << this_coin_diff << ENDL - << "index=" << cxt.sp.pos_entries[i].index << ENDL + LOG_PRINT_GREEN("Found kernel: amount: " << currency::print_money(stake_amount) << ENDL + << "difficulty: " << cxt.basic_diff << ", final_diff: " << final_diff << ENDL + << "index: " << cxt.sp.pos_entries[i].index << ENDL << "kernel info: " << ENDL << print_stake_kernel_info(sk) << ENDL << "kernel_hash(proof): " << kernel_hash, diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 57f00b22..b15bdacc 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -563,17 +563,15 @@ bool test_generator::find_kernel(const std::list& accs, { stake_kernel sk = AUTO_VAL_INIT(sk); - uint64_t coindays_weight = 0; build_kernel(scan_pos_entries.pos_entries[i].amount, scan_pos_entries.pos_entries[i].index, scan_pos_entries.pos_entries[i].keyimage, sk, - coindays_weight, blck_chain, indexes, ts); crypto::hash kernel_hash = crypto::cn_fast_hash(&sk, sizeof(sk)); - wide_difficulty_type this_coin_diff = basic_diff / coindays_weight; + wide_difficulty_type this_coin_diff = basic_diff / scan_pos_entries.pos_entries[i].amount; if (!check_hash(kernel_hash, this_coin_diff)) continue; else @@ -672,12 +670,10 @@ bool test_generator::build_kernel(uint64_t amount, uint64_t global_index, const crypto::key_image& ki, stake_kernel& kernel, - uint64_t& coindays_weight, const test_generator::blockchain_vector& blck_chain, const test_generator::outputs_index& indexes, uint64_t timestamp) { - coindays_weight = 0; kernel = stake_kernel(); kernel.kimage = ki; @@ -701,7 +697,6 @@ bool test_generator::build_kernel(uint64_t amount, kernel.block_timestamp = timestamp; - coindays_weight = get_coinday_weight(amount); build_stake_modifier(kernel.stake_modifier, blck_chain); return true; } diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 8ccec794..6b9b4c04 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -410,7 +410,6 @@ public: uint64_t global_index, const crypto::key_image& ki, currency::stake_kernel& kernel, - uint64_t& coindays_weight, const blockchain_vector& blck_chain, const outputs_index& indexes, uint64_t timestamp);