From 6b152827af12eaed386f3dbc88eea1acc74cf5c7 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 9 Mar 2025 14:59:21 +0400 Subject: [PATCH] more profiling logs + callback for the native lib --- src/rpc/core_rpc_server.cpp | 7 ++++--- src/wallet/plain_wallet_api.cpp | 24 +++++++++++++++++++++--- src/wallet/plain_wallet_api.h | 4 ++++ tests/performance_tests/main.cpp | 9 ++++++--- utils/update_alert.json | 8 ++++---- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 6306d3ac..79b41173 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -311,7 +311,7 @@ namespace currency bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx) { CHECK_CORE_READY(); - + LOG_PRINT_L2("[on_get_blocks]: Prevalidating...."); if (req.block_ids.back() != m_core.get_blockchain_storage().get_block_id_by_height(0)) { //genesis mismatch, return specific @@ -325,7 +325,7 @@ namespace currency res.status = API_RETURN_CODE_BAD_ARG; return true; } - + LOG_PRINT_L2("[on_get_blocks]: find_blockchain_supplement ...."); blockchain_storage::blocks_direct_container bs; if (!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT, req.minimum_height)) { @@ -333,6 +333,7 @@ namespace currency return false; } + LOG_PRINT_L2("[on_get_blocks]: Enumerating over blocks ...."); for (auto& b : bs) { res.blocks.resize(res.blocks.size()+1); @@ -349,7 +350,7 @@ namespace currency i++; } } - + LOG_PRINT_L2("[on_get_blocks]: Finished"); res.status = API_RETURN_CODE_OK; return true; } diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 4fcfe6b7..c86066ee 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -69,6 +69,7 @@ namespace plain_wallet std::atomic initialized = false; std::atomic postponed_run_wallet = false; std::atomic postponed_main_worked_started = false; + callback_type m_callback = nullptr; std::atomic gjobs_counter; std::map gjobs; @@ -555,11 +556,28 @@ namespace plain_wallet { return; } - CRITICAL_REGION_LOCAL(inst_ptr->gjobs_lock); - inst_ptr->gjobs[job_id] = res; - LOG_PRINT_L2("[ASYNC_CALL]: Finished(result put), job id: " << job_id); + if (inst_ptr->m_callback) + { + inst_ptr->m_callback(job_id, res); + LOG_PRINT_L2("[ASYNC_CALL]: Finished(result caalback), job id: " << job_id); + } + else + { + CRITICAL_REGION_LOCAL(inst_ptr->gjobs_lock); + inst_ptr->gjobs[job_id] = res; + LOG_PRINT_L2("[ASYNC_CALL]: Finished(result put), job id: " << job_id); + } } + void set_callback(callback_type callback) + { + auto inst_ptr = std::atomic_load(&ginstance_ptr); + if (!inst_ptr) + { + return; + } + inst_ptr->m_callback = callback; + } std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params) { diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 84fe46ae..b899f17e 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -47,6 +47,10 @@ namespace plain_wallet std::string get_wallet_info(hwallet h); std::string reset_wallet_password(hwallet h, const std::string& password); uint64_t get_current_tx_fee(uint64_t priority); // 0 (default), 1 (unimportant), 2 (normal), 3 (elevated), 4 (priority) + + + typedef void (*callback_type)(uint64_t job_id, const std::string& job_response); + void set_callback(callback_type callback); } diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 62be5de5..0978c989 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -37,12 +37,12 @@ void test_plain_wallet() { //std::string res = plain_wallet::init("195.201.107.230", "33340", "C:\\Users\\roky\\home\\", 0); //std::string res = plain_wallet::init("", "", "C:\\Users\\roky\\home\\", 0); - std::string res = plain_wallet::init("http://zano.api.puffin.systems", "80", "C:\\Users\\roky\\home\\", 0); + std::string res = plain_wallet::init("http://127.0.0.1:11211", "C:\\Users\\roky\\home\\", 0); //std::string res = plain_wallet::init("127.0.0.1", "12111", "C:\\Users\\roky\\home22\\", 0); plain_wallet::configure_object conf = AUTO_VAL_INIT(conf); //plain_wallet::configure_response conf_resp = AUTO_VAL_INIT(conf_resp); - conf.postponed_run_wallet = true; + //conf.postponed_run_wallet = true; std::string r = plain_wallet::sync_call("configure", 0, epee::serialization::store_t_to_json(conf)); @@ -58,7 +58,10 @@ void test_plain_wallet() //res = plain_wallet::sync_call("reset_connection_url", 0, "195.201.107.230:33336"); //res = plain_wallet::sync_call("reset_connection_url", 0, "https://node.zano.org:443"); - res = plain_wallet::sync_call("reset_connection_url", 0, "https://zano.cakewallet.com"); + //res = plain_wallet::sync_call("reset_connection_url", 0, "https://zano.cakewallet.com"); + //res = plain_wallet::sync_call("reset_connection_url", 0, "https://zano.api.wombat.systems:443"); + //res = plain_wallet::sync_call("reset_connection_url", 0, "http://127.0.0.1:11211"); + r = plain_wallet::sync_call("run_wallet", instance_id, ""); diff --git a/utils/update_alert.json b/utils/update_alert.json index 90926d50..6025f950 100644 --- a/utils/update_alert.json +++ b/utils/update_alert.json @@ -1,11 +1,11 @@ { - "maj":1, - "min":0, + "maj":2, + "min":1, "rev":0, - "build":40, + "build":382, "cs":[ { - "build":40, + "build":382, "mode":3 } ]