From 686c1373320f26d0a592b0705987e2ccdb0c7788 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 23 May 2025 23:52:21 +0400 Subject: [PATCH] added wallet_transfer_info to transfer() RPC --- src/common/threads_pool.h | 2 +- src/wallet/wallet2.cpp | 9 +++++ src/wallet/wallet2.h | 2 +- src/wallet/wallet_public_structs_defs.h | 4 ++- src/wallet/wallet_rpc_server.cpp | 9 ++++- tests/performance_tests/main.cpp | 45 +++++++++++++++++++++++-- 6 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/common/threads_pool.h b/src/common/threads_pool.h index 461e8843..23f4e857 100644 --- a/src/common/threads_pool.h +++ b/src/common/threads_pool.h @@ -100,7 +100,7 @@ namespace utils { return cnt == cntr.size(); }); - LOG_PRINT_L0("All jobs finiahed"); + //LOG_PRINT_L0("All jobs finiahed"); } ~threads_pool() diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index cac92913..10cb7481 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5341,6 +5341,15 @@ bool wallet2::build_minted_block(const mining_context& cxt, const currency::acco return true; } //---------------------------------------------------------------------------------------------------- +bool wallet2::find_unconfirmed_tx(const crypto::hash& tx_id, wallet_public::wallet_transfer_info& res) const +{ + auto it = m_unconfirmed_txs.find(tx_id); + if (it == m_unconfirmed_txs.end()) + return false; + res = it->second; + return true; +} +//---------------------------------------------------------------------------------------------------- void wallet2::get_unconfirmed_transfers(std::vector& trs, bool exclude_mining_txs) { for (auto& u : m_unconfirmed_txs) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d1ffe886..dd412494 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -769,7 +769,7 @@ namespace tools void set_concise_mode(bool enabled) { m_concise_mode = enabled; } void set_concise_mode_reorg_max_reorg_blocks(uint64_t max_blocks) { m_wallet_concise_mode_max_reorg_blocks = max_blocks; } void set_concise_mode_truncate_history(uint64_t max_entries) { m_truncate_history_max_entries = max_entries; } - + bool find_unconfirmed_tx(const crypto::hash& tx_id, wallet_public::wallet_transfer_info& res) const; construct_tx_param get_default_construct_tx_param(); diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 9061f182..3ac0f839 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -722,11 +722,13 @@ namespace wallet_public std::string tx_hash; std::string tx_unsigned_hex; // for cold-signing process uint64_t tx_size; + std::optional tx_details; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(tx_hash) DOC_DSCR("Has of the generated transaction(if succeded)") DOC_EXMP("01220e8304d46b940a86e383d55ca5887b34f158a7365bbcdd17c5a305814a93") DOC_END - KV_SERIALIZE(tx_unsigned_hex) + KV_SERIALIZE(tx_unsigned_hex) DOC_DSCR("Has unsigned tx blob in hex encoding") DOC_EXMP("e383d55ca5887b34f158a7365bbcd01220e8304d46b940a86e383d55ca5887b34f158a7365bbcdd17c5a305814a9301220e8304d46b940a86e383d55ca5887b34f158a7365bbcdd17c5a305814a9301220e8304d46b940a86e383d55ca5887b34f158a7365bbcdd17c5a305814a93") DOC_END KV_SERIALIZE(tx_size) DOC_DSCR("Transaction size in bytes") DOC_EXMP(1234) DOC_END + KV_SERIALIZE(tx_details) DOC_DSCR("Tx details[optional]") DOC_EXMP_AGGR() DOC_END END_KV_SERIALIZE_MAP() }; }; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 4216642b..f49a5d3d 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -554,8 +554,15 @@ namespace tools } else { - res.tx_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(result.tx)); + crypto::hash tx_id = currency::get_transaction_hash(result.tx); + res.tx_hash = epee::string_tools::pod_to_hex(tx_id); res.tx_size = get_object_blobsize(result.tx); + //try to get wallet_transfer_info + wallet_public::wallet_transfer_info wti = AUTO_VAL_INIT(wti); + if (w.get_wallet()->find_unconfirmed_tx(tx_id, wti)) + { + res.tx_details = wti; + } } return true; diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index b6ec69e0..66a0f28f 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -27,6 +27,7 @@ #include "wallet/plain_wallet_api.h" #include "wallet/view_iface.h" #include "wallet/plain_wallet_api_defs.h" +#include "math_helper.h" PUSH_VS_WARNINGS DISABLE_VS_WARNINGS(4244) @@ -184,17 +185,57 @@ void test_plain_wallet() } +void multithread_test_of_get_coinbase_hash_cached() +{ + epee::math_helper::once_a_time_seconds<1> print_interwal; + + try + { + crypto::hash h = currency::null_hash; + utils::threads_pool pool; + pool.init(); + for (uint64_t j = 0; j != 100000000; j++) + { + + print_interwal.do_call([&]() { LOG_PRINT_L0("Job " << j << " started, h=" << h); return true; }); + currency::block_extended_info bei = AUTO_VAL_INIT(bei); + utils::threads_pool::jobs_container jobs; + size_t i = 0; + + for (; i != 10; i++) + { + utils::threads_pool::add_job_to_container(jobs, [&, i]() { + h = get_coinbase_hash_cached(bei); + //LOG_PRINT_L0("Job " << i << " started"); + //epee::misc_utils::sleep_no_w(10000); + // ++count_jobs_finished; LOG_PRINT_L0("Job " << i << " finished"); + }); + } + + pool.add_batch_and_wait(jobs); + } + } + catch (...) + { + LOG_ERROR("Exception happened"); + } + + +} + + int main(int argc, char** argv) { epee::string_tools::set_module_name_and_folder(argv[0]); epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); - //epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); //epee::log_space::log_singletone::add_logger(LOGGER_FILE, // epee::log_space::log_singletone::get_default_log_file().c_str(), // epee::log_space::log_singletone::get_default_log_folder().c_str()); - test_tx_json_serialization(); + multithread_test_of_get_coinbase_hash_cached(); + //test_tx_json_serialization(); //test_base64_serialization(); //test_plain_wallet(); //parse_weird_tx();