From fc93a80429461eea538239f94f19ee5e6ca2e059 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 23 May 2022 13:46:03 +0200 Subject: [PATCH 001/127] moved UI to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 32b34f8e..aff23f13 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 32b34f8ea235b91360d4bc5eb5eefde293680759 +Subproject commit aff23f13bc1a886f4d29a48c269228f05f561ec8 From 9ee5b6cbe3b25b0f5f9cff3ecec38db256b6cf73 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 2 Jun 2022 20:42:03 +0200 Subject: [PATCH 002/127] moved UI to latest fixes --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index aff23f13..4c665498 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit aff23f13bc1a886f4d29a48c269228f05f561ec8 +Subproject commit 4c6654980f433b882cd5618cfd886ff1474f1e88 From ea43bcf8a128f27ddbf0c9ca44066dd1228f4608 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Thu, 2 Jun 2022 21:43:34 +0300 Subject: [PATCH 003/127] === build number: 143 -> 144 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index a6d24549..50c2fe88 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 143 +#define PROJECT_VERSION_BUILD_NO 144 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From d26fc8ad7f7761ded06660485e73f40c2732f8fb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 8 Jun 2022 17:33:02 +0200 Subject: [PATCH 004/127] filtering transactions improved --- src/wallet/wallet2.cpp | 14 ++++++++++++++ src/wallet/wallet2.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 54f88e1e..eb697c02 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3234,6 +3234,20 @@ bool enum_container(iterator_t it_begin, iterator_t it_end, callback_t cb) return true; } //---------------------------------------------------------------------------------------------------- +bool wallet2::is_consolidating_transaction(const wallet_public::wallet_transfer_info& wti) +{ + if (!wti.is_income) + { + uint64_t income = 0; + for (uint64_t r : wti.td.rcv){income += r;} + uint64_t spend = 0; + for (uint64_t s : wti.td.spn) { spend += s; } + if (get_tx_fee(wti.tx) + spend = income) + return true; + } + return false; +} +//---------------------------------------------------------------------------------------------------- void wallet2::get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs, bool start_from_end) { if (!count || offset >= m_transfer_history.size()) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d34cc4e0..eec495a0 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -512,6 +512,7 @@ namespace tools const currency::account_base& get_account() const { return m_account; } void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total, uint64_t& last_item_index, bool exclude_mining_txs = false, bool start_from_end = true); + bool is_consolidating_transaction(const wallet_public::wallet_transfer_info& wti); uint64_t get_recent_transfers_total_count(); uint64_t get_transfer_entries_count(); void get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs = false); From 8ec2783860c83691b83fd499b833d24e7fb4b7a0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 8 Jun 2022 17:52:58 +0200 Subject: [PATCH 005/127] filtering transactions improved2 --- src/wallet/wallet2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index eb697c02..6bdc3b49 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3242,7 +3242,7 @@ bool wallet2::is_consolidating_transaction(const wallet_public::wallet_transfer_ for (uint64_t r : wti.td.rcv){income += r;} uint64_t spend = 0; for (uint64_t s : wti.td.spn) { spend += s; } - if (get_tx_fee(wti.tx) + spend = income) + if (get_tx_fee(wti.tx) + spend == income) return true; } return false; @@ -3257,7 +3257,7 @@ void wallet2::get_recent_transfers_history(std::vector Date: Fri, 10 Jun 2022 16:51:37 +0200 Subject: [PATCH 006/127] Returned missing files --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 4c665498..14def6ae 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 4c6654980f433b882cd5618cfd886ff1474f1e88 +Subproject commit 14def6aef99d4f10e81990e2055a7cf490f2e797 From cf0454a208fae1c9465790a442c194126e667d68 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 13 Jun 2022 21:46:32 +0200 Subject: [PATCH 007/127] Improved filtration of PoS-related transactions --- src/wallet/wallet2.cpp | 2 +- utils/test_api_files/get_recent_txs_and_info.json | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 utils/test_api_files/get_recent_txs_and_info.json diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6bdc3b49..170d97de 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3242,7 +3242,7 @@ bool wallet2::is_consolidating_transaction(const wallet_public::wallet_transfer_ for (uint64_t r : wti.td.rcv){income += r;} uint64_t spend = 0; for (uint64_t s : wti.td.spn) { spend += s; } - if (get_tx_fee(wti.tx) + spend == income) + if (get_tx_fee(wti.tx) + income == spend) return true; } return false; diff --git a/utils/test_api_files/get_recent_txs_and_info.json b/utils/test_api_files/get_recent_txs_and_info.json new file mode 100644 index 00000000..b0187813 --- /dev/null +++ b/utils/test_api_files/get_recent_txs_and_info.json @@ -0,0 +1,13 @@ +{ + "jsonrpc": "2.0", + "id": 0, + "method": "get_recent_txs_and_info", + "params": { + "offset": 0, + "update_provision_info": true, + "exclude_mining_txs": true, + "count": 100, + "order": "FROM_BEGIN_TO_END", + "exclude_unconfirmed": true + } +} \ No newline at end of file From b5495f30f0848723c43c7ff629dc0c17aa662b47 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 16 Jun 2022 17:02:00 +0200 Subject: [PATCH 008/127] improved alias detection in transaction history + added RPC API for alias registration --- .../include/serialization/keyvalue_helpers.h | 2 + src/currency_core/blockchain_storage.cpp | 20 +++--- src/currency_core/blockchain_storage.h | 1 + src/rpc/core_rpc_server.cpp | 26 ++++--- src/rpc/core_rpc_server.h | 4 +- src/rpc/core_rpc_server_commands_defs.h | 4 +- src/wallet/core_fast_rpc_proxy.h | 2 +- src/wallet/wallet2.cpp | 67 ++++++++++++++++++- src/wallet/wallet2.h | 6 +- src/wallet/wallet_public_structs_defs.h | 21 ++++++ src/wallet/wallet_rpc_server.cpp | 25 +++++++ src/wallet/wallet_rpc_server.h | 3 + src/wallet/wallets_manager.cpp | 5 +- utils/test_api_files/register_alias.json | 14 ++++ 14 files changed, 170 insertions(+), 30 deletions(-) create mode 100644 utils/test_api_files/register_alias.json diff --git a/contrib/epee/include/serialization/keyvalue_helpers.h b/contrib/epee/include/serialization/keyvalue_helpers.h index 0ae911b0..79a4886b 100644 --- a/contrib/epee/include/serialization/keyvalue_helpers.h +++ b/contrib/epee/include/serialization/keyvalue_helpers.h @@ -62,6 +62,8 @@ namespace epee t_pod_type transform_str_to_t_pod(const std::string& a) { t_pod_type res = AUTO_VAL_INIT(res); + if (a.empty()) + return res; if (!epee::string_tools::hex_to_pod(a, res)) throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type).name()); return res; diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 9ab636f5..b398bd97 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3462,6 +3462,17 @@ std::string blockchain_storage::get_alias_by_address(const account_public_addres return ""; } //------------------------------------------------------------------ +std::set blockchain_storage::get_aliases_by_address(const account_public_address& addr)const +{ + auto alias_ptr = m_db_addr_to_alias.find(addr); + if (alias_ptr && alias_ptr->size()) + { + return *(alias_ptr); + } + + return std::set(); +} +//------------------------------------------------------------------ bool blockchain_storage::pop_alias_info(const extra_alias_entry& ai) { CRITICAL_REGION_LOCAL(m_read_lock); @@ -3651,15 +3662,6 @@ uint64_t blockchain_storage::validate_alias_reward(const transaction& tx, const //validate the price had been paid uint64_t found_alias_reward = get_amount_for_zero_pubkeys(tx); - //@#@ - //work around for net 68's generation -#if CURRENCY_FORMATION_VERSION == 68 - if (alias == "bhrfrrrtret" && get_transaction_hash(tx) == epee::string_tools::parse_tpod_from_hex_string("760b85546678d2235a1843e18d8a016a2e4d9b8273cc4d7c09bebff1f6fa7eaf") ) - return true; - if (alias == "test-420" && get_transaction_hash(tx) == epee::string_tools::parse_tpod_from_hex_string("10f8a2539b2551bd0919bf7e3b1dfbae7553eca63e58cd2264ae60f90030edf8")) - return true; -#endif - CHECK_AND_ASSERT_MES(found_alias_reward >= fee_for_alias, false, "registration of alias '" << alias << "' goes with a reward of " << print_money(found_alias_reward) << " which is less than expected: " << print_money(fee_for_alias) <<"(fee median: " << get_tx_fee_median() << ")" diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index cad2ca91..01a95f52 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -279,6 +279,7 @@ namespace currency bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector& indexs)const; bool get_alias_info(const std::string& alias, extra_alias_entry_base& info)const; std::string get_alias_by_address(const account_public_address& addr)const; + std::set get_aliases_by_address(const account_public_address& addr)const; template bool enumerate_aliases(cb_t cb) const; template diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 5adc60f9..8d0e5858 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1286,7 +1286,7 @@ namespace currency return true; } //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::on_alias_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx) + bool core_rpc_server::on_aliases_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx) { account_public_address addr = AUTO_VAL_INIT(addr); if (!get_account_address_from_str(addr, req)) @@ -1298,22 +1298,28 @@ namespace currency COMMAND_RPC_GET_ALIAS_DETAILS::request req2 = AUTO_VAL_INIT(req2); COMMAND_RPC_GET_ALIAS_DETAILS::response res2 = AUTO_VAL_INIT(res2); - req2.alias = m_core.get_blockchain_storage().get_alias_by_address(addr); - if (!req2.alias.size()) + std::set aliases = m_core.get_blockchain_storage().get_aliases_by_address(addr); + + if (!aliases.size()) { res.status = API_RETURN_CODE_NOT_FOUND; return true; } - bool r = this->on_get_alias_details(req2, res2, error_resp, cntx); - if (!r || res2.status != API_RETURN_CODE_OK) + for (auto it = aliases.begin(); it != aliases.end(); it++) { - res.status = API_RETURN_CODE_FAIL; - return true; - } + req2.alias = *it; + bool r = this->on_get_alias_details(req2, res2, error_resp, cntx); + if (!r || res2.status != API_RETURN_CODE_OK) + { + res.status = API_RETURN_CODE_FAIL; + return true; + } + res.alias_info_list.push_back(alias_rpc_details()); + res.alias_info_list.back().details = res2.alias_details; + res.alias_info_list.back().alias = req2.alias; - res.alias_info.details = res2.alias_details; - res.alias_info.alias = req2.alias; + } res.status = API_RETURN_CODE_OK; return true; } diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index d95dd52b..590b1151 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -71,7 +71,7 @@ namespace currency bool on_get_alias_details(const COMMAND_RPC_GET_ALIAS_DETAILS::request& req, COMMAND_RPC_GET_ALIAS_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_all_aliases(const COMMAND_RPC_GET_ALL_ALIASES::request& req, COMMAND_RPC_GET_ALL_ALIASES::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_aliases(const COMMAND_RPC_GET_ALIASES::request& req, COMMAND_RPC_GET_ALIASES::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); - bool on_alias_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); + bool on_aliases_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_alias_reward(const COMMAND_RPC_GET_ALIAS_REWARD::request& req, COMMAND_RPC_GET_ALIAS_REWARD::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_addendums(const COMMAND_RPC_GET_ADDENDUMS::request& req, COMMAND_RPC_GET_ADDENDUMS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_reset_transaction_pool(const COMMAND_RPC_RESET_TX_POOL::request& req, COMMAND_RPC_RESET_TX_POOL::response& res, connection_context& cntx); @@ -134,7 +134,7 @@ namespace currency MAP_JON_RPC_WE("getblockheaderbyhash", on_get_block_header_by_hash, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH) MAP_JON_RPC_WE("getblockheaderbyheight", on_get_block_header_by_height, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT) MAP_JON_RPC_WE("get_alias_details", on_get_alias_details, COMMAND_RPC_GET_ALIAS_DETAILS) - MAP_JON_RPC_WE("get_alias_by_address", on_alias_by_address, COMMAND_RPC_GET_ALIASES_BY_ADDRESS) + MAP_JON_RPC_WE("get_alias_by_address", on_aliases_by_address, COMMAND_RPC_GET_ALIASES_BY_ADDRESS) MAP_JON_RPC_WE("get_alias_reward", on_get_alias_reward, COMMAND_RPC_GET_ALIAS_REWARD) MAP_JON_RPC ("get_est_height_from_date", on_get_est_height_from_date, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE) //block explorer api diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 531cbe74..3edc5c57 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1069,11 +1069,11 @@ namespace currency struct response { //std::string alias; - alias_rpc_details alias_info; + std::vector alias_info_list; std::string status; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(alias_info) + KV_SERIALIZE(alias_info_list) KV_SERIALIZE(status) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/core_fast_rpc_proxy.h b/src/wallet/core_fast_rpc_proxy.h index 9f1a1225..60035292 100644 --- a/src/wallet/core_fast_rpc_proxy.h +++ b/src/wallet/core_fast_rpc_proxy.h @@ -50,7 +50,7 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ bool call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(const currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res) override { - return m_rpc.on_alias_by_address(req, res, m_err_stub, m_cntxt_stub); + return m_rpc.on_aliases_by_address(req, res, m_err_stub, m_cntxt_stub); } //------------------------------------------------------------------------------------------------------------------------------ bool call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(const currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res) override diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 170d97de..9c46c429 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3265,6 +3265,11 @@ void wallet2::get_recent_transfers_history(std::vector= count) { return false; @@ -3809,13 +3814,56 @@ void wallet2::push_alias_info_to_extra_according_to_hf_status(const currency::ex } } //---------------------------------------------------------------------------------------------------- -void wallet2::request_alias_registration(const currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward) +uint64_t wallet2::get_alias_cost(const std::string& alias) +{ + currency::COMMAND_RPC_GET_ALIAS_REWARD::request req = AUTO_VAL_INIT(req); + currency::COMMAND_RPC_GET_ALIAS_REWARD::response rsp = AUTO_VAL_INIT(rsp); + req.alias = alias; + if (!m_core_proxy->call_COMMAND_RPC_GET_ALIAS_REWARD(req, rsp)) + { + throw std::runtime_error(std::string("Failed to get alias cost")); + } + + return rsp.reward + rsp.reward / 10; //add 10% of price to be sure; +} +//---------------------------------------------------------------------------------------------------- +void wallet2::request_alias_registration(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward, const crypto::secret_key& authority_key) { if (!validate_alias_name(ai.m_alias)) { throw std::runtime_error(std::string("wrong alias characters: ") + ai.m_alias); } + if (ai.m_alias.size() < ALIAS_MINIMUM_PUBLIC_SHORT_NAME_ALLOWED) + { + if (authority_key == currency::null_skey) + { + throw std::runtime_error(std::string("Short aliases is not allowed without authority key: ") + ALIAS_SHORT_NAMES_VALIDATION_PUB_KEY); + } + crypto::public_key authority_pub = AUTO_VAL_INIT(authority_pub); + bool r = crypto::secret_key_to_public_key(authority_key, authority_pub); + CHECK_AND_ASSERT_THROW_MES(r, "Failed to generate pub key from secrete authority key"); + + if (string_tools::pod_to_hex(authority_pub) != ALIAS_SHORT_NAMES_VALIDATION_PUB_KEY) + { + throw std::runtime_error(std::string("Short aliases is not allowed to register by this authority key")); + } + r = currency::sign_extra_alias_entry(ai, authority_pub, authority_key); + CHECK_AND_ASSERT_THROW_MES(r, "Failed to sign alias update"); + WLT_LOG_L2("Generated update alias info: " << ENDL + << "alias: " << ai.m_alias << ENDL + << "signature: " << currency::print_t_array(ai.m_sign) << ENDL + << "signed(owner) pub key: " << m_account.get_keys().account_address.spend_public_key << ENDL + << "to address: " << get_account_address_as_str(ai.m_address) << ENDL + << "sign_buff_hash: " << currency::get_sign_buff_hash_for_alias_update(ai) + ); + } + + if (!reward) + { + reward = get_alias_cost(ai.m_alias); + } + std::vector destinations; std::vector extra; std::vector attachments; @@ -5051,16 +5099,29 @@ void wallet2::add_sent_unconfirmed_tx(const currency::transaction& tx, } //---------------------------------------------------------------------------------------------------- std::string wallet2::get_alias_for_address(const std::string& addr) +{ + std::vector aliases = get_aliases_for_address(addr); + if (aliases.size()) + return aliases.front(); + return ""; +} +//---------------------------------------------------------------------------------------------------- +std::vector wallet2::get_aliases_for_address(const std::string& addr) { PROFILE_FUNC("wallet2::get_alias_for_address"); currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request req = addr; currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response res = AUTO_VAL_INIT(res); + std::vector aliases; if (!m_core_proxy->call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(req, res)) { WLT_LOG_L0("Failed to COMMAND_RPC_GET_ALIASES_BY_ADDRESS"); - return ""; + return aliases; } - return res.alias_info.alias; + for (auto& e : res.alias_info_list) + { + aliases.push_back(e.alias); + } + return aliases; } //---------------------------------------------------------------------------------------------------- void wallet2::transfer(const std::vector& dsts, size_t fake_outputs_count, diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index eec495a0..092d3aad 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -539,7 +539,7 @@ namespace tools void push_offer(const bc_services::offer_details_ex& od, currency::transaction& res_tx); void cancel_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, uint64_t fee, currency::transaction& tx); void update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, const bc_services::offer_details_ex& od, currency::transaction& res_tx); - void request_alias_registration(const currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); + void request_alias_registration(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward, const crypto::secret_key& authority_key = currency::null_skey); void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); bool check_available_sources(std::list& amounts); @@ -865,7 +865,7 @@ namespace tools void set_use_deffered_global_outputs(bool use); construct_tx_param get_default_construct_tx_param_inital(); void set_disable_tor_relay(bool disable); - + uint64_t get_default_fee() {return TX_DEFAULT_FEE;} void export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions = true); /* @@ -930,6 +930,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); + std::vector get_aliases_for_address(const std::string& addr); 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); @@ -1015,6 +1016,7 @@ private: void push_alias_info_to_extra_according_to_hf_status(const currency::extra_alias_entry& ai, std::vector& extra); void remove_transfer_from_amount_gindex_map(uint64_t tid); + uint64_t get_alias_cost(const std::string& alias); static void wti_to_csv_entry(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index); static void wti_to_txt_line(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index); diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index ce318bf5..7bdc76f7 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -377,7 +377,28 @@ namespace wallet_public }; }; + struct COMMAND_RPC_REGISTER_ALIAS + { + struct request + { + currency::alias_rpc_details al; + crypto::secret_key authority_key; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(al) + KV_SERIALIZE_POD_AS_HEX_STRING(authority_key) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + crypto::hash tx_id; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) + END_KV_SERIALIZE_MAP() + }; + }; struct transfer_destination diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index dc809096..7f352048 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -747,6 +747,31 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + WALLET_RPC_BEGIN_TRY_ENTRY(); + currency::extra_alias_entry ai = AUTO_VAL_INIT(ai); + if (!alias_rpc_details_to_alias_info(req.al, ai)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; + er.message = "WALLET_RPC_ERROR_CODE_WRONG_ADDRESS"; + return false; + } + + if (!currency::validate_alias_name(ai.m_alias)) + { + er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS; + er.message = "WALLET_RPC_ERROR_CODE_WRONG_ADDRESS - Wrong alias name"; + return false; + } + + currency::transaction tx = AUTO_VAL_INIT(tx); + m_wallet.request_alias_registration(ai, tx, m_wallet.get_default_fee(), 0, req.authority_key); + res.tx_id = get_transaction_hash(tx); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 8d1aa084..1edd325c 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -54,6 +54,7 @@ namespace tools MAP_JON_RPC_WE("get_restore_info", on_getwallet_restore_info, wallet_public::COMMAND_RPC_GET_WALLET_RESTORE_INFO) MAP_JON_RPC_WE("get_seed_phrase_info", on_get_seed_phrase_info, wallet_public::COMMAND_RPC_GET_SEED_PHRASE_INFO) MAP_JON_RPC_WE("get_mining_history", on_get_mining_history, wallet_public::COMMAND_RPC_GET_MINING_HISTORY) + MAP_JON_RPC_WE("register_alias", on_register_alias, wallet_public::COMMAND_RPC_REGISTER_ALIAS) //contracts API MAP_JON_RPC_WE("contracts_send_proposal", on_contracts_send_proposal, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL) MAP_JON_RPC_WE("contracts_accept_proposal", on_contracts_accept_proposal, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL) @@ -93,6 +94,8 @@ namespace tools bool on_submit_transfer(const wallet_public::COMMAND_SUBMIT_TRANSFER::request& req, wallet_public::COMMAND_SUBMIT_TRANSFER::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_search_for_transactions(const wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::request& req, wallet_public::COMMAND_RPC_SEARCH_FOR_TRANSACTIONS::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_get_mining_history(const wallet_public::COMMAND_RPC_GET_MINING_HISTORY::request& req, wallet_public::COMMAND_RPC_GET_MINING_HISTORY::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_register_alias(const wallet_public::COMMAND_RPC_REGISTER_ALIAS::request& req, wallet_public::COMMAND_RPC_REGISTER_ALIAS::response& res, epee::json_rpc::error& er, connection_context& cntx); + bool on_contracts_send_proposal(const wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_SEND_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_contracts_accept_proposal(const wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::request& req, wallet_public::COMMAND_CONTRACTS_ACCEPT_PROPOSAL::response& res, epee::json_rpc::error& er, connection_context& cntx); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 54a5cb26..4b06ef96 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1254,7 +1254,10 @@ std::string wallets_manager::get_alias_info_by_address(const std::string& addr, if (res.status != API_RETURN_CODE_OK) return res.status; - res_details = res.alias_info; + if (res.alias_info_list.empty()) + return API_RETURN_CODE_NOT_FOUND; + + res_details = res.alias_info_list.front(); return res.status; } diff --git a/utils/test_api_files/register_alias.json b/utils/test_api_files/register_alias.json new file mode 100644 index 00000000..1a3c9f5f --- /dev/null +++ b/utils/test_api_files/register_alias.json @@ -0,0 +1,14 @@ +{ + "jsonrpc": "2.0", + "id": 0, + "method": "register_alias", + "params": { + "al": { + "alias": "zinazinazina", + "address": "ZxDFNTq2Qf3FPvHakortVe3HxQBXwWNkWZydqfksgv9NRh1Z5b4tE91geYbmPn4JEoNxTMbj8Wj6R4v3fhV6K4Qh36hLacW1w", + "tracking_key": "", + "comment": "" + }, + "authority_key": "" + } +} \ No newline at end of file From 7230f7a12e6677c28e3b1b66cbc1f43a8f6577f2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 16 Jun 2022 17:10:53 +0200 Subject: [PATCH 009/127] renamed alias member to proper name --- src/wallet/wallet_public_structs_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 7bdc76f7..bde9d9f4 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -97,7 +97,7 @@ namespace wallet_public uint32_t tx_blob_size; std::string payment_id; std::vector remote_addresses; //optional - std::vector recipients_aliases; //optional + std::vector remote_aliases; //optional, describe only if there only one remote address std::string comment; bool is_income; bool is_service; @@ -127,7 +127,7 @@ namespace wallet_public KV_SERIALIZE(tx_blob_size) KV_SERIALIZE_BLOB_AS_HEX_STRING(payment_id) KV_SERIALIZE(remote_addresses) - KV_SERIALIZE(recipients_aliases) + KV_SERIALIZE(remote_aliases) KV_SERIALIZE(comment) KV_SERIALIZE(is_income) KV_SERIALIZE(timestamp) From 96cdd25ac5daeb0a49fb7ec8961264f928eca64b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 16 Jun 2022 17:33:37 +0200 Subject: [PATCH 010/127] renamed alias member to proper name - fixed in wallet --- src/simplewallet/simplewallet.cpp | 4 ++-- src/wallet/wallet2.cpp | 22 +++++++++++----------- src/wallet/wallet2.h | 2 +- tests/core_tests/wallet_tests.cpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 1cc8d064..7f4ab1b0 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -774,9 +774,9 @@ bool print_wti(const tools::wallet_public::wallet_transfer_info& wti) static const std::string separator = ", "; std::string remote_side; - if (!wti.recipients_aliases.empty()) + if (!wti.remote_aliases.empty()) { - for (auto it : wti.recipients_aliases) + for (auto it : wti.remote_aliases) remote_side += remote_side.empty() ? it : (separator + it); } else diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9c46c429..c1f4f3fb 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -314,8 +314,8 @@ void wallet2::fetch_tx_global_indixes(const std::list* pglobal_indexes) { - std::vector recipients, recipients_aliases; - process_unconfirmed(tx, recipients, recipients_aliases); + std::vector recipients, remote_aliases; + process_unconfirmed(tx, recipients, remote_aliases); std::vector outs; uint64_t tx_money_got_in_outs = 0; crypto::public_key tx_pub_key = null_pkey; @@ -682,7 +682,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t {//this actually is transfer transaction, notify about spend if (tx_money_spent_in_ins > tx_money_got_in_outs) {//usual transfer - handle_money_spent2(b, tx, tx_money_spent_in_ins - (tx_money_got_in_outs+get_tx_fee(tx)), mtd, recipients, recipients_aliases); + handle_money_spent2(b, tx, tx_money_spent_in_ins - (tx_money_got_in_outs+get_tx_fee(tx)), mtd, recipients, remote_aliases); } else {//strange transfer, seems that in one transaction have transfers from different wallets. @@ -705,7 +705,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t else if (mtd.spent_indices.size()) { // multisig spend detected - handle_money_spent2(b, tx, 0, mtd, recipients, recipients_aliases); + handle_money_spent2(b, tx, 0, mtd, recipients, remote_aliases); } } } @@ -1314,27 +1314,27 @@ void wallet2::handle_money_spent2(const currency::block& b, uint64_t amount, const money_transfer2_details& td, const std::vector& recipients, - const std::vector& recipients_aliases) + const std::vector& remote_aliases) { m_transfer_history.push_back(AUTO_VAL_INIT(wallet_public::wallet_transfer_info())); wallet_public::wallet_transfer_info& wti = m_transfer_history.back(); wti.is_income = false; wti.remote_addresses = recipients; - wti.recipients_aliases = recipients_aliases; + wti.remote_aliases = remote_aliases; prepare_wti(wti, get_block_height(b), get_block_datetime(b), in_tx, amount, td); WLT_LOG_L1("[MONEY SPENT]: " << epee::serialization::store_t_to_json(wti)); rise_on_transfer2(wti); } //---------------------------------------------------------------------------------------------------- -void wallet2::process_unconfirmed(const currency::transaction& tx, std::vector& recipients, std::vector& recipients_aliases) +void wallet2::process_unconfirmed(const currency::transaction& tx, std::vector& recipients, std::vector& remote_aliases) { auto unconf_it = m_unconfirmed_txs.find(get_transaction_hash(tx)); if (unconf_it != m_unconfirmed_txs.end()) { wallet_public::wallet_transfer_info& wti = unconf_it->second; recipients = wti.remote_addresses; - recipients_aliases = wti.recipients_aliases; + remote_aliases = wti.remote_aliases; m_unconfirmed_txs.erase(unconf_it); } @@ -3267,7 +3267,7 @@ void wallet2::get_recent_transfers_history(std::vector= count) @@ -3300,7 +3300,7 @@ void wallet2::wti_to_csv_entry(std::ostream& ss, const wallet_public::wallet_tra ss << wti.tx_blob_size << ","; ss << epee::string_tools::buff_to_hex_nodelimer(wti.payment_id) << ","; ss << "["; - std::copy(wti.recipients_aliases.begin(), wti.recipients_aliases.end(), std::ostream_iterator(ss, " ")); + std::copy(wti.remote_aliases.begin(), wti.remote_aliases.end(), std::ostream_iterator(ss, " ")); ss << "]" << ","; ss << (wti.is_income ? "in" : "out") << ","; ss << (wti.is_service ? "[SERVICE]" : "") << (wti.is_mixing ? "[MIXINS]" : "") << (wti.is_mining ? "[MINING]" : "") << ","; @@ -5081,7 +5081,7 @@ void wallet2::add_sent_unconfirmed_tx(const currency::transaction& tx, //unconfirmed_wti.tx = tx; unconfirmed_wti.remote_addresses = recipients; for (auto addr : recipients) - unconfirmed_wti.recipients_aliases.push_back(get_alias_for_address(addr)); + unconfirmed_wti.remote_aliases.push_back(get_alias_for_address(addr)); unconfirmed_wti.is_income = false; unconfirmed_wti.selected_indicies = selected_indicies; /*TODO: add selected_indicies to read_money_transfer2_details_from_tx in case of performance problems*/ diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 092d3aad..d0c80a00 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1160,7 +1160,7 @@ namespace boost a & x.is_income; a & x.td; a & x.tx; - a & x.recipients_aliases; + a & x.remote_aliases; a & x.comment; a & x.contract; a & x.selected_indicies; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index f4f2e027..5aaaf611 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1780,7 +1780,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_ uint64_t biggest_alias_reward = get_alias_coast_from_fee("a", TESTS_DEFAULT_FEE); std::shared_ptr l(new wlt_lambda_on_transfer2_wrapper( [biggest_alias_reward](const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined) -> bool { - return std::count(wti.recipients_aliases.begin(), wti.recipients_aliases.end(), "minerminer") == 1 && + return std::count(wti.remote_aliases.begin(), wti.remote_aliases.end(), "minerminer") == 1 && wti.amount == biggest_alias_reward; } )); From 20eabbd54f4d5253568b818241181fe854c202ad Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 16 Jun 2022 19:14:12 +0200 Subject: [PATCH 011/127] win: build signing temporary disabled --- utils/build_script_windows.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index b5a1451d..6ab41c90 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -173,7 +173,7 @@ set installer_path=%BUILDS_PATH%\builds\%installer_file% %ZANO_SIGN_CMD% %installer_path% IF %ERRORLEVEL% NEQ 0 ( @echo "failed to sign installer" - goto error + rem goto error ) @echo " UPLOADING TO SERVER ...." From af552f6d453dd00513617a10414738bc26e1689a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 17 Jun 2022 18:05:52 +0200 Subject: [PATCH 012/127] pulled latest changes from UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 14def6ae..adbf4f1a 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 14def6aef99d4f10e81990e2055a7cf490f2e797 +Subproject commit adbf4f1a9ac41dd6ad8f1cc1f25743b7b72f8220 From 2ab1ba9341c13c73267bce3377e25f9b229c3a24 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 22 Jun 2022 20:33:43 +0200 Subject: [PATCH 013/127] fixed latest changes --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index adbf4f1a..58b20756 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit adbf4f1a9ac41dd6ad8f1cc1f25743b7b72f8220 +Subproject commit 58b207565d2e818be0e4b13903526a3ff404898e From af1cf46d1e030e084746f0735b3b15047745a681 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 1 Jul 2022 12:35:54 +0200 Subject: [PATCH 014/127] moved UI to latest commits --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 58b20756..abdf2198 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 58b207565d2e818be0e4b13903526a3ff404898e +Subproject commit abdf21986d092d19f1e313ddd63d5ba971af8e25 From 84962b34e755ee128be07a1a57af5fe5fb910aa6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 7 Jul 2022 17:07:46 +0200 Subject: [PATCH 015/127] merged from UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index abdf2198..83540461 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit abdf21986d092d19f1e313ddd63d5ba971af8e25 +Subproject commit 8354046168ab23336c52681e21f90c3633336af9 From 49dc47c8cff47de336d1d07d2fc52a18db040578 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 8 Jul 2022 15:25:07 +0200 Subject: [PATCH 016/127] merged from UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 83540461..22212b20 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 8354046168ab23336c52681e21f90c3633336af9 +Subproject commit 22212b20250b918f713dc90e85dadc2700d23a6a From e1acd4e4e6f8be885cd7268aa9a08dca5b80ab98 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 8 Jul 2022 17:06:26 +0200 Subject: [PATCH 017/127] disable TOR by default for server-mode, fixed --disable-tor-relay which was not working for server mode --- src/gui/qt-daemon/layout | 2 +- src/simplewallet/simplewallet.cpp | 13 ++++++++++++- src/wallet/wallet_rpc_server.cpp | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 22212b20..14def6ae 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 22212b20250b918f713dc90e85dadc2700d23a6a +Subproject commit 14def6aef99d4f10e81990e2055a7cf490f2e797 diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 7f4ab1b0..a11e9cfb 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -56,7 +56,7 @@ namespace const command_line::arg_descriptor arg_offline_mode ( "offline-mode", "Don't connect to daemon, work offline (for cold-signing process)"); const command_line::arg_descriptor arg_scan_for_wallet ( "scan-for-wallet", ""); const command_line::arg_descriptor arg_addr_to_compare ( "addr-to-compare", ""); - const command_line::arg_descriptor arg_disable_tor_relay ( "disable-tor-relay", "Do PoS mining", false); + const command_line::arg_descriptor arg_disable_tor_relay ( "disable-tor-relay", "Disable TOR relay", false); const command_line::arg_descriptor< std::vector > arg_command ("command", ""); @@ -2176,6 +2176,17 @@ int main(int argc, char* argv[]) LOG_PRINT_YELLOW("PoS reward will be sent to another address: " << arg_pos_mining_reward_address_str, LOG_LEVEL_0); } } + + if (command_line::has_arg(vm, arg_disable_tor_relay)) + { + wal.set_disable_tor_relay(command_line::get_arg(vm, arg_disable_tor_relay)); + } + else + { + //disable TOR by default for server-mode, to avoid potential sporadic errors due to TOR connectivity fails + wal.set_disable_tor_relay(true); + } + tools::wallet_rpc_server wrpc(wal); bool r = wrpc.init(vm); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 7f352048..d49148e4 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -143,6 +143,7 @@ namespace tools { m_wallet.set_miner_text_info(command_line::get_arg(vm, arg_miner_text_info)); } + return true; } //------------------------------------------------------------------------------------------------------------------------------ From 30d9d190e137dffc553232299bc8c8ef26e5e7be Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 8 Jul 2022 17:18:35 +0200 Subject: [PATCH 018/127] lean up code with log options --- contrib/epee/include/net/http_client.h | 12 ++++++------ src/simplewallet/simplewallet.cpp | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index c0b57596..e5f869b1 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -322,7 +322,7 @@ using namespace std; LOG_PRINT("Reconnecting...", LOG_LEVEL_3); if(!connect(m_host_buff, m_port)) { - LOG_PRINT("Failed to connect to " << m_host_buff << ":" << m_port, LOG_LEVEL_3); + LOG_PRINT("Failed to connect to " << m_host_buff << ":" << m_port, LOG_LEVEL_1); return false; } } @@ -370,7 +370,7 @@ using namespace std; { if(!m_net_client.recv(recv_buffer)) { - LOG_PRINT("Unexpected reciec fail", LOG_LEVEL_3); + LOG_PRINT("Unexpected reciec fail", LOG_LEVEL_2); m_state = reciev_machine_state_error; } if(!recv_buffer.size()) @@ -415,10 +415,10 @@ using namespace std; return true; } else - { - LOG_PRINT_L3("Returning false because of wrong state machine. state: " << m_state); - return false; - } + { + LOG_PRINT_L3("Returning false because of wrong state machine. state: " << m_state); + return false; + } } //--------------------------------------------------------------------------- inline diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a11e9cfb..eecf05db 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -49,7 +49,7 @@ namespace const command_line::arg_descriptor arg_dont_refresh ( "no-refresh", "Do not refresh after load"); const command_line::arg_descriptor arg_dont_set_date ( "no-set-creation-date", "Do not set wallet creation date", false); const command_line::arg_descriptor arg_daemon_port ("daemon-port", "Use daemon instance at port instead of default", 0); - const command_line::arg_descriptor arg_log_level ("set-log", ""); + //const command_line::arg_descriptor arg_log_level ("set-log", ""); const command_line::arg_descriptor arg_do_pos_mining ( "do-pos-mining", "Do PoS mining", false); const command_line::arg_descriptor arg_pos_mining_reward_address ( "pos-mining-reward-address", "Block reward will be sent to the giving address if specified", "" ); const command_line::arg_descriptor arg_restore_wallet ( "restore-wallet", "Restore wallet from seed phrase or tracking seed and save it to ", "" ); @@ -1994,7 +1994,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_daemon_host); command_line::add_arg(desc_params, arg_daemon_port); command_line::add_arg(desc_params, arg_command); - command_line::add_arg(desc_params, arg_log_level); + //command_line::add_arg(desc_params, arg_log_level); command_line::add_arg(desc_params, arg_dont_refresh); command_line::add_arg(desc_params, arg_dont_set_date); command_line::add_arg(desc_params, arg_do_pos_mining); @@ -2052,11 +2052,11 @@ int main(int argc, char* argv[]) log_space::log_singletone::add_logger(LOGGER_FILE, log_file_path.filename().string().c_str(), log_dir.c_str(), LOG_LEVEL_4); message_writer(epee::log_space::console_color_white, true) << CURRENCY_NAME << " wallet v" << PROJECT_VERSION_LONG; - if (command_line::has_arg(vm, arg_log_level)) - { - LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, arg_log_level)); - log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, arg_log_level)); - } +// if (command_line::has_arg(vm, arg_log_level)) +// { +// LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, arg_log_level)); +// log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, arg_log_level)); +// } if (command_line::has_arg(vm, command_line::arg_log_level)) { LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level)); From 5b80a22157bfd147df5df45eeb80d8e213ab13bb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 8 Jul 2022 17:35:14 +0200 Subject: [PATCH 019/127] more detailed message in set-log option --- src/simplewallet/simplewallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index eecf05db..bd72c802 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2059,8 +2059,9 @@ int main(int argc, char* argv[]) // } if (command_line::has_arg(vm, command_line::arg_log_level)) { - LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level)); log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, command_line::arg_log_level)); + LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level)); + message_writer(epee::log_space::console_color_white, true) << "Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level); } From 788c5be0927d323cd1bb511c2606e0301a813a2c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 12 Jul 2022 23:05:36 +0200 Subject: [PATCH 020/127] Added timeout to wallet rpc transport --- src/simplewallet/simplewallet.cpp | 61 ++++++++++++++++----------- src/wallet/core_default_rpc_proxy.cpp | 3 +- src/wallet/core_default_rpc_proxy.h | 4 +- src/wallet/core_rpc_proxy.h | 1 + src/wallet/wallet2.cpp | 6 ++- src/wallet/wallet2.h | 1 + tests/CMakeLists.txt | 2 +- tests/performance_tests/api_test.cpp | 25 +++++++++++ tests/performance_tests/main.cpp | 4 +- 9 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 tests/performance_tests/api_test.cpp diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index bd72c802..1d78bb3f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -57,6 +57,7 @@ namespace const command_line::arg_descriptor arg_scan_for_wallet ( "scan-for-wallet", ""); const command_line::arg_descriptor arg_addr_to_compare ( "addr-to-compare", ""); const command_line::arg_descriptor arg_disable_tor_relay ( "disable-tor-relay", "Disable TOR relay", false); + const command_line::arg_descriptor arg_set_timeout("set-timeout", "Set timeout for the wallet"); const command_line::arg_descriptor< std::vector > arg_command ("command", ""); @@ -261,6 +262,29 @@ bool simple_wallet::set_log(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- +void process_wallet_command_line_params(const po::variables_map& vm, tools::wallet2& wal, bool is_server_mode = true) +{ + if (command_line::has_arg(vm, arg_disable_tor_relay)) + { + wal.set_disable_tor_relay(command_line::get_arg(vm, arg_disable_tor_relay)); + message_writer(epee::log_space::console_color_default, true, std::string(), LOG_LEVEL_0) << "Notice: Relaying transactions over TOR disabled with command line parameter"; + } + else + { + if (is_server_mode) + { + //disable TOR by default for server-mode, to avoid potential sporadic errors due to TOR connectivity fails + wal.set_disable_tor_relay(true); + } + } + + if (command_line::has_arg(vm, arg_set_timeout)) + { + wal.set_connectivity_options(command_line::get_arg(vm, arg_set_timeout)); + } + +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::init(const boost::program_options::variables_map& vm) { handle_command_line(vm); @@ -305,7 +329,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) m_do_refresh_after_load = false; } - + bool was_open = false; if (!m_generate_new.empty()) { bool r = new_wallet(m_generate_new, pwd_container.password(), false); @@ -356,12 +380,14 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) { bool r = open_wallet(m_wallet_file, pwd_container.password()); CHECK_AND_ASSERT_MES(r, false, "could not open account"); + was_open = true; } - if (m_disable_tor) - { - m_wallet->set_disable_tor_relay(true); - message_writer(epee::log_space::console_color_default, true, std::string(), LOG_LEVEL_0) << "Notice: Relaying transactions over TOR disabled with command line parameter"; - } + process_wallet_command_line_params(vm, *m_wallet, false); + + m_wallet->init(m_daemon_address); + + if (was_open && (m_do_refresh_after_load && !m_offline_mode)) + refresh(std::vector()); return true; } @@ -425,9 +451,6 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas return false; } - m_wallet->init(m_daemon_address); - - success_msg_writer() << "**********************************************************************\n" << "Your wallet has been generated.\n" << @@ -472,7 +495,6 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st fail_msg_writer() << "failed to restore wallet, check your " << (tracking_wallet ? "tracking seed!" : "seed phrase!") << ENDL; return false; } - m_wallet->init(m_daemon_address); success_msg_writer() << "**********************************************************************\n" << @@ -514,12 +536,6 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa } } - - m_wallet->init(m_daemon_address); - - if (m_do_refresh_after_load && !m_offline_mode) - refresh(std::vector()); - success_msg_writer() << "**********************************************************************\n" << "Use \"help\" command to see the list of available commands.\n" << @@ -1946,6 +1962,7 @@ bool search_for_wallet_file(const std::wstring &search_here/*, const std::string } return false; } + //---------------------------------------------------------------------------------------------------- #ifdef WIN32 int wmain( int argc, wchar_t* argv_w[ ], wchar_t* envp[ ] ) @@ -2006,6 +2023,8 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_scan_for_wallet); command_line::add_arg(desc_params, arg_addr_to_compare); command_line::add_arg(desc_params, arg_disable_tor_relay); + command_line::add_arg(desc_params, arg_set_timeout); + tools::wallet_rpc_server::init_options(desc_params); @@ -2148,6 +2167,7 @@ int main(int argc, char* argv[]) try { LOG_PRINT_L0("Initializing wallet..."); + process_wallet_command_line_params(vm, wal); wal.init(daemon_address); if (command_line::get_arg(vm, arg_generate_new_wallet).size() || command_line::get_arg(vm, arg_generate_new_auditable_wallet).size()) return EXIT_FAILURE; @@ -2178,15 +2198,6 @@ int main(int argc, char* argv[]) } } - if (command_line::has_arg(vm, arg_disable_tor_relay)) - { - wal.set_disable_tor_relay(command_line::get_arg(vm, arg_disable_tor_relay)); - } - else - { - //disable TOR by default for server-mode, to avoid potential sporadic errors due to TOR connectivity fails - wal.set_disable_tor_relay(true); - } tools::wallet_rpc_server wrpc(wal); diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index 9de9f344..6fdbd693 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -184,11 +184,10 @@ namespace tools // m_plast_daemon_is_disconnected = plast_daemon_is_disconnected ? plast_daemon_is_disconnected : &m_last_daemon_is_disconnected_stub; // } //------------------------------------------------------------------------------------------------------------------------------ - bool default_http_core_proxy::set_connectivity(unsigned int connection_timeout, size_t repeats_count) + void default_http_core_proxy::set_connectivity(unsigned int connection_timeout, size_t repeats_count) { m_connection_timeout = connection_timeout; m_attempts_count = repeats_count; - return true; } //------------------------------------------------------------------------------------------------------------------------------ default_http_core_proxy::default_http_core_proxy(): //:m_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected_stub), diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index 77d3a4f3..d5773c4e 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -28,7 +28,7 @@ namespace tools bool set_connection_addr(const std::string& url) override; - bool set_connectivity(unsigned int connection_timeout, size_t repeats_count); + void set_connectivity(unsigned int connection_timeout, size_t repeats_count); bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) override; bool call_COMMAND_RPC_GET_BLOCKS_FAST(const currency::COMMAND_RPC_GET_BLOCKS_FAST::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_FAST::response& rsp) override; bool call_COMMAND_RPC_GET_BLOCKS_DIRECT(const currency::COMMAND_RPC_GET_BLOCKS_DIRECT::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& rsp) override; @@ -56,7 +56,7 @@ namespace tools bool check_connection() override; bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) override; - void set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected); + void set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected); default_http_core_proxy(); private: diff --git a/src/wallet/core_rpc_proxy.h b/src/wallet/core_rpc_proxy.h index b8d2e303..68ff46b5 100644 --- a/src/wallet/core_rpc_proxy.h +++ b/src/wallet/core_rpc_proxy.h @@ -63,6 +63,7 @@ namespace tools std::shared_ptr get_proxy_diagnostic_info() const { return m_pdiganostic_info; } std::shared_ptr get_editable_proxy_diagnostic_info() { return m_pdiganostic_info; } virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id){ return false; } + virtual void set_connectivity(unsigned int connection_timeout, size_t repeats_count) {} protected: std::shared_ptr m_pdiganostic_info; }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c1f4f3fb..c73678a6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3323,7 +3323,11 @@ void wallet2::wti_to_json_line(std::ostream& ss, const wallet_public::wallet_tra ss << epee::serialization::store_t_to_json(wti, 4) << ","; }; - +//---------------------------------------------------------------------------------------------------- +void wallet2::set_connectivity_options(unsigned int timeout) +{ + m_core_proxy->set_connectivity(timeout, WALLET_RCP_COUNT_ATTEMNTS); +} //---------------------------------------------------------------------------------------------------- void wallet2::export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions) { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d0c80a00..b8ecac13 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -867,6 +867,7 @@ namespace tools void set_disable_tor_relay(bool disable); uint64_t get_default_fee() {return TX_DEFAULT_FEE;} void export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions = true); + void set_connectivity_options(unsigned int timeout); /* create_htlc_proposal: if htlc_hash == null_hash, then this wallet is originator of the atomic process, and diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e6a9006..40c89aee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(coretests rpc wallet currency_core common crypto zlibstati target_link_libraries(functional_tests rpc wallet currency_core crypto common zlibstatic ethash libminiupnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(hash-tests crypto ethash) target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(performance_tests currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(performance_tests wallet currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(unit_tests wallet currency_core common crypto gtest_main zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_clt currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_srv currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) diff --git a/tests/performance_tests/api_test.cpp b/tests/performance_tests/api_test.cpp new file mode 100644 index 00000000..6a492c28 --- /dev/null +++ b/tests/performance_tests/api_test.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#include "wallet/core_rpc_proxy.h" +#include "wallet/core_default_rpc_proxy.h" + +int test_get_rand_outs() +{ + currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req); + currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response rsp = AUTO_VAL_INIT(rsp); + req.use_forced_mix_outs = false; + req.outs_count = 10 + 1; + for (size_t i = 0; i != 50; i++) + req.amounts.push_back(COIN); + + std::shared_ptr m_core_proxy(new tools::default_http_core_proxy()); + m_core_proxy->set_connection_addr("127.0.0.1:11211"); + m_core_proxy->check_connection(); + + bool r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(req, rsp); + + return 0; +} diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index e8d7a2ed..5472f68b 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -25,6 +25,7 @@ #include "htlc_hash_tests.h" #include "threads_pool_tests.h" +int test_get_rand_outs(); int main(int argc, char** argv) { @@ -36,7 +37,8 @@ int main(int argc, char** argv) epee::log_space::log_singletone::get_default_log_folder().c_str()); - thread_pool_tests(); + test_get_rand_outs(); + //thread_pool_tests(); // std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); // std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX); From 780185fa5ca88c5c102a8f429ebf584ff3c7e43e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 19 Jul 2022 22:32:21 +0200 Subject: [PATCH 021/127] added show_staking_history command --- src/simplewallet/simplewallet.cpp | 67 ++++++++++++++++++++++++++++++- src/simplewallet/simplewallet.h | 1 + 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 1d78bb3f..88ee366b 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -184,7 +184,8 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, ph::_1), "start_mining - Start mining in daemon"); m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, ph::_1), "Stop mining in daemon"); m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, ph::_1), "Resynchronize transactions and balance"); - m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, ph::_1), "Show current wallet balance"); + m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, ph::_1), "Show current wallet balance"); + m_cmd_binder.set_handler("show_staking_history", boost::bind(&simple_wallet::show_staking_history, this, ph::_1), "show_staking_history [2] - Show staking transfers, if option provided - number of days for history to display"); m_cmd_binder.set_handler("incoming_transfers", boost::bind(&simple_wallet::show_incoming_transfers, this, ph::_1), "incoming_transfers [available|unavailable] - Show incoming transfers - all of them or filter them by availability"); m_cmd_binder.set_handler("incoming_counts", boost::bind(&simple_wallet::show_incoming_transfers_counts, this, ph::_1), "incoming_transfers counts"); m_cmd_binder.set_handler("list_recent_transfers", boost::bind(&simple_wallet::list_recent_transfers, this, ph::_1), "list_recent_transfers [offset] [count] - Show recent maximum 1000 transfers, offset default = 0, count default = 100 "); @@ -908,6 +909,70 @@ bool simple_wallet::dump_key_images(const std::vector& args) success_msg_writer() << "Storing text to dump_keyimages.txt...."; file_io_utils::save_string_to_file(log_space::log_singletone::get_default_log_folder() + "/dump_keyimages.txt", ss.str()); success_msg_writer() << "Done...."; + return true; +} +//---------------------------------------------------------------------------------------------------- +bool simple_wallet::show_staking_history(const std::vector& args) +{ + uint64_t n_days = 0; + if (!args.empty()) + { + if (!epee::string_tools::get_xtype_from_string(n_days, args[0])) + { + fail_msg_writer() << "Unknown amount of days to list"; + return true; + } + } + + tools::wallet2::transfer_container transfers; + m_wallet->get_transfers(transfers); + + uint64_t timestamp = 0; + + if (n_days) + timestamp = static_cast(time(nullptr)) - (n_days * 60 * 60 * 24); + + uint64_t amount_total_staked = 0; + bool transfers_found = false; + for (auto it = transfers.rbegin(); it != transfers.rend(); it++) + { + const auto& td = *it; + + if (timestamp && td.m_ptx_wallet_info->m_block_timestamp < timestamp) + break; + + if (!(td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER)) + continue; + + bool pos_coinbase = false; + is_coinbase(td.m_ptx_wallet_info->m_tx, pos_coinbase); + if (!pos_coinbase) + continue; + + if (!transfers_found) + { + message_writer() << " amount \tspent\tglobal index\t tx id"; + transfers_found = true; + } + amount_total_staked += td.amount(); + message_writer(static_cast(td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT) ? epee::log_space::console_color_magenta : epee::log_space::console_color_green, false) << + std::setw(21) << print_money(td.amount()) << '\t' << + std::setw(3) << (static_cast(td.m_flags&WALLET_TRANSFER_DETAIL_FLAG_SPENT) ? 'T' : 'F') << " \t" << + std::setw(12) << td.m_global_output_index << '\t' << + get_transaction_hash(td.m_ptx_wallet_info->m_tx) << "[" << td.m_ptx_wallet_info->m_block_height << "] unlocked: " << (m_wallet->is_transfer_unlocked(td) ? 'T' : 'F'); + } + + if (!transfers_found) + { + success_msg_writer() << "No staking transactions"; + } + else + { + success_msg_writer() << "Total staked: " << print_money(amount_total_staked); + } + + + return true; } //---------------------------------------------------------------------------------------------------- diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index f5138544..03b428c3 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -59,6 +59,7 @@ namespace currency bool dump_trunsfers(const std::vector& args); bool dump_key_images(const std::vector& args); bool show_incoming_transfers(const std::vector &args); + bool show_staking_history(const std::vector& args); bool show_incoming_transfers_counts(const std::vector &args); bool list_outputs(const std::vector &args); bool show_payments(const std::vector &args); From b1d7ad8a698d4afb6e9fba186a36b35861c71e10 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 21 Jul 2022 13:05:21 +0200 Subject: [PATCH 022/127] fixed wallet log spam in server mode --- src/simplewallet/simplewallet.cpp | 2 +- src/wallet/wallet2.cpp | 2 +- src/wallet/wallet_rpc_server.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 88ee366b..1438c63e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2127,7 +2127,7 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; //set up logging options - log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); + log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); boost::filesystem::path log_file_path(command_line::get_arg(vm, command_line::arg_log_file)); if (log_file_path.empty()) log_file_path = log_space::log_singletone::get_default_log_file(); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c73678a6..a42300ad 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3570,7 +3570,7 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address build_minted_block(ctx.sp, ctx.rsp, miner_address); } - WLT_LOG_L0("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); + WLT_LOG_L1("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); return true; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index d49148e4..3c7be246 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -78,7 +78,7 @@ namespace tools size_t blocks_fetched = 0; bool received_money = false, ok = false; std::atomic stop(false); - LOG_PRINT_L2("wallet RPC idle: refreshing..."); + LOG_PRINT_L1("wallet RPC idle: refreshing..."); m_wallet.refresh(blocks_fetched, received_money, ok, stop); if (stop) { From 6ff40cd0f4dc16f92910dca9f2d67ec49e32d646 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 21 Jul 2022 15:06:36 +0200 Subject: [PATCH 023/127] less messages in running wallet --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a42300ad..5e5e9894 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2202,7 +2202,7 @@ void wallet2::refresh(size_t & blocks_fetched, bool& received_money, std::atomic } - WLT_LOG("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()), blocks_fetched > 0 ? LOG_LEVEL_1 : LOG_LEVEL_2); + WLT_LOG("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()), blocks_fetched > 0 ? LOG_LEVEL_2 : LOG_LEVEL_3); } //---------------------------------------------------------------------------------------------------- bool wallet2::handle_expiration_list(uint64_t tx_expiration_ts_median) From ad8a3375db2d7eaa317256f297d0b3cf19f8c5b2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 21 Jul 2022 21:27:16 +0200 Subject: [PATCH 024/127] fixed tor relaying(fixed disabled rnd) --- contrib/epee/include/misc_log_ex.h | 12 ++++++------ src/wallet/wallet2.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 0b957a5f..7fc35112 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -123,22 +123,22 @@ DISABLE_VS_WARNINGS(4100) #if defined(ENABLE_LOGGING_INTERNAL) -#define LOG_PRINT_CHANNEL_NO_PREFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL_NO_PREFIX2(log_channel, log_name, x, y) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str() , y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(log_channel, log_name, x, y) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL2_CB(log_channel, log_name, x, y, cb) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);cb(ss________.str());CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, cb) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL_COLOR2_CB(log_channel, log_name, x, y, color, cb) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name); cb(ss________.str());CATCH_ALL_DO_NOTHING();}} -#define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ +#define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( (y) <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\ {TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}} #define LOG_ERROR2_CB(log_name, x, cb) { \ diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5e5e9894..c73678a6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2202,7 +2202,7 @@ void wallet2::refresh(size_t & blocks_fetched, bool& received_money, std::atomic } - WLT_LOG("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()), blocks_fetched > 0 ? LOG_LEVEL_2 : LOG_LEVEL_3); + WLT_LOG("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()), blocks_fetched > 0 ? LOG_LEVEL_1 : LOG_LEVEL_2); } //---------------------------------------------------------------------------------------------------- bool wallet2::handle_expiration_list(uint64_t tx_expiration_ts_median) @@ -3570,7 +3570,7 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address build_minted_block(ctx.sp, ctx.rsp, miner_address); } - WLT_LOG_L1("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); + WLT_LOG_L0("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); return true; } From 765ad24b39b4618c50069870258aa306a5f2d79f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 21 Jul 2022 21:37:28 +0200 Subject: [PATCH 025/127] fixed disabled rnd for consensus download --- contrib/tor-connect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/tor-connect b/contrib/tor-connect index aa509880..2e7176dc 160000 --- a/contrib/tor-connect +++ b/contrib/tor-connect @@ -1 +1 @@ -Subproject commit aa509880f06292ac8078046f3d49ff854e400716 +Subproject commit 2e7176dcea611c1933bec4133591e3f1885b8b37 From c840ba48a2c6250d932ff56af1c0c3f840afc1d0 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 23 Jul 2022 04:32:11 +0200 Subject: [PATCH 026/127] simplewallet: logs msgs & levels clean up --- .../epee/include/net/http_server_impl_base.h | 6 +++--- src/simplewallet/simplewallet.cpp | 17 +++++++---------- src/wallet/wallet2.cpp | 14 +++++++------- src/wallet/wallet_rpc_server.cpp | 4 +++- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h index c02475c3..5d83353c 100644 --- a/contrib/epee/include/net/http_server_impl_base.h +++ b/contrib/epee/include/net/http_server_impl_base.h @@ -65,7 +65,7 @@ namespace epee bool res = m_net_server.init_server(bind_port, bind_ip); if(!res) { - LOG_ERROR("Failed to bind server"); + LOG_ERROR("Failed to bind to " << bind_ip << ":" << bind_port); return false; } return true; @@ -74,14 +74,14 @@ namespace epee bool run(size_t threads_count, bool wait = true) { //go to loop - LOG_PRINT("Run net_service loop( " << threads_count << " threads)...", LOG_LEVEL_0); + LOG_PRINT("Run net_service loop (" << threads_count << " threads)...", LOG_LEVEL_1); if(!m_net_server.run_server(threads_count, wait)) { LOG_ERROR("Failed to run net tcp server!"); } if(wait) - LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0); + LOG_PRINT("net_service loop stopped.", LOG_LEVEL_1); return true; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 1438c63e..edba3b07 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2136,16 +2136,13 @@ int main(int argc, char* argv[]) log_space::log_singletone::add_logger(LOGGER_FILE, log_file_path.filename().string().c_str(), log_dir.c_str(), LOG_LEVEL_4); message_writer(epee::log_space::console_color_white, true) << CURRENCY_NAME << " wallet v" << PROJECT_VERSION_LONG; -// if (command_line::has_arg(vm, arg_log_level)) -// { -// LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, arg_log_level)); -// log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, arg_log_level)); -// } if (command_line::has_arg(vm, command_line::arg_log_level)) { - log_space::get_set_log_detalisation_level(true, command_line::get_arg(vm, command_line::arg_log_level)); - LOG_PRINT_L0("Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level)); - message_writer(epee::log_space::console_color_white, true) << "Setting log level = " << command_line::get_arg(vm, command_line::arg_log_level); + int old_log_level = log_space::get_set_log_detalisation_level(false); + int new_log_level = command_line::get_arg(vm, command_line::arg_log_level); + log_space::get_set_log_detalisation_level(true, new_log_level); + LOG_PRINT_L0("Log level changed: " << old_log_level << " -> " << new_log_level); + message_writer(epee::log_space::console_color_white, true) << "Log level changed: " << old_log_level << " -> " << new_log_level; } @@ -2166,7 +2163,7 @@ int main(int argc, char* argv[]) // runs wallet as RPC server log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); sw->set_offline_mode(offline_mode); - LOG_PRINT_L0("Starting wallet RPC server..."); + LOG_PRINT_L0("Starting in RPC server mode..."); if (!command_line::has_arg(vm, arg_wallet_file) || command_line::get_arg(vm, arg_wallet_file).empty()) { @@ -2292,7 +2289,7 @@ int main(int argc, char* argv[]) if (command_line::get_arg(vm, arg_do_pos_mining)) { // PoS mining can be turned on only in RPC server mode, please provide --rpc-bind-port to make this - fail_msg_writer() << "PoS mining can be turned on only in RPC server mode, please provide --rpc-bind-port=PORT_NO to enable staking in simplewallet"; + fail_msg_writer() << "PoS mining can only be started in RPC server mode, please use command-line option --rpc-bind-port= along with --do-pos-mining to enable staking"; return EXIT_FAILURE; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c73678a6..ff23bd5d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2684,7 +2684,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) { // old WALLET_FILE_BINARY_HEADER_VERSION version means no encryption need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, data_file); - WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_INITAL(need_to_resync=" << need_to_resync << ")"); + WLT_LOG_L1("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_INITAL (need_to_resync=" << need_to_resync << ")"); } else if (wbh.m_ver == WALLET_FILE_BINARY_HEADER_VERSION_2) { @@ -2693,7 +2693,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) in.push(decrypt_filter); in.push(data_file); need_to_resync = !tools::portable_unserialize_obj_from_stream(*this, in); - WLT_LOG_L0("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_2(need_to_resync=" << need_to_resync << ")"); + WLT_LOG_L1("Detected format: WALLET_FILE_BINARY_HEADER_VERSION_2 (need_to_resync=" << need_to_resync << ")"); } else { @@ -2714,10 +2714,10 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) << ", file_size=" << m_current_wallet_file_size << ", blockchain_size: " << m_chain.get_blockchain_current_size() ); - WLT_LOG_L0("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); + WLT_LOG_L1("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); - WLT_LOG_L0("(after loading: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); + WLT_LOG_L1("(after loading: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); if (need_to_resync) { @@ -2789,7 +2789,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor boost::uintmax_t tmp_file_size = boost::filesystem::file_size(tmp_file_path); WLT_LOG_L0("Stored successfully to temporary file " << tmp_file_path.string() << ", file size=" << tmp_file_size); - WLT_LOG_L0("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); + WLT_LOG_L1("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); // for the sake of safety perform a double-renaming: wallet file -> old tmp, new tmp -> wallet file, remove old tmp @@ -3541,7 +3541,7 @@ bool wallet2::try_mint_pos() bool wallet2::try_mint_pos(const currency::account_public_address& miner_address) { mining_context ctx = AUTO_VAL_INIT(ctx); - WLT_LOG_L1("Starting PoS mining iteration"); + WLT_LOG_L2("Starting PoS mining iteration"); fill_mining_context(ctx); if (!ctx.rsp.is_pos_allowed) { @@ -3570,7 +3570,7 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address build_minted_block(ctx.sp, ctx.rsp, miner_address); } - WLT_LOG_L0("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); + WLT_LOG_L1("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); return true; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 3c7be246..cff267a6 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -68,6 +68,8 @@ namespace tools static const uint64_t wallet_rpc_idle_work_period_ms = 2000; m_do_mint = do_mint; + if (m_do_mint) + LOG_PRINT_CYAN("PoS mining is ON", LOG_LEVEL_0); if (!offline_mode) { @@ -78,7 +80,7 @@ namespace tools size_t blocks_fetched = 0; bool received_money = false, ok = false; std::atomic stop(false); - LOG_PRINT_L1("wallet RPC idle: refreshing..."); + LOG_PRINT_L2("wallet RPC idle: refreshing..."); m_wallet.refresh(blocks_fetched, received_money, ok, stop); if (stop) { From 0f126ffd95c1f1b1bc0ae93bc2f47ffc377701c4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 31 Jul 2022 22:59:29 +0200 Subject: [PATCH 027/127] api auto-documentation implementation basics --- contrib/epee/include/net/http_server_handlers_map2.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index 6b45950a..b3fca164 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -30,12 +30,20 @@ #include "storages/portable_storage_template_helper.h" #include "http_base.h" + + +template +typename_t get_documentation_json_struct() +{ + return AUTO_VAL_INIT_T(typename_t); +} + template bool auto_doc_t(const std::string& prefix_name, std::string& generate_reference) { if (!generate_reference.size()) return true; - request_t req = AUTO_VAL_INIT(req); - response_t res = AUTO_VAL_INIT(res); + request_t req = get_documentation_json_struct(); + response_t res = get_documentation_json_struct(); std::stringstream ss; ss << prefix_name << ENDL << "REQUEST: " << ENDL << epee::serialization::store_t_to_json(req) << ENDL << "--------------------------------" << ENDL From 2e6d05636d9180d8904fef7633289ba24e5322b1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 1 Aug 2022 20:17:38 +0200 Subject: [PATCH 028/127] fixed bug with timestamps on strange wallets(reported by sir Gygabyted) --- src/simplewallet/simplewallet.cpp | 6 ++---- src/wallet/wallet2.cpp | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index edba3b07..d2571d62 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -829,15 +829,13 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) success_msg_writer() << "Unconfirmed transfers: "; for (auto & wti : unconfirmed) { - if (!wti.fee) - wti.fee = currency::get_tx_fee(wti.tx); + wti.fee = currency::get_tx_fee(wti.tx); print_wti(wti); } success_msg_writer() << "Recent transfers: "; for (auto & wti : recent) { - if (!wti.fee) - wti.fee = currency::get_tx_fee(wti.tx); + wti.fee = currency::get_tx_fee(wti.tx); print_wti(wti); } return true; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ff23bd5d..24476f13 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1469,7 +1469,7 @@ void wallet2::process_new_blockchain_entry(const currency::block& b, const curre //optimization: seeking only for blocks that are not older then the wallet creation time plus 1 day. 1 day is for possible user incorrect time setup const std::vector* pglobal_index = nullptr; - if (b.timestamp + 60 * 60 * 24 > m_account.get_createtime()) + if (get_block_height(b) > get_wallet_minimum_height()) // b.timestamp + 60 * 60 * 24 > m_account.get_createtime()) { pglobal_index = nullptr; if (bche.coinbase_ptr.get()) From 4ff66c2b15f941c952cdf7fbfc4f128980f1fb09 Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 3 Jan 2023 12:34:26 +0000 Subject: [PATCH 029/127] Fixes CMAKE_OSX_DEPLOYMENT_TARGET (#337) Hiya, When compiling on macOS, i get "ld: warning: dylib (/opt/homebrew/lib/libboost_filesystem-mt.dylib) was built for newer macOS version (13.0) than being linked (11.0)" This is fixed by adding "CACHE STRING" --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99243a7d..9fcba388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ enable_testing() if(APPLE) - set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10.5) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10.5 CACHE STRING "Minimum OS X deployment version") endif() set(USE_PCH FALSE CACHE BOOL "Use shared precompiled headers") From ffad058c7f6fa4f175b272d5bab83de8e7432ead Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 15 Feb 2023 12:58:59 +0100 Subject: [PATCH 030/127] moved UI to right commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index b091d45a..22212b20 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit b091d45ad697db2d35e94de41be3f175bad0f71d +Subproject commit 22212b20250b918f713dc90e85dadc2700d23a6a From 938c019cc6f1da5824d50ca597192b8c636cc0bb Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 16 Feb 2023 18:52:40 +0100 Subject: [PATCH 031/127] hard-disabled TOR relay due to possible misleading API responses on wallet server --- src/wallet/wallet2.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 54f88e1e..862b1022 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -31,12 +31,16 @@ using namespace epee; #include "version.h" #include "common/encryption_filter.h" #include "crypto/bitcoin/sha256_helper.h" + +#define DISABLE_TOR + #ifndef DISABLE_TOR #include "common/tor_helper.h" #endif #include "storages/levin_abstract_invoke2.h" + using namespace currency; From f5b6ab9c484c4a4ea6795846a57476ab0837191e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 22 Feb 2023 20:49:26 +0100 Subject: [PATCH 032/127] bunch of fixes in UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 22212b20..fe224894 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 22212b20250b918f713dc90e85dadc2700d23a6a +Subproject commit fe224894ddab077d94741a0062500b7306834959 From b51a757e34b1d79cd550e4d0ff05e196912d47b8 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Wed, 22 Feb 2023 22:57:05 +0300 Subject: [PATCH 033/127] === build number: 144 -> 145 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 50c2fe88..e987e914 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 144 +#define PROJECT_VERSION_BUILD_NO 145 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 3b13b6e6f5ff874d787036cf011b89c1ae7ceb53 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 29 Mar 2023 19:24:11 +0200 Subject: [PATCH 034/127] build system: windows builds uploading fixed --- utils/build_script_windows.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index 4ccd5e09..1bda773b 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -179,14 +179,14 @@ set installer_path=%BUILDS_PATH%\builds\%installer_file% @echo " UPLOADING TO SERVER ...." -pscp -load zano_build_server %installer_path% build.zano.org:/var/www/html/builds +pscp %installer_path% zano_build_server:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD EXE TO SERVER" goto error ) call :sha256 %installer_path% installer_checksum -pscp -load zano_build_server %build_zip_path% build.zano.org:/var/www/html/builds +pscp %build_zip_path% zano_build_server:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD ZIP TO SERVER" goto error From 761a01ad9f8f4714cedef65835ded7e5038ba5b3 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 31 Mar 2023 15:00:41 +0200 Subject: [PATCH 035/127] build system: added a href to emails for all platforms --- utils/build_script_linux.sh | 2 +- utils/build_script_linux_appimage.sh | 2 +- utils/build_script_mac_osx.sh | 2 +- utils/build_script_windows.bat | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/build_script_linux.sh b/utils/build_script_linux.sh index fe5adbef..ffc5914a 100755 --- a/utils/build_script_linux.sh +++ b/utils/build_script_linux.sh @@ -137,7 +137,7 @@ fi read checksum <<< $(sha256sum $package_filename | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build for linux-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_linux_appimage.sh b/utils/build_script_linux_appimage.sh index 94cb3cce..f6ee4a70 100755 --- a/utils/build_script_linux_appimage.sh +++ b/utils/build_script_linux_appimage.sh @@ -149,7 +149,7 @@ fi read checksum <<< $(sha256sum $package_filename | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build for linux-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index 15acd9e3..580a0914 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -160,7 +160,7 @@ fi read checksum <<< $( shasum -a 256 $package_filepath | awk '/^/ { print $1 }' ) mail_msg="New ${build_prefix_label}${testnet_label}build for macOS-x64:
-https://build.zano.org/builds/$package_filename
+https://build.zano.org/builds/$package_filename
sha256: $checksum" echo "$mail_msg" diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index 1bda773b..ce180a66 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -193,7 +193,7 @@ IF %ERRORLEVEL% NEQ 0 ( ) call :sha256 %build_zip_path% build_zip_checksum -set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%build_zip_filename%
sha256: %build_zip_checksum%
" +set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: Date: Sat, 10 Jun 2023 15:29:59 +0200 Subject: [PATCH 046/127] Moved UI to letes fixes --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 22212b20..795a42bd 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 22212b20250b918f713dc90e85dadc2700d23a6a +Subproject commit 795a42bd23daad59ca32fbdff9b15f4ad0eafec8 From db637883cbcb6e14fa4ebc94f67ade1f647e70d7 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 12 Jun 2023 18:36:05 +0200 Subject: [PATCH 047/127] add built html to UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 795a42bd..ac9d2b52 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 795a42bd23daad59ca32fbdff9b15f4ad0eafec8 +Subproject commit ac9d2b52f756f9076de2bf3f2d97afa7a17ca41a From b557b0ef93eb2c5870ae61e6ebdd80f00e78e899 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 14 Jun 2023 19:02:39 +0200 Subject: [PATCH 048/127] Moved UI to latest commit(and built html) --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index ac9d2b52..9dd56ad8 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit ac9d2b52f756f9076de2bf3f2d97afa7a17ca41a +Subproject commit 9dd56ad8c5dbb9e82e556c71dd4b2cc75d85e541 From 4e9c328be0e8d113fe6b725df0dc2acbadb32b2c Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 26 May 2023 22:11:23 +0200 Subject: [PATCH 049/127] wallet: PoS mining timings --- src/wallet/wallet2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 862b1022..75be5fa5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3521,6 +3521,7 @@ bool wallet2::try_mint_pos() //------------------------------------------------------------------ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address) { + TIME_MEASURE_START_MS(mining_duration_ms); mining_context ctx = AUTO_VAL_INIT(ctx); WLT_LOG_L1("Starting PoS mining iteration"); fill_mining_context(ctx); @@ -3550,8 +3551,9 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address { build_minted_block(ctx.sp, ctx.rsp, miner_address); } + TIME_MEASURE_FINISH_MS(mining_duration_ms); - WLT_LOG_L0("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); + WLT_LOG_L0("PoS mining: " << ctx.rsp.iterations_processed << " iterations finished (" << std::fixed << std::setprecision(2) << (mining_duration_ms / 1000.0f) << "s), status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount)); return true; } From 6caa5b7ac165ff59ff47cdb00e665425853a6616 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 20 Jun 2023 15:04:24 +0200 Subject: [PATCH 050/127] Moved UI to latest commit(and built html) --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 9dd56ad8..1424e812 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 9dd56ad8c5dbb9e82e556c71dd4b2cc75d85e541 +Subproject commit 1424e812c365d465e76f812a2ed29ddefd123115 From 8bf684f0d8d575c53685f2655001d0cd316d36c2 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 6 Jul 2023 18:48:19 +0200 Subject: [PATCH 051/127] coretests: pos_minting_tx_packing was changed to uncover two a bug in PoS block packing (defragmentation) tx (pre-zarcanum) --- tests/core_tests/pos_validation.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/core_tests/pos_validation.cpp b/tests/core_tests/pos_validation.cpp index 2fb6de17..1593d270 100644 --- a/tests/core_tests/pos_validation.cpp +++ b/tests/core_tests/pos_validation.cpp @@ -1029,6 +1029,12 @@ bool pos_minting_tx_packing::configure_core(currency::core& c, size_t ev_index, bool pos_minting_tx_packing::pos_minting_tx_packing::generate(std::vector& events) const { + // + // THIS TEST IS ONLY FOR PRE-ZARCANUM WALLET + // PLEASE, reject all changes made in master/release2/develop branches and use the version from cryptoassets/multiassets + // -- sowle + // + bool r = false; m_accounts.resize(TOTAL_ACCS_COUNT); account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); @@ -1039,12 +1045,12 @@ bool pos_minting_tx_packing::pos_minting_tx_packing::generate(std::vectorset_pos_mint_packing_size(m_pos_mint_packing_size); + alice_wlt->set_pos_mint_packing_size(100); // no coinbase tx outputs should be packed r = alice_wlt->try_mint_pos(); @@ -1096,7 +1102,7 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1), // total true, UINT64_MAX, - m_alice_start_amount // unlocked (one output with amount == CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size was spent as stake) + UINT64_MAX //m_alice_start_amount // unlocked (one output with amount == CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size was spent as stake) ), false, ""); r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE); @@ -1109,7 +1115,8 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) // unlocked ), false, ""); - // coinbase tx outputs should be packed now, there's enough coinbase outputs (> m_pos_mint_packing_size) + // coinbase tx outputs still should NOT be packed now (it's only possible with the stake) + alice_wlt->set_pos_mint_packing_size(10); r = alice_wlt->try_mint_pos(); CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); @@ -1117,11 +1124,10 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 2), // total (+1 one block reward) true, UINT64_MAX, - // CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake - // CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) locked for packing tx - m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) // unlocked + m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 0) // unlocked ), false, ""); + alice_wlt->set_pos_mint_packing_size(8); r = alice_wlt->try_mint_pos(); CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); @@ -1129,8 +1135,7 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 3), // total (+1 one block reward) true, UINT64_MAX, - // CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake - m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) - CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size // unlocked + 0 // unlocked ), false, ""); return true; From 8cbf3a7ebb4b3614f7a842da1e9505ba12a4462f Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 6 Jul 2023 18:50:15 +0200 Subject: [PATCH 052/127] wallet2: fixed a rare bug preventing PoS block creation when UTXO defragmentation tx accidently uses stake output (pre-zarcanum) --- src/wallet/wallet2.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 75be5fa5..9fe9323c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3596,6 +3596,16 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& tmpl_req.pos_index = req.pos_entries[rsp.index].index; tmpl_req.extra_text = m_miner_text_info; tmpl_req.stake_unlock_time = req.pos_entries[rsp.index].stake_unlock_time; + + // mark stake source as spent and make sure it will be restored in case of error + const std::vector stake_transfer_idx_vec{ req.pos_entries[rsp.index].wallet_index }; + mark_transfers_as_spent(stake_transfer_idx_vec, "stake source"); + bool gracefull_leaving = false; + auto stake_transfer_spent_flag_restorer = epee::misc_utils::create_scope_leave_handler([&](){ + if (!gracefull_leaving) + clear_transfers_from_flag(stake_transfer_idx_vec, WALLET_TRANSFER_DETAIL_FLAG_SPENT, "stake source"); + }); + //generate packing tx transaction pack_tx = AUTO_VAL_INIT(pack_tx); if (generate_packing_transaction_if_needed(pack_tx, 0)) @@ -3643,7 +3653,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& 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); + WLT_LOG_GREEN("Block " << get_block_hash(b) << " @ " << get_block_height(b) << " has been constructed, 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); @@ -3660,6 +3670,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& WLT_LOG_GREEN("POS block generated and accepted, congrats!", LOG_LEVEL_0); m_wcallback->on_pos_block_found(b); + gracefull_leaving = true; // to prevent source transfer flags be cleared in scope leave handler return true; } //---------------------------------------------------------------------------------------------------- From babfde7318a02c97f951e7737ba85527187bc8b3 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 12 Jul 2023 12:31:50 +0200 Subject: [PATCH 053/127] win build system improvements --- utils/build_mail.py | 36 +++++++++++++++++++++++++++++ utils/build_script_windows.bat | 42 ++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 utils/build_mail.py diff --git a/utils/build_mail.py b/utils/build_mail.py new file mode 100644 index 00000000..4b547204 --- /dev/null +++ b/utils/build_mail.py @@ -0,0 +1,36 @@ +import sys +import os +import smtplib +from email.message import EmailMessage + +def getenv(e): + t = os.getenv(e) + if t == None: + print("Error: environment variable " + e + " was not set") + exit(1) + return t + +zs_from = getenv("ZANO_SMTP_FROM") +zs_addr = getenv("ZANO_SMTP_ADDR") +zs_port = getenv("ZANO_SMTP_PORT") +zs_user = getenv("ZANO_SMTP_USER") +zs_pass = getenv("ZANO_SMTP_PASS") + +if len(sys.argv) != 4: + print("Usage: " + sys.argv[0] + " ") + exit(1) + +msg = EmailMessage() +msg['Subject'] = sys.argv[1] +msg['From'] = zs_from +msg['To'] = sys.argv[2] +msg.add_header('Content-Type','text/html') +msg.set_payload(sys.argv[3]) + +s = smtplib.SMTP(zs_addr, zs_port) +s.starttls() +s.login(zs_user, zs_pass) +s.send_message(msg) +s.quit() + +print("e-mail sent.") diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index ce180a66..b44c27ee 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -1,9 +1,5 @@ call configure_local_paths.cmd -;; MSVC version-specific paths -SET LOCAL_BOOST_LIB_PATH=%LOCAL_BOOST_PATH%\lib64-msvc-14.1 -SET QT_MSVC_PATH=%QT_PREFIX_PATH%\msvc2017_64 - SET ACHIVE_NAME_PREFIX=zano-win-x64- SET MY_PATH=%~dp0 SET SOURCES_PATH=%MY_PATH:~0,-7% @@ -44,12 +40,13 @@ cd %SOURCES_PATH% rmdir build /s /q mkdir build cd build -cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_MSVC_PATH%" -D BUILD_GUI=TRUE -D STATIC=FALSE -G "Visual Studio 15 2017 Win64" -T host=x64 .. + +cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2017_64 -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 16 2019" -A x64 -T host=x64 .. IF %ERRORLEVEL% NEQ 0 ( goto error ) -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" x86_amd64 +call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x86_amd64 echo on cd %SOURCES_PATH%\build @@ -96,7 +93,9 @@ del /F /Q %build_zip_path% cd src\release - +call :sign_file Zano.exe || goto error +call :sign_file zanod.exe || goto error +call :sign_file simplewallet.exe || goto error @echo on @@ -168,37 +167,31 @@ IF %ERRORLEVEL% NEQ 0 ( set installer_file=%ACHIVE_NAME_PREFIX%%version%-installer.exe set installer_path=%BUILDS_PATH%\builds\%installer_file% -:: Signing temporary disable -::@echo " SIGNING ...." -:: -::%ZANO_SIGN_CMD% %installer_path% -::IF %ERRORLEVEL% NEQ 0 ( -:: @echo "failed to sign installer" -:: goto error -::) +@echo " SIGNING the installer ...." + +call :sign_file %installer_path% || goto error @echo " UPLOADING TO SERVER ...." -pscp %installer_path% zano_build_server:/var/www/html/builds +pscp -load zano_build_server %installer_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD EXE TO SERVER" goto error ) call :sha256 %installer_path% installer_checksum -pscp %build_zip_path% zano_build_server:/var/www/html/builds +pscp -load zano_build_server %build_zip_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD ZIP TO SERVER" goto error ) call :sha256 %build_zip_path% build_zip_checksum -set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST:
https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%build_zip_filename%
sha256: %build_zip_checksum%
" echo %mail_msg% -senditquiet.exe -t %emails% -subject "Zano win-x64 %build_prefix% %TESTNET_LABEL%build %version%" -body %mail_msg% - +python ../utils/build_mail.py "Zano win-x64 %build_prefix% %TESTNET_LABEL%build %version%" "%emails%" %mail_msg% goto success @@ -228,3 +221,12 @@ EXIT /B %ERRORLEVEL% @set "%2=%hash: =% ) @exit /B 0 + + +:sign_file +%ZANO_SIGN_CMD% %1 +@if %ERRORLEVEL% neq 0 ( + @echo ERROR: failed to sign %1 + @exit /B 1 +) +@exit /B 0 From 9e6530e1468e01e8eec5002625904ed23a8d7f0d Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 14 Jul 2023 19:59:39 +0200 Subject: [PATCH 054/127] win build script updated --- utils/build_script_windows.bat | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index b44c27ee..90fba36a 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -1,5 +1,8 @@ call configure_local_paths.cmd +;; MSVC version-specific paths +SET QT_MSVC_PATH=%QT_PREFIX_PATH%\msvc2017_64 + SET ACHIVE_NAME_PREFIX=zano-win-x64- SET MY_PATH=%~dp0 SET SOURCES_PATH=%MY_PATH:~0,-7% @@ -41,7 +44,7 @@ rmdir build /s /q mkdir build cd build -cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2017_64 -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 16 2019" -A x64 -T host=x64 .. +cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_MSVC_PATH%" -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 16 2019" -A x64 -T host=x64 .. IF %ERRORLEVEL% NEQ 0 ( goto error ) @@ -107,7 +110,7 @@ copy /Y zanod.exe bunch copy /Y simplewallet.exe bunch copy /Y *.pdb bunch -%QT_MSVC_PATH%\bin\windeployqt.exe bunch\Zano.exe +%QT_MSVC_PATH%\bin\windeployqt.exe bunch\Zano.exe || goto error cd bunch @@ -224,7 +227,8 @@ EXIT /B %ERRORLEVEL% :sign_file -%ZANO_SIGN_CMD% %1 +@echo Signing %1... +@call %ZANO_SIGN_CMD% %1 @if %ERRORLEVEL% neq 0 ( @echo ERROR: failed to sign %1 @exit /B 1 From 6156c0dc6c16bfd3d2310eae53b3e9f03375e8fa Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 14 Jul 2023 20:01:21 +0200 Subject: [PATCH 055/127] version bump: 1.5.1.145 -> 1.5.1.146 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index f02b4970..96e674ad 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 145 +#define PROJECT_VERSION_BUILD_NO 146 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 689fa2c63ee314fcad7fb8c35d8eff2f6a0d0c5a Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 14 Jul 2023 20:21:41 +0200 Subject: [PATCH 056/127] linux and mac build: email sending updated improved (switched to python script) --- utils/build_script_linux.sh | 2 +- utils/build_script_linux_appimage.sh | 4 ++-- utils/build_script_mac_osx.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/build_script_linux.sh b/utils/build_script_linux.sh index ffc5914a..96bf6ea0 100755 --- a/utils/build_script_linux.sh +++ b/utils/build_script_linux.sh @@ -142,6 +142,6 @@ sha256: $checksum" echo "$mail_msg" -echo "$mail_msg" | mail -s "Zano linux-x64 ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build $version_str" ${emails} +python3 ../../utils/build_mail.py "Zano linux-x64 ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build $version_str" "${emails}" "$mail_msg" exit 0 diff --git a/utils/build_script_linux_appimage.sh b/utils/build_script_linux_appimage.sh index f6ee4a70..dad4b69e 100755 --- a/utils/build_script_linux_appimage.sh +++ b/utils/build_script_linux_appimage.sh @@ -154,6 +154,6 @@ sha256: $checksum" echo "$mail_msg" -echo "$mail_msg" | mail -s "Zano linux-x64 ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build $version_str" ${emails} +python3 ../../utils/build_mail.py "Zano linux-x64 ${build_prefix_label}${testnet_label}${copy_qt_dev_tools_label}build $version_str" "${emails}" "$mail_msg" -exit 0 \ No newline at end of file +exit 0 diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index 580a0914..7216d9d4 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -165,7 +165,7 @@ sha256: $checksum" echo "$mail_msg" -echo "$mail_msg" | mail -s "Zano macOS-x64 ${build_prefix_label}${testnet_label}build $version_str" ${emails} +python3 ../../../utils/build_mail.py "Zano linux-x64 ${build_prefix_label}${testnet_label}build $version_str" "${emails}" "$mail_msg" ###################### From 145a1b65b54786c79e43f953c8ec29495bdb83cf Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 19 Jul 2023 15:21:44 +0200 Subject: [PATCH 057/127] moved UI to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 1424e812..e1c5dea6 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 1424e812c365d465e76f812a2ed29ddefd123115 +Subproject commit e1c5dea6068c7eb2d3ff60a6423b514ea2e4f5ff From 1a5f9e16e61ab14cb722c44e326ef02b80aa1d26 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 21 Jul 2023 13:17:46 +0200 Subject: [PATCH 058/127] ui submodule updated --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index e1c5dea6..52ffcfe2 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit e1c5dea6068c7eb2d3ff60a6423b514ea2e4f5ff +Subproject commit 52ffcfe23fa03efd968ff0c3910dc66e31c050bb From f8d953afe2ea382731789bc1c37ecc973caf2b56 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 21 Jul 2023 13:18:40 +0200 Subject: [PATCH 059/127] remove annoying debug log message --- src/currency_core/blockchain_storage.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 9ab636f5..dd22e385 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3919,9 +3919,6 @@ bool blockchain_storage::add_transaction_from_block(const transaction& tx, const if (need_to_profile && mixins_count > 0) { m_performance_data.tx_mixin_count.push(mixins_count); -#ifdef _DEBUG - LOG_PRINT_L0("[TX_MIXINS]: " << mixins_count); -#endif } //check if there is already transaction with this hash From 57cf32b6bec53c1d2c38826aa7b692ffe1c33c30 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 21 Jul 2023 13:20:55 +0200 Subject: [PATCH 060/127] build: macOS build script updated --- utils/build_script_mac_osx.sh | 11 +++++--- utils/macosx_build_uploader.sh | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 utils/macosx_build_uploader.sh diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index 7216d9d4..6f842883 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -148,13 +148,17 @@ echo "Build success" echo "############### Uploading... ################" -package_filepath=$package_filename +package_filepath="$(pwd)/$package_filename" -scp $package_filepath zano_build_server:/var/www/html/builds/ +#scp $package_filepath zano_build_server:/var/www/html/builds/ +source ../../../macosx_build_uploader.sh +pushd . +upload_build $package_filepath if [ $? -ne 0 ]; then echo "Failed to upload to remote server" exit 1 fi +popd read checksum <<< $( shasum -a 256 $package_filepath | awk '/^/ { print $1 }' ) @@ -165,8 +169,7 @@ sha256: $checksum" echo "$mail_msg" -python3 ../../../utils/build_mail.py "Zano linux-x64 ${build_prefix_label}${testnet_label}build $version_str" "${emails}" "$mail_msg" - +python3 ../../../utils/build_mail.py "Zano macOS-x64 ${build_prefix_label}${testnet_label}build $version_str" "${emails}" "$mail_msg" ###################### # notarization diff --git a/utils/macosx_build_uploader.sh b/utils/macosx_build_uploader.sh new file mode 100644 index 00000000..acd23652 --- /dev/null +++ b/utils/macosx_build_uploader.sh @@ -0,0 +1,51 @@ +set +e +curr_path=${BASH_SOURCE%/*} + +function upload_build() # $1 - path to the file to be uploaded +{ + if [ -z "$1" ] + then + echo "ERROR: upload_build is called with no or invalid parameters" + return 1 + fi + + # check if the directory contains files + #if [ -n "$(ls -A "$ZANO_BLD_UPL_DIR" 2>/dev/null)" ] + #then + # echo "ERROR: uploading folder contains files" + # return 1 + #fi + + cd "$ZANO_BLD_UPL_DIR" || return 2 + rm -rf ./* || return 3 + #popd || return 4 + + touch WAIT || return 5 + cp $1 . || return 6 + rm WAIT || return 7 + + counter=0 + while [ ! -f DONE ] + do + if [ "$counter" -ge 150 ] + then + echo "ERROR: uploading is taking longer than expected" + touch STOP + return 8 + fi + sleep 2 + echo "waiting..." + counter=$((counter + 1)) + done + + rc=$( Date: Fri, 21 Jul 2023 13:21:52 +0200 Subject: [PATCH 061/127] version bump: 1.5.1.146 -> 1.5.1.147 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 96e674ad..bd2bc71b 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 146 +#define PROJECT_VERSION_BUILD_NO 147 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From e6be30aa5ad5c6ada87e108df8a9981c0e926bb4 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 26 Jul 2023 18:26:53 +0200 Subject: [PATCH 062/127] ui submodule updated --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 52ffcfe2..f2e13497 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 52ffcfe23fa03efd968ff0c3910dc66e31c050bb +Subproject commit f2e13497af5ce4dd27289e2b162e826e60b3d94e From fa4888aecebc879b2c019a3c197fdd619b5b3dfa Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 26 Jul 2023 18:28:18 +0200 Subject: [PATCH 063/127] version bump: 1.5.1.147 -> 1.5.1.148 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index bd2bc71b..53ee8337 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 147 +#define PROJECT_VERSION_BUILD_NO 148 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 07c96ea9b61f2a370ef5caae0d44867abaf1a57b Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 26 Jul 2023 18:43:03 +0200 Subject: [PATCH 064/127] build: macOS build script updated --- utils/build_script_mac_osx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index 6f842883..c26b8da9 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -151,7 +151,7 @@ echo "############### Uploading... ################" package_filepath="$(pwd)/$package_filename" #scp $package_filepath zano_build_server:/var/www/html/builds/ -source ../../../macosx_build_uploader.sh +source ../../../utils/macosx_build_uploader.sh pushd . upload_build $package_filepath if [ $? -ne 0 ]; then From 78890eea6b3e95ffcf4d2b2354158852dc81334d Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Jul 2023 15:27:30 +0200 Subject: [PATCH 065/127] predownload file updated to height 2200000 --- src/common/pre_download.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/pre_download.h b/src/common/pre_download.h index ba3eff1b..373c0bd4 100644 --- a/src/common/pre_download.h +++ b/src/common/pre_download.h @@ -21,8 +21,8 @@ namespace tools }; #ifndef TESTNET - static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.42.247/pre-download/zano_mdbx_95_2100000.pak", "91cff6f45d257dcd77d889329d3918f0d9760061d29549af3276cb3c23540bc3", 2544045360, 5100195840 }; - static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.42.247/pre-download/zano_lmdb_95_2100000.pak", "8ba077de1cf066dcde048a35f7d41876ba6842f9ec8f923b0d3fec88991fa416", 3294916455, 4895219712 }; + static constexpr pre_download_entry c_pre_download_mdbx = { "http://95.217.42.247/pre-download/zano_mdbx_95_2200000.pak", "c3bd64c62495c3f266759750952519f13f32fc161b59547beaa8202b6e26d516", 2628767033, 5100195840 }; + static constexpr pre_download_entry c_pre_download_lmdb = { "http://95.217.42.247/pre-download/zano_lmdb_95_2200000.pak", "fcbf0ab3b23836e1a51fa675e719900fb94110cfb74790b3323cebce7fb9f5bd", 3426025872, 4954472448 }; #else static constexpr pre_download_entry c_pre_download_mdbx = { "", "", 0, 0 }; static constexpr pre_download_entry c_pre_download_lmdb = { "", "", 0, 0 }; From f910b661454789993f863e991ef69856e2cc0555 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Jul 2023 18:12:06 +0200 Subject: [PATCH 066/127] ui submodule updated --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index f2e13497..25c7bb49 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit f2e13497af5ce4dd27289e2b162e826e60b3d94e +Subproject commit 25c7bb49f26bd755d13b30a148530a9b0b486c14 From c756bde213592ce689f87ab30810fcde54e9421d Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Jul 2023 18:15:43 +0200 Subject: [PATCH 067/127] version bump: 1.5.1.148 -> 1.5.2.149 --- src/version.h.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h.in b/src/version.h.in index 53ee8337..1ddc64cf 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -5,9 +5,9 @@ #define PROJECT_MAJOR_VERSION "1" #define PROJECT_MINOR_VERSION "5" -#define PROJECT_REVISION "1" +#define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 148 +#define PROJECT_VERSION_BUILD_NO 149 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 3346a5155ae95de61f82a781e9a089d34d9db96a Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Jul 2023 19:14:22 +0200 Subject: [PATCH 068/127] ui submodule updated --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 25c7bb49..047a4602 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 25c7bb49f26bd755d13b30a148530a9b0b486c14 +Subproject commit 047a4602748e0d3e40456f9d2fc2eeef1bc89b06 From 12bb214276efd71d569ac964699536d20e843914 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Jul 2023 19:15:22 +0200 Subject: [PATCH 069/127] version bump: 1.5.2.149 -> 1.5.2.150 --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 1ddc64cf..9b0be01a 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 149 +#define PROJECT_VERSION_BUILD_NO 150 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 1886fae681101e7030807052486fa5c39ab0cb56 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 3 Oct 2023 22:43:51 +0200 Subject: [PATCH 070/127] implemented governance initial code for wallet/daemon --- .../epee/include/storages/portable_storage.h | 19 +++++++- contrib/epee/include/string_coding.h | 10 +++- src/currency_core/blockchain_storage.cpp | 45 ++++++++++++++++++ src/currency_core/blockchain_storage.h | 1 + src/currency_core/blockchain_storage_basic.h | 22 +++++++++ src/currency_core/currency_config.h | 1 + src/currency_core/currency_format_utils.cpp | 29 ++++++++++++ src/currency_core/currency_format_utils.h | 3 ++ src/rpc/core_rpc_server.cpp | 12 +++++ src/rpc/core_rpc_server.h | 2 + src/rpc/core_rpc_server_commands_defs.h | 28 +++++++++++ src/simplewallet/simplewallet.cpp | 28 ++++++++++- src/simplewallet/simplewallet.h | 2 + src/wallet/wallet2.cpp | 46 +++++++++++++++++-- src/wallet/wallet2.h | 13 ++++-- src/wallet/wallet_public_structs_defs.h | 28 +++++++++++ src/wallet/wallets_manager.cpp | 6 +++ tests/unit_tests/votes_tests.cpp | 26 +++++++++++ 18 files changed, 309 insertions(+), 12 deletions(-) create mode 100644 tests/unit_tests/votes_tests.cpp diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h index 4d36cc03..a5d46e19 100644 --- a/contrib/epee/include/storages/portable_storage.h +++ b/contrib/epee/include/storages/portable_storage.h @@ -77,8 +77,7 @@ namespace epee bool insert_next_section(harray hSecArray, hsection& hinserted_childsection); //------------------------------------------------------------------------ //delete entry (section, value or array) - bool delete_entry(const std::string& pentry_name, hsection hparent_section = nullptr); - + bool delete_entry(const std::string& pentry_name, hsection hparent_section = nullptr); //------------------------------------------------------------------------------- bool store_to_binary(binarybuffer& target); bool load_from_binary(const binarybuffer& target); @@ -87,6 +86,8 @@ namespace epee bool dump_as_json(std::string& targetObj, size_t indent = 0, end_of_line_t eol = eol_crlf); bool load_from_json(const std::string& source); + template + bool enum_entries(hsection hparent_section, cb_t cb); private: section m_root; hsection get_root_section() {return &m_root;} @@ -384,6 +385,20 @@ namespace epee CATCH_ENTRY("portable_storage::insert_first_value", nullptr); } //--------------------------------------------------------------------------------------------------------------- + template + bool portable_storage::enum_entries(hsection hparent_section, cb_t cb) + { + TRY_ENTRY(); + if (!hparent_section) hparent_section = &m_root; + for (const auto& e : hparent_section->m_entries) + { + if (!cb(e.first, e.second)) + break; + } + return true; + CATCH_ENTRY("portable_storage::enum_entries", false); + } + template bool portable_storage::insert_next_value(harray hval_array, const t_value& target) { diff --git a/contrib/epee/include/string_coding.h b/contrib/epee/include/string_coding.h index 0b125bbd..a034dec9 100644 --- a/contrib/epee/include/string_coding.h +++ b/contrib/epee/include/string_coding.h @@ -37,6 +37,7 @@ #endif #include #endif +#include #include "warnings.h" @@ -310,7 +311,14 @@ namespace string_encoding return get_md5_as_hexstring(src.data(), src.size()); } #endif - + inline + std::string toupper(std::string s) + { + std::transform(s.begin(), s.end(), s.begin(), + [](unsigned char c) { return std::toupper(c); } // correct + ); + return s; + } } } diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 6ccb07aa..354e765a 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2808,6 +2808,51 @@ size_t blockchain_storage::get_current_sequence_factor_for_alt(alt_chain_type& a return n; } //------------------------------------------------------------------ +bool blockchain_storage::get_pos_votes(uint64_t start_index, uint64_t end_index, vote_results& r) +{ + CRITICAL_REGION_LOCAL(m_read_lock); + if (start_index >= m_db_blocks.size() || start_index >= end_index) + { + //LOG_PRINT_L0("Wrong starter or end index set: start_index = " << start_index << ", end_index=" << end_index << ", expected max index " << m_db_blocks.size() - 1); + return true; + } + std::map summary; + + for (size_t i = start_index; i < m_db_blocks.size() && i < end_index; i++) + { + auto block_ptr = m_db_blocks[i]; + //only coin holders can vote + if(!is_pos_block(block_ptr->bl)) + continue; + r.total_pos_blocks++; + + extra_user_data eud = AUTO_VAL_INIT(eud); + if (!get_type_in_variant_container(block_ptr->bl.miner_tx.extra, eud)) + { + continue; + } + std::list> votes; + if (!currency::parse_vote(eud.buff, votes)) + { + continue; + } + for (const auto& v : votes) + { + if (v.second) + summary[v.first].vote_1++; + else + summary[v.first].vote_0++; + } + } + for (const auto s_entry : summary) + { + r.votes.push_back(s_entry.second); + r.votes.back().proposal_name = s_entry.first; + } + + return true; +} +//------------------------------------------------------------------ std::string blockchain_storage::get_blockchain_string(uint64_t start_index, uint64_t end_index) const { std::stringstream ss; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 01a95f52..113cff0d 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -451,6 +451,7 @@ namespace currency void serialize(archive_t & ar, const unsigned int version); bool get_est_height_from_date(uint64_t date, uint64_t& res_h)const; + bool get_pos_votes(uint64_t start_h, uint64_t end_h, vote_results& r); //debug functions bool validate_blockchain_prev_links(size_t last_n_blocks_to_check = 10) const; diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index 8a487003..eaa34c47 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -154,6 +154,28 @@ namespace currency transactions_map onboard_transactions; }; + struct vote_on_proposal + { + std::string proposal_name; + uint64_t vote_1; + uint64_t vote_0; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(proposal_name) + KV_SERIALIZE(vote_1) + KV_SERIALIZE(vote_0) + END_KV_SERIALIZE_MAP() + }; + + struct vote_results + { + uint64_t total_pos_blocks; //total pos blocks in a given range + std::list votes; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(total_pos_blocks) + KV_SERIALIZE(votes) + END_KV_SERIALIZE_MAP() + }; } \ No newline at end of file diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 18e38c67..7b5aa9c8 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -214,6 +214,7 @@ #define GUI_INTERNAL_CONFIG2 "gui_internal_config.json" #define GUI_IPC_MESSAGE_CHANNEL_NAME CURRENCY_NAME_BASE "_message_que" +#define CURRENCY_VOTING_CONFIG_DEFAULT_FILENAME "voting_config.json" #define CURRENT_TRANSACTION_CHAIN_ENTRY_ARCHIVE_VER 3 diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7019ce41..2a1b32c0 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1615,6 +1615,35 @@ namespace currency return timestamp; } //--------------------------------------------------------------- + bool parse_vote(const std::string& json_, std::list>& votes) + { + //do preliminary check of text if it looks like json + std::string::size_type pos = json_.find('{'); + if (pos == std::string::npos) + return false; + std::string json = json_.substr(pos); + + epee::serialization::portable_storage ps; + bool rs = ps.load_from_json(json); + if (!rs) + return false; + + + + auto cb = [&](const std::string& name, const epee::serialization::storage_entry& entry) { + if (entry.type() == typeid(uint64_t)) + { + bool vote = boost::get(entry) ? true : false; + votes.push_back(std::make_pair(epee::string_encoding::toupper(name), vote)); + } + return true; + }; + + ps.enum_entries(nullptr, cb); + return true; + + } + //--------------------------------------------------------------- bool sign_multisig_input_in_tx(currency::transaction& tx, size_t ms_input_index, const currency::account_keys& keys, const currency::transaction& source_tx, bool *p_is_input_fully_signed /* = nullptr */) { #define LOC_CHK(cond, msg) CHECK_AND_ASSERT_MES(cond, false, msg << ", ms input index: " << ms_input_index << ", tx: " << get_transaction_hash(tx) << ", source tx: " << get_transaction_hash(source_tx)) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 725b39e1..e8ecadcb 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -362,7 +362,10 @@ namespace currency bool fill_block_rpc_details(block_rpc_extended_info& pei_rpc, const block_extended_info& bei_chain, const crypto::hash& h); void append_per_block_increments_for_tx(const transaction& tx, std::unordered_map& gindices); std::string get_word_from_timstamp(uint64_t timestamp, bool use_password); + uint64_t get_timstamp_from_word(std::string word, bool& password_used, const std::string& buff); uint64_t get_timstamp_from_word(std::string word, bool& password_used); + bool parse_vote(const std::string& buff, std::list>& votes); + std::string generate_origin_for_htlc(const txout_htlc& htlc, const account_keys& acc_keys); template typename std::conditional::value, const std::vector, std::vector >::type& get_txin_etc_options(t_txin_v& in) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 8d0e5858..0337952e 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -631,6 +631,18 @@ namespace currency return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_get_votes(const COMMAND_RPC_GET_VOTES::request& req, COMMAND_RPC_GET_VOTES::response& res, connection_context& cntx) + { + if (!m_core.get_blockchain_storage().get_pos_votes(req.h_start, req.h_end, res.votes)) + { + res.status = API_RETURN_CODE_INTERNAL_ERROR; + res.error_code = "Internal error"; + return true; + } + res.status = API_RETURN_CODE_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_get_main_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx) { if (!m_core.get_blockchain_storage().get_main_block_rpc_details(req.id, res.block_details)) diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 590b1151..bcbe748d 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -85,6 +85,7 @@ namespace currency bool on_get_pool_txs_brief_details(const COMMAND_RPC_GET_POOL_TXS_BRIEF_DETAILS::request& req, COMMAND_RPC_GET_POOL_TXS_BRIEF_DETAILS::response& res, connection_context& cntx); bool on_get_all_pool_tx_list(const COMMAND_RPC_GET_ALL_POOL_TX_LIST::request& req, COMMAND_RPC_GET_ALL_POOL_TX_LIST::response& res, connection_context& cntx); bool on_get_pool_info(const COMMAND_RPC_GET_POOL_INFO::request& req, COMMAND_RPC_GET_POOL_INFO::response& res, connection_context& cntx); + bool on_get_votes(const COMMAND_RPC_GET_VOTES::request& req, COMMAND_RPC_GET_VOTES::response& res, connection_context& cntx); bool on_get_main_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); @@ -150,6 +151,7 @@ namespace currency MAP_JON_RPC ("get_pool_txs_brief_details", on_get_pool_txs_brief_details, COMMAND_RPC_GET_POOL_TXS_BRIEF_DETAILS) MAP_JON_RPC ("get_all_pool_tx_list", on_get_all_pool_tx_list, COMMAND_RPC_GET_ALL_POOL_TX_LIST) MAP_JON_RPC ("get_pool_info", on_get_pool_info, COMMAND_RPC_GET_POOL_INFO) + MAP_JON_RPC ("get_votes", on_get_votes, COMMAND_RPC_GET_VOTES) MAP_JON_RPC_WE("get_main_block_details", on_get_main_block_details, COMMAND_RPC_GET_BLOCK_DETAILS) MAP_JON_RPC_WE("get_alt_block_details", on_get_alt_block_details, COMMAND_RPC_GET_BLOCK_DETAILS) diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 3edc5c57..5fb88872 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -83,6 +83,34 @@ namespace currency }; }; + + struct COMMAND_RPC_GET_VOTES + { + struct request + { + uint64_t h_start; + uint64_t h_end; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(h_start) + KV_SERIALIZE(h_end) + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::string status; + std::string error_code; + vote_results votes; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) + KV_SERIALIZE(error_code) + KV_SERIALIZE(votes) + END_KV_SERIALIZE_MAP() + }; + }; + struct COMMAND_RPC_GET_HEIGHT { struct request diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d2571d62..e4567006 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -58,6 +58,7 @@ namespace const command_line::arg_descriptor arg_addr_to_compare ( "addr-to-compare", ""); const command_line::arg_descriptor arg_disable_tor_relay ( "disable-tor-relay", "Disable TOR relay", false); const command_line::arg_descriptor arg_set_timeout("set-timeout", "Set timeout for the wallet"); + const command_line::arg_descriptor arg_voting_config_file("voting-config-file", "Set voting config instead of getting if from daemon", ""); const command_line::arg_descriptor< std::vector > arg_command ("command", ""); @@ -413,6 +414,7 @@ void simple_wallet::handle_command_line(const boost::program_options::variables_ m_do_pos_mining = command_line::get_arg(vm, arg_do_pos_mining); m_restore_wallet = command_line::get_arg(vm, arg_restore_wallet); m_disable_tor = command_line::get_arg(vm, arg_disable_tor_relay); + m_voting_config_file = command_line::get_arg(vm, arg_voting_config_file); } //---------------------------------------------------------------------------------------------------- bool simple_wallet::try_connect_to_daemon() @@ -433,18 +435,21 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas m_wallet.reset(new tools::wallet2()); m_wallet->callback(this->shared_from_this()); + if (!m_voting_config_file.empty()) + m_wallet->set_votes_config_path(m_voting_config_file); + m_wallet->set_do_rise_transfer(false); try { m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password, create_auditable_wallet); message_writer(epee::log_space::console_color_white, true) << "Generated new " << (create_auditable_wallet ? "AUDITABLE" : "") << " wallet: " << m_wallet->get_account().get_public_address_str(); + display_vote_info(); std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().view_secret_key) << std::endl << std::flush; if (m_wallet->is_auditable()) std::cout << "tracking seed: " << std::endl << m_wallet->get_account().get_tracking_seed() << std::endl << std::flush; if (m_do_not_set_date) m_wallet->reset_creation_time(0); - } catch (const std::exception& e) { @@ -465,6 +470,9 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st m_wallet.reset(new tools::wallet2()); m_wallet->callback(this->shared_from_this()); + if (!m_voting_config_file.empty()) + m_wallet->set_votes_config_path(m_voting_config_file); + m_wallet->set_do_rise_transfer(true); try { @@ -473,6 +481,7 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st // auditable watch-only aka tracking wallet m_wallet->restore(epee::string_encoding::utf8_to_wstring(wallet_file), password, seed_or_tracking_seed, true, ""); message_writer(epee::log_space::console_color_white, true) << "Tracking wallet restored: " << m_wallet->get_account().get_public_address_str(); + display_vote_info(); } else { @@ -509,11 +518,27 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st return true; } //---------------------------------------------------------------------------------------------------- + +void simple_wallet::display_vote_info() +{ + const wallet_vote_config& votes = m_wallet->get_current_votes(); + if (votes.entries.size()) + { + message_writer(epee::log_space::console_color_magenta, true) << "VOTING SET LOADED:"; + for (const auto& e : votes.entries) + { + message_writer(epee::log_space::console_color_magenta, true) << "\t\t" << e.proposal_id << "\t\t" << (e.vote?"1":"0") << "\t\t("<< e.h_start << " - " << e.h_end <<")"; + } + } +} bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password) { m_wallet_file = wallet_file; m_wallet.reset(new tools::wallet2()); m_wallet->callback(shared_from_this()); + if (!m_voting_config_file.empty()) + m_wallet->set_votes_config_path(m_voting_config_file); + while (true) { @@ -521,6 +546,7 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa { m_wallet->load(epee::string_encoding::utf8_to_wstring(m_wallet_file), password); message_writer(epee::log_space::console_color_white, true) << "Opened" << (m_wallet->is_auditable() ? " auditable" : "") << (m_wallet->is_watch_only() ? " watch-only" : "") << " wallet: " << m_wallet->get_account().get_public_address_str(); + display_vote_info(); break; } diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 03b428c3..84348e7f 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -96,6 +96,7 @@ namespace currency uint64_t get_daemon_blockchain_height(std::string& err); bool try_connect_to_daemon(); + void display_vote_info(); //----------------- i_wallet2_callback --------------------- virtual void on_new_block(uint64_t height, const currency::block& block) override; @@ -172,6 +173,7 @@ namespace currency bool m_offline_mode; bool m_disable_tor; std::string m_restore_wallet; + std::string m_voting_config_file; epee::console_handlers_binder m_cmd_binder; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7b7ffc09..8c112c3d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -67,7 +67,8 @@ namespace tools m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE), m_current_wallet_file_size(0), m_use_deffered_global_outputs(false), - m_disable_tor_relay(false) + m_disable_tor_relay(false), + m_votes_config_path(tools::get_default_data_dir() + "/" + CURRENCY_VOTING_CONFIG_DEFAULT_FILENAME) { m_core_runtime_config = currency::get_default_core_runtime_config(); } @@ -171,7 +172,7 @@ std::shared_ptr wallet2::transform_value_to_pt //---------------------------------------------------------------------------------------------------- void wallet2::init(const std::string& daemon_address) { - m_miner_text_info = PROJECT_VERSION_LONG; + //m_miner_text_info = PROJECT_VERSION_LONG; m_core_proxy->set_connection_addr(daemon_address); m_core_proxy->check_connection(); } @@ -2650,6 +2651,19 @@ bool wallet2::check_connection() return m_core_proxy->check_connection(); } //---------------------------------------------------------------------------------------------------- +void wallet2::set_votes_config_path(const std::string& path_to_config_file/* = tools::get_default_data_dir() + "\voting_config.json"*/) +{ + m_votes_config_path = path_to_config_file; +} +//---------------------------------------------------------------------------------------------------- +void wallet2::load_votes_config() +{ + if (boost::filesystem::exists(m_votes_config_path)) + { + epee::serialization::load_t_from_json_file(m_votes_config, m_votes_config_path); + } +} +//---------------------------------------------------------------------------------------------------- void wallet2::load(const std::wstring& wallet_, const std::string& password) { clear(); @@ -2720,6 +2734,7 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) ); WLT_LOG_L1("[LOADING]Blockchain shortener state: " << ENDL << m_chain.get_internal_state_text()); + load_votes_config(); WLT_LOG_L1("(after loading: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); @@ -3599,7 +3614,30 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& { return build_minted_block(req, rsp, m_account.get_public_address(), new_block_expected_height); } - +//------------------------------------------------------------------ +std::string wallet2::get_extra_text_for_block(uint64_t new_block_expected_height) +{ + size_t entries_voted = 0; + std::string extra_text = "{"; + for (const auto& e : m_votes_config.entries) + { + if (e.h_start <= new_block_expected_height && e.h_end >= new_block_expected_height) + { + //do vote for/against this + if (entries_voted != 0) + extra_text += ","; + extra_text += "\""; + extra_text += e.proposal_id; + extra_text += "\":"; + extra_text += e.vote ? "1" : "0"; + entries_voted++; + } + } + if (!entries_voted) + extra_text = ""; + return extra_text; +} +//------------------------------------------------------------------ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& req, const currency::COMMAND_RPC_SCAN_POS::response& rsp, const currency::account_public_address& miner_address, @@ -3617,7 +3655,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& tmpl_req.pos_block = true; tmpl_req.pos_amount = req.pos_entries[rsp.index].amount; tmpl_req.pos_index = req.pos_entries[rsp.index].index; - tmpl_req.extra_text = m_miner_text_info; + tmpl_req.extra_text = get_extra_text_for_block(new_block_expected_height); // m_miner_text_info; tmpl_req.stake_unlock_time = req.pos_entries[rsp.index].stake_unlock_time; // mark stake source as spent and make sure it will be restored in case of error diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index b8ecac13..3ff2a73a 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -541,8 +541,7 @@ namespace tools void update_offer_by_id(const crypto::hash& tx_id, uint64_t of_ind, const bc_services::offer_details_ex& od, currency::transaction& res_tx); void request_alias_registration(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward, const crypto::secret_key& authority_key = currency::null_skey); void request_alias_update(currency::extra_alias_entry& ai, currency::transaction& res_tx, uint64_t fee, uint64_t reward); - bool check_available_sources(std::list& amounts); - + bool check_available_sources(std::list& amounts); bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); @@ -817,6 +816,7 @@ namespace tools bool get_pos_entries(currency::COMMAND_RPC_SCAN_POS::request& req); bool build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& req, const currency::COMMAND_RPC_SCAN_POS::response& rsp, uint64_t new_block_expected_height = UINT64_MAX); bool build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& req, const currency::COMMAND_RPC_SCAN_POS::response& rsp, const currency::account_public_address& miner_address, uint64_t new_block_expected_height = UINT64_MAX); + std::string get_extra_text_for_block(uint64_t new_block_expected_height); bool reset_history(); bool is_transfer_unlocked(const transfer_details& td) const; bool is_transfer_unlocked(const transfer_details& td, bool for_pos_mining, uint64_t& stake_lock_time) const; @@ -879,6 +879,9 @@ namespace tools void redeem_htlc(const crypto::hash& htlc_tx_id, const std::string& origin, currency::transaction& result_tx); void redeem_htlc(const crypto::hash& htlc_tx_id, const std::string& origin); bool check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& origin, crypto::hash& redeem_tx_id); + + void set_votes_config_path(const std::string& path_to_config_file); + const wallet_vote_config& get_current_votes() { return m_votes_config; } private: // -------- t_transport_state_notifier ------------------------------------------------ @@ -958,10 +961,9 @@ private: bool handle_cancel_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::escrow_cancel_templates_body& ectb, const std::vector& decrypted_attach); bool handle_expiration_list(uint64_t tx_expiration_ts_median); void handle_contract_expirations(uint64_t tx_expiration_ts_median); - void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const wallet_public::wallet_transfer_info& wti) const; void change_contract_state(wallet_public::escrow_contract_details_basic& contract, uint32_t new_state, const crypto::hash& contract_id, const std::string& reason = "internal intention") const; - + void load_votes_config(); const construct_tx_param& get_default_construct_tx_param(); @@ -1073,6 +1075,9 @@ private: mutable uint64_t m_current_wallet_file_size; bool m_use_deffered_global_outputs; bool m_disable_tor_relay; + + std::string m_votes_config_path; + wallet_vote_config m_votes_config; //this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions friend class test_generator; diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index bde9d9f4..141f6e8f 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1147,6 +1147,34 @@ namespace wallet_public }; }; + + + struct wallet_vote_config_entry + { + std::string proposal_id; + uint64_t h_start; + uint64_t h_end; + bool vote; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(proposal_id) + KV_SERIALIZE(h_start) + KV_SERIALIZE(h_end) + KV_SERIALIZE(vote) + END_KV_SERIALIZE_MAP() + + }; + + struct wallet_vote_config + { + std::vector entries; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(entries) + END_KV_SERIALIZE_MAP() + }; + + inline std::string get_escrow_contract_state_name(uint32_t state) { switch (state) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 0b20459a..8b3bd2aa 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -956,6 +956,9 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st LOG_ERROR("Unexpected location reached"); #endif } + + w->set_votes_config_path(m_data_dir + "/" + CURRENCY_VOTING_CONFIG_DEFAULT_FILENAME); + std::string return_code = API_RETURN_CODE_OK; while (true) @@ -970,6 +973,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history, exclude_mining_txs); owr.wallet_local_bc_size = w->get_blockchain_current_size(); + //workaround for missed fee //owr.seed = w->get_account().get_seed_phrase(); break; @@ -1061,6 +1065,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std { std::shared_ptr w(new tools::wallet2()); w->set_use_deffered_global_outputs(m_use_deffered_global_outputs); + w->set_votes_config_path(m_data_dir + "/" + CURRENCY_VOTING_CONFIG_DEFAULT_FILENAME); owr.wallet_id = m_wallet_id_counter++; w->callback(std::shared_ptr(new i_wallet_to_i_backend_adapter(this, owr.wallet_id))); if (m_remote_node_mode) @@ -1167,6 +1172,7 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: { std::shared_ptr w(new tools::wallet2()); w->set_use_deffered_global_outputs(m_use_deffered_global_outputs); + w->set_votes_config_path(m_data_dir + "/" + CURRENCY_VOTING_CONFIG_DEFAULT_FILENAME); owr.wallet_id = m_wallet_id_counter++; w->callback(std::shared_ptr(new i_wallet_to_i_backend_adapter(this, owr.wallet_id))); if (m_remote_node_mode) diff --git a/tests/unit_tests/votes_tests.cpp b/tests/unit_tests/votes_tests.cpp new file mode 100644 index 00000000..d6f0a90c --- /dev/null +++ b/tests/unit_tests/votes_tests.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2012-2014 The Zano developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "gtest/gtest.h" + +#include +#include + +#include "misc_language.h" +#include "currency_core/currency_format_utils.h" + + +TEST(governance_testig, governance_tests_1) +{ + std::string vote = "{\"ZGP11\":1,\"ZGP23\":0}"; + + std::list> votes; + currency::parse_vote(vote, votes); + ASSERT_TRUE(votes.size() == 2); + ASSERT_TRUE(votes.begin()->first == "ZGP11"); + ASSERT_TRUE(votes.begin()->second == true); + ASSERT_TRUE((++votes.begin())->first == "ZGP23"); + ASSERT_TRUE((++votes.begin())->second == false); + +} \ No newline at end of file From aedab1e68e4f13fa6f76679c69297c41a8537e36 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 4 Oct 2023 16:08:48 +0200 Subject: [PATCH 071/127] implemented governance code in wallet --- src/simplewallet/simplewallet.cpp | 40 +++++++++++++++++++------------ src/simplewallet/simplewallet.h | 1 - src/wallet/wallet2.cpp | 5 ++++ src/wallet/wallet2.h | 4 ++-- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e4567006..106c4bbf 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -160,6 +160,26 @@ namespace } } +void display_vote_info(tools::wallet2& w) +{ + const tools::wallet_public::wallet_vote_config& votes = w.get_current_votes(); + if (votes.entries.size()) + { + message_writer(epee::log_space::console_color_magenta, true) << "VOTING SET LOADED:"; + for (const auto& e : votes.entries) + { + epee::log_space::console_colors color = epee::log_space::console_color_green; + if (e.h_end < w.get_top_block_height()) + { + color = epee::log_space::console_color_white; + } + + message_writer(color, true) << "\t\t" << e.proposal_id << "\t\t" << (e.vote ? "1" : "0") << "\t\t(" << e.h_start << " - " << e.h_end << ")"; + } + } +} + + std::string simple_wallet::get_commands_str() { std::stringstream ss; @@ -443,7 +463,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas { m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password, create_auditable_wallet); message_writer(epee::log_space::console_color_white, true) << "Generated new " << (create_auditable_wallet ? "AUDITABLE" : "") << " wallet: " << m_wallet->get_account().get_public_address_str(); - display_vote_info(); + display_vote_info(*m_wallet); std::cout << "view key: " << string_tools::pod_to_hex(m_wallet->get_account().get_keys().view_secret_key) << std::endl << std::flush; if (m_wallet->is_auditable()) std::cout << "tracking seed: " << std::endl << m_wallet->get_account().get_tracking_seed() << std::endl << std::flush; @@ -481,7 +501,6 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st // auditable watch-only aka tracking wallet m_wallet->restore(epee::string_encoding::utf8_to_wstring(wallet_file), password, seed_or_tracking_seed, true, ""); message_writer(epee::log_space::console_color_white, true) << "Tracking wallet restored: " << m_wallet->get_account().get_public_address_str(); - display_vote_info(); } else { @@ -492,6 +511,7 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st if (m_wallet->is_auditable()) std::cout << "tracking seed: " << std::endl << m_wallet->get_account().get_tracking_seed() << std::endl << std::flush; } + display_vote_info(*m_wallet); if (m_do_not_set_date) m_wallet->reset_creation_time(0); } @@ -519,18 +539,6 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st } //---------------------------------------------------------------------------------------------------- -void simple_wallet::display_vote_info() -{ - const wallet_vote_config& votes = m_wallet->get_current_votes(); - if (votes.entries.size()) - { - message_writer(epee::log_space::console_color_magenta, true) << "VOTING SET LOADED:"; - for (const auto& e : votes.entries) - { - message_writer(epee::log_space::console_color_magenta, true) << "\t\t" << e.proposal_id << "\t\t" << (e.vote?"1":"0") << "\t\t("<< e.h_start << " - " << e.h_end <<")"; - } - } -} bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password) { m_wallet_file = wallet_file; @@ -546,7 +554,7 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa { m_wallet->load(epee::string_encoding::utf8_to_wstring(m_wallet_file), password); message_writer(epee::log_space::console_color_white, true) << "Opened" << (m_wallet->is_auditable() ? " auditable" : "") << (m_wallet->is_watch_only() ? " watch-only" : "") << " wallet: " << m_wallet->get_account().get_public_address_str(); - display_vote_info(); + display_vote_info(*m_wallet); break; } @@ -2113,6 +2121,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_addr_to_compare); command_line::add_arg(desc_params, arg_disable_tor_relay); command_line::add_arg(desc_params, arg_set_timeout); + command_line::add_arg(desc_params, arg_voting_config_file); @@ -2255,6 +2264,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Initializing wallet..."); process_wallet_command_line_params(vm, wal); wal.init(daemon_address); + display_vote_info(wal); if (command_line::get_arg(vm, arg_generate_new_wallet).size() || command_line::get_arg(vm, arg_generate_new_auditable_wallet).size()) return EXIT_FAILURE; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 84348e7f..b7867d9a 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -96,7 +96,6 @@ namespace currency uint64_t get_daemon_blockchain_height(std::string& err); bool try_connect_to_daemon(); - void display_vote_info(); //----------------- i_wallet2_callback --------------------- virtual void on_new_block(uint64_t height, const currency::block& block) override; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 8c112c3d..ffd7810b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -23,6 +23,7 @@ using namespace epee; #include "currency_core/bc_offers_service_basic.h" #include "rpc/core_rpc_server_commands_defs.h" #include "misc_language.h" +#include "common/util.h" #include "common/boost_serialization_helper.h" #include "crypto/crypto.h" @@ -3569,6 +3570,10 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address return true; } +#ifdef _DEBUG + get_extra_text_for_block(m_last_pow_block_h); +#endif + uint64_t pos_entries_amount = 0; for (auto& ent : ctx.sp.pos_entries) pos_entries_amount += ent.amount; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3ff2a73a..5013272e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -881,7 +881,7 @@ namespace tools bool check_htlc_redeemed(const crypto::hash& htlc_tx_id, std::string& origin, crypto::hash& redeem_tx_id); void set_votes_config_path(const std::string& path_to_config_file); - const wallet_vote_config& get_current_votes() { return m_votes_config; } + const tools::wallet_public::wallet_vote_config& get_current_votes() { return m_votes_config; } private: // -------- t_transport_state_notifier ------------------------------------------------ @@ -1077,7 +1077,7 @@ private: bool m_disable_tor_relay; std::string m_votes_config_path; - wallet_vote_config m_votes_config; + tools::wallet_public::wallet_vote_config m_votes_config; //this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions friend class test_generator; From 453927e72fd0246b22f557c0c07243ecea7b2af2 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Wed, 4 Oct 2023 17:09:35 +0300 Subject: [PATCH 072/127] === build number: 150 -> 151 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 9b0be01a..098ce2f2 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 150 +#define PROJECT_VERSION_BUILD_NO 151 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 492ec85f206ef0074878003e9c440e8a3874e958 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 4 Oct 2023 18:34:20 +0200 Subject: [PATCH 073/127] build script updated for windows --- utils/build_script_windows.bat | 42 +++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/utils/build_script_windows.bat b/utils/build_script_windows.bat index ce180a66..90fba36a 100644 --- a/utils/build_script_windows.bat +++ b/utils/build_script_windows.bat @@ -1,7 +1,6 @@ call configure_local_paths.cmd ;; MSVC version-specific paths -SET LOCAL_BOOST_LIB_PATH=%LOCAL_BOOST_PATH%\lib64-msvc-14.1 SET QT_MSVC_PATH=%QT_PREFIX_PATH%\msvc2017_64 SET ACHIVE_NAME_PREFIX=zano-win-x64- @@ -44,12 +43,13 @@ cd %SOURCES_PATH% rmdir build /s /q mkdir build cd build -cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_MSVC_PATH%" -D BUILD_GUI=TRUE -D STATIC=FALSE -G "Visual Studio 15 2017 Win64" -T host=x64 .. + +cmake %TESTNET_DEF% -D OPENSSL_ROOT_DIR="%OPENSSL_ROOT_DIR%" -D CMAKE_PREFIX_PATH="%QT_MSVC_PATH%" -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 16 2019" -A x64 -T host=x64 .. IF %ERRORLEVEL% NEQ 0 ( goto error ) -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat" x86_amd64 +call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x86_amd64 echo on cd %SOURCES_PATH%\build @@ -96,7 +96,9 @@ del /F /Q %build_zip_path% cd src\release - +call :sign_file Zano.exe || goto error +call :sign_file zanod.exe || goto error +call :sign_file simplewallet.exe || goto error @echo on @@ -108,7 +110,7 @@ copy /Y zanod.exe bunch copy /Y simplewallet.exe bunch copy /Y *.pdb bunch -%QT_MSVC_PATH%\bin\windeployqt.exe bunch\Zano.exe +%QT_MSVC_PATH%\bin\windeployqt.exe bunch\Zano.exe || goto error cd bunch @@ -168,37 +170,31 @@ IF %ERRORLEVEL% NEQ 0 ( set installer_file=%ACHIVE_NAME_PREFIX%%version%-installer.exe set installer_path=%BUILDS_PATH%\builds\%installer_file% -:: Signing temporary disable -::@echo " SIGNING ...." -:: -::%ZANO_SIGN_CMD% %installer_path% -::IF %ERRORLEVEL% NEQ 0 ( -:: @echo "failed to sign installer" -:: goto error -::) +@echo " SIGNING the installer ...." + +call :sign_file %installer_path% || goto error @echo " UPLOADING TO SERVER ...." -pscp %installer_path% zano_build_server:/var/www/html/builds +pscp -load zano_build_server %installer_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD EXE TO SERVER" goto error ) call :sha256 %installer_path% installer_checksum -pscp %build_zip_path% zano_build_server:/var/www/html/builds +pscp -load zano_build_server %build_zip_path% %ZANO_BUILDS_HOST%:/var/www/html/builds IF %ERRORLEVEL% NEQ 0 ( @echo "FAILED TO UPLOAD ZIP TO SERVER" goto error ) call :sha256 %build_zip_path% build_zip_checksum -set mail_msg="New %build_prefix% %TESTNET_LABEL%build for win-x64:
INST: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%installer_file%
sha256: %installer_checksum%

