diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 55e46505..aa31f8b4 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2660,6 +2660,149 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO return true; } //------------------------------------------------------------------ +bool blockchain_storage::get_target_outs_for_amount_prezarcanum(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution& details, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, std::map& amounts_to_up_index_limit_cache) const +{ + size_t decoys_count = details.offsets.size(); + uint64_t amount = details.amount; + + uint64_t outs_container_size = m_db_outputs.get_item_size(details.amount); + if (!outs_container_size) + { + LOG_ERROR("COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS: not outs for amount " << amount << ", wallet should use some real outs when it lookup for some mix, so, at least one out for this amount should exist"); + return false;//actually this is strange situation, wallet should use some real outs when it lookup for some mix, so, at least one out for this amount should exist + } + //it is not good idea to use top fresh outs, because it increases possibility of transaction canceling on split + //lets find upper bound of not fresh outs + size_t up_index_limit = 0; + auto it_limit = amounts_to_up_index_limit_cache.find(amount); + if (it_limit == amounts_to_up_index_limit_cache.end()) + { + up_index_limit = find_end_of_allowed_index(amount); + amounts_to_up_index_limit_cache[up_index_limit]; + } + else + { + up_index_limit = it_limit->second; + } + + CHECK_AND_ASSERT_MES(up_index_limit <= outs_container_size, false, "internal error: find_end_of_allowed_index returned wrong index=" << up_index_limit << ", with amount_outs.size = " << outs_container_size); + if (up_index_limit >= decoys_count) + { + std::set used; + size_t try_count = 0; + for (uint64_t j = 0; j != decoys_count && try_count < up_index_limit;) + { + size_t g_index = crypto::rand() % up_index_limit; + if (used.count(g_index)) + continue; + bool added = add_out_to_get_random_outs(result_outs, amount, g_index, decoys_count, req.use_forced_mix_outs, req.height_upper_limit); + used.insert(g_index); + if (added) + ++j; + ++try_count; + } + if (result_outs.outs.size() < decoys_count) + { + LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << decoys_count << ", added " << result_outs.outs.size() << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total", LOG_LEVEL_0); + } + return true; + } + else + { + size_t added = 0; + for (size_t i = 0; i != up_index_limit; i++) + added += add_out_to_get_random_outs(result_outs, amount, i, decoys_count, req.use_forced_mix_outs, req.height_upper_limit) ? 1 : 0; + LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << decoys_count << ", added " << added << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total - respond with all good outs", LOG_LEVEL_0); + return true; + } +} +//------------------------------------------------------------------ + +bool blockchain_storage::get_target_outs_for_amount_postzarcanum(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution& details, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, std::map& amounts_to_up_index_limit_cache) const +{ + size_t decoys_count = details.offsets.size(); + for (auto offset : details.offsets) + { + //perfectly we would need to find transaction's output on the given height, with the given probability + //of being coinbase(coinbase outputs should be included less in decoy selection algorithm) + bool is_coinbase = (crypto::rand() % 101) > req.coinbase_percents ? false : true; + + //TODO: Consider including PoW coinbase to transactions(does it needed?) + + // convert offset to estimated height + uint64_t estimated_h = this->get_current_blockchain_size() - 1 - offset; + //make sure it's after zc hardfork + if (estimated_h < m_core_runtime_config.hard_forks.m_height_the_hardfork_n_active_after[ZANO_HARDFORK_04_ZARCANUM]) + { + LOG_ERROR("Wrong estimated offset(" << offset << "), it hits zone before zarcanum hardfork"); + return false; + } + +#define TARGET_RANDOM_OUTS_SELECTIOM_POOL_MIN 10 + //try to find output around given H + std::vector selected_global_indexes; + + + auto process_tx = [&](const crypto::hash& tx_id) { + + auto tx_ptr = m_db_transactions.find(tx_id); + CHECK_AND_ASSERT_THROW_MES(tx_ptr, "internal error: tx_id " << tx_id << " around estimated_h = " << estimated_h << " not found in db"); + //go through tx outputs + for (size_t i = 0; i != tx_ptr->tx.vout.size(); i++) + { + if (tx_ptr->tx.vout[i].type() != typeid(tx_out_zarcanum)) + { + continue; + } + const tx_out_zarcanum& z_out = boost::get(tx_ptr->tx.vout[i]); + + // NOTE: second part of condition (mix_attr >= CURRENCY_TO_KEY_OUT_FORCED_MIX_LOWER_BOUND && ..) might be not accurate + // since the wallet might want to request more inputs then it planning to do mixins. For now let's keep it this way and fix + // it if we see the problems about it. + if (z_out.mix_attr == CURRENCY_TO_KEY_OUT_FORCED_NO_MIX || (z_out.mix_attr >= CURRENCY_TO_KEY_OUT_FORCED_MIX_LOWER_BOUND && z_out.mix_attr < details.offsets.size())) + { + continue; + } + + // skip spent outptus + if (tx_ptr->m_spent_flags[i]) + { + continue; + } + + // add output + // note: code that will process selected_global_indes will be revisiting transactions entries to obtain all + // needed data, that should work relatively effective because of on-top-of-db cache keep daya unserialized + selected_global_indexes.push_back(selected_global_indexes[i]); + } + + }; + + while (selected_global_indexes.size() < TARGET_RANDOM_OUTS_SELECTIOM_POOL_MIN) + { + auto block_ptr = m_db_blocks.get(estimated_h--); + if (is_coinbase && is_pos_block(block_ptr->bl) ) + { + process_tx(get_transaction_hash(block_ptr->bl.miner_tx)); + } + else + { + //looking for regular output of regular transactions + for (auto tx_id : block_ptr->bl.tx_hashes) + { + process_tx(tx_id); + } + } + } + + //pick up a random output from selected_global_indes + uint64_t global_index = selected_global_indexes[crypto::rand() % selected_global_indexes.size()]; + bool res = add_out_to_get_random_outs(result_outs, details.amount, global_index, details.offsets.size(), req.use_forced_mix_outs, req.height_upper_limit); + CHECK_AND_ASSERT_THROW_MES(res, "Failed to add_out_to_get_random_outs([" << global_index << "]) at postzarcanum era"); + } + return true; +} +//------------------------------------------------------------------ bool blockchain_storage::get_random_outs_for_amounts2(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::response& res)const { CRITICAL_REGION_LOCAL(m_read_lock); @@ -2669,67 +2812,19 @@ bool blockchain_storage::get_random_outs_for_amounts2(const COMMAND_RPC_GET_RAND for (size_t i = 0; i != req.amounts.size(); i++) { uint64_t amount = req.amounts[i].amount; - const std::list& offsets = req.amounts[i].offsets; + //const std::vector& offsets = req.amounts[i].offsets; COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs = *res.outs.insert(res.outs.end(), COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount()); result_outs.amount = amount; - uint64_t zc_hard_fork_after_h = m_core_runtime_config.hard_forks[ZANO_HARDFORK_04_ZARCANUM]; - for (auto it = offsets.begin(); it != offsets.end(); it++) + if (amount == 0) { - uint64_t target_height = - - } - - - - - uint64_t outs_container_size = m_db_outputs.get_item_size(amount); - if (!outs_container_size) - { - LOG_ERROR("COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS: not outs for amount " << amount << ", wallet should use some real outs when it lookup for some mix, so, at least one out for this amount should exist"); - continue;//actually this is strange situation, wallet should use some real outs when it lookup for some mix, so, at least one out for this amount should exist - } - //it is not good idea to use top fresh outs, because it increases possibility of transaction canceling on split - //lets find upper bound of not fresh outs - size_t up_index_limit = 0; - auto it_limit = amounts_to_up_index_limit_cache.find(amount); - if (it_limit == amounts_to_up_index_limit_cache.end()) - { - up_index_limit = find_end_of_allowed_index(amount); - amounts_to_up_index_limit_cache[up_index_limit]; + //zarcanum era inputs + get_target_outs_for_amount_postzarcanum(req, req.amounts[i], result_outs, amounts_to_up_index_limit_cache); } else { - up_index_limit = it_limit->second; - } - - CHECK_AND_ASSERT_MES(up_index_limit <= outs_container_size, false, "internal error: find_end_of_allowed_index returned wrong index=" << up_index_limit << ", with amount_outs.size = " << outs_container_size); - if (up_index_limit >= req.decoys_count) - { - std::set used; - size_t try_count = 0; - for (uint64_t j = 0; j != req.decoys_count && try_count < up_index_limit;) - { - size_t g_index = crypto::rand() % up_index_limit; - if (used.count(g_index)) - continue; - bool added = add_out_to_get_random_outs(result_outs, amount, g_index, req.decoys_count, req.use_forced_mix_outs, req.height_upper_limit); - used.insert(g_index); - if (added) - ++j; - ++try_count; - } - if (result_outs.outs.size() < req.decoys_count) - { - LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.decoys_count << ", added " << result_outs.outs.size() << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total", LOG_LEVEL_0); - } - } - else - { - size_t added = 0; - for (size_t i = 0; i != up_index_limit; i++) - added += add_out_to_get_random_outs(result_outs, amount, i, req.decoys_count, req.use_forced_mix_outs, req.height_upper_limit) ? 1 : 0; - LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.decoys_count << ", added " << added << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total - respond with all good outs", LOG_LEVEL_0); + //zarcanum era inputs + get_target_outs_for_amount_prezarcanum(req, req.amounts[i], result_outs, amounts_to_up_index_limit_cache); } } return true; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 7eb8aeb4..ca11163c 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -637,6 +637,8 @@ namespace currency bool push_transaction_to_global_outs_index(const transaction& tx, const crypto::hash& tx_id, std::vector& global_indexes); bool pop_transaction_from_global_index(const transaction& tx, const crypto::hash& tx_id); bool add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, uint64_t amount, size_t i, uint64_t mix_count, bool use_only_forced_to_mix = false, uint64_t height_upper_limit = 0) const; + bool get_target_outs_for_amount_prezarcanum(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution& details, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, std::map& amounts_to_up_index_limit_cache) const; + bool get_target_outs_for_amount_postzarcanum(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution& details, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& result_outs, std::map& amounts_to_up_index_limit_cache) const; bool add_block_as_invalid(const block& bl, const crypto::hash& h); bool add_block_as_invalid(const block_extended_info& bei, const crypto::hash& h); size_t find_end_of_allowed_index(uint64_t amount)const; diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index d88b20ff..96d872fc 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -110,6 +110,7 @@ namespace currency MAP_URI_AUTO_BIN2("/getblocks.bin", on_get_blocks, COMMAND_RPC_GET_BLOCKS_FAST) MAP_URI_AUTO_BIN2("/get_o_indexes.bin", on_get_indexes, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES) MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS) + MAP_URI_AUTO_BIN2("/getrandom_outs2.bin", on_get_random_outs2, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2) MAP_URI_AUTO_BIN2("/set_maintainers_info.bin", on_set_maintainers_info, COMMAND_RPC_SET_MAINTAINERS_INFO) MAP_URI_AUTO_BIN2("/get_tx_pool.bin", on_get_tx_pool, COMMAND_RPC_GET_TX_POOL) MAP_URI_AUTO_BIN2("/check_keyimages.bin", on_check_keyimages, COMMAND_RPC_CHECK_KEYIMAGES) diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index a0cfbdf8..ee17f228 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -429,7 +429,7 @@ namespace currency struct offsets_distribution { uint64_t amount; //if amount is 0 then lookup in post-zarcanum zone only, if not 0 then pre-zarcanum only - std::list offsets; //[i] = height, estimated location where to pickup output of transaction + std::vector offsets; //[i] = height, estimated location where to pickup output of transaction BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amount) @@ -440,55 +440,20 @@ namespace currency struct request { - std::list amounts; + std::vector amounts; uint64_t height_upper_limit; // if nonzero, all the decoy outputs must be either older than, or the same age as this height bool use_forced_mix_outs; + uint64_t coinbase_percents; //from 0 to 100, estimate percents of coinbase outputs included in decoy sets BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(amounts) KV_SERIALIZE(decoys_count) KV_SERIALIZE(height_upper_limit) KV_SERIALIZE(use_forced_mix_outs) + KV_SERIALIZE(coinbase_percents) END_KV_SERIALIZE_MAP() }; -#pragma pack (push, 1) - struct out_entry - { - out_entry() = default; - out_entry(uint64_t global_amount_index, const crypto::public_key& stealth_address) - : global_amount_index(global_amount_index), stealth_address(stealth_address), concealing_point{}, amount_commitment{}, blinded_asset_id{} - {} - out_entry(uint64_t global_amount_index, const crypto::public_key& stealth_address, const crypto::public_key& amount_commitment, const crypto::public_key& concealing_point, const crypto::public_key& blinded_asset_id) - : global_amount_index(global_amount_index), stealth_address(stealth_address), concealing_point(concealing_point), amount_commitment(amount_commitment), blinded_asset_id(blinded_asset_id) - {} - uint64_t global_amount_index; - crypto::public_key stealth_address; - crypto::public_key concealing_point; // premultiplied by 1/8 - crypto::public_key amount_commitment; // premultiplied by 1/8 - crypto::public_key blinded_asset_id; // premultiplied by 1/8 - }; -#pragma pack(pop) - - struct outs_for_amount - { - uint64_t amount; - std::list outs; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(amount) - KV_SERIALIZE_CONTAINER_POD_AS_BLOB(outs) - END_KV_SERIALIZE_MAP() - }; - - struct response - { - std::vector outs; - std::string status; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(outs) - KV_SERIALIZE(status) - END_KV_SERIALIZE_MAP() - }; + typedef COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response response; }; diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index 8e0638c5..c1dda036 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -77,6 +77,11 @@ namespace tools return invoke_http_bin_remote_command2_update_is_disconnect("/getrandom_outs.bin", req, res); } //------------------------------------------------------------------------------------------------------------------------------ + bool default_http_core_proxy::call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::response& res) + { + return invoke_http_bin_remote_command2_update_is_disconnect("/getrandom_outs2.bin", req, res); + } + //------------------------------------------------------------------------------------------------------------------------------ bool default_http_core_proxy::call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& req, currency::COMMAND_RPC_SEND_RAW_TX::response& res) { return invoke_http_json_remote_command2_update_is_disconnect("/sendrawtransaction", req, res); diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index f344bfd9..2d28c071 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -37,6 +37,7 @@ namespace tools bool call_COMMAND_RPC_GET_TX_POOL(const currency::COMMAND_RPC_GET_TX_POOL::request& rqt, currency::COMMAND_RPC_GET_TX_POOL::response& rsp) override; bool call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(const currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& rqt, currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& rsp) override; bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& rqt, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& rsp) override; + bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& rqt, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::response& rsp) override; bool call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& rqt, currency::COMMAND_RPC_SEND_RAW_TX::response& rsp) override; bool call_COMMAND_RPC_FORCE_RELAY_RAW_TXS(const currency::COMMAND_RPC_FORCE_RELAY_RAW_TXS::request& rqt, currency::COMMAND_RPC_FORCE_RELAY_RAW_TXS::response& rsp) override; bool call_COMMAND_RPC_GET_ALL_ALIASES(currency::COMMAND_RPC_GET_ALL_ALIASES::response& rsp) override; diff --git a/src/wallet/core_fast_rpc_proxy.h b/src/wallet/core_fast_rpc_proxy.h index 3e3f9b40..d08a6eac 100644 --- a/src/wallet/core_fast_rpc_proxy.h +++ b/src/wallet/core_fast_rpc_proxy.h @@ -58,6 +58,11 @@ namespace tools return m_rpc.on_get_random_outs(req, res, m_cntxt_stub); } //------------------------------------------------------------------------------------------------------------------------------ + bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& req, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::response& res) override + { + return m_rpc.on_get_random_outs2(req, res, m_cntxt_stub); + } + //------------------------------------------------------------------------------------------------------------------------------ bool call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& req, currency::COMMAND_RPC_SEND_RAW_TX::response& res) override { return m_rpc.on_send_raw_tx(req, res, m_cntxt_stub); diff --git a/src/wallet/core_rpc_proxy.h b/src/wallet/core_rpc_proxy.h index 747e06e2..effec340 100644 --- a/src/wallet/core_rpc_proxy.h +++ b/src/wallet/core_rpc_proxy.h @@ -36,6 +36,7 @@ namespace tools virtual bool call_COMMAND_RPC_GET_TX_POOL(const currency::COMMAND_RPC_GET_TX_POOL::request& rqt, currency::COMMAND_RPC_GET_TX_POOL::response& rsp){ return false; } virtual bool call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(const currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& rqt, currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& rsp){ return false; } virtual bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& rqt, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& rsp){ return false; } + virtual bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request& rqt, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::response& rsp) { return false; } virtual bool call_COMMAND_RPC_SEND_RAW_TX(const currency::COMMAND_RPC_SEND_RAW_TX::request& rqt, currency::COMMAND_RPC_SEND_RAW_TX::response& rsp){ return false; } virtual bool call_COMMAND_RPC_FORCE_RELAY_RAW_TXS(const currency::COMMAND_RPC_FORCE_RELAY_RAW_TXS::request& rqt, currency::COMMAND_RPC_FORCE_RELAY_RAW_TXS::response& rsp){ return false; } virtual bool call_COMMAND_RPC_GET_ALL_ALIASES(currency::COMMAND_RPC_GET_ALL_ALIASES::response& rsp){ return false; } diff --git a/src/wallet/decoy_selection.cpp b/src/wallet/decoy_selection.cpp new file mode 100644 index 00000000..a75f333d --- /dev/null +++ b/src/wallet/decoy_selection.cpp @@ -0,0 +1,128 @@ +// Copyright (c) 2014-2023 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "decoy_selection.h" +#include "decoy_selection_default_distribution.hpp" +#include "crypto/crypto.h" + +bool scaler::config_scale(uint64_t original, uint64_t scale_to) +{ + m_x_m = original; + m_y_m = scale_to; + return true; +} + +uint64_t scaler::scale(uint64_t h) +{ + double k = double(m_x_m) / m_y_m; + double e_pow_minus_k = std::exp(-1 * k); + double a = e_pow_minus_k / (k - 1 + e_pow_minus_k); + double y = h * a + (1 - std::exp(-1 * (double(h) / double(m_y_m)) )) * m_y_m * (1 - a); + return static_cast(std::round(y)); +} + +void decoy_selection_generator::init(uint64_t max_h) +{ + load_distribution(g_default_distribution, max_h); + m_is_initialized = true; + +} +bool decoy_selection_generator::load_distribution_from_file(const char* path) +{ + return true; +} + +#define TWO63 0x8000000000000000u +#define TWO64f (TWO63*2.0) + +double map_uint_to_double(uint64_t u) { + double y = (double)u; + return y / TWO64f; +} + +std::vector decoy_selection_generator::generate_distribution(uint64_t count) +{ + std::vector res; + for (size_t i = 0; i != count; i++) + { + uint64_t r = 0; + crypto::generate_random_bytes(sizeof(r), &r); + double r_ = map_uint_to_double(r); + auto it = m_distribution_mapping.upper_bound(r_); + if (it == m_distribution_mapping.end()) + { + throw(std::runtime_error(std::string("_r not found in m_distribution_mapping: ") + std::to_string(r_) )); + } + uint64_t h = it->second; + if (it != m_distribution_mapping.begin()) + { + uint64_t h_0 = (--it)->second; + crypto::generate_random_bytes(sizeof(r), &r); + h = h_0 + r % (h - h_0) + 1; + } + //scale from nominal to max_h + res.push_back(h); } + return res; +} + +uint64_t get_distance(const std::vector entries, size_t i) +{ + if (i == 0) + return 1; + return entries[i].h - entries[i - 1].h; +} + +bool decoy_selection_generator::load_distribution(const std::vector& original_distribution, uint64_t max_h) +{ + + //do prescale of distribution + std::vector derived_distribution; + scaler scl; + scl.config_scale(original_distribution.back().h, max_h); + + uint64_t last_scaled_h = 0; + std::list last_scaled_array; + + + for (size_t i = 0; i <= original_distribution.size(); i++) + { + if (i == original_distribution.size() || (scl.scale(original_distribution[i].h) != last_scaled_h && last_scaled_array.size())) + { + //put avg to data_scaled + double summ = 0; + for (auto item: last_scaled_array) + { + summ += item; + } + double avg = summ / last_scaled_array.size(); + uint64_t prev_h = scl.scale(original_distribution[i - 1].h); + derived_distribution.push_back(decoy_selection_generator::distribution_entry{ prev_h, avg}); + last_scaled_array.clear(); + } + if (i == original_distribution.size()) + { + break; + } + last_scaled_array.push_back(original_distribution[i].v); + last_scaled_h = scl.scale(original_distribution[i].h); + } + + + double total_v = 0; + + for (size_t i = 0; i != derived_distribution.size(); i++) + { + total_v += derived_distribution[i].v * get_distance(derived_distribution, i); + } + + double summ_current = 0; + for (size_t i = 0; i != derived_distribution.size(); i++) + { + double k = (derived_distribution[i].v * get_distance(derived_distribution, i))/ total_v; + summ_current += k; + m_distribution_mapping[summ_current] = derived_distribution[i].h; + } + + return true; +} diff --git a/src/wallet/decoy_selection.h b/src/wallet/decoy_selection.h new file mode 100644 index 00000000..230cbc1d --- /dev/null +++ b/src/wallet/decoy_selection.h @@ -0,0 +1,53 @@ +// Copyright (c) 2014-2023 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 +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "include_base_utils.h" +#include "profile_tools.h" +#include "sync_locked_object.h" + + + +class scaler +{ +public: + //See the graph on https://www.desmos.com/calculator/zfx4bolfqx + bool config_scale(uint64_t original, uint64_t scale_to); + uint64_t scale(uint64_t h); +private: + uint64_t m_x_m; + uint64_t m_y_m; +}; + + +class decoy_selection_generator +{ +public: + struct distribution_entry + { + uint64_t h; + double v; + }; + + void init(uint64_t max_h); + bool load_distribution_from_file(const char* path); + std::vector generate_distribution(uint64_t count); + bool is_initialized() { return m_is_initialized; } + +private: + bool load_distribution(const std::vector& entries, uint64_t max_h); + bool m_is_initialized = false; + std::map m_distribution_mapping; +}; diff --git a/src/wallet/decoy_selection_default_distribution.hpp b/src/wallet/decoy_selection_default_distribution.hpp new file mode 100644 index 00000000..9dc44579 --- /dev/null +++ b/src/wallet/decoy_selection_default_distribution.hpp @@ -0,0 +1,1826 @@ +// Copyright (c) 2014-2023 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +const std::vector g_default_distribution = +{ + {10,141}, + {11,407}, + {12,447}, + {13,439}, + {14,430}, + {15,418}, + {16,408}, + {17,390}, + {18,371}, + {19,359}, + {20,344.4}, + {21,332.1}, + {22,322.6}, + {23,317.4}, + {24,310.7}, + {25,306.6}, + {26,300.6}, + {27,296.3}, + {28,290.3}, + {29,285.1}, + {30,280.3}, + {31,276.7}, + {32,272.6}, + {33,269}, + {34,263.9}, + {35,257.7}, + {36,258}, + {37,256.6}, + {38,251.7}, + {39,247.4}, + {40,244.7}, + {41,244.6}, + {42,242.3}, + {43,239.4}, + {44,236.3}, + {45,234}, + {46,232.9}, + {47,230.4}, + {48,225}, + {49,225.4}, + {50,222}, + {51,218.7}, + {52,214.4}, + {53,211.6}, + {54,210.1}, + {55,207.6}, + {56,203.3}, + {57,200}, + {58,201}, + {59,199.7}, + {60,196.7}, + {61,192}, + {62,194.3}, + {63,193.1}, + {64,190.9}, + {65,184.4}, + {66,182.9}, + {67,179.9}, + {68,181.1}, + {69,178.4}, + {70,174}, + {71,172.7}, + {72,172.6}, + {73,170.4}, + {74,169.4}, + {75,163.4}, + {76,159.7}, + {77,160.1}, + {78,157.6}, + {79,156.1}, + {80,154.7}, + {81,153.3}, + {82,155}, + {83,152}, + {84,151}, + {85,149.7}, + {86,146.4}, + {87,146.9}, + {88,145}, + {89,141.3}, + {90,141.6}, + {91,139.4}, + {92,137.8}, + {93,136.6}, + {94,137.7}, + {95,139.5}, + {96,139.9}, + {97,140.5}, + {98,140.9}, + {99,139.8}, + {100,139.5}, + {101,140.1}, + {102,140.4}, + {103,139.5}, + {104,139.4}, + {105,138.9}, + {106,138.1}, + {107,137.8}, + {108,137.3}, + {109,136.8}, + {110,135.9}, + {111,132.5}, + {112,129.2}, + {113,127.1}, + {114,124.7}, + {115,122.3}, + {116,120.8}, + {117,119.5}, + {118,117.6}, + {119,115.6}, + {120,114.9}, + {121,113.9}, + {122,113.3}, + {123,113.1}, + {124,111.9}, + {125,110.9}, + {126,110.5}, + {127,110}, + {128,108.6}, + {129,108.2}, + {130,107.8}, + {131,108.2}, + {132,108.3}, + {133,108}, + {134,107.2}, + {135,106.8}, + {136,106.4}, + {137,105.5}, + {138,105.4}, + {139,104.9}, + {140,104.8}, + {141,104.9}, + {142,104.9}, + {143,105}, + {144,104.4}, + {145,104.6}, + {146,104.3}, + {147,104}, + {148,103.3}, + {149,103.1}, + {150,103.1}, + {151,103.6}, + {152,103.5}, + {153,103.4}, + {154,104.1}, + {155,102.5}, + {156,102.9}, + {157,102.7}, + {158,102.9}, + {159,102.6}, + {160,101.7}, + {161,101.6}, + {162,101.6}, + {163,101.5}, + {164,100.5}, + {165,100.5}, + {166,100.4}, + {167,100.1}, + {168,99.53}, + {169,99.24}, + {170,99.29}, + {171,98.71}, + {172,99.29}, + {173,98.88}, + {174,98.47}, + {175,97.94}, + {176,97.24}, + {177,97.76}, + {178,98.06}, + {179,97.82}, + {180,97.47}, + {181,97.65}, + {182,97.41}, + {183,96.71}, + {184,96.47}, + {185,96.29}, + {186,96.41}, + {187,95.82}, + {188,96}, + {189,96.47}, + {190,95.59}, + {191,95.24}, + {192,95.06}, + {193,95.53}, + {194,95.12}, + {195,94.53}, + {196,94.12}, + {197,94.53}, + {198,94.53}, + {199,94.18}, + {200,93.71}, + {201,93.47}, + {202,93.88}, + {203,93.47}, + {204,93.88}, + {205,93}, + {206,92.35}, + {207,93.29}, + {208,93.76}, + {209,93.76}, + {210,93.35}, + {211,93.18}, + {212,93.65}, + {213,93.24}, + {214,92.82}, + {215,92.76}, + {216,92.76}, + {217,93.59}, + {218,94.29}, + {219,94.18}, + {220,94.24}, + {221,93.71}, + {222,93.65}, + {223,93.53}, + {224,92.94}, + {225,92.88}, + {226,92.94}, + {227,92.88}, + {228,92.88}, + {229,92.47}, + {230,93.29}, + {231,93.53}, + {232,93.59}, + {233,93.35}, + {234,92.59}, + {235,91.88}, + {236,91.41}, + {237,91.18}, + {238,91.18}, + {239,91.35}, + {240,91.18}, + {241,91.29}, + {242,91.06}, + {243,91}, + {244,90.76}, + {245,90.35}, + {246,90.35}, + {247,89.53}, + {248,89.18}, + {249,88.59}, + {250,88.94}, + {251,89}, + {252,89}, + {253,88.35}, + {254,88.65}, + {255,88.82}, + {256,89.24}, + {257,89.59}, + {258,88.76}, + {259,89.41}, + {260,89.06}, + {261,89.06}, + {262,89.29}, + {263,89.35}, + {264,89.71}, + {265,89.94}, + {266,90.24}, + {267,89.94}, + {268,90.06}, + {269,90.24}, + {270,91.29}, + {271,90.76}, + {272,90.41}, + {273,89.76}, + {274,89.06}, + {275,89.71}, + {276,88.94}, + {277,89.24}, + {278,89.53}, + {279,89.35}, + {280,88.88}, + {281,88.82}, + {282,88.59}, + {283,88.29}, + {284,87.71}, + {285,87.71}, + {286,87.35}, + {287,86.53}, + {288,87.53}, + {289,87.71}, + {290,87.71}, + {291,87.88}, + {292,87.35}, + {293,88.12}, + {294,88.18}, + {295,87.59}, + {296,87.59}, + {297,88.18}, + {298,87.94}, + {299,87.65}, + {300,87.94}, + {301,88.12}, + {302,87.94}, + {303,88.12}, + {304,88.29}, + {305,87.29}, + {306,87.47}, + {307,87.76}, + {308,88.76}, + {309,89.06}, + {310,88.59}, + {311,88.18}, + {312,88.53}, + {313,88.41}, + {314,88.35}, + {315,88.18}, + {316,88.29}, + {317,88}, + {318,88.12}, + {319,88.41}, + {320,87.94}, + {321,87.65}, + {322,87.47}, + {323,87.18}, + {324,87.24}, + {325,85.88}, + {326,86.06}, + {327,86.12}, + {328,86.35}, + {329,86.18}, + {330,86.82}, + {331,86.76}, + {332,87.29}, + {333,87.12}, + {334,87.71}, + {335,87.82}, + {336,88.12}, + {337,88.53}, + {338,89.12}, + {339,89.12}, + {340,89.24}, + {341,89.29}, + {342,89.71}, + {343,89.18}, + {344,88.65}, + {345,88.41}, + {346,88.41}, + {347,88}, + {348,87.65}, + {349,87.88}, + {350,87.94}, + {351,87.47}, + {352,87.47}, + {353,86.88}, + {354,86.71}, + {355,86.53}, + {356,86.59}, + {357,86.06}, + {358,85.65}, + {359,85.24}, + {360,85.71}, + {361,85.76}, + {362,86.18}, + {363,85.76}, + {364,86.35}, + {365,86.53}, + {366,86.18}, + {367,85.82}, + {368,86.53}, + {369,86.53}, + {370,86.65}, + {371,86.94}, + {372,86.82}, + {373,87.12}, + {374,87.71}, + {375,87.76}, + {376,87.88}, + {377,87.71}, + {378,88.12}, + {379,87.65}, + {380,88.06}, + {381,87.47}, + {382,86.82}, + {383,86.88}, + {384,87.06}, + {385,86.41}, + {386,86}, + {387,86.82}, + {388,86.71}, + {389,86}, + {390,85.82}, + {391,85.71}, + {392,85.88}, + {393,85.94}, + {394,85.65}, + {395,85}, + {396,85.06}, + {397,85.24}, + {398,85.06}, + {399,85.82}, + {400,85.47}, + {401,85.88}, + {402,86}, + {403,86.29}, + {404,85.88}, + {405,85.47}, + {406,86}, + {407,85.76}, + {408,85.65}, + {409,85.41}, + {410,85.59}, + {411,85.59}, + {412,86.53}, + {413,86.71}, + {414,86.53}, + {415,86.82}, + {416,86.65}, + {417,86.65}, + {418,86.24}, + {419,86.18}, + {420,86.18}, + {421,85.41}, + {422,85.82}, + {423,85.76}, + {424,86.12}, + {425,86.35}, + {426,86.71}, + {427,86.88}, + {428,87.29}, + {429,86.35}, + {430,86.41}, + {431,85.82}, + {432,85.24}, + {433,85.24}, + {434,85.35}, + {435,85.41}, + {436,85.29}, + {437,85.35}, + {438,85.53}, + {439,85.12}, + {440,85.59}, + {441,85.53}, + {442,84.71}, + {443,84.18}, + {444,83.76}, + {445,83.94}, + {446,84}, + {447,83.82}, + {448,84.24}, + {449,84.71}, + {450,84.47}, + {451,84.41}, + {452,84.24}, + {453,84.18}, + {454,84.29}, + {455,84.06}, + {456,84.41}, + {457,83.88}, + {458,83.76}, + {459,84.41}, + {460,84.76}, + {461,84.88}, + {462,84.53}, + {463,84.41}, + {464,84.24}, + {465,84.29}, + {466,84.06}, + {467,83.82}, + {468,84.29}, + {469,84.65}, + {470,84.88}, + {471,84.76}, + {472,85.29}, + {473,85.06}, + {474,85.24}, + {475,85.18}, + {476,84.82}, + {477,83.88}, + {478,83.82}, + {479,83.82}, + {480,83.41}, + {481,83.29}, + {482,83.12}, + {483,83.18}, + {484,83.71}, + {485,83.24}, + {486,83.35}, + {487,83.24}, + {488,82.76}, + {489,82.24}, + {490,82.41}, + {491,82.29}, + {492,82.71}, + {493,82.82}, + {494,84}, + {495,84.29}, + {496,83.76}, + {497,84.65}, + {498,85.18}, + {499,85.18}, + {500,84.82}, + {501,84.76}, + {502,84.65}, + {503,84.24}, + {504,84}, + {505,84.24}, + {506,84.65}, + {507,84.65}, + {508,84.71}, + {509,84.88}, + {510,84.82}, + {511,84.65}, + {512,85}, + {513,85.71}, + {514,85.53}, + {515,84.65}, + {516,84.29}, + {517,84.59}, + {518,84.59}, + {519,84.65}, + {520,84.94}, + {521,85.24}, + {522,85.88}, + {523,86.06}, + {524,85.76}, + {525,85.59}, + {526,84.88}, + {527,84.88}, + {528,84}, + {529,83.47}, + {530,83}, + {531,82.88}, + {532,83.06}, + {533,83.29}, + {534,83.18}, + {535,82.82}, + {536,82.59}, + {537,82}, + {538,81.06}, + {539,80.59}, + {540,80.06}, + {541,80.47}, + {542,80.76}, + {543,81.41}, + {544,81.53}, + {545,82}, + {546,82.24}, + {547,82.94}, + {548,83.06}, + {549,83.29}, + {550,83.59}, + {551,83.71}, + {552,84.18}, + {553,83.88}, + {554,84.06}, + {555,84.47}, + {556,84.29}, + {557,84.29}, + {558,83.76}, + {559,83.71}, + {560,82.76}, + {561,83.18}, + {562,83.18}, + {563,82.71}, + {564,82.06}, + {565,81.76}, + {566,81.88}, + {567,81.88}, + {568,81.65}, + {569,80.88}, + {570,80.88}, + {571,80.88}, + {572,80.94}, + {573,81.06}, + {574,81.06}, + {575,81.41}, + {576,80.82}, + {577,81.12}, + {578,80.24}, + {579,80.41}, + {580,80.24}, + {581,80.35}, + {582,80.59}, + {583,80.88}, + {584,81.18}, + {585,81.41}, + {586,81.35}, + {587,81.76}, + {588,82.41}, + {589,82.41}, + {590,82.47}, + {591,82.76}, + {592,82.53}, + {593,83.18}, + {594,83.18}, + {595,83.47}, + {596,83.12}, + {597,83.59}, + {598,82.94}, + {599,83.06}, + {600,83.12}, + {601,82.71}, + {602,82.71}, + {603,82.88}, + {604,82.82}, + {605,82.76}, + {606,83.24}, + {607,82.94}, + {608,83.29}, + {609,83.06}, + {610,82.94}, + {611,82.94}, + {612,82.71}, + {613,83}, + {614,82.53}, + {615,82.94}, + {616,83.06}, + {617,82.65}, + {618,82.71}, + {619,82.76}, + {620,83.18}, + {621,83.24}, + {622,82.18}, + {623,81.88}, + {624,81.65}, + {625,80.94}, + {626,81.65}, + {627,81.59}, + {628,81.59}, + {629,81.65}, + {630,81.41}, + {631,81.59}, + {632,81.88}, + {633,81.47}, + {634,81.29}, + {635,80.94}, + {636,80.35}, + {637,80.12}, + {638,80}, + {639,80.35}, + {640,81.06}, + {641,81.53}, + {642,81.53}, + {643,80.59}, + {644,80.76}, + {645,80.35}, + {646,80.71}, + {647,80.65}, + {648,80.71}, + {649,80.29}, + {650,79.94}, + {651,80.29}, + {652,80.71}, + {653,81.06}, + {654,81.12}, + {655,81}, + {656,81.41}, + {657,80.71}, + {658,80.59}, + {659,80.88}, + {660,81.53}, + {661,80.88}, + {662,81.71}, + {663,81.29}, + {664,81.06}, + {665,80.76}, + {666,80.65}, + {667,81.12}, + {668,80.65}, + {669,80.47}, + {670,80.41}, + {671,80.53}, + {672,80.18}, + {673,79.59}, + {674,79.59}, + {675,79.47}, + {676,79.12}, + {677,79.06}, + {678,79.53}, + {679,79.18}, + {680,79.06}, + {681,79.53}, + {682,79.71}, + {683,79.82}, + {684,79.18}, + {685,79.41}, + {686,79.18}, + {687,79.29}, + {688,79.18}, + {689,80.12}, + {690,80.35}, + {691,80.71}, + {692,80.59}, + {693,81.24}, + {694,80.76}, + {695,80.65}, + {696,80.29}, + {697,80.35}, + {698,80.41}, + {699,80.18}, + {700,80.24}, + {701,80.47}, + {702,80.18}, + {703,80.24}, + {704,79.76}, + {705,79.41}, + {706,78.53}, + {707,78.53}, + {708,77.88}, + {709,77.94}, + {710,77.06}, + {711,77.41}, + {712,77}, + {713,77.41}, + {714,77.47}, + {715,76.88}, + {716,76.71}, + {717,76.47}, + {718,76.53}, + {719,76.76}, + {720,76.71}, + {721,77.24}, + {722,77.53}, + {723,78.53}, + {724,78.18}, + {725,77.94}, + {726,77.71}, + {727,77.65}, + {728,76.94}, + {729,77.29}, + {730,76.88}, + {731,76.65}, + {732,76.82}, + {733,77.24}, + {734,77.71}, + {735,77.41}, + {736,77.24}, + {737,77.29}, + {738,76.82}, + {739,76.35}, + {740,75.76}, + {741,76}, + {742,76.12}, + {743,76.47}, + {744,76.41}, + {745,76.71}, + {746,76}, + {747,75.94}, + {748,75.53}, + {749,75.47}, + {750,75.06}, + {751,74.29}, + {752,74.35}, + {753,74.24}, + {754,74}, + {755,74.06}, + {756,74.41}, + {757,74.12}, + {758,74}, + {759,73.82}, + {760,73.47}, + {761,73.71}, + {762,74.06}, + {763,74.29}, + {764,74.06}, + {765,74.59}, + {766,74.47}, + {767,74.88}, + {768,75}, + {769,74.82}, + {770,75.12}, + {771,75.06}, + {772,75.18}, + {773,74.88}, + {774,74.76}, + {775,74.35}, + {776,74.82}, + {777,74.24}, + {778,74.41}, + {779,73.88}, + {780,74.06}, + {781,74.47}, + {782,74.41}, + {783,75}, + {784,74.76}, + {785,74.88}, + {786,75}, + {787,74.18}, + {788,74.06}, + {789,74.41}, + {790,74.88}, + {791,74.65}, + {792,74.53}, + {793,74.41}, + {794,75.12}, + {795,74.71}, + {796,74.88}, + {797,75}, + {798,74.76}, + {799,74.59}, + {800,74.06}, + {801,73.94}, + {802,73.53}, + {803,73.41}, + {804,73.24}, + {805,73.06}, + {806,72.47}, + {807,71.29}, + {808,71.12}, + {809,71.06}, + {810,70.76}, + {811,70.18}, + {812,70.18}, + {813,69.76}, + {814,69.18}, + {815,68.88}, + {816,68.82}, + {817,68.47}, + {818,67.76}, + {819,67.94}, + {820,67.82}, + {821,68.76}, + {822,69.41}, + {823,69.18}, + {824,69.53}, + {825,70.06}, + {826,70.12}, + {827,69.82}, + {828,70.24}, + {829,70.06}, + {830,70.24}, + {831,70.18}, + {832,70.24}, + {833,70.18}, + {834,70.35}, + {835,71.06}, + {836,71.12}, + {837,70.76}, + {838,69.71}, + {839,68.94}, + {840,69.24}, + {841,69.24}, + {842,69.18}, + {843,69.59}, + {844,69.82}, + {845,69.59}, + {846,70.18}, + {847,70.59}, + {848,70.76}, + {849,70.76}, + {850,70.76}, + {851,70.76}, + {852,70.41}, + {853,70.35}, + {854,70.82}, + {855,70.94}, + {856,71.29}, + {857,71.06}, + {858,70.88}, + {859,70.35}, + {860,70.18}, + {861,70.53}, + {862,70.12}, + {863,69.29}, + {864,69.47}, + {865,69.41}, + {866,69.59}, + {867,69.47}, + {868,69.24}, + {869,69.12}, + {870,69.24}, + {871,68.59}, + {872,68.35}, + {873,68}, + {874,67.76}, + {875,67.88}, + {876,68.18}, + {877,67.76}, + {878,67.29}, + {879,67.47}, + {880,68}, + {881,67.65}, + {882,68.12}, + {883,67.59}, + {884,67.53}, + {885,67.65}, + {886,67.71}, + {887,67.53}, + {888,67.82}, + {889,68.35}, + {890,68.65}, + {891,68.29}, + {892,68.53}, + {893,68.24}, + {894,68.88}, + {895,68.59}, + {896,68.94}, + {897,68.71}, + {898,68.24}, + {899,67.71}, + {900,67.82}, + {901,68.12}, + {902,68.12}, + {903,68.12}, + {904,67.82}, + {905,67.65}, + {906,67.76}, + {907,67.24}, + {908,67.29}, + {909,66.88}, + {910,66.82}, + {911,66.29}, + {912,66.12}, + {913,65.88}, + {914,65.88}, + {915,66}, + {916,66.29}, + {917,66.59}, + {918,66.41}, + {919,66.29}, + {920,66}, + {921,66.06}, + {922,66.65}, + {923,66.59}, + {924,66.71}, + {925,66.94}, + {926,67}, + {927,66.59}, + {928,66.59}, + {929,66.94}, + {930,66.65}, + {931,66.76}, + {932,66.88}, + {933,66.47}, + {934,65.88}, + {935,65.71}, + {936,66}, + {937,66.35}, + {938,66.35}, + {939,65.82}, + {940,65.18}, + {941,64.94}, + {942,65.18}, + {943,64.88}, + {944,64.94}, + {945,65.18}, + {946,64.88}, + {947,64.82}, + {948,64.47}, + {949,64}, + {950,63.88}, + {951,64.53}, + {952,63.88}, + {953,63.47}, + {954,63.24}, + {955,63.12}, + {956,63.29}, + {957,63.29}, + {958,63.65}, + {959,63.59}, + {960,63.65}, + {961,64.18}, + {962,63.94}, + {963,63.88}, + {964,64.29}, + {965,64.24}, + {966,64.35}, + {967,64.59}, + {968,64.06}, + {969,64.35}, + {970,64.59}, + {971,64.24}, + {972,64.24}, + {973,64.24}, + {974,64.76}, + {975,65.12}, + {976,64.24}, + {977,64.53}, + {978,64.41}, + {979,64.59}, + {980,64.59}, + {981,64.12}, + {982,64.29}, + {983,64.59}, + {984,64.76}, + {985,64.71}, + {986,64.82}, + {987,64.65}, + {988,64.65}, + {989,64.88}, + {990,64.59}, + {991,64.59}, + {992,63.88}, + {993,65.12}, + {994,64.71}, + {995,64.53}, + {996,63.94}, + {997,63.47}, + {998,63.24}, + {999,63.06}, + {1000,62.76}, + {1001,62.41}, + {1002,62.29}, + {1003,62.12}, + {1004,62.06}, + {1005,62.09}, + {1006,62.1}, + {1007,62.09}, + {1008,61.91}, + {1009,61.9}, + {1109,57.65}, + {1209,52.6}, + {1309,49.29}, + {1409,45.15}, + {1509,42.12}, + {1609,38.85}, + {1709,36.16}, + {1809,33.49}, + {1909,30.78}, + {2009,28.2}, + {2109,25.89}, + {2209,23.86}, + {2309,22.16}, + {2409,20.72}, + {2509,19.55}, + {2609,18.54}, + {2709,17.65}, + {2809,16.83}, + {2909,16.07}, + {3009,15.35}, + {3109,14.69}, + {3209,14.07}, + {3309,13.48}, + {3409,12.96}, + {3509,12.47}, + {3609,12}, + {3709,11.57}, + {3809,11.12}, + {3909,10.72}, + {4009,10.33}, + {4109,9.982}, + {4209,9.645}, + {4309,9.341}, + {4409,9.039}, + {4509,8.806}, + {4609,8.58}, + {4709,8.39}, + {4809,8.239}, + {4909,8.099}, + {5009,7.986}, + {5109,7.849}, + {5209,7.708}, + {5309,7.559}, + {5409,7.426}, + {5509,7.303}, + {5609,7.191}, + {5709,7.072}, + {5809,6.971}, + {5909,6.862}, + {6009,6.782}, + {6109,6.675}, + {6209,6.562}, + {6309,6.444}, + {6409,6.321}, + {6509,6.171}, + {6609,6.021}, + {6709,5.869}, + {6809,5.741}, + {6909,5.612}, + {7009,5.508}, + {7109,5.405}, + {7209,5.314}, + {7309,5.222}, + {7409,5.148}, + {7509,5.068}, + {7609,5.026}, + {7709,4.954}, + {7809,4.898}, + {7909,4.84}, + {8009,4.79}, + {8109,4.738}, + {8209,4.682}, + {8309,4.638}, + {8409,4.604}, + {8509,4.564}, + {8609,4.535}, + {8709,4.485}, + {8809,4.435}, + {8909,4.374}, + {9009,4.318}, + {9109,4.252}, + {9209,4.198}, + {9309,4.132}, + {9409,4.059}, + {9509,3.999}, + {9609,3.922}, + {9709,3.864}, + {9809,3.808}, + {9909,3.742}, + {10009,3.683}, + {10109,3.616}, + {10209,3.544}, + {10309,3.476}, + {10409,3.421}, + {10509,3.369}, + {10609,3.322}, + {10709,3.268}, + {10809,3.218}, + {10909,3.149}, + {11009,3.08}, + {11109,3.023}, + {11209,2.962}, + {11309,2.919}, + {11409,2.864}, + {11509,2.846}, + {11609,2.815}, + {11709,2.768}, + {11809,2.724}, + {11909,2.69}, + {12009,2.651}, + {12109,2.631}, + {12209,2.593}, + {12309,2.549}, + {12409,2.511}, + {12509,2.482}, + {12609,2.448}, + {12709,2.423}, + {12809,2.39}, + {12909,2.359}, + {13009,2.33}, + {13109,2.299}, + {13209,2.227}, + {13309,2.186}, + {13409,2.162}, + {13509,2.138}, + {13609,2.125}, + {13709,2.104}, + {13809,2.079}, + {13909,2.049}, + {14009,2.042}, + {14109,2.035}, + {14209,2.021}, + {14309,2.018}, + {14409,1.994}, + {14509,1.973}, + {14609,1.948}, + {14709,1.919}, + {14809,1.887}, + {14910,1.859}, + {15011,1.827}, + {15111,1.786}, + {15613,1.745}, + {16114,1.693}, + {16615,1.647}, + {17115,1.594}, + {17617,1.557}, + {18118,1.504}, + {18619,1.456}, + {19122,1.406}, + {19625,1.357}, + {20129,1.319}, + {20634,1.281}, + {21138,1.246}, + {21645,1.211}, + {22152,1.176}, + {22664,1.139}, + {23169,1.104}, + {23678,1.074}, + {24186,1.043}, + {24696,1.013}, + {25203,0.9871}, + {25719,0.9611}, + {26233,0.9361}, + {26752,0.9126}, + {27284,0.8929}, + {27810,0.8693}, + {28343,0.8486}, + {28875,0.8262}, + {29407,0.8076}, + {29929,0.7891}, + {30457,0.7719}, + {30991,0.7565}, + {31531,0.7435}, + {32073,0.7346}, + {32607,0.7232}, + {33145,0.7135}, + {33689,0.7026}, + {34226,0.6907}, + {34773,0.6787}, + {35328,0.6701}, + {35873,0.6582}, + {36431,0.645}, + {36982,0.6333}, + {37528,0.6231}, + {38074,0.6103}, + {38639,0.5985}, + {39189,0.5859}, + {39753,0.5779}, + {40328,0.5674}, + {40901,0.5588}, + {41484,0.5504}, + {42049,0.5419}, + {42653,0.5313}, + {43228,0.5232}, + {43822,0.5176}, + {44405,0.5121}, + {45023,0.504}, + {45612,0.4991}, + {46195,0.4936}, + {46779,0.4915}, + {47393,0.4864}, + {48007,0.4824}, + {48626,0.479}, + {49230,0.4773}, + {49829,0.4716}, + {50437,0.4676}, + {51046,0.4651}, + {51645,0.4621}, + {52277,0.4579}, + {52912,0.4554}, + {53518,0.4512}, + {54119,0.4472}, + {54742,0.4422}, + {55366,0.4381}, + {55983,0.4331}, + {56597,0.4295}, + {57225,0.4243}, + {57856,0.4212}, + {58501,0.4189}, + {59132,0.4143}, + {59776,0.4082}, + {60414,0.4053}, + {61057,0.4034}, + {61718,0.3975}, + {62362,0.3914}, + {62997,0.3859}, + {63642,0.3825}, + {64292,0.3778}, + {64981,0.3734}, + {65656,0.3684}, + {66311,0.3636}, + {66977,0.3611}, + {67680,0.3588}, + {68360,0.3552}, + {69033,0.3535}, + {69720,0.3529}, + {70419,0.3514}, + {71134,0.351}, + {71843,0.349}, + {72541,0.3451}, + {73225,0.3428}, + {73904,0.3414}, + {74572,0.3409}, + {75225,0.3392}, + {75915,0.339}, + {76599,0.3378}, + {77287,0.3382}, + {77992,0.3378}, + {78671,0.3376}, + {79369,0.3366}, + {80057,0.3365}, + {80743,0.3358}, + {81462,0.3342}, + {82188,0.3353}, + {82880,0.3356}, + {83600,0.3357}, + {84307,0.3366}, + {84991,0.3366}, + {85682,0.336}, + {86370,0.3348}, + {87074,0.3328}, + {87735,0.3319}, + {88419,0.3315}, + {89131,0.3305}, + {89855,0.329}, + {90557,0.3274}, + {91285,0.3259}, + {92005,0.3239}, + {92745,0.322}, + {93489,0.3201}, + {94215,0.3155}, + {94939,0.3116}, + {95678,0.3076}, + {96400,0.3037}, + {97110,0.2999}, + {97840,0.2968}, + {98555,0.2948}, + {99281,0.2922}, + {100045,0.2889}, + {100816,0.2878}, + {101577,0.2868}, + {102366,0.2846}, + {103164,0.2831}, + {103971,0.2808}, + {104747,0.2789}, + {105539,0.2761}, + {106338,0.2738}, + {107078,0.2728}, + {107831,0.2721}, + {108636,0.2728}, + {109396,0.2735}, + {110183,0.2743}, + {110947,0.2737}, + {111731,0.2736}, + {112467,0.2733}, + {113222,0.2736}, + {114011,0.2723}, + {114783,0.2706}, + {115580,0.2721}, + {116331,0.2721}, + {117144,0.2722}, + {117934,0.2722}, + {118741,0.2732}, + {119527,0.2731}, + {120326,0.2719}, + {121136,0.2712}, + {121921,0.2699}, + {122697,0.2689}, + {123489,0.2676}, + {124243,0.2688}, + {125012,0.2682}, + {125806,0.2682}, + {126613,0.2679}, + {127398,0.2682}, + {128231,0.2673}, + {129032,0.2657}, + {129851,0.2643}, + {130630,0.2622}, + {131424,0.2602}, + {132219,0.258}, + {133018,0.2565}, + {133771,0.2572}, + {134623,0.2567}, + {135427,0.2557}, + {136257,0.2551}, + {137115,0.2555}, + {137963,0.2546}, + {138795,0.2549}, + {139653,0.2549}, + {140427,0.2542}, + {141232,0.2528}, + {142052,0.2542}, + {142889,0.255}, + {143665,0.2556}, + {144483,0.2562}, + {145271,0.256}, + {146066,0.2557}, + {146876,0.256}, + {147688,0.2538}, + {148455,0.2541}, + {149221,0.2538}, + {150021,0.2528}, + {150822,0.2508}, + {151661,0.249}, + {152484,0.2475}, + {153308,0.2468}, + {154171,0.2463}, + {154964,0.2459}, + {155813,0.2441}, + {156653,0.2414}, + {157502,0.2377}, + {158370,0.2355}, + {159188,0.2345}, + {160021,0.2319}, + {160848,0.2298}, + {161685,0.2296}, + {162517,0.2277}, + {163384,0.2271}, + {164328,0.2275}, + {165236,0.2284}, + {166093,0.2293}, + {167034,0.2285}, + {167944,0.228}, + {168817,0.2263}, + {169687,0.225}, + {170564,0.2228}, + {171397,0.2228}, + {172237,0.2249}, + {173072,0.2261}, + {173913,0.2279}, + {174796,0.2299}, + {175699,0.2314}, + {176572,0.231}, + {177536,0.2315}, + {178399,0.2335}, + {179232,0.2338}, + {180073,0.2338}, + {180870,0.2338}, + {181723,0.2343}, + {182570,0.2358}, + {183438,0.238}, + {184315,0.2389}, + {185088,0.2409}, + {185907,0.2409}, + {186756,0.24}, + {187588,0.2385}, + {188432,0.2371}, + {189210,0.2358}, + {190006,0.2346}, + {190828,0.234}, + {191677,0.2332}, + {192540,0.2291}, + {193389,0.2269}, + {194284,0.224}, + {195157,0.2222}, + {196078,0.2197}, + {196937,0.2161}, + {197852,0.214}, + {198751,0.2124}, + {199682,0.2107}, + {200565,0.2097}, + {201523,0.2092}, + {202435,0.2094}, + {203365,0.2075}, + {204308,0.2076}, + {205188,0.2065}, + {206108,0.2062}, + {207064,0.2047}, + {207995,0.2045}, + {208902,0.2038}, + {209792,0.2048}, + {210757,0.2038}, + {211654,0.2031}, + {212589,0.2043}, + {213523,0.2047}, + {214453,0.2044}, + {215402,0.205}, + {216343,0.2046}, + {217215,0.204}, + {218177,0.2037}, + {219137,0.2042}, + {219990,0.2059}, + {220877,0.2078}, + {221814,0.2094}, + {222722,0.2125}, + {223647,0.2152}, + {224586,0.2184}, + {225482,0.2201}, + {226402,0.2222}, + {227234,0.2243}, + {228073,0.2228}, + {228930,0.2217}, + {229729,0.2209}, + {230550,0.2199}, + {231331,0.2196}, + {232163,0.2193}, + {233007,0.2192}, + {233892,0.2194}, + {234864,0.2169}, + {235790,0.2157}, + {236774,0.2152}, + {237709,0.2136}, + {238644,0.2125}, + {239596,0.2109}, + {240525,0.2094}, + {241416,0.2082}, + {242344,0.2065}, + {243256,0.2051}, + {244140,0.2035}, + {245024,0.2031}, + {245920,0.2016}, + {246831,0.2009}, + {247751,0.2002}, + {248683,0.1984}, + {249678,0.1966}, + {250745,0.1962}, + {251795,0.1947}, + {252829,0.1916}, + {253857,0.1887}, + {254832,0.1858}, + {255784,0.184}, + {256765,0.1818}, + {257754,0.1791}, + {258724,0.1783}, + {259671,0.1762}, + {260681,0.175}, + {261734,0.1738}, + {262737,0.1726}, + {263690,0.1705}, + {264669,0.1676}, + {265775,0.1655}, + {266786,0.1633}, + {268073,0.1603}, + {269187,0.1573}, + {270281,0.1556}, + {271426,0.1543}, + {272575,0.1524}, + {273786,0.1499}, + {274944,0.1471}, + {276167,0.1461}, + {277357,0.1435}, + {278589,0.1441}, + {279743,0.1438}, + {280892,0.1432}, + {282041,0.1428}, + {283184,0.1425}, + {284431,0.1427}, + {285566,0.1423}, + {286808,0.1424}, + {287974,0.1424}, + {289115,0.1421}, + {290231,0.1417}, + {291389,0.141}, + {292612,0.1409}, + {293766,0.1403}, + {294980,0.141}, + {296201,0.1408}, + {297351,0.1408}, + {298601,0.1407}, + {299815,0.1391}, + {301012,0.1375}, + {302226,0.1355}, + {303478,0.1333}, + {304646,0.1312}, + {305835,0.1299}, + {307026,0.1284}, + {308237,0.1268}, + {309567,0.1265}, + {310913,0.1262}, + {312369,0.1262}, + {313848,0.1254}, + {315330,0.1248}, + {316757,0.1245}, + {318137,0.1265}, + {319522,0.1282}, + {320821,0.1295}, + {322052,0.1317}, + {323248,0.1329}, + {324507,0.1347}, + {325765,0.1366}, + {326928,0.1387}, + {327912,0.1401}, + {328955,0.1422}, + {330032,0.1444}, + {331110,0.1452}, + {332243,0.1457}, + {333424,0.146}, + {334603,0.1464}, + {335776,0.1469}, + {336994,0.1463}, + {338134,0.1441}, + {339258,0.1419}, + {340503,0.1404}, + {341689,0.1388}, + {342891,0.1379}, + {344146,0.1377}, + {345368,0.1372}, + {346632,0.1369}, + {347842,0.137}, + {349123,0.1365}, + {350322,0.1365}, + {351590,0.1361}, + {352854,0.1361}, + {354072,0.1349}, + {355282,0.1349}, + {356459,0.1344}, + {357671,0.1338}, + {358840,0.1331}, + {359983,0.1326}, + {361230,0.1321}, + {362394,0.1314}, + {363766,0.1314}, + {364964,0.1308}, + {366224,0.1312}, + {367546,0.1311}, + {368815,0.1312}, + {370160,0.1319}, + {371481,0.1313}, + {372855,0.1323}, + {374170,0.1327}, + {375474,0.1342}, + {376649,0.1347}, + {377887,0.1346}, + {379098,0.134}, + {380207,0.1341}, + {381395,0.1336}, + {382517,0.1337}, + {383680,0.1342}, + {384822,0.1344}, + {385991,0.1341}, + {387296,0.1322}, + {388666,0.1312}, + {389944,0.1305}, + {391353,0.1284}, + {392586,0.1273}, + {393862,0.1254}, + {395108,0.1232}, + {396471,0.1211}, + {397897,0.1196}, + {399312,0.1195}, + {400600,0.1195}, + {401946,0.119}, + {403282,0.1187}, + {404674,0.1181}, + {406093,0.1193}, + {407540,0.1187}, + {408901,0.1195}, + {410217,0.1203}, + {411631,0.1202}, + {412997,0.1199}, + {414400,0.1196}, + {415784,0.1195}, + {416999,0.1207}, + {418300,0.1219}, + {419542,0.123}, + {420863,0.124}, + {422264,0.1239}, + {423578,0.1246}, + {424981,0.1248}, + {426286,0.1257}, + {427573,0.126}, + {428879,0.1253}, + {430156,0.126}, + {431393,0.1255}, + {432710,0.1254}, + {434036,0.1254}, + {435384,0.1248}, + {436709,0.125}, + {438026,0.1251}, + {439240,0.1243}, + {440484,0.1236}, + {441786,0.123}, + {443101,0.1216}, + {444456,0.1212}, + {445890,0.1208}, + {447245,0.1205}, + {448604,0.1201}, + {449924,0.1201}, + {451307,0.1194}, + {452611,0.1188}, + {454023,0.1191}, + {455436,0.12}, + {456840,0.1204}, + {458257,0.121}, + {459606,0.122}, + {460937,0.1241}, + {462249,0.1265}, + {463586,0.1283}, + {464876,0.1296}, + {466149,0.132}, + {467510,0.1356}, + {468842,0.1385}, + {470091,0.1406}, + {471257,0.1409}, + {472338,0.1422}, + {473505,0.1449}, + {474759,0.1466}, + {475916,0.1465}, + {476960,0.1467}, + {478051,0.1479}, + {479266,0.1482}, + {480635,0.1471}, + {481869,0.1444}, + {482971,0.142}, + {484175,0.1403}, + {485525,0.1393}, + {486739,0.1383}, + {488001,0.1354}, + {489334,0.1331}, + {490709,0.1316}, + {492128,0.1322}, + {493442,0.1316}, + {494768,0.1294}, + {496098,0.1283}, + {497374,0.1284}, + {498656,0.1275}, + {499971,0.1266}, + {501314,0.1267}, + {502579,0.1274}, + {503822,0.1284}, + {505090,0.1282}, + {506324,0.1286}, + {507616,0.129}, + {509023,0.1286}, + {510362,0.1289}, + {511655,0.1289}, + {512920,0.1273}, + {514248,0.1249}, + {515603,0.1239}, + {516893,0.1225}, + {518189,0.1207}, + {519510,0.1191}, + {520758,0.1171}, + {522036,0.1143}, + {523623,0.112}, + {525303,0.1096}, + {526688,0.1075}, + {528111,0.1054}, + {529601,0.103}, + {531150,0.1009}, + {532942,0.0999}, + {534906,0.0989}, + {536601,0.0985}, + {538356,0.0998}, + {540168,0.1012}, + {542046,0.1018}, + {544036,0.1021}, + {545810,0.1025}, + {547327,0.1028}, + {548713,0.1049}, + {550072,0.1083}, + {551378,0.1127}, + {552740,0.1185}, + {554047,0.121}, + {555402,0.1227}, + {556841,0.1231}, + {558250,0.122}, + {559507,0.121}, + {560848,0.1191}, + {561950,0.1173}, + {562967,0.1153}, + {564243,0.1133}, + {565607,0.1119}, + {567230,0.1115}, + {569352,0.1111}, + {571072,0.1115}, + {572799,0.1112}, + {574525,0.1099}, + {576274,0.106}, + {578035,0.102}, + {579568,0.1007}, + {580971,0.1001}, + {582477,0.1012}, + {583824,0.1032}, + {585144,0.1044}, + {586493,0.1046}, + {588092,0.1044}, + {589398,0.1046}, + {590804,0.1056}, + {592281,0.1057}, + {593675,0.1048}, + {595126,0.1036}, + {596490,0.1013}, + {598199,0.0985}, + {599930,0.096}, + {601566,0.0942}, + {603100,0.0911}, + {604590,0.0886}, + {606246,0.0863}, + {608012,0.0833}, + {609931,0.0809}, + {612044,0.0787}, + {614035,0.0779}, + {616290,0.0771}, + {618424,0.0753}, + {620579,0.072}, + {622776,0.0684}, + {625110,0.0653}, + {627373,0.0627}, + {629480,0.0612}, + {631531,0.0596}, + {633608,0.0589}, + {636073,0.0585}, + {639322,0.0578}, + {642777,0.057}, + {646356,0.056}, + {649699,0.0553}, + {652653,0.0548}, + {655849,0.0531}, + {658290,0.052}, + {660714,0.0512}, + {663224,0.0507}, + {665715,0.0514}, + {668624,0.0519}, + {671343,0.0531}, + {673968,0.0539}, + {677030,0.0548}, + {679481,0.0556}, + {681763,0.0533}, + {684242,0.0509}, + {686671,0.0484}, + {689332,0.0461}, + {691596,0.0442}, + {693985,0.0421}, + {696053,0.0399}, + {698329,0.0387}, + {704316,0.0364}, + {712335,0.0339}, + {721199,0.0317}, + {729062,0.0293}, + {737687,0.0275}, + {745415,0.0251}, + {752870,0.023}, + {758886,0.0204}, + {766990,0.0186}, + {775133,0.0188}, + {783348,0.019}, + {791450,0.0195}, + {798063,0.0198}, + {805369,0.0201}, + {812244,0.02}, + {818090,0.02}, + {823019,0.0195}, + {828460,0.0194}, + {835069,0.0194}, + {840633,0.0199}, + {846481,0.0199}, + {853327,0.0202}, + {861817,0.0208}, + {868947,0.0211}, + {877368,0.0213}, + {886495,0.0209}, + {894745,0.0204}, + {900510,0.0203}, + {907909,0.0199}, + {913367,0.019}, + {918248,0.0186}, + {923616,0.0201}, + {929445,0.0217}, + {935781,0.0236}, + {944243,0.0229}, + {951716,0.0221}, + {959341,0.0207}, + {974575,0.0198}, + {985657,0.0185}, + {988920,0.0171}, + {991843,0.0157}, + {994663,0.0143}, + {1038282,0.0132}, + {1113543,0.0123}, + {1222949,0.0014}, + {1291746,0.0016}, + {1346860,0.0021}, + {1383625,0.0029}, + {1449764,0.0027}, + {1658572,0.0013}, + {1717325,0.0014}, + {1886527,0.0014} +}; \ No newline at end of file diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9de9f022..031229e3 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -44,6 +44,7 @@ using namespace epee; #include "currency_core/crypto_config.h" #include "crypto/zarcanum.h" #include "wallet_debug_events_definitions.h" +#include "decoy_selection.h" using namespace currency; @@ -5864,21 +5865,51 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector= zarcanum_start_from) + { + //in Zarcanum era + const uint64_t test_scale_size = current_size - 1 - zarcanum_start_from; + zarcanum_decoy_set_generator.init(test_scale_size - 1); + } + + + + COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::request req = AUTO_VAL_INIT(req); req.height_upper_limit = m_last_pow_block_h; // request decoys to be either older than, or the same age as stake output's height req.use_forced_mix_outs = false; // TODO: add this feature to UI later - req.decoys_count = fake_outputs_count + 1; // one more to be able to skip a decoy in case it hits the real output + //req.decoys_count = fake_outputs_count + 1; // one more to be able to skip a decoy in case it hits the real output for (uint64_t i: selected_indicies) { + req.amounts.push_back(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution()); + COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2::offsets_distribution& rdisttib = req.amounts.back(); + auto it = m_transfers.begin() + i; WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it->m_ptx_wallet_info->m_tx.vout.size() > it->m_internal_output_index, "m_internal_output_index = " << it->m_internal_output_index << " is greater or equal to outputs count = " << it->m_ptx_wallet_info->m_tx.vout.size()); - req.amounts.push_back(it->is_zc() ? 0 : it->m_amount); + + //check if we have Zarcanum era output of pre-Zarcanum + if (it->is_zc()) + { + //Zarcanum era + rdisttib.amount = 0; + //generate distribution in Zarcanum hardfork + THROW_IF_FALSE_WALLET_INT_ERR_EX(zarcanum_decoy_set_generator.is_initialized(), "zarcanum_decoy_set_generator are not initialized"); + rdisttib.offsets = zarcanum_decoy_set_generator.generate_distribution(fake_outputs_count); + } + else + { + //for prezarcanum era use flat distribution + rdisttib.amount = it->m_amount; + rdisttib.offsets.resize(fake_outputs_count, 0); + } } - bool r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(req, daemon_resp); - THROW_IF_FALSE_WALLET_EX(r, error::no_connection_to_daemon, "getrandom_outs.bin"); + bool r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS2(req, daemon_resp); + THROW_IF_FALSE_WALLET_EX(r, error::no_connection_to_daemon, "getrandom_outs2.bin"); THROW_IF_FALSE_WALLET_EX(daemon_resp.status != API_RETURN_CODE_BUSY, error::daemon_busy, "getrandom_outs.bin"); THROW_IF_FALSE_WALLET_EX(daemon_resp.status == API_RETURN_CODE_OK, error::get_random_outs_error, daemon_resp.status); WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(daemon_resp.outs.size() == selected_indicies.size(), @@ -5887,7 +5918,7 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector scanty_outs; for(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& amount_outs : daemon_resp.outs) { - if (amount_outs.outs.size() < req.decoys_count) + if (amount_outs.outs.size() < fake_outputs_count) { scanty_outs.push_back(amount_outs); } diff --git a/tests/unit_tests/decoy_selection.cpp b/tests/unit_tests/decoy_selection.cpp new file mode 100644 index 00000000..47ff298d --- /dev/null +++ b/tests/unit_tests/decoy_selection.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 2019 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + +#include "gtest/gtest.h" +#include "wallet/decoy_selection.h" + +TEST(decoy_selection_test, decoy_selection_test) +{ + const uint64_t test_scale_size = 20000; + decoy_selection_generator dsg; + dsg.init(test_scale_size - 1); + std::map hits; + //std::vector hits(test_scale_size, 0); + + +// while (true) +// { +// std::vector decoys = dsg.generate_distribution(15); +// for (auto d : decoys) +// { +// hits[d]++; +// } +// +// if (hits[10] > 500) +// break; +// +// } +// std::stringstream ss; +// for (auto it = hits.begin(); it != hits.end(); it++) +// { +// //if (hits[i] != 0) +// { +// ss << it->first << ", " << it->second << ENDL; +// } +// } +// epee::file_io_utils::save_string_to_file("distribution.csv", ss.str()); + + + +} +