ZIP: https://build.zano.org/builds/%build_zip_filename%
sha256: %build_zip_checksum%
" echo %mail_msg% -senditquiet.exe -t %emails% -subject "Zano win-x64 %build_prefix% %TESTNET_LABEL%build %version%" -body %mail_msg% - +python ../utils/build_mail.py "Zano win-x64 %build_prefix% %TESTNET_LABEL%build %version%" "%emails%" %mail_msg% goto success @@ -228,3 +224,13 @@ EXIT /B %ERRORLEVEL% @set "%2=%hash: =% ) @exit /B 0 + + +:sign_file +@echo Signing %1... +@call %ZANO_SIGN_CMD% %1 +@if %ERRORLEVEL% neq 0 ( + @echo ERROR: failed to sign %1 + @exit /B 1 +) +@exit /B 0 From 83e543bcec69ba4d294b235643387f4e799d9519 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 5 Oct 2023 12:26:43 +0200 Subject: [PATCH 074/127] fixed bug with voting --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ffd7810b..eb2147bd 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3660,7 +3660,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& tmpl_req.pos_block = true; tmpl_req.pos_amount = req.pos_entries[rsp.index].amount; tmpl_req.pos_index = req.pos_entries[rsp.index].index; - tmpl_req.extra_text = get_extra_text_for_block(new_block_expected_height); // m_miner_text_info; + tmpl_req.extra_text = get_extra_text_for_block(m_chain.get_top_block_height()); // m_miner_text_info; tmpl_req.stake_unlock_time = req.pos_entries[rsp.index].stake_unlock_time; // mark stake source as spent and make sure it will be restored in case of error From 2e4c6df22c79847127dbaeffdff8c130eb86d4f0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 5 Oct 2023 14:36:22 +0200 Subject: [PATCH 075/127] fixed bug with voting - again --- src/wallet/wallet2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index eb2147bd..1275b88b 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3638,6 +3638,7 @@ std::string wallet2::get_extra_text_for_block(uint64_t new_block_expected_height entries_voted++; } } + extra_text += "}"; if (!entries_voted) extra_text = ""; return extra_text; From bdb5af0490c58616a56c1fd9d93d2c3afa684340 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 5 Oct 2023 14:44:27 +0200 Subject: [PATCH 076/127] added votes state logging --- src/wallet/wallet2.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 1275b88b..ba704480 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -176,6 +176,19 @@ void wallet2::init(const std::string& daemon_address) //m_miner_text_info = PROJECT_VERSION_LONG; m_core_proxy->set_connection_addr(daemon_address); m_core_proxy->check_connection(); + + std::stringstream ss; + const tools::wallet_public::wallet_vote_config& votes = this->get_current_votes(); + if (votes.entries.size()) + { + ss << "VOTING SET LOADED:"; + for (const auto& e : votes.entries) + { + ss << "\t\t" << e.proposal_id << "\t\t" << (e.vote ? "1" : "0") << "\t\t(" << e.h_start << " - " << e.h_end << ")"; + } + } + WLT_LOG_L0(ss.str()); + } //---------------------------------------------------------------------------------------------------- bool wallet2::set_core_proxy(const std::shared_ptr& proxy) From 4762e39c776a0ecb1401daff123b2e0fbd056bed Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 6 Oct 2023 15:03:57 +0200 Subject: [PATCH 077/127] changed fields names --- src/currency_core/blockchain_storage.cpp | 4 ++-- src/currency_core/blockchain_storage_basic.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 354e765a..065da7ef 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2839,9 +2839,9 @@ bool blockchain_storage::get_pos_votes(uint64_t start_index, uint64_t end_index, for (const auto& v : votes) { if (v.second) - summary[v.first].vote_1++; + summary[v.first].yes++; else - summary[v.first].vote_0++; + summary[v.first].no++; } } for (const auto s_entry : summary) diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index eaa34c47..190a247e 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -157,13 +157,13 @@ namespace currency struct vote_on_proposal { std::string proposal_name; - uint64_t vote_1; - uint64_t vote_0; + uint64_t yes; + uint64_t no; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(proposal_name) - KV_SERIALIZE(vote_1) - KV_SERIALIZE(vote_0) + KV_SERIALIZE(yes) + KV_SERIALIZE(no) END_KV_SERIALIZE_MAP() }; From 63354b91c304dc31c7670654daf24880d7f4390b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 6 Oct 2023 17:36:10 +0200 Subject: [PATCH 078/127] changed fields names one more time --- src/currency_core/blockchain_storage.cpp | 2 +- src/currency_core/blockchain_storage_basic.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 065da7ef..6b8fb0d2 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2847,7 +2847,7 @@ bool blockchain_storage::get_pos_votes(uint64_t start_index, uint64_t end_index, for (const auto s_entry : summary) { r.votes.push_back(s_entry.second); - r.votes.back().proposal_name = s_entry.first; + r.votes.back().proposal_id = s_entry.first; } return true; diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index 190a247e..6180968f 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -156,12 +156,12 @@ namespace currency struct vote_on_proposal { - std::string proposal_name; + std::string proposal_id; uint64_t yes; uint64_t no; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(proposal_name) + KV_SERIALIZE(proposal_id) KV_SERIALIZE(yes) KV_SERIALIZE(no) END_KV_SERIALIZE_MAP() From cd7ec1cf1851114374893f4b66c49413c1fd4317 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 11 Oct 2023 21:57:18 +0200 Subject: [PATCH 079/127] build: 1) fixed issue where CMake couldn't find local Boost with system-wide Boost present and 2) added a patch for Boost compilation when GCC version >= 8.3 (+minor warning fix) --- README.md | 6 +++++- src/serialization/binary_archive.h | 2 +- utils/boost_1.70_gcc_8.patch | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 utils/boost_1.70_gcc_8.patch diff --git a/README.md b/README.md index 13558e5f..51d2494e 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,17 @@ Recommended OS version: Ubuntu 18.04 LTS. sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev mesa-common-dev libglu1-mesa-dev 2. Download and build Boost +(Assuming you have cloned Zano into `zano` folder. If used different location for Zano, edit line 4 correspondingly) curl -OL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.bz2 echo "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778 boost_1_70_0.tar.bz2" | shasum -c && tar -xjf boost_1_70_0.tar.bz2 - cd boost_1_70_0 + rm boost_1_70_0.tar.bz2 && cd boost_1_70_0 + patch -p0 < ../zano/utils/boost_1.70_gcc_8.patch || cd .. ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer,log ./b2 +Make sure that you see "The Boost C++ Libraries were successfully built!" message at the end. + 3. Install Qt\ (*GUI version only, skip this step if you're building server version*) diff --git a/src/serialization/binary_archive.h b/src/serialization/binary_archive.h index b951a106..3fe31e72 100644 --- a/src/serialization/binary_archive.h +++ b/src/serialization/binary_archive.h @@ -51,7 +51,7 @@ template <> struct binary_archive : public binary_archive_base { explicit binary_archive(stream_type &s) : base_type(s) { - stream_type::streampos pos = stream_.tellg(); + stream_type::pos_type pos = stream_.tellg(); stream_.seekg(0, std::ios_base::end); eof_pos_ = stream_.tellg(); stream_.seekg(pos); diff --git a/utils/boost_1.70_gcc_8.patch b/utils/boost_1.70_gcc_8.patch new file mode 100644 index 00000000..812eed14 --- /dev/null +++ b/utils/boost_1.70_gcc_8.patch @@ -0,0 +1,15 @@ +# This patch fixes compilation issue in Boost 1.70-1.71 while it is being compiled by GCC ver >= 8.3 +# -- sowle +# see also: https://github.com/boostorg/thread/pull/297 +# +--- boost/thread/pthread/thread_data.hpp.orig 2023-10-10 20:22:30.860192033 +0000 ++++ boost/thread/pthread/thread_data.hpp 2023-10-10 18:19:22.460764089 +0000 +@@ -57,7 +57,7 @@ + #else + std::size_t page_size = ::sysconf( _SC_PAGESIZE); + #endif +-#if PTHREAD_STACK_MIN > 0 ++#ifdef PTHREAD_STACK_MIN + if (size Date: Wed, 11 Oct 2023 22:27:40 +0200 Subject: [PATCH 080/127] build: CMake issue fix --- CMakeLists.txt | 5 +++++ README.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2530c6b..515023b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,11 @@ else() endif() +# If BOOST_ROOT is set, ignore system-wide Boost +if(DEFINED ENV{BOOST_ROOT}) + set(Boost_NO_SYSTEM_PATHS ON) +endif() + if(MSVC) set(Boost_USE_STATIC_LIBS ON) endif() diff --git a/README.md b/README.md index 51d2494e..f298e3a8 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Recommended OS version: Ubuntu 18.04 LTS. sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev mesa-common-dev libglu1-mesa-dev 2. Download and build Boost -(Assuming you have cloned Zano into `zano` folder. If used different location for Zano, edit line 4 correspondingly) +(Assuming you have cloned Zano into the 'zano' folder. If you used a different location for Zano, edit line 4 accordingly.) curl -OL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.bz2 echo "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778 boost_1_70_0.tar.bz2" | shasum -c && tar -xjf boost_1_70_0.tar.bz2 From 6e952c11d87b9415c7a039367d0d529e9113418b Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 13 Oct 2023 14:11:11 +0200 Subject: [PATCH 081/127] readme: minor edit --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f298e3a8..a1ea68e9 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ Recommended OS version: Ubuntu 18.04 LTS. sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev mesa-common-dev libglu1-mesa-dev -2. Download and build Boost -(Assuming you have cloned Zano into the 'zano' folder. If you used a different location for Zano, edit line 4 accordingly.) +2. Download and build Boost\ + (Assuming you have cloned Zano into the 'zano' folder. If you used a different location for Zano, edit line 4 accordingly.) curl -OL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.bz2 echo "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778 boost_1_70_0.tar.bz2" | shasum -c && tar -xjf boost_1_70_0.tar.bz2 @@ -51,8 +51,7 @@ Recommended OS version: Ubuntu 18.04 LTS. patch -p0 < ../zano/utils/boost_1.70_gcc_8.patch || cd .. ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer,log ./b2 - -Make sure that you see "The Boost C++ Libraries were successfully built!" message at the end. + Make sure that you see "The Boost C++ Libraries were successfully built!" message at the end. 3. Install Qt\ (*GUI version only, skip this step if you're building server version*) From 446d2dd69da9e087a819b256a356309514566c5c Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 13 Oct 2023 15:07:32 +0200 Subject: [PATCH 082/127] readme: several changes on Linux building process --- README.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a1ea68e9..464c1410 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,13 @@ Be sure to clone the repository properly:\ ### Dependencies | component / version | minimum
(not recommended but may work) | recommended | most recent of what we have ever tested | |--|--|--|--| -| gcc (Linux) | 5.4.0 | 7.5.0 | 8.3.0 | +| gcc (Linux) | 5.4.0 | 9.4.0 | 12.3.0 | | llvm/clang (Linux) | UNKNOWN | 7.0.1 | 8.0.0 | -| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2015 (14.0 update 1) | 2017 (15.9.0) | 2022 (17.4.2) | +| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2015 (14.0 update 1) | 2017 (15.9.0) | 2022 (17.7.5) | | [XCode](https://developer.apple.com/downloads/) (macOS) | 9.2 | 12.3 | 12.3 | -| [CMake](https://cmake.org/download/) | 2.8.6 | 3.15.5 | 3.26.3 | +| [CMake](https://cmake.org/download/) | 3.15.5 | 3.22.1 | 3.26.3 | | [Boost](https://www.boost.org/users/download/) | 1.70 | 1.70 | 1.76 | -| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | - | 1.1.1n | 1.1.1n | +| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | 1.1.1n | 1.1.1w | 1.1.1w | | [Qt](https://download.qt.io/archive/qt/) (*only for GUI*) | 5.8.0 | 5.11.2 | 5.15.2 | Note:\ @@ -30,13 +30,13 @@ Note:\ ### Linux -Recommended OS version: Ubuntu 18.04 LTS. +Recommended OS versions: Ubuntu 20.04, 22.04 LTS. 1. Prerequisites [*server version*] - sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev + sudo apt-get install -y build-essential g++ curl autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev [*GUI version*] @@ -66,15 +66,13 @@ Recommended OS version: Ubuntu 18.04 LTS. 4. Install OpenSSL - We recommend installing OpenSSL v1.1.1n locally unless you would like to use the same version system-wide. Adjust the local path `/home/user/openssl` in the commands below according to your needs. + We recommend installing OpenSSL v1.1.1w locally unless you would like to use the same version system-wide. Adjust the local path `/home/user/openssl` in the commands below according to your needs. - curl -OL https://www.openssl.org/source/openssl-1.1.1n.tar.gz - echo "40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a openssl-1.1.1n.tar.gz" | shasum -c && tar xaf openssl-1.1.1n.tar.gz - cd openssl-1.1.1n/ + curl -OL https://www.openssl.org/source/openssl-1.1.1w.tar.gz + echo "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8 openssl-1.1.1w.tar.gz" | shasum -c && tar xaf openssl-1.1.1w.tar.gz + cd openssl-1.1.1w/ ./config --prefix=/home/user/openssl --openssldir=/home/user/openssl shared zlib - make - make test - make install + make && make test && make install 5. Set environment variables properly\ @@ -92,7 +90,7 @@ For instance, by adding the following lines to `~/.bashrc` export OPENSSL_ROOT_DIR=/home/user/openssl export QT_PREFIX_PATH=/home/user/Qt5.11.2/5.11.2/gcc_64 - + Make sure you've restarted your terminal session (by reopening the terminal window or reconnecting the server) to apply these changes. 6. Build the binaries 1. Build daemon and simplewallet: From 0421e2e3667c33c9ff87b9dabfca98f498ca73f6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 23 Oct 2023 17:03:47 +0200 Subject: [PATCH 083/127] Removed preloader from UI --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 047a4602..5c46578b 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 047a4602748e0d3e40456f9d2fc2eeef1bc89b06 +Subproject commit 5c46578ba2cf2bd9bcb377e550e0701f8e5c9b77 From a15ce736cae90737eded44c1afb02cc3341c4101 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Mon, 23 Oct 2023 19:24:18 +0300 Subject: [PATCH 084/127] === build number: 150 -> 151 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 9b0be01a..098ce2f2 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 150 +#define PROJECT_VERSION_BUILD_NO 151 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 8fb3d58f68768fed4df7bce20abfb590dcdf6334 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Mon, 23 Oct 2023 19:24:39 +0300 Subject: [PATCH 085/127] === build number: 151 -> 152 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 098ce2f2..1afa6660 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 151 +#define PROJECT_VERSION_BUILD_NO 152 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 56de784054b7c24c31cdcdef9165a4e1c2b2d38f Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 30 Oct 2023 20:09:02 +0100 Subject: [PATCH 086/127] potential fix for call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE in wallet --- tests/core_tests/chaingen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 4ec33355..b2a24b36 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -425,6 +425,7 @@ bool test_generator::build_wallets(const blockchain_vector& blocks, wallets.back()->assign_account(a); wallets.back()->get_account().set_createtime(0); wallets.back()->set_core_proxy(tmp_proxy); + wallets.back()->set_minimum_height(0); currency::core_runtime_config pc = cc; pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; From 6343812006154f674329e718ecf9bc0b685b3dc8 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 31 Oct 2023 15:45:35 +0100 Subject: [PATCH 087/127] mixins support implemented in wallet2::prepare_and_sign_pos_block() --- src/currency_core/currency_config.h | 2 + src/currency_core/currency_format_utils.cpp | 11 +- src/rpc/core_rpc_server_commands_defs.h | 4 + src/wallet/wallet2.cpp | 169 ++++++++++++++------ src/wallet/wallet2.h | 8 +- tests/core_tests/chaingen.cpp | 3 +- tests/core_tests/chaingen_main.cpp | 2 +- 7 files changed, 132 insertions(+), 67 deletions(-) diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 7b5aa9c8..97e89eb4 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -30,6 +30,8 @@ #define HF1_BLOCK_MAJOR_VERSION 1 #define CURRENT_BLOCK_MAJOR_VERSION 2 +#define CURRENCY_DEFAULT_DECOY_SET_SIZE 10 + #define CURRENT_BLOCK_MINOR_VERSION 0 #define CURRENCY_BLOCK_FUTURE_TIME_LIMIT 60*60*2 #define CURRENCY_POS_BLOCK_FUTURE_TIME_LIMIT 60*20 diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 2a1b32c0..15e130f3 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -188,14 +188,9 @@ namespace currency if (pos) { - txin_to_key posin; - posin.amount = pe.amount; - posin.key_offsets.push_back(pe.index); - posin.k_image = pe.keyimage; - tx.vin.push_back(posin); - //reserve place for ring signature - tx.signatures.resize(1); - tx.signatures[0].resize(posin.key_offsets.size()); + // just placeholders, they will be filled in wallet2::prepare_and_sign_pos_block() + tx.vin.emplace_back(std::move(txin_to_key())); + tx.signatures.emplace_back(); } uint64_t no = 0; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 5fb88872..9ebe9c4e 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -359,6 +359,10 @@ namespace currency #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), out_key(stealth_address) + {} uint64_t global_amount_index; crypto::public_key out_key; }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ba704480..a4edf54c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -66,6 +66,7 @@ namespace tools m_last_pow_block_h(0), m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST), m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE), + m_required_decoys_count(CURRENCY_DEFAULT_DECOY_SET_SIZE), m_current_wallet_file_size(0), m_use_deffered_global_outputs(false), m_disable_tor_relay(false), @@ -3476,52 +3477,125 @@ bool wallet2::get_pos_entries(currency::COMMAND_RPC_SCAN_POS::request& req) return true; } //---------------------------------------------------------------------------------------------------- -bool wallet2::prepare_and_sign_pos_block(currency::block& b, - const currency::pos_entry& pos_info, - const crypto::public_key& source_tx_pub_key, - uint64_t in_tx_output_index, - const std::vector& keys_ptrs) +bool wallet2::prepare_and_sign_pos_block(const currency::pos_entry& pe, currency::block& b) { - //generate coinbase transaction - WLT_CHECK_AND_ASSERT_MES(b.miner_tx.vin[0].type() == typeid(currency::txin_gen), false, "Wrong output input in transaction"); - WLT_CHECK_AND_ASSERT_MES(b.miner_tx.vin[1].type() == typeid(currency::txin_to_key), false, "Wrong output input in transaction"); - auto& txin = boost::get(b.miner_tx.vin[1]); - txin.k_image = pos_info.keyimage; - WLT_CHECK_AND_ASSERT_MES(b.miner_tx.signatures.size() == 1 && b.miner_tx.signatures[0].size() == txin.key_offsets.size(), - false, "Wrong signatures amount in coinbase transacton"); + bool r = false; + WLT_CHECK_AND_ASSERT_MES(pe.wallet_index < m_transfers.size(), false, "invalid pe.wallet_index: " << pe.wallet_index); + const transfer_details& td = m_transfers[pe.wallet_index]; + const transaction& source_tx = td.m_ptx_wallet_info->m_tx; + const crypto::public_key source_tx_pub_key = get_tx_pub_key_from_extra(source_tx); + WLT_CHECK_AND_ASSERT_MES(td.m_internal_output_index < source_tx.vout.size(), false, "invalid td.m_internal_output_index: " << td.m_internal_output_index); + const currency::tx_out& stake_out = source_tx.vout[td.m_internal_output_index]; + + // calculate stake_out_derivation and secret_x (derived ephemeral secret key) + crypto::key_derivation stake_out_derivation = AUTO_VAL_INIT(stake_out_derivation); + r = crypto::generate_key_derivation(source_tx_pub_key, m_account.get_keys().view_secret_key, stake_out_derivation); // d = 8 * v * R + WLT_CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed, tid: " << pe.wallet_index << ", source_tx: " << get_transaction_hash(source_tx)); + crypto::secret_key secret_x = AUTO_VAL_INIT(secret_x); + crypto::derive_secret_key(stake_out_derivation, td.m_internal_output_index, m_account.get_keys().spend_secret_key, secret_x); // x = Hs(8 * v * R, i) + s + + WLT_CHECK_AND_ASSERT_MES(b.miner_tx.vin[0].type() == typeid(currency::txin_gen), false, "Wrong input 0 type in transaction: " << b.miner_tx.vin[0].type().name()); + WLT_CHECK_AND_ASSERT_MES(b.miner_tx.vin[1].type() == typeid(currency::txin_to_key), false, "Wrong input 1 type in transaction: " << b.miner_tx.vin[1].type().name()); + WLT_CHECK_AND_ASSERT_MES(b.miner_tx.signatures.size() == 1, false, "Wrong sig prepared in PoS block"); + WLT_CHECK_AND_ASSERT_MES(stake_out.target.type() == typeid(currency::txout_to_key), false, "wrong type_id in source transaction in coinbase tx"); + + std::vector& sig = b.miner_tx.signatures[0]; + txin_to_key& stake_input = boost::get(b.miner_tx.vin[1]); + const txout_to_key& stake_out_target = boost::get(stake_out.target); + + // partially fill stake input + stake_input.k_image = pe.keyimage; + stake_input.amount = stake_out.amount; + // get decoys outputs and construct miner tx + COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response decoys_resp = AUTO_VAL_INIT(decoys_resp); + std::vector ring; + uint64_t secret_index = 0; // index of the real stake output + if (m_required_decoys_count > 0) + { + COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request decoys_req = AUTO_VAL_INIT(decoys_req); + decoys_req.use_forced_mix_outs = false; + decoys_req.outs_count = m_required_decoys_count + 1; // one more to be able to skip a decoy in case it hits the real output + decoys_req.amounts.push_back(pe.amount); // request one batch of decoys - //derive secret key - crypto::key_derivation pos_coin_derivation = AUTO_VAL_INIT(pos_coin_derivation); - bool r = crypto::generate_key_derivation(source_tx_pub_key, - m_account.get_keys().view_secret_key, - pos_coin_derivation); + r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(decoys_req, decoys_resp); + // TODO @#@# do we need these exceptions? + THROW_IF_FALSE_WALLET_EX(r, error::no_connection_to_daemon, "getrandom_outs.bin"); + THROW_IF_FALSE_WALLET_EX(decoys_resp.status != API_RETURN_CODE_BUSY, error::daemon_busy, "getrandom_outs.bin"); + THROW_IF_FALSE_WALLET_EX(decoys_resp.status == API_RETURN_CODE_OK, error::get_random_outs_error, decoys_resp.status); + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(decoys_resp.outs.size() == 1, "got wrong number of decoys batches: " << decoys_resp.outs.size()); + + // we expect that less decoys can be returned than requested, we will use them all anyway + WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(decoys_resp.outs[0].outs.size() <= m_required_decoys_count + 1, "for PoS stake tx got greater decoys to mix than requested: " << decoys_resp.outs[0].outs.size() << " < " << m_required_decoys_count + 1); - WLT_CHECK_AND_ASSERT_MES(r, false, "internal error: pos coin base generator: failed to generate_key_derivation(" - << source_tx_pub_key - << ", view secret key: " << m_account.get_keys().view_secret_key << ")"); + auto& ring_candidates = decoys_resp.outs[0].outs; + ring_candidates.emplace_front(td.m_global_output_index, stake_out_target.key); - crypto::secret_key derived_secret_ephemeral_key = AUTO_VAL_INIT(derived_secret_ephemeral_key); - crypto::derive_secret_key(pos_coin_derivation, - in_tx_output_index, - m_account.get_keys().spend_secret_key, - derived_secret_ephemeral_key); + std::unordered_set used_gindices; + size_t good_outs_count = 0; + for(auto it = ring_candidates.begin(); it != ring_candidates.end(); ) + { + if (used_gindices.count(it->global_amount_index) != 0) + { + it = ring_candidates.erase(it); + continue; + } + used_gindices.insert(it->global_amount_index); + if (++good_outs_count == m_required_decoys_count + 1) + { + ring_candidates.erase(++it, ring_candidates.end()); + break; + } + ++it; + } + + // won't assert that ring_candidates.size() == m_required_decoys_count + 1 here as we will use all the decoys anyway + if (ring_candidates.size() < m_required_decoys_count + 1) + LOG_PRINT_YELLOW("PoS: using " << ring_candidates.size() - 1 << " decoys for mining tx, while " << m_required_decoys_count << " are required", LOG_LEVEL_1); + + ring_candidates.sort([](auto& l, auto& r){ return l.global_amount_index < r.global_amount_index; }); // sort them now (note absolute_output_offsets_to_relative() below) + + uint64_t i = 0; + for(auto& el : ring_candidates) + { + uint64_t gindex = el.global_amount_index; + if (gindex == td.m_global_output_index) + secret_index = i; + ++i; + ring.emplace_back(&el.out_key); + stake_input.key_offsets.push_back(el.global_amount_index); + } + stake_input.key_offsets = absolute_output_offsets_to_relative(stake_input.key_offsets); + } + else + { + // no decoys, the ring consist of one element -- the real stake output + ring.emplace_back(&stake_out_target.key); + stake_input.key_offsets.push_back(td.m_global_output_index); + } // sign block actually in coinbase transaction crypto::hash block_hash = currency::get_block_hash(b); - crypto::generate_ring_signature(block_hash, - txin.k_image, - keys_ptrs, - derived_secret_ephemeral_key, - 0, - &b.miner_tx.signatures[0][0]); + // generate sring signature + sig.resize(ring.size()); + crypto::generate_ring_signature(block_hash, stake_input.k_image, ring, secret_x, secret_index, sig.data()); - WLT_LOG_L4("GENERATED RING SIGNATURE: block_id " << block_hash - << "txin.k_image" << txin.k_image - << "key_ptr:" << *keys_ptrs[0] - << "signature:" << b.miner_tx.signatures[0][0]); + if (epee::log_space::get_set_log_detalisation_level() >= LOG_LEVEL_4) + { + std::stringstream ss; + ss << "GENERATED RING SIGNATURE for PoS block coinbase:" << ENDL << + " block hash: " << block_hash << ENDL << + " key image: " << stake_input.k_image << ENDL << + " ring:" << ENDL; + for(auto el: ring) + ss << " " << *el << ENDL; + ss << " signature:" << ENDL; + for(auto el: sig) + ss << " " << el << ENDL; + WLT_LOG_L4(ss.str()); + } return true; } @@ -3666,19 +3740,20 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& WLT_LOG_GREEN("Found kernel, constructing block", LOG_LEVEL_0); CHECK_AND_NO_ASSERT_MES(rsp.index < req.pos_entries.size(), false, "call_COMMAND_RPC_SCAN_POS returned wrong index: " << rsp.index << ", expected less then " << req.pos_entries.size()); + const pos_entry& pe = req.pos_entries[rsp.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; - tmpl_req.pos_amount = req.pos_entries[rsp.index].amount; - tmpl_req.pos_index = req.pos_entries[rsp.index].index; + tmpl_req.pos_amount = pe.amount; + tmpl_req.pos_index = pe.index; tmpl_req.extra_text = get_extra_text_for_block(m_chain.get_top_block_height()); // m_miner_text_info; - tmpl_req.stake_unlock_time = req.pos_entries[rsp.index].stake_unlock_time; + tmpl_req.stake_unlock_time = pe.stake_unlock_time; // mark stake source as spent and make sure it will be restored in case of error - const std::vector stake_transfer_idx_vec{ req.pos_entries[rsp.index].wallet_index }; + const std::vector stake_transfer_idx_vec{ pe.wallet_index }; mark_transfers_as_spent(stake_transfer_idx_vec, "stake source"); bool gracefull_leaving = false; auto stake_transfer_spent_flag_restorer = epee::misc_utils::create_scope_leave_handler([&](){ @@ -3710,27 +3785,17 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& } std::vector keys_ptrs; - WLT_CHECK_AND_ASSERT_MES(req.pos_entries[rsp.index].wallet_index < m_transfers.size(), + WLT_CHECK_AND_ASSERT_MES(pe.wallet_index < m_transfers.size(), false, "Wrong wallet_index at generating coinbase transacton"); - const auto& target = m_transfers[req.pos_entries[rsp.index].wallet_index].m_ptx_wallet_info->m_tx.vout[m_transfers[req.pos_entries[rsp.index].wallet_index].m_internal_output_index].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& txtokey = boost::get(target); - keys_ptrs.push_back(&txtokey.key); - // set a real timestamp b.timestamp = rsp.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); + WLT_LOG_MAGENTA("Applying actual timestamp: " << current_timestamp, LOG_LEVEL_2); //sign block - res = prepare_and_sign_pos_block(b, - req.pos_entries[rsp.index], - get_tx_pub_key_from_extra(m_transfers[req.pos_entries[rsp.index].wallet_index].m_ptx_wallet_info->m_tx), - m_transfers[req.pos_entries[rsp.index].wallet_index].m_internal_output_index, - keys_ptrs); + res = prepare_and_sign_pos_block(pe, b); WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to prepare_and_sign_pos_block"); WLT_LOG_GREEN("Block " << get_block_hash(b) << " @ " << get_block_height(b) << " has been constructed, sending to core...", LOG_LEVEL_0); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 5013272e..694851f3 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -545,6 +545,7 @@ namespace tools bool set_core_proxy(const std::shared_ptr& proxy); void set_pos_mint_packing_size(uint64_t new_size); + void set_pos_required_decoys_count(size_t v) { m_required_decoys_count = v; } void set_minimum_height(uint64_t h); std::shared_ptr get_core_proxy(); uint64_t balance() const; @@ -802,11 +803,7 @@ namespace tools //next functions in public area only becausce of test_generator //TODO: Need refactoring - remove it back to private zone void set_genesis(const crypto::hash& genesis_hash); - bool prepare_and_sign_pos_block(currency::block& b, - const currency::pos_entry& pos_info, - const crypto::public_key& source_tx_pub_key, - uint64_t in_tx_output_index, - const std::vector& keys_ptrs); + bool prepare_and_sign_pos_block(const currency::pos_entry& pe, currency::block& b); void process_new_blockchain_entry(const currency::block& b, const currency::block_direct_data_entry& bche, const crypto::hash& bl_id, @@ -1036,6 +1033,7 @@ private: std::atomic m_last_bc_timestamp; bool m_do_rise_transfer; uint64_t m_pos_mint_packing_size; + size_t m_required_decoys_count; transfer_container m_transfers; multisig_transfer_container m_multisig_transfers; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index b2a24b36..f4e1fc4e 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -382,7 +382,7 @@ bool test_generator::sign_block(currency::block& b, std::vector keys_ptrs; keys_ptrs.push_back(&out_key); - r = w.prepare_and_sign_pos_block(b, pe, source_tx_pub_key, out_i, keys_ptrs); + r = w.prepare_and_sign_pos_block(pe, b); CHECK_AND_ASSERT_THROW_MES(r,"Failed to prepare_and_sign_pos_block()"); return true; @@ -426,6 +426,7 @@ bool test_generator::build_wallets(const blockchain_vector& blocks, wallets.back()->get_account().set_createtime(0); wallets.back()->set_core_proxy(tmp_proxy); wallets.back()->set_minimum_height(0); + wallets.back()->set_pos_required_decoys_count(0); currency::core_runtime_config pc = cc; pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index d09d1558..7fbdf178 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -891,7 +891,7 @@ int main(int argc, char* argv[]) // GENERATE_AND_PLAY(pos_wallet_minting_same_amount_diff_outs); // Long test! Takes ~10 hours to simulate 6000 blocks on 2015 middle-end computer //GENERATE_AND_PLAY(pos_emission_test); // Long test! by demand only GENERATE_AND_PLAY(pos_wallet_big_block_test); - GENERATE_AND_PLAY(block_template_against_txs_size); + //GENERATE_AND_PLAY(block_template_against_txs_size); // Long test! by demand only GENERATE_AND_PLAY(pos_altblocks_validation); // alternative blocks and generic chain-switching tests From 760ff033cb1006d025a28da38229a0d49319b154 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 31 Oct 2023 16:56:56 +0100 Subject: [PATCH 088/127] set C++14 as a minimum requirement --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 515023b8..913dcb72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,9 @@ set(VERSION "1.0") # cmake_policy(SET CMP0020 OLD) # endif() +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") add_definitions(-DMOBILE_WALLET_BUILD) if(CMAKE_SYSTEM_NAME STREQUAL "iOS" ) From ebb8f7b6ff5fd808faf71b6fd2df7daac5523b0c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 18:29:57 +0100 Subject: [PATCH 089/127] wallet sync state moved to separate base structure --- src/common/boost_serialization_maps.h | 1 + src/currency_core/currency_config.h | 4 +- src/simplewallet/simplewallet.cpp | 16 +- src/wallet/wallet2.cpp | 53 +- src/wallet/wallet2.h | 654 ++++-------------- src/wallet/wallet_chain_shortener.cpp | 5 +- src/wallet/wallet_chain_shortener.h | 7 +- src/wallet/wallet_rpc_server.cpp | 6 +- src/wallet/wallets_manager.cpp | 4 +- tests/core_tests/chaingen.cpp | 8 +- .../escrow_wallet_altchain_test.cpp | 2 +- tests/core_tests/escrow_wallet_common.h | 6 +- tests/core_tests/escrow_wallet_tests.cpp | 34 +- tests/core_tests/multiassets_test.cpp | 6 +- tests/core_tests/multisig_wallet_tests.cpp | 16 +- tests/core_tests/wallet_rpc_tests.cpp | 4 +- tests/core_tests/wallet_tests.cpp | 20 +- .../transactions_flow_test.cpp | 10 +- 18 files changed, 203 insertions(+), 653 deletions(-) diff --git a/src/common/boost_serialization_maps.h b/src/common/boost_serialization_maps.h index 805febee..7f44e4d2 100644 --- a/src/common/boost_serialization_maps.h +++ b/src/common/boost_serialization_maps.h @@ -18,6 +18,7 @@ template struct TAssertEquality { #define BOOST_SERIALIZE(x) _arch & x; +#define BOOST_SERIALIZE_BASE_CLASS(class_type) _arch & static_cast(*this); #define BOOST_END_VERSION_UNDER(x) \ if(ver < x ) {return;} diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 3a48cf8c..84436bbb 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -246,8 +246,8 @@ #define WALLET_FILE_SERIALIZATION_VERSION 160 #define WALLET_FILE_LAST_SUPPORTED_VERSION 160 #else -#define WALLET_FILE_LAST_SUPPORTED_VERSION (CURRENCY_FORMATION_VERSION+74) -#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+74) +#define WALLET_FILE_LAST_SUPPORTED_VERSION (CURRENCY_FORMATION_VERSION+75) +#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+75) #endif #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index d26d0849..e3ce4e54 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1087,7 +1087,7 @@ bool simple_wallet::show_incoming_transfers(const std::vector& args } } - tools::wallet2::transfer_container transfers; + tools::transfer_container transfers; m_wallet->get_transfers(transfers); bool transfers_found = false; @@ -1130,7 +1130,7 @@ bool simple_wallet::show_incoming_transfers(const std::vector& args bool simple_wallet::show_incoming_transfers_counts(const std::vector& args) { - tools::wallet2::transfer_container transfers; + tools::transfer_container transfers; m_wallet->get_transfers(transfers); uint64_t spent_count = 0; @@ -1189,7 +1189,7 @@ bool simple_wallet::fix_collisions(const std::vector &args) return true; } -void print_td_list(const std::list& td) +void print_td_list(const std::list& td) { message_writer() << "entries found: " << td.size(); for (auto& e : td) @@ -1208,7 +1208,7 @@ bool simple_wallet::scan_transfers_for_id(const std::vector &args) fail_msg_writer() << "expected valid tx id"; return true; } - std::list td; + std::list td; m_wallet->scan_for_transaction_entries(id, currency::null_ki, td); print_td_list(td); return true; @@ -1222,7 +1222,7 @@ bool simple_wallet::scan_transfers_for_ki(const std::vector &args) fail_msg_writer() << "expected valid key_image"; return true; } - std::list td; + std::list td; m_wallet->scan_for_transaction_entries(currency::null_hash, ki, td); print_td_list(td); return true; @@ -1249,7 +1249,7 @@ bool simple_wallet::get_transfer_info(const std::vector &args) } size_t i = 0; - tools::wallet2::transfer_details td = AUTO_VAL_INIT(td); + tools::transfer_details td = AUTO_VAL_INIT(td); if (epee::string_tools::get_xtype_from_string(i, args[0])) { @@ -1294,7 +1294,7 @@ bool simple_wallet::show_payments(const std::vector &args) bool payments_found = false; for(std::string arg : args) { - std::list payments; + std::list payments; m_wallet->get_payments(arg, payments); if (payments.empty()) { @@ -1302,7 +1302,7 @@ bool simple_wallet::show_payments(const std::vector &args) continue; } - for (const tools::wallet2::payment_details& pd : payments) + for (const tools::payment_details& pd : payments) { if (!payments_found) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e805280d..c67243e9 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -66,18 +66,13 @@ namespace tools , m_wcallback(new i_wallet2_callback()) //stub , m_core_proxy(new default_http_core_proxy()) , m_upper_transaction_size_limit(0) - , m_height_of_start_sync(0) - , m_last_sync_percent(0) , m_fake_outputs_count(0) , m_do_rise_transfer(false) , m_log_prefix("???") , m_watch_only(false) - , m_last_pow_block_h(0) - , m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST) , m_min_utxo_count_for_defragmentation_tx(WALLET_MIN_UTXO_COUNT_FOR_DEFRAGMENTATION_TX) , m_max_utxo_count_for_defragmentation_tx(WALLET_MAX_UTXO_COUNT_FOR_DEFRAGMENTATION_TX) , m_decoys_count_for_defragmentation_tx(WALLET_DEFAULT_DECOYS_COUNT_FOR_DEFRAGMENTATION_TX) - , m_current_wallet_file_size(0) , m_use_deffered_global_outputs(false) #ifdef DISABLE_TOR , m_disable_tor_relay(true) @@ -149,25 +144,25 @@ currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str) return currency::transaction(); } //---------------------------------------------------------------------------------------------------- -uint64_t wallet2::transfer_details_base_to_amount(const transfer_details_base& tdb) +uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) { return tdb.amount(); } //---------------------------------------------------------------------------------------------------- -std::string wallet2::transfer_details_base_to_tx_hash(const transfer_details_base& tdb) +std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) { return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); } //---------------------------------------------------------------------------------------------------- -const wallet2::transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr& a) +const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr& a) { return *a; } //---------------------------------------------------------------------------------------------------- -std::shared_ptr wallet2::transform_value_to_ptr(const wallet2::transaction_wallet_info& d) +std::shared_ptr wallet2::transform_value_to_ptr(const transaction_wallet_info& d) { THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); - return std::shared_ptr(); + return std::shared_ptr(); } //---------------------------------------------------------------------------------------------------- @@ -1248,12 +1243,12 @@ void wallet2::change_contract_state(wallet_public::escrow_contract_details_basic contract.state = new_state; } //----------------------------------------------------------------------------------------------------- -void from_outs_to_received_items(const std::vector& outs, std::vector& received, const currency::transaction& tx) +void from_outs_to_received_items(const std::vector& outs, std::vector& received, const currency::transaction& tx) { for (const auto& item : outs) { if(!out_is_multisig(tx.vout[item.index])) - received.push_back(tools::wallet2::payment_details_subtransfer{ item.asset_id, item.amount}); + received.push_back(tools::payment_details_subtransfer{ item.asset_id, item.amount}); } } //----------------------------------------------------------------------------------------------------- @@ -2820,29 +2815,9 @@ bool wallet2::clear() //---------------------------------------------------------------------------------------------------- bool wallet2::reset_all() { - //m_blockchain.clear(); - m_chain.clear(); - m_transfers.clear(); - m_amount_gindex_to_transfer_id.clear(); - m_key_images.clear(); - // m_pending_key_images is not cleared intentionally - m_unconfirmed_in_transfers.clear(); - m_unconfirmed_txs.clear(); - m_unconfirmed_multisig_transfers.clear(); - // m_tx_keys is not cleared intentionally, considered to be safe - m_multisig_transfers.clear(); - m_payments.clear(); - m_transfer_history.clear(); - //m_account = AUTO_VAL_INIT(m_account); - - //m_local_bc_size = 1; //including genesis - m_last_bc_timestamp = 0; - m_height_of_start_sync = 0; - m_last_sync_percent = 0; - m_last_pow_block_h = 0; - m_current_wallet_file_size = 0; - m_custom_assets.clear(); - m_own_asset_descriptors.clear(); + //static_cast(*this) = wallet2_base_state{}; + static_cast(*this).~wallet2_base_state(); + new (static_cast(this)) wallet2_base_state(); return true; } //---------------------------------------------------------------------------------------------------- @@ -3571,7 +3546,7 @@ bool wallet2::load_whitelisted_tokens_if_not_loaded() const return load_whitelisted_tokens(); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_transfers(wallet2::transfer_container& incoming_transfers) const +void wallet2::get_transfers(transfer_container& incoming_transfers) const { incoming_transfers = m_transfers; } @@ -3673,7 +3648,7 @@ std::string wallet2::get_balance_str() const return ss.str(); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height) const +void wallet2::get_payments(const std::string& payment_id, std::list& payments, uint64_t min_height) const { auto range = m_payments.equal_range(payment_id); std::for_each(range.first, range.second, [&payments, &min_height](const payment_container::value_type& x) @@ -4912,10 +4887,10 @@ std::string get_random_rext(size_t len) // local_transfers_struct - structure to avoid copying the whole m_transfers struct local_transfers_struct { - local_transfers_struct(wallet2::transfer_container& tf) :l_transfers_ref(tf) + local_transfers_struct(transfer_container& tf) :l_transfers_ref(tf) {} - wallet2::transfer_container& l_transfers_ref; + transfer_container& l_transfers_ref; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(l_transfers_ref) END_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 63eb6d0c..3d75569d 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -45,18 +45,11 @@ #include "tor-connect/torlib/tor_lib_iface.h" #include "currency_core/pos_mining.h" #include "view_iface.h" - +#include "wallet2_base.h" #define WALLET_DEFAULT_TX_SPENDABLE_AGE 10 #define WALLET_POS_MINT_CHECK_HEIGHT_INTERVAL 1 -#define WALLET_TRANSFER_DETAIL_FLAG_SPENT uint32_t(1 << 0) -#define WALLET_TRANSFER_DETAIL_FLAG_BLOCKED uint32_t(1 << 1) -#define WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION uint32_t(1 << 2) -#define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3) -#define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing) -#define WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM uint32_t(1 << 5) // for htlc keeps info if this htlc belong as redeem or as refund - const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits::max(); @@ -84,9 +77,6 @@ const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits #define WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_CMN_ERR_EX(cond, "[W:" << m_log_prefix << "] " << msg) #define WLT_THROW_IF_FALSE_WALLET_EX_MES(cond, exception_t, msg, ...) THROW_IF_FALSE_WALLET_EX_MES(cond, exception_t, "[W:" << m_log_prefix << "] " << msg, ## __VA_ARGS__) - - - class test_generator; namespace tools @@ -124,194 +114,110 @@ namespace tools virtual bool on_mw_select_wallet(uint64_t wallet_id) { return true; } }; - struct tx_dust_policy - { - uint64_t dust_threshold = 0; - bool add_to_fee = false; - currency::account_public_address addr_for_dust; - tx_dust_policy(uint64_t a_dust_threshold = DEFAULT_DUST_THRESHOLD, bool an_add_to_fee = true, currency::account_public_address an_addr_for_dust = currency::account_public_address()) - : dust_threshold(a_dust_threshold) - , add_to_fee(an_add_to_fee) - , addr_for_dust(an_addr_for_dust) - { - } - - BEGIN_SERIALIZE_OBJECT() - FIELD(dust_threshold) - FIELD(add_to_fee) - FIELD(addr_for_dust) - END_SERIALIZE() - }; class test_generator; -#pragma pack(push, 1) - struct out_key_to_ki + + /* + This structure aggregates all variables that hold current wallet synchronization state and could be reset + */ + struct wallet2_base_state { - crypto::public_key out_key; - crypto::key_image key_image; - }; -#pragma pack(pop) + wallet_chain_shortener m_chain; + uint64_t m_minimum_height = WALLET_MINIMUM_HEIGHT_UNSET_CONST; + amount_gindex_to_transfer_id_container m_amount_gindex_to_transfer_id; + transfer_container m_transfers; + multisig_transfer_container m_multisig_transfers; + payment_container m_payments; + std::unordered_map m_key_images; + std::vector m_transfer_history; + std::unordered_map m_unconfirmed_in_transfers; + std::unordered_map m_unconfirmed_txs; + std::unordered_set m_unconfirmed_multisig_transfers; + std::unordered_map m_tx_keys; + std::unordered_map m_own_asset_descriptors; + std::unordered_map m_custom_assets; //assets that manually added by user + escrow_contracts_container m_contracts; + std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration + amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index + std::unordered_map m_active_htlcs_txid; // map [txid] -> transfer index, limitation: 1 transactiom -> 1 htlc + std::list m_money_expirations; + std::unordered_map m_pending_key_images; // (out_pk -> ki) pairs of change outputs to be added in watch-only wallet without spend sec key + uint64_t m_last_pow_block_h = 0; + std::list> m_rollback_events; + //variables that not being serialized + std::atomic m_last_bc_timestamp = 0; + uint64_t m_height_of_start_sync = 0; + std::atomic m_last_sync_percent = 0; + mutable uint64_t m_current_wallet_file_size = 0; - typedef tools::pod_array_file_container pending_ki_file_container_t; - - namespace detail - { - //---------------------------------------------------------------------------------------------------- - inline void digit_split_strategy(const std::vector& dsts, - const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, - std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) + //=============================================================== + template + inline void serialize(t_archive &a, const unsigned int ver) { - splitted_dsts.clear(); - dust = 0; - - for(auto& de : dsts) + if (t_archive::is_saving::value) { - if (de.addr.size() > 1) - { - //for multisig we don't split - splitted_dsts.push_back(de); - } - else if (de.htlc_options.expiration != 0) - { - //for htlc we don't do split - splitted_dsts.push_back(de); - } - else - { - currency::decompose_amount_into_digits(de.amount, dust_threshold, - [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, de.addr, de.asset_id)); }, - [&](uint64_t a_dust) { splitted_dsts.push_back(currency::tx_destination_entry(a_dust, de.addr, de.asset_id)); }, max_output_allowed); - } + LOG_PRINT_MAGENTA("Serializing file with ver: " << ver, LOG_LEVEL_0); } - if (change_dst.amount > 0) + + // do not load wallet if data version is greather than the code version + if (ver > WALLET_FILE_SERIALIZATION_VERSION) { - if (change_dst.addr.size() > 1) + LOG_PRINT_MAGENTA("Wallet file truncated due to WALLET_FILE_SERIALIZATION_VERSION is more then curren build", LOG_LEVEL_0); + return; + } + if (ver < WALLET_FILE_LAST_SUPPORTED_VERSION) + { + LOG_PRINT_MAGENTA("Wallet file truncated due to ver(" << ver << ") is less then WALLET_FILE_LAST_SUPPORTED_VERSION", LOG_LEVEL_0); + return; + } + + if (t_archive::is_saving::value) + { + uint64_t formation_ver = CURRENCY_FORMATION_VERSION; + a & formation_ver; + } + else + { + uint64_t formation_ver = 0; + a & formation_ver; + if (formation_ver != CURRENCY_FORMATION_VERSION) { - //for multisig we don't split - splitted_dsts.push_back(change_dst); - } - else - { - currency::decompose_amount_into_digits(change_dst.amount, dust_threshold, - [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, change_dst.addr)); }, - [&](uint64_t a_dust) { dust = a_dust; }, max_output_allowed); + LOG_PRINT_MAGENTA("Wallet file truncated due to mismatch CURRENCY_FORMATION_VERSION", LOG_LEVEL_0); + return; } } + //convert from old version + a & m_chain; + a & m_minimum_height; + a & m_amount_gindex_to_transfer_id; + a & m_transfers; + a & m_multisig_transfers; + a & m_key_images; + a & m_unconfirmed_txs; + a & m_unconfirmed_multisig_transfers; + a & m_payments; + a & m_transfer_history; + a & m_unconfirmed_in_transfers; + a & m_contracts; + a & m_money_expirations; + a & m_pending_key_images; + a & m_tx_keys; + a & m_last_pow_block_h; + a & m_htlcs; + a & m_active_htlcs; + a & m_active_htlcs_txid; + a & m_own_asset_descriptors; + a & m_custom_assets; + a & m_rollback_events; } - //---------------------------------------------------------------------------------------------------- - inline void null_split_strategy(const std::vector& dsts, - const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, - std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) - { - splitted_dsts = dsts; - - dust = 0; - uint64_t change = change_dst.amount; - if (0 < dust_threshold) - { - for (uint64_t order = 10; order <= 10 * dust_threshold; order *= 10) - { - uint64_t dust_candidate = change_dst.amount % order; - uint64_t change_candidate = (change_dst.amount / order) * order; - if (dust_candidate <= dust_threshold) - { - dust = dust_candidate; - change = change_candidate; - } - else - { - break; - } - } - } - - if (0 != change) - { - splitted_dsts.push_back(currency::tx_destination_entry(change, change_dst.addr)); - } - } - //---------------------------------------------------------------------------------------------------- - inline void void_split_strategy(const std::vector& dsts, - const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, - std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) - { - splitted_dsts.insert(splitted_dsts.end(), dsts.begin(), dsts.end()); - if (change_dst.amount > 0) - splitted_dsts.push_back(change_dst); - } - //---------------------------------------------------------------------------------------------------- - enum split_strategy_id_t { ssi_none = 0, ssi_digit = 1, ssi_null = 2, ssi_void = 3 }; - //---------------------------------------------------------------------------------------------------- - inline bool apply_split_strategy_by_id(split_strategy_id_t id, const std::vector& dsts, - const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, - std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) - { - switch (id) - { - case ssi_digit: - digit_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); - return true; - case ssi_null: - null_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); - return true; - case ssi_void: - void_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); - return true; - default: - return false; - } - } - - } // namespace detail - - struct construct_tx_param - { - // preparing data for tx - std::vector dsts; - size_t fake_outputs_count = 0; - uint64_t fee = 0; - tx_dust_policy dust_policy; - crypto::hash multisig_id = currency::null_hash; - uint8_t flags = 0; - uint8_t split_strategy_id = 0; - bool mark_tx_as_complete = false; - - crypto::hash htlc_tx_id; - std::string htlc_origin; - - // constructing tx - uint64_t unlock_time = 0; - std::vector extra; - std::vector attachments; - currency::account_public_address crypt_address; - uint8_t tx_outs_attr = 0; - bool shuffle = false; - bool create_utxo_defragmentation_tx = false; - bool need_at_least_1_zc = false; - crypto::secret_key asset_deploy_control_key = currency::null_skey; - }; - - struct mode_separate_context - { - currency::transaction tx_for_mode_separate; - view::ionic_swap_proposal_info proposal_info; - bool escrow = false; }; - struct selection_for_amount - { - uint64_t needed_amount = 0; - uint64_t found_amount = 0; - //std::vector selected_indicies; - }; - typedef std::unordered_map assets_selection_context; - - class wallet2: public tools::tor::t_transport_state_notifier, public boost::static_visitor + class wallet2: public tools::tor::t_transport_state_notifier, public boost::static_visitor, public wallet2_base_state { wallet2(const wallet2&) = delete; public: @@ -321,195 +227,12 @@ namespace tools static std::string transform_tx_to_str(const currency::transaction& tx); static currency::transaction transform_str_to_tx(const std::string& tx_str); - //general rollback mechanism - struct asset_register_event - { - crypto::public_key asset_id = currency::null_pkey; - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_id) - END_BOOST_SERIALIZATION() - - }; - - struct wallet_own_asset_context - { - currency::asset_descriptor_base asset_descriptor; - crypto::secret_key control_key; - //uint64_t height = 0; - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_descriptor) - BOOST_SERIALIZE(control_key) - //BOOST_SERIALIZE(height) - END_BOOST_SERIALIZATION() - }; - - struct asset_update_event - { - crypto::public_key asset_id = currency::null_pkey; - wallet_own_asset_context own_context; - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_id) - BOOST_SERIALIZE(own_context) - END_BOOST_SERIALIZATION() - }; - - struct asset_unown_event - { - crypto::public_key asset_id = currency::null_pkey; - wallet_own_asset_context own_context; - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_id) - BOOST_SERIALIZE(own_context) - END_BOOST_SERIALIZATION() - }; - - typedef boost::variant wallet_event_t; - - struct transaction_wallet_info - { - uint64_t m_block_height = 0; - uint64_t m_block_timestamp = 0; - currency::transaction m_tx; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(m_block_height) - KV_SERIALIZE(m_block_timestamp) - KV_SERIALIZE_CUSTOM(m_tx, std::string, tools::wallet2::transform_tx_to_str, tools::wallet2::transform_str_to_tx) - END_KV_SERIALIZE_MAP() - }; - static const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr& a); static std::shared_ptr transform_value_to_ptr(const transaction_wallet_info& d); - - struct transfer_details_base; + static uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb); static std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb); - struct transfer_details_base - { - struct ZC_out_info // TODO: @#@# consider using wallet_out_info instead - { - ZC_out_info() = default; - ZC_out_info(const crypto::scalar_t& amount_blinding_mask, const crypto::scalar_t& asset_id_blinding_mask, const crypto::public_key& asset_id) - : amount_blinding_mask(amount_blinding_mask), asset_id_blinding_mask(asset_id_blinding_mask), asset_id(asset_id) - {} - crypto::scalar_t amount_blinding_mask = 0; - crypto::scalar_t asset_id_blinding_mask = 0; - crypto::public_key asset_id = currency::null_pkey; // not blinded, not multiplied by 1/8 TODO: @#@# consider changing to point_t, also consider using wallet wallet_out_info - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(amount_blinding_mask) - KV_SERIALIZE(asset_id_blinding_mask) - KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) - END_KV_SERIALIZE_MAP() - }; - - std::shared_ptr m_ptx_wallet_info; - uint64_t m_internal_output_index = 0; - uint64_t m_spent_height = 0; - uint32_t m_flags = 0; - uint64_t m_amount = 0; - boost::shared_ptr m_zc_info_ptr; - - uint64_t amount() const { return m_amount; } - uint64_t amount_for_global_output_index() const { return is_zc() ? 0 : m_amount; } // amount value for global outputs index, it's zero for outputs with hidden amounts - - // @#@ will throw if type is not tx_out_bare, TODO: change according to new model, - // need to replace all get_tx_out_bare_from_out_v() to proper code - //const currency::tx_out_bare& output() const { return currency::get_tx_out_bare_from_out_v(m_ptx_wallet_info->m_tx.vout[m_internal_output_index]); } - - const currency::tx_out_v& output() const { return m_ptx_wallet_info->m_tx.vout[m_internal_output_index]; } - uint8_t mix_attr() const { uint8_t result = UINT8_MAX; get_mix_attr_from_tx_out_v(output(), result); return result; } - crypto::hash tx_hash() const { return get_transaction_hash(m_ptx_wallet_info->m_tx); } - bool is_spent() const { return m_flags & WALLET_TRANSFER_DETAIL_FLAG_SPENT; } - bool is_spendable() const { return (m_flags & (WALLET_TRANSFER_DETAIL_FLAG_SPENT | WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION | WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION)) == 0; } - bool is_reserved_for_escrow() const { return ( (m_flags & WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION) != 0 ); } - bool is_zc() const { return m_zc_info_ptr.get(); } - const crypto::public_key& get_asset_id() const { if (m_zc_info_ptr.get()) { return m_zc_info_ptr->asset_id; } else { return currency::native_coin_asset_id; } } - bool is_native_coin() const { return m_zc_info_ptr.get() ? (m_zc_info_ptr->asset_id == currency::native_coin_asset_id) : true; } - bool is_htlc() const { - - if (m_ptx_wallet_info->m_tx.vout[m_internal_output_index].type() == typeid(currency::tx_out_bare) && - boost::get(m_ptx_wallet_info->m_tx.vout[m_internal_output_index]).target.type() == typeid(currency::txout_htlc)) - return true; - return false; - } - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, tools::wallet2::transform_ptr_to_value, tools::wallet2::transform_value_to_ptr) - KV_SERIALIZE(m_internal_output_index) - KV_SERIALIZE(m_spent_height) - KV_SERIALIZE(m_flags) - KV_SERIALIZE(m_amount) - KV_SERIALIZE_N(m_zc_info_ptr, "zc_out_info") - KV_SERIALIZE_EPHEMERAL_N(uint64_t, tools::wallet2::transfer_details_base_to_amount, "amount") - KV_SERIALIZE_EPHEMERAL_N(std::string, tools::wallet2::transfer_details_base_to_tx_hash, "tx_id") - END_KV_SERIALIZE_MAP() - - }; - - - struct transfer_details_extra_option_htlc_info - { - std::string origin; //this field filled only if htlc had been redeemed - crypto::hash redeem_tx_id = currency::null_hash; - }; - - - typedef boost::variant transfer_details_extra_options_v; - - struct transfer_details : public transfer_details_base - { - uint64_t m_global_output_index = 0; - crypto::key_image m_key_image; //TODO: key_image stored twice :( - std::vector varian_options; - - //v2 - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(m_global_output_index) - KV_SERIALIZE_POD_AS_HEX_STRING(m_key_image) - KV_CHAIN_BASE(transfer_details_base) - END_KV_SERIALIZE_MAP() - }; - - //used in wallet - struct htlc_expiration_trigger - { - bool is_wallet_owns_redeem = false; //specify if this HTLC belong to this wallet by pkey_redeem or by pkey_refund - uint64_t transfer_index = 0; - }; - - - struct payment_details_subtransfer - { - crypto::public_key asset_id = currency::null_pkey; - uint64_t amount = 0; - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(asset_id) - BOOST_SERIALIZE(amount) - END_BOOST_SERIALIZATION() - }; - - struct payment_details - { - crypto::hash m_tx_hash = currency::null_hash; - uint64_t m_amount = 0; // native coins amount - uint64_t m_block_height = 0; - uint64_t m_unlock_time = 0; - std::vector subtransfers; //subtransfers added for confidential asset only, native amount should be stored in m_amount (for space saving) - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(m_tx_hash) - BOOST_SERIALIZE(m_amount) - BOOST_SERIALIZE(m_block_height) - BOOST_SERIALIZE(m_unlock_time) - BOOST_SERIALIZE(subtransfers) - END_BOOST_SERIALIZATION() - }; - struct mining_context : public currency::pos_mining_context { std::string status; @@ -528,20 +251,6 @@ namespace tools uint64_t total_amount_checked = 0; }; - struct expiration_entry_info - { - std::vector selected_transfers; - uint64_t expiration_time = 0; - crypto::hash related_tx_id = currency::null_hash; // tx id which caused money lock, if any (ex: escrow proposal transport tx) - std::vector receved; - - BEGIN_BOOST_SERIALIZATION() - BOOST_SERIALIZE(selected_transfers) - BOOST_SERIALIZE(expiration_time) - BOOST_SERIALIZE(related_tx_id) - BOOST_SERIALIZE(receved) - END_BOOST_SERIALIZATION() - }; /* This might be not the best solution so far, but after discussion with @sowle we came up to conclusion @@ -559,17 +268,6 @@ namespace tools }; - - typedef std::unordered_multimap payment_container; - - typedef std::deque transfer_container; - typedef std::unordered_map multisig_transfer_container; - typedef std::unordered_map escrow_contracts_container; - typedef std::map > free_amounts_cache_type; - typedef std::unordered_map free_assets_amounts_cache_type; - typedef std::unordered_map, uint64_t> amount_gindex_to_transfer_id_container; // maps [amount; gindex] -> tid - - struct keys_file_data_old { crypto::chacha8_iv iv; @@ -832,7 +530,7 @@ namespace tools bool scan_pos(mining_context& cxt, std::atomic& stop, idle_condition_cb_t idle_condition_cb, const currency::core_runtime_config &runtime_config); bool fill_mining_context(mining_context& ctx); - void get_transfers(wallet2::transfer_container& incoming_transfers) const; + void get_transfers(transfer_container& incoming_transfers) const; std::string get_transfers_str(bool include_spent = true, bool include_unspent = true, bool show_only_unknown = false, const std::string& filter_asset_ticker = std::string{}) const; std::string get_balance_str() const; @@ -868,61 +566,7 @@ namespace tools template inline void serialize(t_archive &a, const unsigned int ver) { - if (t_archive::is_saving::value) - { - WLT_LOG_MAGENTA("Serializing file with ver: " << ver, LOG_LEVEL_0); - } - - - // do not load wallet if data version is greather than the code version - if (ver > WALLET_FILE_SERIALIZATION_VERSION) - { - WLT_LOG_MAGENTA("Wallet file truncated due to WALLET_FILE_SERIALIZATION_VERSION is more then curren build", LOG_LEVEL_0); - return; - } - if(ver < WALLET_FILE_LAST_SUPPORTED_VERSION) - { - WLT_LOG_MAGENTA("Wallet file truncated due to ver(" << ver << ") is less then WALLET_FILE_LAST_SUPPORTED_VERSION", LOG_LEVEL_0); - return; - } - - if (t_archive::is_saving::value) - { - uint64_t formation_ver = CURRENCY_FORMATION_VERSION; - a & formation_ver; - } - else - { - uint64_t formation_ver = 0; - a & formation_ver; - if (formation_ver != CURRENCY_FORMATION_VERSION) - { - WLT_LOG_MAGENTA("Wallet file truncated due to mismatch CURRENCY_FORMATION_VERSION", LOG_LEVEL_0); - return; - } - } - //convert from old version - a & m_chain; - a & m_minimum_height; - a & m_amount_gindex_to_transfer_id; - a & m_transfers; - a & m_multisig_transfers; - a & m_key_images; - a & m_unconfirmed_txs; - a & m_unconfirmed_multisig_transfers; - a & m_payments; - a & m_transfer_history; - a & m_unconfirmed_in_transfers; - a & m_contracts; - a & m_money_expirations; - a & m_pending_key_images; - a & m_tx_keys; - a & m_last_pow_block_h; - a & m_htlcs; - a & m_active_htlcs; - a & m_active_htlcs_txid; - a & m_own_asset_descriptors; - a & m_custom_assets; + wallet2_base_state::serialize(a, ver); } bool is_transfer_ready_to_go(const transfer_details& td, uint64_t fake_outputs_count); @@ -1197,71 +841,52 @@ private: static void wti_to_txt_line(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index); static void wti_to_json_line(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index); + + + /* + + !!!!! IMPORTAN !!!!! + + All variables that supposed to hold wallet state of synchronization(i.e. transfers, assets, htlc, swaps, contracts) - should + be placed in wallet2_base_state base class to avoid typical bugs when it's forgotten to be included in reset/resync/serialize functions + + */ + + + currency::account_base m_account; bool m_watch_only; std::string m_log_prefix; // part of pub address, prefix for logging functions std::wstring m_wallet_file; std::wstring m_pending_ki_file; std::string m_password; - uint64_t m_minimum_height; + - std::atomic m_last_bc_timestamp; bool m_do_rise_transfer; uint64_t m_min_utxo_count_for_defragmentation_tx; uint64_t m_max_utxo_count_for_defragmentation_tx; size_t m_decoys_count_for_defragmentation_tx; - - transfer_container m_transfers; - multisig_transfer_container m_multisig_transfers; - amount_gindex_to_transfer_id_container m_amount_gindex_to_transfer_id; - payment_container m_payments; - std::unordered_map m_key_images; - std::unordered_map m_pending_key_images; // (out_pk -> ki) pairs of change outputs to be added in watch-only wallet without spend sec key pending_ki_file_container_t m_pending_key_images_file_container; uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value std::atomic m_stop; - std::vector m_transfer_history; - std::unordered_map m_unconfirmed_in_transfers; - std::unordered_map m_unconfirmed_txs; - std::unordered_set m_unconfirmed_multisig_transfers; - std::unordered_map m_tx_keys; - std::unordered_map m_own_asset_descriptors; - std::unordered_map m_custom_assets; //assets that manually added by user mutable std::unordered_map m_whitelisted_assets; //assets that whitelisted - - - std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration - amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index - std::unordered_map m_active_htlcs_txid; // map [txid] -> transfer index, limitation: 1 transactiom -> 1 htlc - std::shared_ptr m_core_proxy; std::shared_ptr m_wcallback; - uint64_t m_height_of_start_sync; - std::atomic m_last_sync_percent; - uint64_t m_last_pow_block_h; - currency::core_runtime_config m_core_runtime_config; - escrow_contracts_container m_contracts; - wallet_chain_shortener m_chain; - std::list m_money_expirations; - //optimization for big wallets and batch tx + + currency::core_runtime_config m_core_runtime_config; + //optimization for big wallets and batch tx free_assets_amounts_cache_type m_found_free_amounts; uint64_t m_fake_outputs_count; std::string m_miner_text_info; - mutable uint64_t m_current_wallet_file_size; bool m_use_deffered_global_outputs; bool m_disable_tor_relay; bool m_use_assets_whitelisting = true; - mutable current_operation_context m_current_context; //this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions friend class test_generator; - - std::list> m_rollback_events; - - }; // class wallet2 } // namespace tools @@ -1269,70 +894,23 @@ private: BOOST_CLASS_VERSION(tools::wallet2, WALLET_FILE_SERIALIZATION_VERSION) BOOST_CLASS_VERSION(tools::wallet_public::wallet_transfer_info, 12) -BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 3) -BOOST_CLASS_VERSION(tools::wallet2::transfer_details_base, 2) namespace boost { namespace serialization { - template - inline void serialize(Archive &a, tools::wallet2::transaction_wallet_info &x, const boost::serialization::version_type ver) - { - a & x.m_block_height; - a & x.m_block_timestamp; - a & x.m_tx; - } - template - inline void serialize(Archive& a, tools::wallet2::transfer_details_base::ZC_out_info& x, const boost::serialization::version_type ver) - { - a & x.amount_blinding_mask; - a & x.asset_id_blinding_mask; - a & x.asset_id; - } +// template +// inline void serialize(Archive &a, tools::transfer_details &x, const boost::serialization::version_type ver) +// { +// a & x.m_global_output_index; +// a & x.m_key_image; +// a & static_cast(x); +// if (ver < 3) +// return; +// a & x.varian_options; +// } - template - inline void serialize(Archive &a, tools::wallet2::transfer_details_base &x, const boost::serialization::version_type ver) - { - a & x.m_ptx_wallet_info; - a & x.m_internal_output_index; - a & x.m_flags; - a & x.m_spent_height; - if (ver < 2) - { - x.m_amount = get_amount_from_variant(x.output()); - return; - } - a & x.m_amount; - a & x.m_zc_info_ptr; - } - - - template - inline void serialize(Archive &a, tools::wallet2::transfer_details_extra_option_htlc_info &x, const boost::serialization::version_type ver) - { - a & x.origin; - } - - - template - inline void serialize(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver) - { - a & x.m_global_output_index; - a & x.m_key_image; - a & static_cast(x); - if (ver < 3) - return; - a & x.varian_options; - } - - template - inline void serialize(Archive &a, tools::wallet2::htlc_expiration_trigger &x, const boost::serialization::version_type ver) - { - a & x.is_wallet_owns_redeem; - a & x.transfer_index; - } template inline void serialize(Archive& a, tools::wallet_public::escrow_contract_details_basic& x, const boost::serialization::version_type ver) diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index e353c1a6..77c5d82c 100644 --- a/src/wallet/wallet_chain_shortener.cpp +++ b/src/wallet/wallet_chain_shortener.cpp @@ -15,10 +15,7 @@ static void exception_handler(){} -wallet_chain_shortener::wallet_chain_shortener(): m_genesis(currency::gdefault_genesis) -{ - m_local_bc_size = 1; -} + void wallet_chain_shortener::clear() { m_local_bc_size = 1; diff --git a/src/wallet/wallet_chain_shortener.h b/src/wallet/wallet_chain_shortener.h index 500c2494..e3d851ca 100644 --- a/src/wallet/wallet_chain_shortener.h +++ b/src/wallet/wallet_chain_shortener.h @@ -18,12 +18,11 @@ #include "include_base_utils.h" #include "crypto/crypto.h" - +#include "currency_core/currency_basic.h" class wallet_chain_shortener { public: - wallet_chain_shortener(); void push_new_block_id(const crypto::hash& id, uint64_t height); uint64_t get_top_block_height() const; uint64_t get_blockchain_current_size() const; @@ -48,8 +47,8 @@ public: //debug functions std::string get_internal_state_text() const; private: - std::atomic m_local_bc_size; //temporary workaround - crypto::hash m_genesis; + std::atomic m_local_bc_size = 1; //temporary workaround + crypto::hash m_genesis = currency::gdefault_genesis; std::map m_last_20_blocks; std::map m_last_144_blocks_every_10; //1 day std::map m_last_144_blocks_every_100; //10 days diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 223cd8ae..ec3d3a00 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -448,7 +448,7 @@ namespace tools } res.payments.clear(); - std::list payment_list; + std::list payment_list; w.get_wallet()->get_payments(payment_id, payment_list); for (auto payment : payment_list) { @@ -486,7 +486,7 @@ namespace tools return false; } - std::list payment_list; + std::list payment_list; w.get_wallet()->get_payments(payment_id, payment_list, req.min_block_height); for (auto & payment : payment_list) @@ -772,7 +772,7 @@ namespace tools bool wallet_rpc_server::on_contracts_get_all(const wallet_public::COMMAND_CONTRACTS_GET_ALL::request& req, wallet_public::COMMAND_CONTRACTS_GET_ALL::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); - tools::wallet2::escrow_contracts_container ecc; + tools::escrow_contracts_container ecc; w.get_wallet()->get_contracts(ecc); res.contracts.resize(ecc.size()); size_t i = 0; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 3889ea4c..67a99557 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1669,7 +1669,7 @@ std::string wallets_manager::get_wallet_info_extra(uint64_t wallet_id, view::wal std::string wallets_manager::get_contracts(size_t wallet_id, std::vector& contracts) { - tools::wallet2::escrow_contracts_container cc; + tools::escrow_contracts_container cc; GET_WALLET_OPT_BY_ID(wallet_id, w); try { @@ -1693,7 +1693,7 @@ std::string wallets_manager::get_contracts(size_t wallet_id, std::vector& accs, found_timestamp = context.sk.block_timestamp; found_kh = crypto::cn_fast_hash(&context.sk, sizeof(context.sk)); // TODO: consider passing kernel_hash from scan_pos and do_pos_mining_iteration - tools::wallet2::transfer_details td = AUTO_VAL_INIT(td); + tools::transfer_details td = AUTO_VAL_INIT(td); r = w->get_transfer_info_by_index(context.index, td); CHECK_AND_NO_ASSERT_MES(r, false, "get_transfer_info_by_index() failed for index " << context.index); @@ -2151,18 +2151,18 @@ bool make_tx_multisig_to_key(const currency::transaction& source_tx, bool estimate_wallet_balance_blocked_for_escrow(const tools::wallet2& w, uint64_t& result, bool substruct_change_from_result /* = true */) { - std::deque transfers; + std::deque transfers; w.get_transfers(transfers); result = 0; - for (const tools::wallet2::transfer_details& td : transfers) + for (const tools::transfer_details& td : transfers) { if (td.m_flags == (WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION)) result += td.amount(); } if (substruct_change_from_result) { - const std::list& ee = w.get_expiration_entries(); + const std::list& ee = w.get_expiration_entries(); for (auto &e : ee) { uint64_t change_amount_native = 0; diff --git a/tests/core_tests/escrow_wallet_altchain_test.cpp b/tests/core_tests/escrow_wallet_altchain_test.cpp index 3b105cae..a59063c2 100644 --- a/tests/core_tests/escrow_wallet_altchain_test.cpp +++ b/tests/core_tests/escrow_wallet_altchain_test.cpp @@ -312,7 +312,7 @@ bool escrow_altchain_meta_impl::c1(currency::core& c, size_t ev_index, const std LOG_PRINT_YELLOW("sub event #" << eam_event_index << " (height " << e.height << "): eam_event_refresh_and_check", LOG_LEVEL_0); LOG_PRINT_GREEN("Alice's wallet is refreshing...", LOG_LEVEL_1); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; bool stub; alice_wlt->scan_tx_pool(stub); size_t blocks_fetched = 0; diff --git a/tests/core_tests/escrow_wallet_common.h b/tests/core_tests/escrow_wallet_common.h index 85264e9b..f084809c 100644 --- a/tests/core_tests/escrow_wallet_common.h +++ b/tests/core_tests/escrow_wallet_common.h @@ -67,7 +67,7 @@ inline bool refresh_wallet_and_check_1_contract_state(const char* wallet_name, s LOG_PRINT_CYAN("Scan tx pool for " << wallet_name << "'s wallet...", LOG_LEVEL_0); wallet->scan_tx_pool(stub_bool); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = wallet->get_contracts(contracts); CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for " << wallet_name << " failed or returned wrong contracts count: " << contracts.size()); CHECK_AND_ASSERT_MES(contracts.begin()->second.state == expected_contract_state, false, wallet_name << " has invalid contract state: " << tools::wallet_public::get_escrow_contract_state_name(contracts.begin()->second.state) @@ -85,7 +85,7 @@ inline bool refresh_wallet_and_check_contract_state(const char* wallet_name, std CHECK_AND_ASSERT_MES(block_to_be_fetched == SIZE_MAX || blocks_fetched == block_to_be_fetched, false, wallet_name << ": incorrect amount of fetched blocks: " << blocks_fetched << ", expected: " << block_to_be_fetched); wallet->scan_tx_pool(stub_bool); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = wallet->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for " << wallet_name << " failed"); for (const auto& c : contracts) @@ -611,7 +611,7 @@ inline bool operator==(const bc_services::contract_private_details& lhs, const b lhs.title == rhs.title; } -inline bool check_contract_state(const tools::wallet2::escrow_contracts_container& contracts, const bc_services::contract_private_details& cpd, tools::wallet_public::escrow_contract_details::contract_state state, const char* party) +inline bool check_contract_state(const tools::escrow_contracts_container& contracts, const bc_services::contract_private_details& cpd, tools::wallet_public::escrow_contract_details::contract_state state, const char* party) { CHECK_AND_ASSERT_MES(contracts.size() == 1, false, party << " has incorrect number of contracts: " << contracts.size()); CHECK_AND_ASSERT_MES(contracts.begin()->second.private_detailes == cpd, false, party << " has invalid contract's private details"); diff --git a/tests/core_tests/escrow_wallet_tests.cpp b/tests/core_tests/escrow_wallet_tests.cpp index d8fbf387..b4bfaca3 100644 --- a/tests/core_tests/escrow_wallet_tests.cpp +++ b/tests/core_tests/escrow_wallet_tests.cpp @@ -126,7 +126,7 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const wallet_buyer->refresh(); wallet_seller->refresh(); - tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller; + tools::escrow_contracts_container contracts_buyer, contracts_seller; wallet_buyer->get_contracts(contracts_buyer); wallet_seller->get_contracts(contracts_seller); @@ -163,7 +163,7 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const CHECK_AND_FORCE_ASSERT_MES(contracts_buyer.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_buyer state"); CHECK_AND_FORCE_ASSERT_MES(contracts_seller.begin()->second.state == tools::wallet_public::escrow_contract_details_basic::contract_accepted, false, "Incorrect contracts_seller state"); - tools::wallet2::multisig_transfer_container ms_buyer, ms_seller; + tools::multisig_transfer_container ms_buyer, ms_seller; wallet_buyer->get_multisig_transfers(ms_buyer); wallet_seller->get_multisig_transfers(ms_seller); CHECK_AND_FORCE_ASSERT_MES(ms_buyer.size() == 1, false, "Incorrect contracts_buyer state"); @@ -195,7 +195,7 @@ bool escrow_wallet_test::exec_test_with_specific_release_type(currency::core& c, expected_state = tools::wallet_public::escrow_contract_details_basic::contract_released_burned; } - tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller; + tools::escrow_contracts_container contracts_buyer, contracts_seller; wallet_buyer->finish_contract(multisig_id, release_instruction); r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); @@ -232,7 +232,7 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c wallet_miner->transfer(TESTS_DEFAULT_FEE, wallet_buyer->get_account().get_public_address()); r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 10); wallet_buyer->refresh(); - tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller; + tools::escrow_contracts_container contracts_buyer, contracts_seller; wallet_buyer->request_cancel_contract(multisig_id, TESTS_DEFAULT_FEE, 60 * 60); r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); @@ -643,7 +643,7 @@ bool escrow_incorrect_proposal::check_normal_proposal(currency::core& c, size_t std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); alice_wlt->refresh(); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice didn't receive escrow proposal"); CHECK_AND_ASSERT_MES(contracts.begin()->second.is_a == false, false, "proposal has wrong is_a"); @@ -682,7 +682,7 @@ bool escrow_incorrect_proposal::check_incorrect_proposal(currency::core& c, size std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX); alice_wlt->refresh(); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; alice_wlt->get_contracts(contracts); if (contracts.size() != 0) @@ -780,7 +780,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st uint64_t alice_post_proposal_balance = alice_wlt->balance(); uint64_t alice_post_proposal_balance_expected = alice_start_balance - TESTS_DEFAULT_FEE; CHECK_AND_ASSERT_MES(alice_post_proposal_balance == alice_post_proposal_balance_expected, false, "Incorrect alice_post_proposal_balance: " << print_money(alice_post_proposal_balance) << ", expected: " << print_money(alice_post_proposal_balance_expected)); - std::deque transfers; + std::deque transfers; alice_wlt->get_transfers(transfers); CHECK_AND_ASSERT_MES(transfers.size() == 2 && ( (transfers[0].is_spent() && (transfers[1].m_flags & (WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION))) || @@ -1330,7 +1330,7 @@ bool escrow_incorrect_proposal_acceptance::check_normal_acceptance(currency::cor CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); @@ -1393,7 +1393,7 @@ bool escrow_incorrect_proposal_acceptance::check_incorrect_acceptance(currency:: alice_wlt->dump_trunsfers(ss, false); LOG_PRINT_L0("check_incorrect_acceptance(" << param << "):" << ENDL << "Alice balance: " << print_money(alice_balance) << ", transfers: " << ENDL << ss.str()); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); @@ -1723,7 +1723,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons bob_wlt->refresh(); CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_start_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, ""); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = bob_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Bob failed"); CHECK_AND_ASSERT_MES(check_contract_state(contracts, cd.cpd, tools::wallet_public::escrow_contract_details::proposal_sent, "Bob"), false, "wrong contract"); @@ -2121,7 +2121,7 @@ bool escrow_incorrect_cancel_proposal::check_normal_cancel_proposal(currency::co CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size()); @@ -2209,7 +2209,7 @@ bool escrow_incorrect_cancel_proposal::check_incorrect_cancel_proposal_internal( CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size()); @@ -2283,7 +2283,7 @@ bool escrow_proposal_not_enough_money::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", MK_TEST_COINS(30), 0, MK_TEST_COINS(30), 0, 0), false, ""); - std::deque transfers; + std::deque transfers; alice_wlt->get_transfers(transfers); CHECK_AND_ASSERT_MES(transfers.size() == 1, false, "Incorrect transfers size: " << transfers.size()); @@ -2392,7 +2392,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co LOG_PRINT_GREEN("\n" "alice_wlt->send_escrow_proposal()", LOG_LEVEL_0); alice_wlt->send_escrow_proposal(cpd, 0, 0, expiration_time, TESTS_DEFAULT_FEE, TESTS_DEFAULT_FEE, "", proposal_tx, escrow_template_tx); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size()); @@ -2593,7 +2593,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in LOG_PRINT_GREEN("\n" "alice_wlt->send_escrow_proposal()", LOG_LEVEL_0); alice_wlt->send_escrow_proposal(cpd, 0, 0, expiration_time, TESTS_DEFAULT_FEE, b_release_fee, "", proposal_tx, escrow_template_tx); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r, false, "get_contracts() for Alice failed"); CHECK_AND_ASSERT_MES(contracts.size() == 1, false, "Alice has incorrect number of contracts: " << contracts.size()); @@ -2843,7 +2843,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Alice", alice_wlt, tools::wallet_public::escrow_contract_details::proposal_sent), false, ""); CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_public::escrow_contract_details::proposal_sent), false, ""); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed"); crypto::hash contract_id = contracts.begin()->first; @@ -3217,7 +3217,7 @@ bool escrow_balance::c1(currency::core& c, size_t ev_index, const std::vectorcheck(), false, "balance callback check failed, see above"); - tools::wallet2::escrow_contracts_container contracts; + tools::escrow_contracts_container contracts; r = alice_wlt->get_contracts(contracts); CHECK_AND_ASSERT_MES(r && contracts.size() == 1, false, "get_contracts() for Alice failed"); crypto::hash contract_id = contracts.begin()->first; diff --git a/tests/core_tests/multiassets_test.cpp b/tests/core_tests/multiassets_test.cpp index 6a92499d..a186d7bb 100644 --- a/tests/core_tests/multiassets_test.cpp +++ b/tests/core_tests/multiassets_test.cpp @@ -493,9 +493,9 @@ bool assets_and_explicit_native_coins_in_outs::c2_alice_deploys_asset(currency:: CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_initial_balance - TESTS_DEFAULT_FEE, 0, m_alice_initial_balance - TESTS_DEFAULT_FEE, 0, 0), false, ""); // make sure Alice has two UTXO now - tools::wallet2::transfer_container transfers{}; + tools::transfer_container transfers{}; alice_wlt->get_transfers(transfers); - size_t unspent_transfers = std::count_if(transfers.begin(), transfers.end(), [](const tools::wallet2::transfer_details& tr){ return !tr.is_spent(); }); + size_t unspent_transfers = std::count_if(transfers.begin(), transfers.end(), [](const tools::transfer_details& tr){ return !tr.is_spent(); }); CHECK_AND_ASSERT_MES(unspent_transfers == 2, false, "unexpected number of Alice's unspent transfers: " << unspent_transfers); asset_descriptor_base adb{}; @@ -654,7 +654,7 @@ bool asset_depoyment_and_few_zc_utxos::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", m_alice_initial_balance, 0, m_alice_initial_balance, 0, 0), false, ""); // make sure Alice has correct UTXO wallet structure - tools::wallet2::transfer_container transfers{}; + tools::transfer_container transfers{}; alice_wlt->get_transfers(transfers); size_t zc_unspent_outs = 0, unspent_outs = 0; for(auto& td : transfers) diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 1253b6ee..fd327b76 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -185,7 +185,7 @@ bool multisig_wallet_test::c1(currency::core& c, size_t ev_index, const std::vec wallet_a->refresh(); wallet_b->refresh(); - tools::wallet2::multisig_transfer_container ms_a, ms_b; + tools::multisig_transfer_container ms_a, ms_b; wallet_a->get_multisig_transfers(ms_a); wallet_b->get_multisig_transfers(ms_b); CHECK_AND_ASSERT_MES(ms_a.size() == 1 && ms_b.size() == 1, false, "Multisig failed: ms_a.size() == 1 && ms_b.size() == 1"); @@ -334,7 +334,7 @@ bool multisig_wallet_test_many_dst::c1(currency::core& c, size_t ev_index, const r = check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", amount - TESTS_DEFAULT_FEE); CHECK_AND_ASSERT_MES(r, false, "invalid balance"); - tools::wallet2::multisig_transfer_container mstc; + tools::multisig_transfer_container mstc; alice_wlt->get_multisig_transfers(mstc); CHECK_AND_ASSERT_MES(mstc.empty(), false, "Got invalid multisig transfer"); @@ -446,7 +446,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(blocks_fetched == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1, false, "Incorrect numbers of blocks fetched"); r = check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", amount5 + TESTS_DEFAULT_FEE); CHECK_AND_ASSERT_MES(r, false, "Invalid wallet balance"); - tools::wallet2::multisig_transfer_container alice_mstc; + tools::multisig_transfer_container alice_mstc; alice_wlt->get_multisig_transfers(alice_mstc); CHECK_AND_ASSERT_MES(alice_mstc.size() == 2 && alice_mstc.count(ms1_hash) == 1 && alice_mstc.count(ms3_hash) == 1, false, "Alice has incorrect multisig transfers"); @@ -456,7 +456,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(blocks_fetched == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1, false, "Incorrect numbers of blocks fetched"); r = check_balance_via_wallet(*bob_wlt.get(), "bob_wlt", 0); CHECK_AND_ASSERT_MES(r, false, "Invalid wallet balance"); - tools::wallet2::multisig_transfer_container bob_mstc; + tools::multisig_transfer_container bob_mstc; bob_wlt->get_multisig_transfers(bob_mstc); CHECK_AND_ASSERT_MES(bob_mstc.size() == 2 && bob_mstc.count(ms1_hash) == 1 && bob_mstc.count(ms4_hash) == 1, false, "Bob has incorrect multisig transfers"); @@ -466,7 +466,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(blocks_fetched == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1, false, "Incorrect numbers of blocks fetched"); r = check_balance_via_wallet(*carol_wlt.get(), "carol_wlt", 0); CHECK_AND_ASSERT_MES(r, false, "Invalid wallet balance"); - tools::wallet2::multisig_transfer_container carol_mstc; + tools::multisig_transfer_container carol_mstc; carol_wlt->get_multisig_transfers(carol_mstc); CHECK_AND_ASSERT_MES(carol_mstc.size() == 2 && carol_mstc.count(ms2_hash) == 1 && carol_mstc.count(ms4_hash) == 1, false, "Carol has incorrect multisig transfers"); @@ -476,7 +476,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(blocks_fetched == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1, false, "Incorrect numbers of blocks fetched"); r = check_balance_via_wallet(*dan_wlt.get(), "dan_wlt", amount6 + TESTS_DEFAULT_FEE); CHECK_AND_ASSERT_MES(r, false, "Invalid wallet balance"); - tools::wallet2::multisig_transfer_container dan_mstc; + tools::multisig_transfer_container dan_mstc; dan_wlt->get_multisig_transfers(dan_mstc); CHECK_AND_ASSERT_MES(dan_mstc.size() == 2 && dan_mstc.count(ms2_hash) == 1 && dan_mstc.count(ms3_hash) == 1, false, "Dan has incorrect multisig transfers"); @@ -2540,7 +2540,7 @@ bool multisig_unconfirmed_transfer_and_multiple_scan_pool_calls::c1(currency::co miner_wlt->refresh(); alice_wlt->refresh(); - tools::wallet2::multisig_transfer_container ms_m, ms_a; + tools::multisig_transfer_container ms_m, ms_a; miner_wlt->get_multisig_transfers(ms_m); alice_wlt->get_multisig_transfers(ms_a); CHECK_AND_ASSERT_MES(ms_m.size() == 1 && ms_a.size() == 1, false, "Multisig failed: ms_m.size() == 1 && ms_a.size() == 1"); @@ -2571,7 +2571,7 @@ bool multisig_unconfirmed_transfer_and_multiple_scan_pool_calls::c1(currency::co LOG_PRINT_YELLOW("%%%%% tx " << get_transaction_hash(tx) << " is spending multisig output " << multisig_id, LOG_LEVEL_0); bool stub; - std::deque transfers; + std::deque transfers; std::vector unconfirmed_transfers; alice_wlt->scan_tx_pool(stub); diff --git a/tests/core_tests/wallet_rpc_tests.cpp b/tests/core_tests/wallet_rpc_tests.cpp index 4db60da5..a767071a 100644 --- a/tests/core_tests/wallet_rpc_tests.cpp +++ b/tests/core_tests/wallet_rpc_tests.cpp @@ -144,7 +144,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, tds.amount), false, ""); // check the transfer has been received - std::list payments; + std::list payments; alice_wlt->get_payments(payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 1, false, "Invalid payments count: " << payments.size()); CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(3), false, "Invalid payment"); @@ -254,7 +254,7 @@ bool wallet_rpc_transfer::c1(currency::core& c, size_t ev_index, const std::vect CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, tds.amount), false, ""); // check the transfer has been received - tools::wallet2::transfer_details td = AUTO_VAL_INIT(td); + tools::transfer_details td = AUTO_VAL_INIT(td); CHECK_AND_ASSERT_MES(alice_wlt->get_transfer_info_by_index(0, td), false, ""); CHECK_AND_ASSERT_MES(td.amount() == MK_TEST_COINS(3), false, "Invalid payment"); CHECK_AND_ASSERT_MES(check_mixin_value_for_each_input(2, td.tx_hash(), c), false, ""); diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 08c113eb..c4ed9c93 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1072,10 +1072,10 @@ bool gen_wallet_payment_id::generate(std::vector& events) cons CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(alice_wlt, MK_TEST_COINS(40 + 5 + 7 - 10 + 13 + 1) - TESTS_DEFAULT_FEE); DO_CALLBACK_PARAMS(events, "check_balance", params_check_balance(ALICE_ACC_IDX, MK_TEST_COINS(40 + 5 + 7 - 10 + 13 + 1) - TESTS_DEFAULT_FEE)); - std::list payments; + std::list payments; alice_wlt->get_payments(m_payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 3, false, "Invalid payments count"); - payments.sort([](const tools::wallet2::payment_details& lhs, const tools::wallet2::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks + payments.sort([](const tools::payment_details& lhs, const tools::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(5) && payments.front().m_tx_hash == get_transaction_hash(tx_1), false, "Invalid payments #1"); CHECK_AND_ASSERT_MES(payments.back().m_amount == MK_TEST_COINS(13) && payments.back().m_tx_hash == get_transaction_hash(tx_4), false, "Invalid payments #3"); payments.clear(); @@ -1104,7 +1104,7 @@ bool gen_wallet_payment_id::generate(std::vector& events) cons payments.clear(); alice_wlt->get_payments(m_payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 3, false, "Invalid payments count (2)"); - payments.sort([](const tools::wallet2::payment_details& lhs, const tools::wallet2::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks + payments.sort([](const tools::payment_details& lhs, const tools::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(5) && payments.front().m_tx_hash == get_transaction_hash(tx_1), false, "Invalid payments #1"); CHECK_AND_ASSERT_MES(payments.back().m_amount == MK_TEST_COINS(9) && payments.back().m_tx_hash == get_transaction_hash(tx_6), false, "Invalid payments #3"); @@ -1126,10 +1126,10 @@ bool gen_wallet_payment_id::c1(currency::core& c, size_t ev_index, const std::ve if (!check_balance_via_wallet(*alice_wlt.get(), "alice_wlt", MK_TEST_COINS(56) - TESTS_DEFAULT_FEE, 0, 0, 0, 0)) return false; - std::list payments; + std::list payments; alice_wlt->get_payments(m_payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 3, false, "Invalid payments count (4)"); - payments.sort([](const tools::wallet2::payment_details& lhs, const tools::wallet2::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks + payments.sort([](const tools::payment_details& lhs, const tools::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(5), false, "Invalid payments #1"); CHECK_AND_ASSERT_MES(payments.back().m_amount == MK_TEST_COINS(13), false, "Invalid payments #3"); @@ -1157,10 +1157,10 @@ bool gen_wallet_payment_id::c2(currency::core& c, size_t ev_index, const std::ve return false; - std::list payments; + std::list payments; alice_wlt->get_payments(m_payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 3, false, "Invalid payments count (4)"); - payments.sort([](const tools::wallet2::payment_details& lhs, const tools::wallet2::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks + payments.sort([](const tools::payment_details& lhs, const tools::payment_details& rhs) -> bool { return lhs.m_amount < rhs.m_amount; } ); // sort payments by amount to order them for further checks CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(5), false, "Invalid payments #1"); CHECK_AND_ASSERT_MES(payments.back().m_amount == MK_TEST_COINS(9), false, "Invalid payments #3"); @@ -1230,7 +1230,7 @@ bool gen_wallet_oversized_payment_id::c1(currency::core& c, size_t ev_index, con alice_wlt->refresh(blocks_fetched, received_money, atomic_false); CHECK_AND_ASSERT_MES(blocks_fetched == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3 + 1, false, "incorrect number of blocks fetched by Alice's wallet: " << blocks_fetched); - std::list payments; + std::list payments; alice_wlt->get_payments(payment_id, payments); CHECK_AND_ASSERT_MES(payments.size() == 1, false, "Invalid payments count: " << payments.size()); CHECK_AND_ASSERT_MES(payments.front().m_amount == MK_TEST_COINS(3), false, "Invalid payment"); @@ -1306,7 +1306,7 @@ bool gen_wallet_transfers_and_outdated_unconfirmed_txs::generate(std::vectorget_transfers(trs); CHECK_AND_ASSERT_MES(trs.size() == 2 && !trs[0].is_spent() && !trs[1].is_spent(), false, "Wrong transfers state"); @@ -1383,7 +1383,7 @@ bool gen_wallet_transfers_and_chain_switch::generate(std::vectorget_transfers(trs); CHECK_AND_ASSERT_MES(trs.size() == 2 && !trs[0].is_spent() && !trs[1].is_spent(), false, "Wrong transfers state"); diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index b6128929..95646b63 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -193,11 +193,11 @@ bool do_send_money_by_fractions(tools::wallet2& w1, tools::wallet2& w2, size_t m } } -uint64_t got_money_in_first_transfers(const tools::wallet2::transfer_container& incoming_transfers, size_t n_transfers) +uint64_t got_money_in_first_transfers(const tools::transfer_container& incoming_transfers, size_t n_transfers) { uint64_t summ = 0; size_t count = 0; - BOOST_FOREACH(const tools::wallet2::transfer_details& td, incoming_transfers) + BOOST_FOREACH(const tools::transfer_details& td, incoming_transfers) { summ += boost::get(td.m_ptx_wallet_info->m_tx.vout[td.m_internal_output_index]).amount; if(++count >= n_transfers) @@ -240,7 +240,7 @@ void wait_unlock_money(tools::wallet2& w, flow_test_context& control) std::string get_incoming_transfers_str(tools::wallet2& w) { - tools::wallet2::transfer_container transfers; + tools::transfer_container transfers; w.get_transfers(transfers); uint64_t spent_count = 0; @@ -453,7 +453,7 @@ bool transactions_flow_test( LOG_PRINT_GREEN("Transfers: " << get_incoming_transfers_str(w1), LOG_LEVEL_0); uint64_t transfer_size = TX_DEFAULT_FEE;//amount_to_transfer / transactions_count; - tools::wallet2::transfer_container incoming_transfers; + tools::transfer_container incoming_transfers; size_t prepared_transfers = 0; @@ -469,7 +469,7 @@ bool transactions_flow_test( //lets go! size_t count = 0; prepared_transfers = 0; - BOOST_FOREACH(tools::wallet2::transfer_details& td, incoming_transfers) + BOOST_FOREACH(tools::transfer_details& td, incoming_transfers) { if (td.is_spent()) continue; From d1dc240a733b12345f664749b2a7266cf419ca61 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 18:37:58 +0100 Subject: [PATCH 090/127] added forgoten wallet2_base.h --- src/wallet/wallet2_base.h | 493 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 493 insertions(+) create mode 100644 src/wallet/wallet2_base.h diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h new file mode 100644 index 00000000..26978519 --- /dev/null +++ b/src/wallet/wallet2_base.h @@ -0,0 +1,493 @@ +// Copyright (c) 2014-2023 Zano Project +// Copyright (c) 2014-2018 The Louisdor Project +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#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" + + +#include "currency_core/currency_boost_serialization.h" +#include "currency_core/account_boost_serialization.h" +#include "currency_core/currency_format_utils.h" + +#include "common/make_hashable.h" +#include "wallet_public_structs_defs.h" +#include "currency_core/currency_format_utils.h" +#include "common/unordered_containers_boost_serialization.h" +#include "common/atomics_boost_serialization.h" +#include "storages/portable_storage_template_helper.h" +#include "crypto/chacha8.h" +#include "crypto/hash.h" +#include "core_rpc_proxy.h" +#include "core_default_rpc_proxy.h" +#include "wallet_errors.h" +#include "currency_core/core_runtime_config.h" +#include "currency_core/bc_offers_serialization.h" +#include "currency_core/bc_escrow_service.h" +#include "common/pod_array_file_container.h" +#include "wallet_chain_shortener.h" +#include "tor-connect/torlib/tor_lib_iface.h" +#include "currency_core/pos_mining.h" +#include "view_iface.h" + + +#define WALLET_TRANSFER_DETAIL_FLAG_SPENT uint32_t(1 << 0) +#define WALLET_TRANSFER_DETAIL_FLAG_BLOCKED uint32_t(1 << 1) +#define WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION uint32_t(1 << 2) +#define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3) +#define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing) +#define WALLET_TRANSFER_DETAIL_FLAG_HTLC_REDEEM uint32_t(1 << 5) // for htlc keeps info if this htlc belong as redeem or as refund + + + +namespace tools +{ + +#pragma pack(push, 1) + struct out_key_to_ki + { + crypto::public_key out_key; + crypto::key_image key_image; + }; +#pragma pack(pop) + + typedef tools::pod_array_file_container pending_ki_file_container_t; + + namespace detail + { + //---------------------------------------------------------------------------------------------------- + inline void digit_split_strategy(const std::vector& dsts, + const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, + std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) + { + splitted_dsts.clear(); + dust = 0; + + for (auto& de : dsts) + { + if (de.addr.size() > 1) + { + //for multisig we don't split + splitted_dsts.push_back(de); + } + else if (de.htlc_options.expiration != 0) + { + //for htlc we don't do split + splitted_dsts.push_back(de); + } + else + { + currency::decompose_amount_into_digits(de.amount, dust_threshold, + [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, de.addr, de.asset_id)); }, + [&](uint64_t a_dust) { splitted_dsts.push_back(currency::tx_destination_entry(a_dust, de.addr, de.asset_id)); }, max_output_allowed); + } + } + + if (change_dst.amount > 0) + { + if (change_dst.addr.size() > 1) + { + //for multisig we don't split + splitted_dsts.push_back(change_dst); + } + else + { + currency::decompose_amount_into_digits(change_dst.amount, dust_threshold, + [&](uint64_t chunk) { splitted_dsts.push_back(currency::tx_destination_entry(chunk, change_dst.addr)); }, + [&](uint64_t a_dust) { dust = a_dust; }, max_output_allowed); + } + } + } + //---------------------------------------------------------------------------------------------------- + inline void null_split_strategy(const std::vector& dsts, + const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, + std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) + { + splitted_dsts = dsts; + + dust = 0; + uint64_t change = change_dst.amount; + if (0 < dust_threshold) + { + for (uint64_t order = 10; order <= 10 * dust_threshold; order *= 10) + { + uint64_t dust_candidate = change_dst.amount % order; + uint64_t change_candidate = (change_dst.amount / order) * order; + if (dust_candidate <= dust_threshold) + { + dust = dust_candidate; + change = change_candidate; + } + else + { + break; + } + } + } + + if (0 != change) + { + splitted_dsts.push_back(currency::tx_destination_entry(change, change_dst.addr)); + } + } + //---------------------------------------------------------------------------------------------------- + inline void void_split_strategy(const std::vector& dsts, + const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, + std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) + { + splitted_dsts.insert(splitted_dsts.end(), dsts.begin(), dsts.end()); + if (change_dst.amount > 0) + splitted_dsts.push_back(change_dst); + } + //---------------------------------------------------------------------------------------------------- + enum split_strategy_id_t { ssi_none = 0, ssi_digit = 1, ssi_null = 2, ssi_void = 3 }; + //---------------------------------------------------------------------------------------------------- + inline bool apply_split_strategy_by_id(split_strategy_id_t id, const std::vector& dsts, + const currency::tx_destination_entry& change_dst, uint64_t dust_threshold, + std::vector& splitted_dsts, uint64_t& dust, uint64_t max_output_allowed) + { + switch (id) + { + case ssi_digit: + digit_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); + return true; + case ssi_null: + null_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); + return true; + case ssi_void: + void_split_strategy(dsts, change_dst, dust_threshold, splitted_dsts, dust, max_output_allowed); + return true; + default: + return false; + } + } + + } // namespace detail + + struct tx_dust_policy + { + uint64_t dust_threshold = 0; + bool add_to_fee = false; + currency::account_public_address addr_for_dust; + + tx_dust_policy(uint64_t a_dust_threshold = DEFAULT_DUST_THRESHOLD, bool an_add_to_fee = true, currency::account_public_address an_addr_for_dust = currency::account_public_address()) + : dust_threshold(a_dust_threshold) + , add_to_fee(an_add_to_fee) + , addr_for_dust(an_addr_for_dust) + { + } + + BEGIN_SERIALIZE_OBJECT() + FIELD(dust_threshold) + FIELD(add_to_fee) + FIELD(addr_for_dust) + END_SERIALIZE() + }; + + struct construct_tx_param + { + // preparing data for tx + std::vector dsts; + size_t fake_outputs_count = 0; + uint64_t fee = 0; + tx_dust_policy dust_policy; + crypto::hash multisig_id = currency::null_hash; + uint8_t flags = 0; + uint8_t split_strategy_id = 0; + bool mark_tx_as_complete = false; + + crypto::hash htlc_tx_id; + std::string htlc_origin; + + // constructing tx + uint64_t unlock_time = 0; + std::vector extra; + std::vector attachments; + currency::account_public_address crypt_address; + uint8_t tx_outs_attr = 0; + bool shuffle = false; + bool create_utxo_defragmentation_tx = false; + bool need_at_least_1_zc = false; + crypto::secret_key asset_deploy_control_key = currency::null_skey; + }; + + struct mode_separate_context + { + currency::transaction tx_for_mode_separate; + view::ionic_swap_proposal_info proposal_info; + bool escrow = false; + }; + + + struct selection_for_amount + { + uint64_t needed_amount = 0; + uint64_t found_amount = 0; + //std::vector selected_indicies; + }; + typedef std::unordered_map assets_selection_context; + + //general rollback mechanism + struct asset_register_event + { + crypto::public_key asset_id = currency::null_pkey; + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_id) + END_BOOST_SERIALIZATION() + + }; + + struct wallet_own_asset_context + { + currency::asset_descriptor_base asset_descriptor; + crypto::secret_key control_key; + //uint64_t height = 0; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_descriptor) + BOOST_SERIALIZE(control_key) + //BOOST_SERIALIZE(height) + END_BOOST_SERIALIZATION() + }; + + struct asset_update_event + { + crypto::public_key asset_id = currency::null_pkey; + wallet_own_asset_context own_context; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_id) + BOOST_SERIALIZE(own_context) + END_BOOST_SERIALIZATION() + }; + + struct asset_unown_event + { + crypto::public_key asset_id = currency::null_pkey; + wallet_own_asset_context own_context; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_id) + BOOST_SERIALIZE(own_context) + END_BOOST_SERIALIZATION() + }; + + typedef boost::variant wallet_event_t; + + struct transaction_wallet_info + { + uint64_t m_block_height = 0; + uint64_t m_block_timestamp = 0; + currency::transaction m_tx; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(m_block_height) + KV_SERIALIZE(m_block_timestamp) + KV_SERIALIZE_CUSTOM(m_tx, std::string, tools::wallet2::transform_tx_to_str, tools::wallet2::transform_str_to_tx) + END_KV_SERIALIZE_MAP() + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(m_block_height) + BOOST_SERIALIZE(m_block_timestamp) + BOOST_SERIALIZE(m_tx) + END_BOOST_SERIALIZATION() + + }; + + + struct transfer_details_base + { + struct ZC_out_info // TODO: @#@# consider using wallet_out_info instead + { + ZC_out_info() = default; + ZC_out_info(const crypto::scalar_t& amount_blinding_mask, const crypto::scalar_t& asset_id_blinding_mask, const crypto::public_key& asset_id) + : amount_blinding_mask(amount_blinding_mask), asset_id_blinding_mask(asset_id_blinding_mask), asset_id(asset_id) + {} + crypto::scalar_t amount_blinding_mask = 0; + crypto::scalar_t asset_id_blinding_mask = 0; + crypto::public_key asset_id = currency::null_pkey; // not blinded, not multiplied by 1/8 TODO: @#@# consider changing to point_t, also consider using wallet wallet_out_info + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(amount_blinding_mask) + KV_SERIALIZE(asset_id_blinding_mask) + KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) + END_KV_SERIALIZE_MAP() + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(amount_blinding_mask) + BOOST_SERIALIZE(asset_id_blinding_mask) + BOOST_SERIALIZE(asset_id) + END_BOOST_SERIALIZATION() + }; + + std::shared_ptr m_ptx_wallet_info; + uint64_t m_internal_output_index = 0; + uint64_t m_spent_height = 0; + uint32_t m_flags = 0; + uint64_t m_amount = 0; + boost::shared_ptr m_zc_info_ptr; + + uint64_t amount() const { return m_amount; } + uint64_t amount_for_global_output_index() const { return is_zc() ? 0 : m_amount; } // amount value for global outputs index, it's zero for outputs with hidden amounts + + // @#@ will throw if type is not tx_out_bare, TODO: change according to new model, + // need to replace all get_tx_out_bare_from_out_v() to proper code + //const currency::tx_out_bare& output() const { return currency::get_tx_out_bare_from_out_v(m_ptx_wallet_info->m_tx.vout[m_internal_output_index]); } + + const currency::tx_out_v& output() const { return m_ptx_wallet_info->m_tx.vout[m_internal_output_index]; } + uint8_t mix_attr() const { uint8_t result = UINT8_MAX; get_mix_attr_from_tx_out_v(output(), result); return result; } + crypto::hash tx_hash() const { return get_transaction_hash(m_ptx_wallet_info->m_tx); } + bool is_spent() const { return m_flags & WALLET_TRANSFER_DETAIL_FLAG_SPENT; } + bool is_spendable() const { return (m_flags & (WALLET_TRANSFER_DETAIL_FLAG_SPENT | WALLET_TRANSFER_DETAIL_FLAG_BLOCKED | WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION | WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION)) == 0; } + bool is_reserved_for_escrow() const { return ((m_flags & WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION) != 0); } + bool is_zc() const { return m_zc_info_ptr.get(); } + const crypto::public_key& get_asset_id() const { if (m_zc_info_ptr.get()) { return m_zc_info_ptr->asset_id; } else { return currency::native_coin_asset_id; } } + bool is_native_coin() const { return m_zc_info_ptr.get() ? (m_zc_info_ptr->asset_id == currency::native_coin_asset_id) : true; } + bool is_htlc() const { + + if (m_ptx_wallet_info->m_tx.vout[m_internal_output_index].type() == typeid(currency::tx_out_bare) && + boost::get(m_ptx_wallet_info->m_tx.vout[m_internal_output_index]).target.type() == typeid(currency::txout_htlc)) + return true; + return false; + } + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, tools::wallet2::transform_ptr_to_value, tools::wallet2::transform_value_to_ptr) + KV_SERIALIZE(m_internal_output_index) + KV_SERIALIZE(m_spent_height) + KV_SERIALIZE(m_flags) + KV_SERIALIZE(m_amount) + KV_SERIALIZE_N(m_zc_info_ptr, "zc_out_info") + KV_SERIALIZE_EPHEMERAL_N(uint64_t, tools::transfer_details_base_to_amount, "amount") + KV_SERIALIZE_EPHEMERAL_N(std::string, tools::transfer_details_base_to_tx_hash, "tx_id") + END_KV_SERIALIZE_MAP() + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(m_ptx_wallet_info) + BOOST_SERIALIZE(m_internal_output_index) + BOOST_SERIALIZE(m_flags) + BOOST_SERIALIZE(m_spent_height) + BOOST_SERIALIZE(m_amount) + BOOST_SERIALIZE(m_zc_info_ptr) + END_BOOST_SERIALIZATION() + }; + + + struct transfer_details_extra_option_htlc_info + { + std::string origin; //this field filled only if htlc had been redeemed + crypto::hash redeem_tx_id = currency::null_hash; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(origin) + BOOST_SERIALIZE(redeem_tx_id) + END_BOOST_SERIALIZATION() + }; + + + typedef boost::variant transfer_details_extra_options_v; + + struct transfer_details : public transfer_details_base + { + uint64_t m_global_output_index = 0; + crypto::key_image m_key_image; //TODO: key_image stored twice :( + std::vector varian_options; + + //v2 + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(m_global_output_index) + KV_SERIALIZE_POD_AS_HEX_STRING(m_key_image) + KV_CHAIN_BASE(transfer_details_base) + END_KV_SERIALIZE_MAP() + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(m_global_output_index) + BOOST_SERIALIZE(m_key_image) + BOOST_SERIALIZE_BASE_CLASS(transfer_details_base) + BOOST_SERIALIZE(varian_options) + END_BOOST_SERIALIZATION() + }; + + //used in wallet + struct htlc_expiration_trigger + { + bool is_wallet_owns_redeem = false; //specify if this HTLC belong to this wallet by pkey_redeem or by pkey_refund + uint64_t transfer_index = 0; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(is_wallet_owns_redeem) + BOOST_SERIALIZE(transfer_index) + END_BOOST_SERIALIZATION() + }; + + + struct payment_details_subtransfer + { + crypto::public_key asset_id = currency::null_pkey; + uint64_t amount = 0; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(asset_id) + BOOST_SERIALIZE(amount) + END_BOOST_SERIALIZATION() + }; + + struct payment_details + { + crypto::hash m_tx_hash = currency::null_hash; + uint64_t m_amount = 0; // native coins amount + uint64_t m_block_height = 0; + uint64_t m_unlock_time = 0; + std::vector subtransfers; //subtransfers added for confidential asset only, native amount should be stored in m_amount (for space saving) + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(m_tx_hash) + BOOST_SERIALIZE(m_amount) + BOOST_SERIALIZE(m_block_height) + BOOST_SERIALIZE(m_unlock_time) + BOOST_SERIALIZE(subtransfers) + END_BOOST_SERIALIZATION() + }; + + struct expiration_entry_info + { + std::vector selected_transfers; + uint64_t expiration_time = 0; + crypto::hash related_tx_id = currency::null_hash; // tx id which caused money lock, if any (ex: escrow proposal transport tx) + std::vector receved; + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(selected_transfers) + BOOST_SERIALIZE(expiration_time) + BOOST_SERIALIZE(related_tx_id) + BOOST_SERIALIZE(receved) + END_BOOST_SERIALIZATION() + }; + + typedef std::unordered_multimap payment_container; + + typedef std::deque transfer_container; + typedef std::unordered_map multisig_transfer_container; + typedef std::unordered_map escrow_contracts_container; + typedef std::map > free_amounts_cache_type; + typedef std::unordered_map free_assets_amounts_cache_type; + typedef std::unordered_map, uint64_t> amount_gindex_to_transfer_id_container; // maps [amount; gindex] -> tid + +}// namespace tools + +BOOST_CLASS_VERSION(tools::transfer_details, 3) +BOOST_CLASS_VERSION(tools::transfer_details_base, 2) From cacdb4a4ce5be33e1ff7f2fa08e6747f4084c5f6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 19:22:29 +0100 Subject: [PATCH 091/127] moved serialization-specific adaptor-functions from wallet2 to base header file --- .../currency_format_utils_transactions.cpp | 24 +++++++++++++++++++ .../currency_format_utils_transactions.h | 6 +++++ src/wallet/wallet2.cpp | 22 ----------------- src/wallet/wallet2.h | 4 ---- src/wallet/wallet2_base.h | 4 ++-- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/currency_core/currency_format_utils_transactions.cpp b/src/currency_core/currency_format_utils_transactions.cpp index d4650dfa..7554aae5 100644 --- a/src/currency_core/currency_format_utils_transactions.cpp +++ b/src/currency_core/currency_format_utils_transactions.cpp @@ -408,4 +408,28 @@ namespace currency #endif } + //---------------------------------------------------------------------------------------------------- + std::string wallet2::transform_tx_to_str(const currency::transaction& tx) + { + return currency::obj_to_json_str(tx); + } + //---------------------------------------------------------------------------------------------------- + currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str) + { + THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called"); + return currency::transaction(); + } + //---------------------------------------------------------------------------------------------------- + const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr& a) + { + return *a; + } + //---------------------------------------------------------------------------------------------------- + std::shared_ptr wallet2::transform_value_to_ptr(const transaction_wallet_info& d) + { + THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); + return std::shared_ptr(); + } + + } \ No newline at end of file diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 087e19be..2944d755 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -329,5 +329,11 @@ namespace currency }; // struct tx_generation_context bool validate_tx_output_details_againt_tx_generation_context(const transaction& tx, const tx_generation_context& gen_context, const crypto::secret_key& onet_time_key); + std::string transform_tx_to_str(const transaction& tx); + transaction transform_str_to_tx(const std::string& tx_str); + const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr& a); + std::shared_ptr transform_value_to_ptr(const transaction_wallet_info& d); + + } // namespace currency diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c67243e9..0d1c3e6c 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -133,17 +133,6 @@ std::string wallet2::transfer_flags_to_str(uint32_t flags) return result; } //---------------------------------------------------------------------------------------------------- -std::string wallet2::transform_tx_to_str(const currency::transaction& tx) -{ - return currency::obj_to_json_str(tx); -} -//---------------------------------------------------------------------------------------------------- -currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str) -{ - THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called"); - return currency::transaction(); -} -//---------------------------------------------------------------------------------------------------- uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) { return tdb.amount(); @@ -153,17 +142,6 @@ std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) { return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); } -//---------------------------------------------------------------------------------------------------- -const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr& a) -{ - return *a; -} -//---------------------------------------------------------------------------------------------------- -std::shared_ptr wallet2::transform_value_to_ptr(const transaction_wallet_info& d) -{ - THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); - return std::shared_ptr(); -} //---------------------------------------------------------------------------------------------------- void wallet2::init(const std::string& daemon_address) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3d75569d..8c2974f3 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -224,11 +224,7 @@ namespace tools wallet2(); static std::string transfer_flags_to_str(uint32_t flags); - static std::string transform_tx_to_str(const currency::transaction& tx); - static currency::transaction transform_str_to_tx(const std::string& tx_str); - static const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr& a); - static std::shared_ptr transform_value_to_ptr(const transaction_wallet_info& d); static uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb); static std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb); diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h index 26978519..5f3e052f 100644 --- a/src/wallet/wallet2_base.h +++ b/src/wallet/wallet2_base.h @@ -298,7 +298,7 @@ namespace tools BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(m_block_height) KV_SERIALIZE(m_block_timestamp) - KV_SERIALIZE_CUSTOM(m_tx, std::string, tools::wallet2::transform_tx_to_str, tools::wallet2::transform_str_to_tx) + KV_SERIALIZE_CUSTOM(m_tx, std::string, currency::wallet2::transform_tx_to_str, currency::transform_str_to_tx) END_KV_SERIALIZE_MAP() BEGIN_BOOST_SERIALIZATION() @@ -366,7 +366,7 @@ namespace tools } BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, tools::wallet2::transform_ptr_to_value, tools::wallet2::transform_value_to_ptr) + KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, currency::transform_ptr_to_value, currency::transform_value_to_ptr) KV_SERIALIZE(m_internal_output_index) KV_SERIALIZE(m_spent_height) KV_SERIALIZE(m_flags) From 76577d21a9272a318c46377e62f15b7df4903bf2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 19:31:18 +0100 Subject: [PATCH 092/127] more fixes with namespaces and inline functions --- .../currency_format_utils_transactions.cpp | 11 ----------- .../currency_format_utils_transactions.h | 2 -- src/wallet/wallet2_base.h | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/currency_core/currency_format_utils_transactions.cpp b/src/currency_core/currency_format_utils_transactions.cpp index 7554aae5..d64ebd15 100644 --- a/src/currency_core/currency_format_utils_transactions.cpp +++ b/src/currency_core/currency_format_utils_transactions.cpp @@ -419,17 +419,6 @@ namespace currency THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called"); return currency::transaction(); } - //---------------------------------------------------------------------------------------------------- - const transaction_wallet_info& wallet2::transform_ptr_to_value(const std::shared_ptr& a) - { - return *a; - } - //---------------------------------------------------------------------------------------------------- - std::shared_ptr wallet2::transform_value_to_ptr(const transaction_wallet_info& d) - { - THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); - return std::shared_ptr(); - } } \ No newline at end of file diff --git a/src/currency_core/currency_format_utils_transactions.h b/src/currency_core/currency_format_utils_transactions.h index 2944d755..2fc8beaf 100644 --- a/src/currency_core/currency_format_utils_transactions.h +++ b/src/currency_core/currency_format_utils_transactions.h @@ -331,8 +331,6 @@ namespace currency bool validate_tx_output_details_againt_tx_generation_context(const transaction& tx, const tx_generation_context& gen_context, const crypto::secret_key& onet_time_key); std::string transform_tx_to_str(const transaction& tx); transaction transform_str_to_tx(const std::string& tx_str); - const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr& a); - std::shared_ptr transform_value_to_ptr(const transaction_wallet_info& d); diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h index 5f3e052f..8839c022 100644 --- a/src/wallet/wallet2_base.h +++ b/src/wallet/wallet2_base.h @@ -298,7 +298,7 @@ namespace tools BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(m_block_height) KV_SERIALIZE(m_block_timestamp) - KV_SERIALIZE_CUSTOM(m_tx, std::string, currency::wallet2::transform_tx_to_str, currency::transform_str_to_tx) + KV_SERIALIZE_CUSTOM(m_tx, std::string, currency::transform_tx_to_str, currency::transform_str_to_tx) END_KV_SERIALIZE_MAP() BEGIN_BOOST_SERIALIZATION() @@ -308,6 +308,20 @@ namespace tools END_BOOST_SERIALIZATION() }; + namespace detail + { + //---------------------------------------------------------------------------------------------------- + inline const transaction_wallet_info& transform_ptr_to_value(const std::shared_ptr& a) + { + return *a; + } + //---------------------------------------------------------------------------------------------------- + inline std::shared_ptr transform_value_to_ptr(const transaction_wallet_info& d) + { + THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); + return std::shared_ptr(); + } + } struct transfer_details_base @@ -366,7 +380,7 @@ namespace tools } BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, currency::transform_ptr_to_value, currency::transform_value_to_ptr) + KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, detail::transform_ptr_to_value, detail::transform_value_to_ptr) KV_SERIALIZE(m_internal_output_index) KV_SERIALIZE(m_spent_height) KV_SERIALIZE(m_flags) From 3f0bed48991d47dc0f6b51c2b5c49d597f79203a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 19:43:28 +0100 Subject: [PATCH 093/127] fixed few compilation issues --- src/currency_core/currency_format_utils_transactions.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/currency_core/currency_format_utils_transactions.cpp b/src/currency_core/currency_format_utils_transactions.cpp index d64ebd15..d29fab6a 100644 --- a/src/currency_core/currency_format_utils_transactions.cpp +++ b/src/currency_core/currency_format_utils_transactions.cpp @@ -409,15 +409,15 @@ namespace currency } //---------------------------------------------------------------------------------------------------- - std::string wallet2::transform_tx_to_str(const currency::transaction& tx) + std::string transform_tx_to_str(const currency::transaction& tx) { return currency::obj_to_json_str(tx); } //---------------------------------------------------------------------------------------------------- - currency::transaction wallet2::transform_str_to_tx(const std::string& tx_str) + transaction transform_str_to_tx(const std::string& tx_str) { - THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_str_to_tx shoruld never be called"); - return currency::transaction(); + CHECK_AND_ASSERT_THROW_MES(false, "transform_str_to_tx shoruld never be called"); + return transaction(); } From 66fbe640efa81b9c29b2cec4be3ee01848e43943 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 19:53:26 +0100 Subject: [PATCH 094/127] fixed few compilation issues - 2 --- src/wallet/wallet2.cpp | 11 ----------- src/wallet/wallet2.h | 2 -- src/wallet/wallet2_base.h | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0d1c3e6c..fa91f698 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -132,17 +132,6 @@ std::string wallet2::transfer_flags_to_str(uint32_t flags) result[4] = 'c'; return result; } -//---------------------------------------------------------------------------------------------------- -uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) -{ - return tdb.amount(); -} -//---------------------------------------------------------------------------------------------------- -std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) -{ - return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); -} - //---------------------------------------------------------------------------------------------------- void wallet2::init(const std::string& daemon_address) { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 8c2974f3..2b782d1e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -226,8 +226,6 @@ namespace tools static std::string transfer_flags_to_str(uint32_t flags); - static uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb); - static std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb); struct mining_context : public currency::pos_mining_context { diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h index 8839c022..fa6eb9ef 100644 --- a/src/wallet/wallet2_base.h +++ b/src/wallet/wallet2_base.h @@ -321,6 +321,16 @@ namespace tools THROW_IF_TRUE_WALLET_INT_ERR_EX_NO_HANDLER(false, "transform_value_to_ptr shoruld never be called"); return std::shared_ptr(); } + //---------------------------------------------------------------------------------------------------- + inline uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) + { + return tdb.amount(); + } + //---------------------------------------------------------------------------------------------------- + inline std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) + { + return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); + } } @@ -386,8 +396,8 @@ namespace tools KV_SERIALIZE(m_flags) KV_SERIALIZE(m_amount) KV_SERIALIZE_N(m_zc_info_ptr, "zc_out_info") - KV_SERIALIZE_EPHEMERAL_N(uint64_t, tools::transfer_details_base_to_amount, "amount") - KV_SERIALIZE_EPHEMERAL_N(std::string, tools::transfer_details_base_to_tx_hash, "tx_id") + KV_SERIALIZE_EPHEMERAL_N(uint64_t, detail::transfer_details_base_to_amount, "amount") + KV_SERIALIZE_EPHEMERAL_N(std::string, detail::transfer_details_base_to_tx_hash, "tx_id") END_KV_SERIALIZE_MAP() BEGIN_BOOST_SERIALIZATION() From 6f4d2477155ccd35d8aaf27f16784d60f2f3cc1b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 31 Oct 2023 20:01:31 +0100 Subject: [PATCH 095/127] fixed few compilation issues - 3 --- src/wallet/wallet2_base.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/wallet/wallet2_base.h b/src/wallet/wallet2_base.h index fa6eb9ef..52da0c59 100644 --- a/src/wallet/wallet2_base.h +++ b/src/wallet/wallet2_base.h @@ -308,6 +308,8 @@ namespace tools END_BOOST_SERIALIZATION() }; + + namespace detail { //---------------------------------------------------------------------------------------------------- @@ -322,15 +324,6 @@ namespace tools return std::shared_ptr(); } //---------------------------------------------------------------------------------------------------- - inline uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) - { - return tdb.amount(); - } - //---------------------------------------------------------------------------------------------------- - inline std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) - { - return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); - } } @@ -388,6 +381,17 @@ namespace tools return true; return false; } + static inline uint64_t transfer_details_base_to_amount(const transfer_details_base& tdb) + { + return tdb.amount(); + } + //---------------------------------------------------------------------------------------------------- + static inline std::string transfer_details_base_to_tx_hash(const transfer_details_base& tdb) + { + return epee::string_tools::pod_to_hex(currency::get_transaction_hash(tdb.m_ptx_wallet_info->m_tx)); + } + + BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE_CUSTOM(m_ptx_wallet_info, const transaction_wallet_info&, detail::transform_ptr_to_value, detail::transform_value_to_ptr) @@ -396,8 +400,8 @@ namespace tools KV_SERIALIZE(m_flags) KV_SERIALIZE(m_amount) KV_SERIALIZE_N(m_zc_info_ptr, "zc_out_info") - KV_SERIALIZE_EPHEMERAL_N(uint64_t, detail::transfer_details_base_to_amount, "amount") - KV_SERIALIZE_EPHEMERAL_N(std::string, detail::transfer_details_base_to_tx_hash, "tx_id") + KV_SERIALIZE_EPHEMERAL_N(uint64_t, transfer_details_base_to_amount, "amount") + KV_SERIALIZE_EPHEMERAL_N(std::string, transfer_details_base_to_tx_hash, "tx_id") END_KV_SERIALIZE_MAP() BEGIN_BOOST_SERIALIZATION() @@ -411,6 +415,8 @@ namespace tools }; + + struct transfer_details_extra_option_htlc_info { std::string origin; //this field filled only if htlc had been redeemed From 299124877e8f57fc0c30b4eb4eb041e7299683b7 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 31 Oct 2023 21:22:15 +0100 Subject: [PATCH 096/127] coretests: pos_mining_with_decoys test added --- src/currency_core/blockchain_storage.cpp | 4 +- tests/core_tests/chaingen_main.cpp | 1 + tests/core_tests/pos_basic_tests.cpp | 118 +++++++++++++++++++++++ tests/core_tests/pos_basic_tests.h | 10 ++ 4 files changed, 131 insertions(+), 2 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 6b8fb0d2..00b46131 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -2569,14 +2569,14 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO } if (result_outs.outs.size() < req.outs_count) { - LOG_PRINT_RED_L0("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.outs_count << ", added " << result_outs.outs.size() << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total"); + LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.outs_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.outs_count, req.use_forced_mix_outs) ? 1 : 0; - LOG_PRINT_RED_L0("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.outs_count << ", added " << added << " good outs from " << up_index_limit << " unlocked of " << outs_container_size << " total - respond with all good outs"); + LOG_PRINT_YELLOW("Not enough inputs for amount " << print_money_brief(amount) << ", needed " << req.outs_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; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 7fbdf178..e92e3f72 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -893,6 +893,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(pos_wallet_big_block_test); //GENERATE_AND_PLAY(block_template_against_txs_size); // Long test! by demand only GENERATE_AND_PLAY(pos_altblocks_validation); + GENERATE_AND_PLAY(pos_mining_with_decoys); // alternative blocks and generic chain-switching tests GENERATE_AND_PLAY(gen_chain_switch_pow_pos); diff --git a/tests/core_tests/pos_basic_tests.cpp b/tests/core_tests/pos_basic_tests.cpp index 22b40f78..6bc00a5d 100644 --- a/tests/core_tests/pos_basic_tests.cpp +++ b/tests/core_tests/pos_basic_tests.cpp @@ -139,3 +139,121 @@ bool gen_pos_basic_tests::check_exchange_1(currency::core& c, size_t ev_index, c CHECK_EQ(offers.size(), 1); return true; } + + +//------------------------------------------------------------------------------ + +pos_mining_with_decoys::pos_mining_with_decoys() +{ + REGISTER_CALLBACK_METHOD(pos_mining_with_decoys, c1); +} + +bool pos_mining_with_decoys::generate(std::vector& events) const +{ + uint64_t ts = test_core_time::get_time(); + m_accounts.resize(TOTAL_ACCS_COUNT); + currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); + currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); + currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); + currency::account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); + DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1); + + bool r = false; + std::vector sources; + r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), 2 * COIN, 0); + CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); + std::vector destinations; + destinations.emplace_back(47 * TESTS_DEFAULT_FEE, alice_acc.get_public_address()); + destinations.emplace_back(47 * TESTS_DEFAULT_FEE, miner_acc.get_public_address()); // as a decoy for Alice + destinations.emplace_back(5 * TESTS_DEFAULT_FEE, bob_acc.get_public_address()); + destinations.emplace_back(COIN, carol_acc.get_public_address()); + + transaction tx_0{}; + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0); + CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + events.push_back(tx_0); + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); + + REWIND_BLOCKS_N(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + DO_CALLBACK(events, "c1"); + + return true; +} + +bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + bool r = false; + CHECK_AND_ASSERT_MES(!c.get_blockchain_storage().get_core_runtime_config().is_hardfork_active_for_height(4, c.get_top_block_height()), false, "HF4 should not be active"); + + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); + miner_wlt->refresh(); + + std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); + alice_wlt->refresh(); + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", 47 * TESTS_DEFAULT_FEE, INVALID_BALANCE_VAL, 47 * TESTS_DEFAULT_FEE), false, ""); + + std::shared_ptr bob_wlt = init_playtime_test_wallet(events, c, m_accounts[BOB_ACC_IDX]); + bob_wlt->refresh(); + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt, "Bob", 5 * TESTS_DEFAULT_FEE, INVALID_BALANCE_VAL, 5 * TESTS_DEFAULT_FEE), false, ""); + + std::shared_ptr carol_wlt = init_playtime_test_wallet(events, c, m_accounts[CAROL_ACC_IDX]); + carol_wlt->refresh(); + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*carol_wlt, "Carol", COIN, INVALID_BALANCE_VAL, COIN), false, ""); + + + // 1. Alice should be able to mine a PoS block with 1 decoys (ring size == 2) + size_t top_block_height = c.get_top_block_height(); + + r = alice_wlt->try_mint_pos(m_accounts[ALICE_ACC_IDX].get_public_address()); + CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); + + { + block b{}; + CHECK_AND_ASSERT_MES(c.get_blockchain_storage().get_top_block(b), false, ""); + CHECK_AND_ASSERT_MES(get_block_height(b) == top_block_height + 1, false, "unexpected top block height"); + + txin_to_key& intk = boost::get(b.miner_tx.vin[1]); + CHECK_AND_ASSERT_MES(intk.amount == 47 * TESTS_DEFAULT_FEE, false, "incorrect amount: " << intk.amount); + CHECK_AND_ASSERT_MES(intk.key_offsets.size() == 2, false, "unexpected ring size: " << intk.key_offsets.size()); + } + + + // 2. Bob should only be able to mine a PoS block with zero decoys (ring size == 1) + top_block_height = c.get_top_block_height(); + + r = bob_wlt->try_mint_pos(m_accounts[BOB_ACC_IDX].get_public_address()); + CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); + + { + block b{}; + CHECK_AND_ASSERT_MES(c.get_blockchain_storage().get_top_block(b), false, ""); + CHECK_AND_ASSERT_MES(get_block_height(b) == top_block_height + 1, false, "unexpected top block height"); + + txin_to_key& intk = boost::get(b.miner_tx.vin[1]); + CHECK_AND_ASSERT_MES(intk.amount == 5 * TESTS_DEFAULT_FEE, false, "incorrect amount: " << intk.amount); + CHECK_AND_ASSERT_MES(intk.key_offsets.size() == 1, false, "unexpected ring size: " << intk.key_offsets.size()); + } + + + // 3. Carol should only be able to mine a PoS block with CURRENCY_DEFAULT_DECOY_SET_SIZE decoys (ring size == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1) + top_block_height = c.get_top_block_height(); + + r = carol_wlt->try_mint_pos(m_accounts[CAROL_ACC_IDX].get_public_address()); + CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); + + { + block b{}; + CHECK_AND_ASSERT_MES(c.get_blockchain_storage().get_top_block(b), false, ""); + CHECK_AND_ASSERT_MES(get_block_height(b) == top_block_height + 1, false, "unexpected top block height"); + + txin_to_key& intk = boost::get(b.miner_tx.vin[1]); + CHECK_AND_ASSERT_MES(intk.amount == COIN, false, "incorrect amount: " << intk.amount); + CHECK_AND_ASSERT_MES(intk.key_offsets.size() == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1, false, "unexpected ring size: " << intk.key_offsets.size()); + } + + return true; +} diff --git a/tests/core_tests/pos_basic_tests.h b/tests/core_tests/pos_basic_tests.h index 6bdb5c45..bd4fbf10 100644 --- a/tests/core_tests/pos_basic_tests.h +++ b/tests/core_tests/pos_basic_tests.h @@ -5,6 +5,7 @@ #pragma once #include "chaingen.h" +#include "wallet_tests_basic.h" struct gen_pos_basic_tests : public test_chain_unit_base { @@ -22,3 +23,12 @@ struct gen_pos_basic_tests : public test_chain_unit_base bool check_exchange_1(currency::core& c, size_t ev_index, const std::vector& events); }; + + +struct pos_mining_with_decoys : public wallet_test +{ + pos_mining_with_decoys(); + bool generate(std::vector& events) const; + bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); + bool c1(currency::core& c, size_t ev_index, const std::vector& events); +}; From 20dbbdf81e5c70d2e9417bfc8ecf2645f8c62a23 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 31 Oct 2023 22:47:54 +0100 Subject: [PATCH 097/127] === build number: 152 -> 153 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 1afa6660..ba99b00a 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 152 +#define PROJECT_VERSION_BUILD_NO 153 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 8f6b4036e968e16823724232d4e78d88f933b9d4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 1 Nov 2023 11:30:39 +0100 Subject: [PATCH 098/127] duplicated get_random_outputs in json-like api --- src/rpc/core_rpc_server.h | 1 + .../COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS.json | 1 + 2 files changed, 2 insertions(+) create mode 100644 utils/test_api_files/COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS.json diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index d95dd52b..181dab35 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -150,6 +150,7 @@ namespace currency MAP_JON_RPC ("get_pool_txs_brief_details", on_get_pool_txs_brief_details, COMMAND_RPC_GET_POOL_TXS_BRIEF_DETAILS) MAP_JON_RPC ("get_all_pool_tx_list", on_get_all_pool_tx_list, COMMAND_RPC_GET_ALL_POOL_TX_LIST) MAP_JON_RPC ("get_pool_info", on_get_pool_info, COMMAND_RPC_GET_POOL_INFO) + MAP_JON_RPC ("getrandom_outs", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS) MAP_JON_RPC_WE("get_main_block_details", on_get_main_block_details, COMMAND_RPC_GET_BLOCK_DETAILS) MAP_JON_RPC_WE("get_alt_block_details", on_get_alt_block_details, COMMAND_RPC_GET_BLOCK_DETAILS) diff --git a/utils/test_api_files/COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS.json b/utils/test_api_files/COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS.json new file mode 100644 index 00000000..1397a49d --- /dev/null +++ b/utils/test_api_files/COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS.json @@ -0,0 +1 @@ +{"method": "getrandom_outs","params": {"amounts": [80000000000000000],"outs_count": 11, "use_forced_mix_outs": false }} \ No newline at end of file From 970d6891847dac3b4dd7a91127978de4f148a541 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 1 Nov 2023 13:08:51 +0100 Subject: [PATCH 099/127] migrated to notarytool for macos --- utils/build_script_mac_osx.sh | 40 +++++------------------------------ 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index c26b8da9..e9f554b4 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -185,41 +185,11 @@ rm -f Zano.zip /usr/bin/ditto -c -k --keepParent ./Zano.app ./Zano.zip tmpfile="tmptmptmp" -xcrun altool --notarize-app --primary-bundle-id "org.zano.desktop" -u "andrey@zano.org" -p "@keychain:Developer-altool" --file ./Zano.zip > $tmpfile 2>&1 -NOTARIZE_RES=$? -NOTARIZE_OUTPUT=$( cat $tmpfile ) -rm $tmpfile -echo "NOTARIZE_OUTPUT=$NOTARIZE_OUTPUT" -if [ $NOTARIZE_RES -ne 0 ]; then - echo "Notarization failed" - exit 1 -fi - -GUID=$(echo "$NOTARIZE_OUTPUT" | egrep -Ewo '[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}') -if [ ${#GUID} -ne 36 ]; then - echo "Couldn't get correct GUID from the response, got only \"$GUID\"" - exit 1 -fi - - -success=0 - -# check notarization status -for i in {1..10}; do - xcrun altool --notarization-info $GUID -u "andrey@zano.org" -p "@keychain:Developer-altool" > $tmpfile 2>&1 - NOTARIZE_OUTPUT=$( cat $tmpfile ) - rm $tmpfile - NOTARIZATION_LOG_URL=$(echo "$NOTARIZE_OUTPUT" | sed -n "s/.*LogFileURL\: \([[:graph:]]*\).*/\1/p") - if [ ${#NOTARIZATION_LOG_URL} -ge 30 ]; then - success=1 - curl -L $NOTARIZATION_LOG_URL - break - fi - sleep 60 -done - -if [ $success -ne 1 ]; then - echo "Build notarization failed" +#xcrun altool --notarize-app --primary-bundle-id "org.zano.desktop" -u "andrey@zano.org" -p "@keychain:Developer-altool" --file ./Zano.zip > $tmpfile 2>&1 +xcrun notarytool submit --wait --apple-id "andrey@zano.org" --team-id "562DC258Q6" --password "@keychain:Developer-altool" ./Zano.zip +RETURN=$? +if [ $RETURN -ne 0 ]; then + echo "Failed to submit for notarization or notarization failed, error code $RETURN" exit 1 fi From 301f0341b457f05983d671b6b2a13ff94a678b1b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 1 Nov 2023 14:04:47 +0100 Subject: [PATCH 100/127] notarytool switched to keychain profile option --- utils/build_script_mac_osx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build_script_mac_osx.sh b/utils/build_script_mac_osx.sh index e9f554b4..7153fff9 100755 --- a/utils/build_script_mac_osx.sh +++ b/utils/build_script_mac_osx.sh @@ -186,7 +186,7 @@ rm -f Zano.zip tmpfile="tmptmptmp" #xcrun altool --notarize-app --primary-bundle-id "org.zano.desktop" -u "andrey@zano.org" -p "@keychain:Developer-altool" --file ./Zano.zip > $tmpfile 2>&1 -xcrun notarytool submit --wait --apple-id "andrey@zano.org" --team-id "562DC258Q6" --password "@keychain:Developer-altool" ./Zano.zip +xcrun notarytool submit --wait --keychain-profile "notarytool-password" ./Zano.zip RETURN=$? if [ $RETURN -ne 0 ]; then echo "Failed to submit for notarization or notarization failed, error code $RETURN" From 3c19bb969d1badf5cbb7dc6874d6e3b4d0d61868 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Thu, 2 Nov 2023 00:33:38 +0300 Subject: [PATCH 101/127] === build number: 153 -> 154 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index ba99b00a..3f3082ea 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 153 +#define PROJECT_VERSION_BUILD_NO 154 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 964968ded097afd27aea65b910df2b1866478600 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 16:47:18 +0100 Subject: [PATCH 102/127] get_actual_timestamp() -> get_block_timestamp_from_miner_tx_extra(), corresponding check in pos block validation has been adjusted --- src/currency_core/blockchain_storage.cpp | 20 ++++++++++++-------- src/currency_core/currency_format_utils.cpp | 5 ++--- src/currency_core/currency_format_utils.h | 4 +--- tests/core_tests/chaingen.cpp | 2 +- tests/core_tests/emission_test.cpp | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 1048c9b1..fa41923f 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -5705,15 +5705,19 @@ bool blockchain_storage::validate_pos_block(const block& b, CHECK_AND_ASSERT_MES(!have_tx_keyimg_as_spent(stake_key_image), false, "stake key image has been already spent in blockchain: " << stake_key_image); } - // the following check is de-facto not applicable since 2021-10, but left intact to avoid consensus issues - // PoS blocks don't use etc_tx_time anymore to store actual timestamp; instead, they use tx_service_attachment in mining tx extra - uint64_t actual_ts = get_actual_timestamp(b); - if ((actual_ts > b.timestamp && actual_ts - b.timestamp > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) || - (actual_ts < b.timestamp && b.timestamp - actual_ts > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) - ) + if (!is_hardfork_active(ZANO_HARDFORK_04_ZARCANUM)) { - LOG_PRINT_L0("PoS block actual timestamp " << actual_ts << " differs from b.timestamp " << b.timestamp << " by " << ((int64_t)actual_ts - (int64_t)b.timestamp) << " s, it's more than allowed " << POS_MAX_ACTUAL_TIMESTAMP_TO_MINED << " s."); - return false; + // the following check is de-facto not applicable since 2021-10, but left intact to avoid consensus issues + // PoS blocks don't use etc_tx_time anymore to store actual timestamp; instead, they use tx_service_attachment in mining tx extra + // TODO: remove this entire section after HF4 -- sowle + uint64_t actual_ts = get_block_timestamp_from_miner_tx_extra(b); + if ((actual_ts > b.timestamp && actual_ts - b.timestamp > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) || + (actual_ts < b.timestamp && b.timestamp - actual_ts > POS_MAX_ACTUAL_TIMESTAMP_TO_MINED) + ) + { + LOG_PRINT_L0("PoS block actual timestamp " << actual_ts << " differs from b.timestamp " << b.timestamp << " by " << ((int64_t)actual_ts - (int64_t)b.timestamp) << " s, it's more than allowed " << POS_MAX_ACTUAL_TIMESTAMP_TO_MINED << " s."); + return false; + } } // build kernel and calculate hash diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 87bd14bb..3c63c21b 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3396,9 +3396,8 @@ namespace currency return median_fee * 10; } //--------------------------------------------------------------- - // NOTE: this function is obsolete and depricated - [[deprecated("PoS block real timestamp is set using a service attachment in mining tx extra since 2021-10")]] - uint64_t get_actual_timestamp(const block& b) + // TODO: remove this function after HF4 -- sowle + uint64_t get_block_timestamp_from_miner_tx_extra(const block& b) { uint64_t tes_ts = b.timestamp; if (is_pos_block(b)) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index e30c40dd..f1b6d6f9 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -413,7 +413,7 @@ namespace currency // prints amount in format "3.14", "0.0" std::string print_money_brief(uint64_t amount, size_t decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT); - uint64_t get_actual_timestamp(const block& b); // obsolete and depricated, use get_block_datetime + uint64_t get_block_timestamp_from_miner_tx_extra(const block& b); // remove this function after HF4 -- sowle uint64_t get_block_datetime(const block& b); void set_block_datetime(uint64_t datetime, block& b); @@ -425,8 +425,6 @@ namespace currency bool does_tx_have_only_mixin_inputs(const transaction& tx); bool is_showing_sender_addres(const transaction& tx); bool check_native_coins_amount_burnt_in_outs(const transaction& tx, const uint64_t amount, uint64_t* p_amount_burnt = nullptr); - [[deprecated("Use check_native_coins_amount_burnt_in_outs instead")]] uint64_t get_amount_for_zero_pubkeys(const transaction& tx); - //std::string get_comment_from_tx(const transaction& tx); std::string print_stake_kernel_info(const stake_kernel& sk); std::string dump_ring_sig_data(const crypto::hash& hash_for_sig, const crypto::key_image& k_image, const std::vector& output_keys_ptrs, const std::vector& sig); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index a158e044..fde7294e 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -1458,7 +1458,7 @@ bool fill_tx_sources(std::vector& sources, const std: } } - uint64_t head_block_ts = get_actual_timestamp(blk_head); + uint64_t head_block_ts = get_block_datetime(blk_head); uint64_t next_block_height = blockchain.size(); // Iterate in reverse is more efficiency diff --git a/tests/core_tests/emission_test.cpp b/tests/core_tests/emission_test.cpp index f5aca21b..035726ca 100644 --- a/tests/core_tests/emission_test.cpp +++ b/tests/core_tests/emission_test.cpp @@ -118,7 +118,7 @@ bool emission_test::c1(currency::core& c, size_t ev_index, const std::vector(pb.m_block.miner_tx.vin[1]).amount; already_generated_coins += gen_coins; CHECK_AND_ASSERT_MES(already_generated_coins == bcs.total_coins(), false, "total coins missmatch: BCS has: " << bcs.total_coins() << ", expected: " << already_generated_coins); From 96cde2ae07b6aae4386fcb702c6deb6a46016554 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 16:51:45 +0100 Subject: [PATCH 103/127] deprecated uint64_t get_amount_for_zero_pubkeys() removed, various compilation fixes --- src/currency_core/currency_format_utils.cpp | 27 --------------------- src/simplewallet/simplewallet.cpp | 2 +- tests/performance_tests/api_test.cpp | 2 +- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 3c63c21b..a0004d42 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3829,33 +3829,6 @@ namespace currency } return sum_of_amount_commitments == amount * native_coin_asset_id_pt; } - //--------------------------------------------------------------- - // DEPRECATED, don't use -- sowle - uint64_t get_amount_for_zero_pubkeys(const transaction& tx) - { - uint64_t found_alias_reward = 0; - for (const auto& out : tx.vout) - { - VARIANT_SWITCH_BEGIN(out); - VARIANT_CASE_CONST(tx_out_bare, out) - if (out.target.type() != typeid(txout_to_key)) - continue; - - const txout_to_key& o = boost::get(out.target); - if (o.key == null_pkey) - found_alias_reward += out.amount; - VARIANT_CASE_CONST(tx_out_zarcanum, o) - //@#@ - VARIANT_SWITCH_END(); - } -#ifdef TESTNET - found_alias_reward = 10 * COIN; -#else - @#@ fix it for mainnet bui -#endif - return found_alias_reward; - } - //--------------------------------------------------------------- bool get_aliases_reward_account(account_public_address& acc) { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index ce4eed61..4da5fb2a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1130,7 +1130,7 @@ bool simple_wallet::show_staking_history(const std::vector& args) } } - tools::wallet2::transfer_container transfers; + tools::transfer_container transfers; m_wallet->get_transfers(transfers); uint64_t timestamp = 0; diff --git a/tests/performance_tests/api_test.cpp b/tests/performance_tests/api_test.cpp index 6a492c28..47fa456e 100644 --- a/tests/performance_tests/api_test.cpp +++ b/tests/performance_tests/api_test.cpp @@ -11,7 +11,7 @@ int test_get_rand_outs() currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req); currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response rsp = AUTO_VAL_INIT(rsp); req.use_forced_mix_outs = false; - req.outs_count = 10 + 1; + req.decoys_count = 10 + 1; for (size_t i = 0; i != 50; i++) req.amounts.push_back(COIN); From 406bc5d78ee81b9c379b06e558357c1e1251c905 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 18:29:55 +0100 Subject: [PATCH 104/127] removed deprecated absolute_output_offsets_to_relative(), chaingen was adapted accordingly --- src/currency_core/currency_format_utils.cpp | 44 --------------------- src/currency_core/currency_format_utils.h | 2 - tests/core_tests/chaingen.h | 41 +++++++++---------- tests/core_tests/tx_builder.h | 3 +- 4 files changed, 21 insertions(+), 69 deletions(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index a0004d42..94a3af5d 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3686,50 +3686,6 @@ namespace currency boost::get(res[i]) += boost::get(res[i - 1]); } - return res; - } - //--------------------------------------------------------------- - // DEPRECATED: consider using prepare_outputs_entries_for_key_offsets and absolute_sorted_output_offsets_to_relative_in_place instead - std::vector absolute_output_offsets_to_relative(const std::vector& off) - { - std::vector res = off; - if (off.size() < 2) - return res; - - std::sort(res.begin(), res.end(), [](const txout_ref_v& lft, const txout_ref_v& rght) - { - if (lft.type() == typeid(uint64_t)) - { - if (rght.type() == typeid(uint64_t)) - return boost::get(lft) < boost::get(rght); - else if (rght.type() == typeid(ref_by_id)) - return true; - else - LOG_ERROR("Unknown type in txout_v"); - } - else if (lft.type() == typeid(ref_by_id)) - { - if (rght.type() == typeid(uint64_t)) - return false; - else if (rght.type() == typeid(ref_by_id)) - return false; // don't change the order of ref_by_id elements - else - LOG_ERROR("Unknown type in txout_v"); - } - return false; - });//just to be sure, actually it is already should be sorted - - //find starter index - skip ref_by_id entries - size_t i = res.size() - 1; - while (i != 0 && res[i].type() == typeid(ref_by_id)) - --i; - - for (; i != 0; i--) - { - boost::get(res[i]) -= boost::get(res[i - 1]); - } - - return res; } //--------------------------------------------------------------- diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index f1b6d6f9..96cb7c3b 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -405,8 +405,6 @@ namespace currency uint64_t get_block_height(const transaction& coinbase); uint64_t get_block_height(const block& b); std::vector relative_output_offsets_to_absolute(const std::vector& off); - // DEPRECATED: consider using prepare_outputs_entries_for_key_offsets and absolute_sorted_output_offsets_to_relative_in_place instead - [[deprecated]] std::vector absolute_output_offsets_to_relative(const std::vector& off); bool absolute_sorted_output_offsets_to_relative_in_place(std::vector& offsets) noexcept; diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index e1029aae..43a28913 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -819,47 +819,44 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons struct input_generation_context_data { currency::keypair in_ephemeral; + std::vector sorted_outputs; + size_t real_out_index = 0; }; std::vector in_contexts; uint64_t summary_inputs_money = 0; - //fill inputs - BOOST_FOREACH(const currency::tx_source_entry& src_entr, sources) + // fill inputs + for(const currency::tx_source_entry& src_entr : sources) { - if (src_entr.real_output >= src_entr.outputs.size()) - { - LOG_ERROR("real_output index (" << src_entr.real_output << ")bigger than output_keys.size()=" << src_entr.outputs.size()); - return false; - } + CHECK_AND_ASSERT_MES(src_entr.real_output < src_entr.outputs.size(), false, "real_output index = " << src_entr.real_output << " is bigger than output_keys.size() = " << src_entr.outputs.size()); + + input_generation_context_data& igc = in_contexts.emplace_back(); + igc.sorted_outputs = prepare_outputs_entries_for_key_offsets(src_entr.outputs, src_entr.real_output, igc.real_out_index); summary_inputs_money += src_entr.amount; - //key_derivation recv_derivation; - in_contexts.push_back(input_generation_context_data()); - currency::keypair& in_ephemeral = in_contexts.back().in_ephemeral; crypto::key_image img; - if (!currency::generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, in_ephemeral, img)) + if (!currency::generate_key_image_helper(sender_account_keys, src_entr.real_out_tx_key, src_entr.real_output_in_tx_index, igc.in_ephemeral, img)) return false; //check that derivated key is equal with real output key - if (!(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].stealth_address)) + if (!(igc.in_ephemeral.pub == igc.sorted_outputs[igc.real_out_index].stealth_address)) { LOG_ERROR("derived public key missmatch with output public key! " << ENDL << "derived_key:" - << epst::pod_to_hex(in_ephemeral.pub) << ENDL << "real output_public_key:" - << epst::pod_to_hex(src_entr.outputs[src_entr.real_output].stealth_address)); + << epst::pod_to_hex(igc.in_ephemeral.pub) << ENDL << "real output_public_key:" + << epst::pod_to_hex(igc.sorted_outputs[igc.real_out_index].stealth_address)); return false; } - //put key image into tx input + // fill tx input currency::txin_to_key input_to_key; input_to_key.amount = src_entr.amount; input_to_key.k_image = img; - //fill outputs array and use relative offsets - BOOST_FOREACH(const currency::tx_source_entry::output_entry& out_entry, src_entr.outputs) + // fill ring references + for(const currency::tx_source_entry::output_entry& out_entry : igc.sorted_outputs) input_to_key.key_offsets.push_back(out_entry.out_reference); - input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets); // TODO @#@# tx.vin.push_back(input_to_key); } @@ -899,11 +896,11 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons std::stringstream ss_ring_s; size_t i = 0; - BOOST_FOREACH(const currency::tx_source_entry& src_entr, sources) + for(const currency::tx_source_entry& src_entr : sources) { ss_ring_s << "pub_keys:" << ENDL; std::vector keys_ptrs; - BOOST_FOREACH(const currency::tx_source_entry::output_entry& o, src_entr.outputs) + for(const currency::tx_source_entry::output_entry& o : in_contexts[i].sorted_outputs) { keys_ptrs.push_back(&o.stealth_address); ss_ring_s << o.stealth_address << ENDL; @@ -912,10 +909,10 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons tx.signatures.push_back(currency::NLSAG_sig()); std::vector& sigs = boost::get(tx.signatures.back()).s; sigs.resize(src_entr.outputs.size()); - crypto::generate_ring_signature(tx_prefix_hash, boost::get(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); + crypto::generate_ring_signature(tx_prefix_hash, boost::get(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, in_contexts[i].real_out_index, sigs.data()); ss_ring_s << "signatures:" << ENDL; std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL; }); - ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output; + ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << in_contexts[i].real_out_index; i++; } diff --git a/tests/core_tests/tx_builder.h b/tests/core_tests/tx_builder.h index 22ff3f5c..e373acd3 100644 --- a/tests/core_tests/tx_builder.h +++ b/tests/core_tests/tx_builder.h @@ -37,7 +37,8 @@ struct tx_builder for(const currency::tx_source_entry::output_entry& out_entry : src_entr.outputs) input_to_key.key_offsets.push_back(out_entry.out_reference); - input_to_key.key_offsets = currency::absolute_output_offsets_to_relative(input_to_key.key_offsets); // TODO @#@# + // if the following line fails, consider using prepare_outputs_entries_for_key_offsets() for correct calculation of real out index + CHECK_AND_ASSERT_THROW_MES(absolute_sorted_output_offsets_to_relative_in_place(input_to_key.key_offsets), "absolute_sorted_output_offsets_to_relative_in_place failed"); m_tx.vin.push_back(input_to_key); } } From 2dab8ab3862a62bc8326369fc518fc7f6a9a191b Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 18:31:08 +0100 Subject: [PATCH 105/127] === build number: 237 -> 238 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 40fffc58..dfa01688 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 237 +#define PROJECT_VERSION_BUILD_NO 238 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 88ec0706dabbc16e8a3015f33717fcf7f5efa274 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 18:34:04 +0100 Subject: [PATCH 106/127] coretests: pos_mining_with_decoys was pinned to HF3 --- 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 bd62a042..e2188c53 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1104,7 +1104,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(pos_wallet_big_block_test); //GENERATE_AND_PLAY(block_template_against_txs_size); // Long test! by demand only GENERATE_AND_PLAY(pos_altblocks_validation); - GENERATE_AND_PLAY(pos_mining_with_decoys); + GENERATE_AND_PLAY_HF(pos_mining_with_decoys, "3"); // alternative blocks and generic chain-switching tests GENERATE_AND_PLAY(gen_chain_switch_pow_pos); From 920a08c5ce594505f153171e9d38ea047f537b59 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 18:40:09 +0100 Subject: [PATCH 107/127] gcc compilation fix --- tests/core_tests/chaingen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 43a28913..97dd5bce 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -819,7 +819,7 @@ bool construct_broken_tx(const currency::account_keys& sender_account_keys, cons struct input_generation_context_data { currency::keypair in_ephemeral; - std::vector sorted_outputs; + std::vector sorted_outputs; size_t real_out_index = 0; }; std::vector in_contexts; From 00b663e425f4c902277d492de9ed29b7b3c3e9ba Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 19:06:17 +0100 Subject: [PATCH 108/127] gcc warning 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 e2188c53..e1930227 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -118,7 +118,7 @@ bool test_parse_hardfork_str_mask() { static_assert(ZANO_HARDFORKS_TOTAL >= 5, "this test was made in assumption that this condition holds"); auto v_range = [](size_t a, size_t b) -> std::vector { std::vector r; for(size_t i = a; i <= b; ++i) r.push_back(i); return r; }; - auto v_concat = [](const std::vector& a, const std::vector& b) -> std::vector { std::vector r = a; r.insert(r.end(), b.begin(), b.end()); return r; }; + //auto v_concat = [](const std::vector& a, const std::vector& b) -> std::vector { std::vector r = a; r.insert(r.end(), b.begin(), b.end()); return r; }; const std::vector res_empty; const std::vector res_all_hf = v_range(0, ZANO_HARDFORKS_TOTAL - 1); std::string hf_total_num_str_m_1 = epee::string_tools::num_to_string_fast(ZANO_HARDFORKS_TOTAL - 1); From e45793826ecf2eddcaaf3b2e82947dd48c0ff212 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 19:07:03 +0100 Subject: [PATCH 109/127] === build number: 238 -> 239 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index dfa01688..686c6cdc 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 238 +#define PROJECT_VERSION_BUILD_NO 239 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 4a819afe184a792c88cc58fc9fe1cabc6fdc6559 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 2 Nov 2023 21:14:41 +0100 Subject: [PATCH 110/127] removed unneeded logging --- src/currency_core/blockchain_storage.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index fa41923f..9ccee98b 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -4246,9 +4246,6 @@ bool blockchain_storage::add_transaction_from_block(const transaction& tx, const if (need_to_profile && max_mixins_count > 0) { m_performance_data.tx_mixin_count.push(max_mixins_count); -#ifdef _DEBUG - LOG_PRINT_L0("[TX_MIXINS]: " << max_mixins_count); -#endif } //check if there is already transaction with this hash From 257c19662c3a5c02cbb650ec055345f8ac4df2e6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 6 Nov 2023 14:49:09 +0100 Subject: [PATCH 111/127] merged UI from main --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index f7d1a92e..5a8320e5 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit f7d1a92e9d3b2126cca41f589260802346b29a17 +Subproject commit 5a8320e580f5510e64e967a8a4f7fb2cbc76194a From 7d9ba7ef6407e093260b07bddb0065363a41cefd Mon Sep 17 00:00:00 2001 From: zano build machine Date: Mon, 6 Nov 2023 16:51:01 +0300 Subject: [PATCH 112/127] === build number: 239 -> 240 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 686c6cdc..b1d134a6 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 239 +#define PROJECT_VERSION_BUILD_NO 240 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From c0ab3dc48a21c6e8a26bfce3c1ff595db1c7b8aa Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 6 Nov 2023 16:36:25 +0100 Subject: [PATCH 113/127] staking improvement in GUI version --- src/wallet/wallets_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 8b3bd2aa..16dfe0a3 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1935,7 +1935,7 @@ void wallets_manager::wallet_vs_options::worker_func() { LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet handler thread started, addr: " << w->get()->get_account().get_public_address_str(), LOG_LEVEL_0); epee::math_helper::once_a_time_seconds scan_pool_interval; - epee::math_helper::once_a_time_seconds pos_minin_interval; + epee::math_helper::once_a_time_seconds<2> pos_minin_interval; view::wallet_status_info wsi = AUTO_VAL_INIT(wsi); while (!major_stop) { From a151cab066fef33256aa6960f9da941c9f389f18 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Mon, 6 Nov 2023 18:39:54 +0300 Subject: [PATCH 114/127] === build number: 154 -> 155 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 3f3082ea..c54bd284 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 154 +#define PROJECT_VERSION_BUILD_NO 155 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 34b37ce45c087fb70997c828209d34836864403b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 6 Nov 2023 17:33:58 +0100 Subject: [PATCH 115/127] added missing info for tx rpc details --- src/currency_core/currency_format_utils.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 94a3af5d..0ff7c36f 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -3838,7 +3838,11 @@ namespace currency VARIANT_SWITCH_END(); } VARIANT_CASE_CONST(tx_out_zarcanum, o) - //@#@ + tei.outs.back().pub_keys.push_back(epee::string_tools::pod_to_hex(o.stealth_address)); + tei.outs.back().pub_keys.push_back(epee::string_tools::pod_to_hex(o.concealing_point)); + tei.outs.back().pub_keys.push_back(epee::string_tools::pod_to_hex(o.amount_commitment)); + tei.outs.back().pub_keys.push_back(epee::string_tools::pod_to_hex(o.blinded_asset_id)); + tei.outs.back().pub_keys.push_back(epee::string_tools::pod_to_hex(o.encrypted_amount)); VARIANT_SWITCH_END(); ++i; } From 1f0faf2c8e95f19a446480b7a60217f56764cc90 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 9 Nov 2023 18:47:13 +0100 Subject: [PATCH 116/127] coretests: pos_mining_with_decoys improved to reveal a bug with staking using auditable wallets --- tests/core_tests/pos_basic_tests.cpp | 38 ++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/tests/core_tests/pos_basic_tests.cpp b/tests/core_tests/pos_basic_tests.cpp index 6bc00a5d..3ea45e20 100644 --- a/tests/core_tests/pos_basic_tests.cpp +++ b/tests/core_tests/pos_basic_tests.cpp @@ -152,10 +152,11 @@ bool pos_mining_with_decoys::generate(std::vector& events) con { uint64_t ts = test_core_time::get_time(); m_accounts.resize(TOTAL_ACCS_COUNT); - currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); - currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); - currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); - currency::account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts); + currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts); + currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts); + currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts); + currency::account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts); + currency::account_base& dan_acc = m_accounts[DAN_ACC_IDX]; dan_acc.generate(true); dan_acc.set_createtime(ts); // Dan has an auditable wallet MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts); DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks @@ -167,7 +168,8 @@ bool pos_mining_with_decoys::generate(std::vector& events) con CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed"); std::vector destinations; destinations.emplace_back(47 * TESTS_DEFAULT_FEE, alice_acc.get_public_address()); - destinations.emplace_back(47 * TESTS_DEFAULT_FEE, miner_acc.get_public_address()); // as a decoy for Alice + destinations.emplace_back(47 * TESTS_DEFAULT_FEE, miner_acc.get_public_address()); // as a decoy for Alice and Dan + destinations.emplace_back(47 * TESTS_DEFAULT_FEE, dan_acc.get_public_address()); destinations.emplace_back(5 * TESTS_DEFAULT_FEE, bob_acc.get_public_address()); destinations.emplace_back(COIN, carol_acc.get_public_address()); @@ -204,6 +206,10 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v carol_wlt->refresh(); CHECK_AND_ASSERT_MES(check_balance_via_wallet(*carol_wlt, "Carol", COIN, INVALID_BALANCE_VAL, COIN), false, ""); + std::shared_ptr dan_wlt = init_playtime_test_wallet(events, c, m_accounts[DAN_ACC_IDX]); + dan_wlt->refresh(); + CHECK_AND_ASSERT_MES(check_balance_via_wallet(*dan_wlt, "Dan", 47 * TESTS_DEFAULT_FEE, INVALID_BALANCE_VAL, 47 * TESTS_DEFAULT_FEE), false, ""); + // 1. Alice should be able to mine a PoS block with 1 decoys (ring size == 2) size_t top_block_height = c.get_top_block_height(); @@ -225,6 +231,7 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v // 2. Bob should only be able to mine a PoS block with zero decoys (ring size == 1) top_block_height = c.get_top_block_height(); + bob_wlt->refresh(); r = bob_wlt->try_mint_pos(m_accounts[BOB_ACC_IDX].get_public_address()); CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); @@ -242,6 +249,7 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v // 3. Carol should only be able to mine a PoS block with CURRENCY_DEFAULT_DECOY_SET_SIZE decoys (ring size == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1) top_block_height = c.get_top_block_height(); + carol_wlt->refresh(); r = carol_wlt->try_mint_pos(m_accounts[CAROL_ACC_IDX].get_public_address()); CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); @@ -255,5 +263,25 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(intk.key_offsets.size() == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1, false, "unexpected ring size: " << intk.key_offsets.size()); } + + // 4. Dan has an auditable wallet that couldn't use mixins, but still he should be able to successfully mine a PoS block (ring size = 1, zero decoys) + top_block_height = c.get_top_block_height(); + + CHECK_AND_ASSERT_MES(dan_wlt->is_auditable(), false, "Dan's wallet is not auditable, which is unexpected"); + + dan_wlt->refresh(); + r = dan_wlt->try_mint_pos(m_accounts[DAN_ACC_IDX].get_public_address()); + CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); + + { + block b{}; + CHECK_AND_ASSERT_MES(c.get_blockchain_storage().get_top_block(b), false, ""); + CHECK_AND_ASSERT_MES(get_block_height(b) == top_block_height + 1, false, "unexpected top block height"); + + txin_to_key& intk = boost::get(b.miner_tx.vin[1]); + CHECK_AND_ASSERT_MES(intk.amount == 47 * TESTS_DEFAULT_FEE, false, "incorrect amount: " << intk.amount); + CHECK_AND_ASSERT_MES(intk.key_offsets.size() == 1, false, "unexpected ring size: " << intk.key_offsets.size()); + } + return true; } From ee89a6ce128692fc99e509a98748a325ba80c86c Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 9 Nov 2023 19:25:06 +0100 Subject: [PATCH 117/127] wallet2: auditable wallets won't be requesting decoys for PoS anymore as they couldn't be used --- src/wallet/wallet2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a4edf54c..377d667d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3512,7 +3512,7 @@ bool wallet2::prepare_and_sign_pos_block(const currency::pos_entry& pe, currency COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response decoys_resp = AUTO_VAL_INIT(decoys_resp); std::vector ring; uint64_t secret_index = 0; // index of the real stake output - if (m_required_decoys_count > 0) + if (m_required_decoys_count > 0 && !is_auditable()) { COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request decoys_req = AUTO_VAL_INIT(decoys_req); decoys_req.use_forced_mix_outs = false; From f9cabb0bd2b0e7db294859300ebb3ea10d16b294 Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 9 Nov 2023 19:42:06 +0100 Subject: [PATCH 118/127] === build number: 155 -> 156 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index c54bd284..9dfd81f9 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "2" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 155 +#define PROJECT_VERSION_BUILD_NO 156 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 800c1e5802aab91f8dc84283771739c6a07436f3 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Thu, 9 Nov 2023 23:42:30 +0300 Subject: [PATCH 119/127] === build number: 240 -> 241 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index b1d134a6..913156d9 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 240 +#define PROJECT_VERSION_BUILD_NO 241 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From a270fcdbf9fd3033b3e719d3a64042e8b17abd4f Mon Sep 17 00:00:00 2001 From: zano build machine Date: Fri, 10 Nov 2023 14:32:12 +0300 Subject: [PATCH 120/127] === build number: 241 -> 242 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 913156d9..31e8872d 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 241 +#define PROJECT_VERSION_BUILD_NO 242 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 6849a341c385fccd30c101789a49c0b484526dc0 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 10 Nov 2023 16:38:57 +0100 Subject: [PATCH 121/127] ui updated --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 5a8320e5..5a87cb4a 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 5a8320e580f5510e64e967a8a4f7fb2cbc76194a +Subproject commit 5a87cb4af887da6c1f6ac015477bc2527e153acd From 8f78abb19f350ba67b837bb33451ed8a821423b7 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 10 Nov 2023 16:41:04 +0100 Subject: [PATCH 122/127] === build number: 242 -> 243 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 31e8872d..34e42e54 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 242 +#define PROJECT_VERSION_BUILD_NO 243 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 400b0d09d33d971853a8891622d28a4499ffec59 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 14 Nov 2023 17:25:34 +0100 Subject: [PATCH 123/127] updated ui --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 5a87cb4a..ea512b08 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 5a87cb4af887da6c1f6ac015477bc2527e153acd +Subproject commit ea512b08c9166406ae5fd84ae69a6b57c9a03b67 From bfb7e22ae751ae9dca41c0a5d1bc34124f946f44 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 14 Nov 2023 17:26:21 +0100 Subject: [PATCH 124/127] === build number: 243 -> 244 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 34e42e54..28dbd4ae 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 243 +#define PROJECT_VERSION_BUILD_NO 244 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From 5bd815e66f0cfe5242c3b8d3d10d7122f2d58237 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 21 Nov 2023 17:59:01 +0100 Subject: [PATCH 125/127] added m_whitelisted_assets to serialized state(to hold correct assets balances on open time) --- src/currency_core/currency_config.h | 4 ++-- src/wallet/wallet2.cpp | 9 +++++---- src/wallet/wallet2.h | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 8944a143..e291cc02 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -249,8 +249,8 @@ #define WALLET_FILE_SERIALIZATION_VERSION 160 #define WALLET_FILE_LAST_SUPPORTED_VERSION 160 #else -#define WALLET_FILE_LAST_SUPPORTED_VERSION (CURRENCY_FORMATION_VERSION+75) -#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+75) +#define WALLET_FILE_LAST_SUPPORTED_VERSION (CURRENCY_FORMATION_VERSION+76) +#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+76) #endif #define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 150867de..6c1b4c78 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3519,8 +3519,6 @@ bool wallet2::load_whitelisted_tokens() const if(!m_use_assets_whitelisting) return true; - - m_whitelisted_assets.clear(); std::string body; wallet_public::assets_whitelist aw = AUTO_VAL_INIT(aw); @@ -3536,11 +3534,14 @@ bool wallet2::load_whitelisted_tokens() const //---------------------------------------------------------------------------------------------------- bool wallet2::load_whitelisted_tokens_if_not_loaded() const { - if (m_whitelisted_assets.size()) + if (m_whitelist_updated) { return true; } - return load_whitelisted_tokens(); + if (!load_whitelisted_tokens()) + return false; + m_whitelist_updated = true; + return true; } //---------------------------------------------------------------------------------------------------- void wallet2::get_transfers(transfer_container& incoming_transfers) const diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 52471f95..8c2295fa 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -138,6 +138,7 @@ namespace tools std::unordered_map m_tx_keys; std::unordered_map m_own_asset_descriptors; std::unordered_map m_custom_assets; //assets that manually added by user + std::unordered_map m_whitelisted_assets; //assets that whitelisted escrow_contracts_container m_contracts; std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index @@ -153,6 +154,7 @@ namespace tools std::atomic m_last_sync_percent = 0; mutable uint64_t m_current_wallet_file_size = 0; + //=============================================================== template inline void serialize(t_archive &a, const unsigned int ver) @@ -213,6 +215,7 @@ namespace tools a & m_own_asset_descriptors; a & m_custom_assets; a & m_rollback_events; + a & m_whitelisted_assets; } }; @@ -874,7 +877,7 @@ private: uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value std::atomic m_stop; - mutable std::unordered_map m_whitelisted_assets; //assets that whitelisted + std::atomic whitelist_updated = false; std::shared_ptr m_core_proxy; std::shared_ptr m_wcallback; From c33cfd29b7d358b74d8c55da7917ccd18a8842f9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 21 Nov 2023 18:01:29 +0100 Subject: [PATCH 126/127] added m_whitelisted_assets to serialized state(to hold correct assets balances on open time) - 2 --- src/wallet/wallet2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 8c2295fa..56ae0658 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -877,7 +877,7 @@ private: uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value std::atomic m_stop; - std::atomic whitelist_updated = false; + mutable std::atomic m_whitelist_updated = false; std::shared_ptr m_core_proxy; std::shared_ptr m_wcallback; From 1277818b23fe364d93b9b2934b9c7e6cc4db75a0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 21 Nov 2023 18:04:51 +0100 Subject: [PATCH 127/127] added mutable to variable --- src/wallet/wallet2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 56ae0658..0e42bc0b 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -138,7 +138,7 @@ namespace tools std::unordered_map m_tx_keys; std::unordered_map m_own_asset_descriptors; std::unordered_map m_custom_assets; //assets that manually added by user - std::unordered_map m_whitelisted_assets; //assets that whitelisted + mutable std::unordered_map m_whitelisted_assets; //assets that whitelisted escrow_contracts_container m_contracts; std::multimap m_htlcs; //map [expired_if_more_then] -> height of expiration amount_gindex_to_transfer_id_container m_active_htlcs; // map [amount; gindex] -> transfer index