From 87462bb4f9bf18dec7840891015885befc02c05d Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 25 Feb 2019 17:31:21 +0300 Subject: [PATCH 1/5] wallet2/account: minor const refactoring --- src/currency_core/account.cpp | 2 +- src/currency_core/account.h | 2 +- src/wallet/wallet2.h | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/currency_core/account.cpp b/src/currency_core/account.cpp index ce8b177c..37f5aab9 100644 --- a/src/currency_core/account.cpp +++ b/src/currency_core/account.cpp @@ -116,7 +116,7 @@ namespace currency return true; } //----------------------------------------------------------------- - std::string account_base::get_public_address_str() + std::string account_base::get_public_address_str() const { //TODO: change this code into base 58 return get_account_address_as_str(m_keys.m_account_address); diff --git a/src/currency_core/account.h b/src/currency_core/account.h index 7e259731..656c497c 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -50,7 +50,7 @@ namespace currency void generate(); const account_keys& get_keys() const; const account_public_address& get_public_address() const { return m_keys.m_account_address; }; - std::string get_public_address_str(); + std::string get_public_address_str() const; std::string get_restore_data() const; std::string get_restore_braindata() const; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 927015a5..9efefcea 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -255,7 +255,8 @@ namespace tools void store(); void store(const std::wstring& path); std::wstring get_wallet_path(){ return m_wallet_file; } - currency::account_base& get_account(){return m_account;} + currency::account_base& get_account() { return m_account; } + 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 get_recent_transfers_total_count(); @@ -497,6 +498,8 @@ namespace tools std::vector& prepared_destinations, crypto::hash multisig_id = currency::null_hash); + std::string get_log_prefix() const { return m_log_prefix; } + private: void add_transfers_to_expiration_list(const std::vector& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id); void remove_transfer_from_expiration_list(uint64_t transfer_index); From bd52a48382df996032b436c1d491c6f7cdaecf50 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 25 Feb 2019 17:32:53 +0300 Subject: [PATCH 2/5] locked_object made more const-friendly --- contrib/epee/include/sync_locked_object.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/sync_locked_object.h b/contrib/epee/include/sync_locked_object.h index 1a60b7dc..09e85178 100644 --- a/contrib/epee/include/sync_locked_object.h +++ b/contrib/epee/include/sync_locked_object.h @@ -78,7 +78,7 @@ namespace epee { t_object t; - std::recursive_mutex m; + mutable std::recursive_mutex m; template friend class locked_object_proxy; public: @@ -106,6 +106,16 @@ namespace epee return locked_object_proxy(t, m); } + locked_object_proxy operator->() const + { + return locked_object_proxy(t, m); + } + + locked_object_proxy operator*() const + { + return locked_object_proxy(t, m); + } + /*locked_object_proxy operator()() { return locked_object_proxy(t, m); From 1cb53a48bb3462a0793175bb54a953322ea91dee Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 25 Feb 2019 18:31:58 +0300 Subject: [PATCH 3/5] gui/backend: wallet logging improved --- .../qt-daemon/application/daemon_backend.cpp | 72 +++++++++---------- .../qt-daemon/application/daemon_backend.h | 6 +- src/gui/qt-daemon/application/mainwindow.cpp | 21 ++---- src/gui/qt-daemon/application/mainwindow.h | 1 + src/gui/qt-daemon/application/view_iface.h | 6 -- 5 files changed, 43 insertions(+), 63 deletions(-) diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index b5ae3a4b..cfbcecc3 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -204,8 +204,7 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler) if (command_line::has_arg(m_vm, arg_remote_node)) { - bool r = configure_for_remote_node(command_line::get_arg(m_vm, arg_remote_node)); - CHECK_AND_ASSERT_MES(r, false, "Failed to configure_for_remote_node"); + // configure for remote node } m_pview->init(path_to_html); @@ -222,18 +221,6 @@ bool daemon_backend::init(int argc, char* argv[], view::i_view* pview_handler) CATCH_ENTRY_L0("init", false); } -bool daemon_backend::configure_for_remote_node(const std::string& remote_host) -{ - //parse node - tools::default_http_core_proxy* proxy = new tools::default_http_core_proxy(); - m_rpc_proxy.reset(proxy); - bool r = proxy->set_connection_addr(remote_host); - CHECK_AND_ASSERT_MES(r, false, "Failed to assign remote node address"); - proxy->set_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected); - m_remote_node_mode = true; - return true; -} - bool daemon_backend::start() { TRY_ENTRY(); @@ -618,7 +605,7 @@ std::string daemon_backend::get_my_offers(const bc_services::core_offers_filter& size_t offers_added = offers_count_after - offers_count_before; if (offers_added > 0) { - LOG_PRINT("get_my_offers(): " << offers_added << " offers added from wallet " << wallet_title, LOG_LEVEL_2); + LOG_PRINT(get_wallet_log_prefix(w.second.wallet_id) + "get_my_offers(): " << offers_added << " offers added from wallet " << wallet_title, LOG_LEVEL_2); } ++wallet_index; @@ -948,14 +935,14 @@ std::string daemon_backend::request_alias_registration(const currency::alias_rpc } catch (const std::exception& e) { - LOG_ERROR("request_alias_registration error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "request_alias_registration error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("request_alias_registration error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "request_alias_registration error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -987,14 +974,14 @@ std::string daemon_backend::request_alias_update(const currency::alias_rpc_detai } catch (const std::exception& e) { - LOG_ERROR("request_alias_update error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "request_alias_update error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("request_alias_update error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "request_alias_update error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -1094,14 +1081,14 @@ std::string daemon_backend::transfer(size_t wallet_id, const view::transfer_para } catch (const std::exception& e) { - LOG_ERROR("Transfer error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "Transfer error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("Transfer error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "Transfer error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } @@ -1156,20 +1143,20 @@ std::string daemon_backend::create_proposal(size_t wallet_id, } catch (const tools::error::not_enough_money& e) { - LOG_ERROR("send_escrow_proposal error: API_RETURN_CODE_NOT_ENOUGH_MONEY: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: API_RETURN_CODE_NOT_ENOUGH_MONEY: " << e.what()); std::string err_code = API_RETURN_CODE_NOT_ENOUGH_MONEY; return err_code; } catch (const std::exception& e) { - LOG_ERROR("send_escrow_proposal error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("send_escrow_proposal error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "send_escrow_proposal error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -1225,7 +1212,7 @@ std::string daemon_backend::accept_cancel_contract(size_t wallet_id, const crypt //TODO: add some TIME_MEASURE_FINISH_MS(timing1); if (timing1 > 500) - LOG_PRINT_RED_L0("[daemon_backend::accept_cancel_contract] LOW PERFORMANCE: " << timing1 ); + LOG_PRINT_RED_L0(get_wallet_log_prefix(wallet_id) + "[daemon_backend::accept_cancel_contract] LOW PERFORMANCE: " << timing1 ); return API_RETURN_CODE_OK; } @@ -1344,14 +1331,14 @@ std::string daemon_backend::push_offer(size_t wallet_id, const bc_services::offe } catch (const std::exception& e) { - LOG_ERROR("push_offer error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "push_offer error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("push_offer error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "push_offer error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -1365,14 +1352,14 @@ std::string daemon_backend::cancel_offer(const view::cancel_offer_param& co, cur } catch (const std::exception& e) { - LOG_ERROR("cancel_offer error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(co.wallet_id) + "cancel_offer error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("cancel_offer error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(co.wallet_id) + "cancel_offer error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -1388,14 +1375,14 @@ std::string daemon_backend::push_update_offer(const bc_services::update_offer_de } catch (const std::exception& e) { - LOG_ERROR("cancel_offer error: " << e.what()); + LOG_ERROR(get_wallet_log_prefix(uo.wallet_id) + "push_update_offer error: " << e.what()); std::string err_code = API_RETURN_CODE_INTERNAL_ERROR; err_code += std::string(":") + e.what(); return err_code; } catch (...) { - LOG_ERROR("cancel_offer error: unknown error"); + LOG_ERROR(get_wallet_log_prefix(uo.wallet_id) + "push_update_offer error: unknown error"); return API_RETURN_CODE_INTERNAL_ERROR; } } @@ -1468,7 +1455,7 @@ void daemon_backend::on_transfer_canceled(size_t wallet_id, const tools::wallet_ } else { - LOG_ERROR("on_transfer() wallet with id = " << wallet_id << " not found"); + LOG_ERROR(get_wallet_log_prefix(wallet_id) + "on_transfer() wallet with id = " << wallet_id << " not found"); } m_pview->money_transfer_cancel(tei); } @@ -1546,10 +1533,10 @@ void daemon_backend::wallet_vs_options::worker_func() { pos_minin_interval.do_call([this](){ tools::wallet2::mining_context ctx = AUTO_VAL_INIT(ctx); - LOG_PRINT_L1("Starting PoS mint iteration"); + LOG_PRINT_L1(w->get()->get_log_prefix() + " Starting PoS mint iteration"); if (!w->get()->fill_mining_context(ctx) || ctx.rsp.status != CORE_RPC_STATUS_OK) return true; - LOG_PRINT_L1("POS_ENTRIES: " << ctx.sp.pos_entries.size()); + LOG_PRINT_L1(w->get()->get_log_prefix() + " POS_ENTRIES: " << ctx.sp.pos_entries.size()); tools::wallet2::scan_pos(ctx, break_mining_loop, [this](){ return *plast_daemon_network_state == currency::COMMAND_RPC_GET_INFO::daemon_network_state_online && *plast_daemon_height == last_wallet_synch_height; }, core_conf); @@ -1558,7 +1545,7 @@ void daemon_backend::wallet_vs_options::worker_func() { w->get()->build_minted_block(ctx.sp, ctx.rsp); } - LOG_PRINT_L1("PoS mint iteration finished(" << ctx.rsp.status << ")"); + LOG_PRINT_L1(w->get()->get_log_prefix() + " PoS mint iteration finished(" << ctx.rsp.status << ")"); return true; }); } @@ -1577,7 +1564,7 @@ void daemon_backend::wallet_vs_options::worker_func() catch (const std::exception& e) { - LOG_PRINT_L0("Failed to refresh wallet: " << e.what()); + LOG_PRINT_L0(w->get()->get_log_prefix() + "Failed to refresh wallet: " << e.what()); wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_error; pview->update_wallet_status(wsi); return; @@ -1585,7 +1572,7 @@ void daemon_backend::wallet_vs_options::worker_func() catch (...) { - LOG_PRINT_L0("Failed to refresh wallet, unknownk exception"); + LOG_PRINT_L0(w->get()->get_log_prefix() + "Failed to refresh wallet, unknownk exception"); wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_error; pview->update_wallet_status(wsi); return; @@ -1602,3 +1589,14 @@ daemon_backend::wallet_vs_options::~wallet_vs_options() if (miner_thread.joinable()) miner_thread.join(); } + +std::string daemon_backend::get_wallet_log_prefix(size_t wallet_id) const +{ + CRITICAL_REGION_LOCAL(m_wallets_lock); + auto it = m_wallets.find(wallet_id); + if (it == m_wallets.end()) + return std::string("[W:???id=") + epee::string_tools::num_to_string_fast(wallet_id) + "]"; + + return std::string("[W:") + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]"; +} + diff --git a/src/gui/qt-daemon/application/daemon_backend.h b/src/gui/qt-daemon/application/daemon_backend.h index 5b23b895..95d2ec3e 100644 --- a/src/gui/qt-daemon/application/daemon_backend.h +++ b/src/gui/qt-daemon/application/daemon_backend.h @@ -137,8 +137,8 @@ public: void subscribe_to_core_events(currency::i_core_event_handler* pevents_handler); void unsubscribe_to_core_events(); void get_gui_options(view::gui_options& opt); - bool is_remote_node_mode() { return m_remote_node_mode; } - bool configure_for_remote_node(const std::string& remote_host); + std::string get_wallet_log_prefix(size_t wallet_id) const; + private: void main_worker(const po::variables_map& vm); bool init_local_daemon(); @@ -163,7 +163,7 @@ private: view::i_view m_view_stub; view::i_view* m_pview; std::shared_ptr m_rpc_proxy; - critical_section m_wallets_lock; + mutable critical_section m_wallets_lock; po::variables_map m_vm; std::atomic m_last_daemon_height; diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 9f7d8d12..1629feff 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -542,7 +542,7 @@ bool MainWindow::init_backend(int argc, char* argv[]) QString MainWindow::is_remnotenode_mode_preconfigured() { - return m_backend.is_remote_node_mode() ? "TRUE":"FALSE"; + return "FALSE"; } QString MainWindow::start_backend(const QString& params) @@ -555,19 +555,6 @@ QString MainWindow::start_backend(const QString& params) ar.error_code = API_RETURN_CODE_BAD_ARG; return MAKE_RESPONSE(ar); } - if (sbp.configure_for_remote_node) - { - //@#@ - sbp.remote_node_host = "88.198.50.112"; - sbp.remote_node_port = 11512; - - bool r = m_backend.configure_for_remote_node(sbp.remote_node_host + ":" + std::to_string(sbp.remote_node_port)); - if (!r) - { - ar.error_code = API_RETURN_CODE_BAD_ARG; - return MAKE_RESPONSE(ar); - } - } bool r = m_backend.start(); if (!r) @@ -627,7 +614,7 @@ bool MainWindow::money_transfer(const view::transfer_event_info& tei) std::string json_str; epee::serialization::store_t_to_json(tei, json_str); - LOG_PRINT_L0("SENDING SIGNAL -> [money_transfer]" << std::endl << json_str); + LOG_PRINT_L0(get_wallet_log_prefix(tei.wallet_id) + "SENDING SIGNAL -> [money_transfer]" << std::endl << json_str); //this->money_transfer(json_str.c_str()); QMetaObject::invokeMethod(this, "money_transfer", Qt::QueuedConnection, Q_ARG(QString, json_str.c_str())); if (!m_tray_icon) @@ -670,7 +657,7 @@ bool MainWindow::money_transfer_cancel(const view::transfer_event_info& tei) std::string json_str; epee::serialization::store_t_to_json(tei, json_str); - LOG_PRINT_L0("SENDING SIGNAL -> [money_transfer_cancel]"); + LOG_PRINT_L0(get_wallet_log_prefix(tei.wallet_id) + "SENDING SIGNAL -> [money_transfer_cancel]"); //this->money_transfer_cancel(json_str.c_str()); QMetaObject::invokeMethod(this, "money_transfer_cancel", Qt::QueuedConnection, Q_ARG(QString, json_str.c_str())); @@ -679,7 +666,7 @@ bool MainWindow::money_transfer_cancel(const view::transfer_event_info& tei) } bool MainWindow::wallet_sync_progress(const view::wallet_sync_progres_param& p) { - LOG_PRINT_L2("SENDING SIGNAL -> [wallet_sync_progress]" << " wallet_id: " << p.wallet_id << ": " << p.progress << "%"); + LOG_PRINT_L2(get_wallet_log_prefix(p.wallet_id) + "SENDING SIGNAL -> [wallet_sync_progress]" << " wallet_id: " << p.wallet_id << ": " << p.progress << "%"); //this->wallet_sync_progress(epee::serialization::store_t_to_json(p).c_str()); QMetaObject::invokeMethod(this, "wallet_sync_progress", Qt::QueuedConnection, Q_ARG(QString, epee::serialization::store_t_to_json(p).c_str())); return true; diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 85528d6e..11f5c57d 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -215,6 +215,7 @@ private: bool store_app_config(); bool load_app_config(); + std::string get_wallet_log_prefix(size_t wallet_id) const { return m_backend.get_wallet_log_prefix(wallet_id); } //MediatorObject mo; diff --git a/src/gui/qt-daemon/application/view_iface.h b/src/gui/qt-daemon/application/view_iface.h index 3a20ccf4..41a66838 100644 --- a/src/gui/qt-daemon/application/view_iface.h +++ b/src/gui/qt-daemon/application/view_iface.h @@ -509,14 +509,8 @@ public: struct start_backend_params { - bool configure_for_remote_node; - std::string remote_node_host; - uint64_t remote_node_port; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(configure_for_remote_node) - KV_SERIALIZE(remote_node_host) - KV_SERIALIZE(remote_node_port) END_KV_SERIALIZE_MAP() }; From aff66bf0a4dcadba40a1de4e37ecd9de8f2c6f1f Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 26 Feb 2019 11:48:05 +0300 Subject: [PATCH 4/5] build: added BUILD_TESTS=TRUE in configuration helpers for windows --- utils/configure_win64_msvs2013_gui.cmd | 2 +- utils/configure_win64_msvs2015_gui.cmd | 2 +- utils/configure_win64_msvs2017_gui.cmd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/configure_win64_msvs2013_gui.cmd b/utils/configure_win64_msvs2013_gui.cmd index 889fdad1..ddc715d3 100644 --- a/utils/configure_win64_msvs2013_gui.cmd +++ b/utils/configure_win64_msvs2013_gui.cmd @@ -4,4 +4,4 @@ cd .. @mkdir build_msvc2013_64 cd build_msvc2013_64 -cmake -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2013_64 -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-12.0" -G "Visual Studio 12 2013 Win64" ".." \ No newline at end of file +cmake -D BUILD_TESTS=TRUE -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2013_64 -D BUILD_GUI=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-12.0" -G "Visual Studio 12 2013 Win64" ".." \ No newline at end of file diff --git a/utils/configure_win64_msvs2015_gui.cmd b/utils/configure_win64_msvs2015_gui.cmd index 2648c7d5..07884551 100644 --- a/utils/configure_win64_msvs2015_gui.cmd +++ b/utils/configure_win64_msvs2015_gui.cmd @@ -4,4 +4,4 @@ cd .. @mkdir build_msvc2015_64 cd build_msvc2015_64 -cmake -D USE_PCH=TRUE -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2015_64 -D BUILD_GUI=TRUE -D USE_OPENCL=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.0" -G "Visual Studio 14 2015 Win64" -T host=x64 ".." \ No newline at end of file +cmake -D USE_PCH=TRUE -D BUILD_TESTS=TRUE -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2015_64 -D BUILD_GUI=TRUE -D USE_OPENCL=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.0" -G "Visual Studio 14 2015 Win64" -T host=x64 ".." \ No newline at end of file diff --git a/utils/configure_win64_msvs2017_gui.cmd b/utils/configure_win64_msvs2017_gui.cmd index 2c505030..a104a1fa 100644 --- a/utils/configure_win64_msvs2017_gui.cmd +++ b/utils/configure_win64_msvs2017_gui.cmd @@ -4,4 +4,4 @@ cd .. @mkdir build_msvc2017_64 cd build_msvc2017_64 -cmake -D USE_PCH=TRUE -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2017_64 -D BUILD_GUI=TRUE -D USE_OPENCL=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 15 2017 Win64" -T host=x64 ".." \ No newline at end of file +cmake -D USE_PCH=TRUE -D BUILD_TESTS=TRUE -D CMAKE_PREFIX_PATH="%QT_PREFIX_PATH%"\msvc2017_64 -D BUILD_GUI=TRUE -D USE_OPENCL=TRUE -D STATIC=FALSE -DBOOST_ROOT="%BOOST_ROOT%" -DBOOST_LIBRARYDIR="%BOOST_ROOT%\lib64-msvc-14.1" -G "Visual Studio 15 2017 Win64" -T host=x64 ".." \ No newline at end of file From 5dd8f584cc1f35d1e9661d56e1a5b33ab0a152ac Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 27 Feb 2019 00:59:02 +0300 Subject: [PATCH 5/5] wallet2: advanced logging for difficult issues --- src/currency_core/tx_pool.cpp | 19 ++++++++++++++----- src/currency_core/tx_pool.h | 2 +- .../qt-daemon/application/daemon_backend.cpp | 4 ++-- src/gui/qt-daemon/application/mainwindow.cpp | 2 +- src/wallet/wallet2.cpp | 11 +++++++++-- src/wallet/wallet2.h | 2 ++ 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index f8165353..665e9e92 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -145,9 +145,10 @@ namespace currency //check key images for transaction if it is not kept by block if(!from_core && !kept_by_block) { - if(have_tx_keyimges_as_spent(tx)) + crypto::key_image spent_ki = AUTO_VAL_INIT(spent_ki); + if(have_tx_keyimges_as_spent(tx, &spent_ki)) { - LOG_ERROR("Transaction with id= "<< id << " used already spent key images"); + LOG_ERROR("Transaction " << id << " uses already spent key image " << spent_ki); tvc.m_verification_failed = true; return false; } @@ -735,15 +736,19 @@ namespace currency return false; } //--------------------------------------------------------------------------------- - bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx) const + bool tx_memory_pool::have_tx_keyimges_as_spent(const transaction& tx, crypto::key_image* p_spent_ki /* = nullptr */) const { for(const auto& in : tx.vin) { if (in.type() == typeid(txin_to_key)) { CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, true);//should never fail - if(have_tx_keyimg_as_spent(tokey_in.k_image)) - return true; + if (have_tx_keyimg_as_spent(tokey_in.k_image)) + { + if (p_spent_ki) + *p_spent_ki = tokey_in.k_image; + return true; + } } } @@ -761,8 +766,10 @@ namespace currency auto ki_entry_ptr = m_db_key_images_set.get(tokey_in.k_image); if (ki_entry_ptr.get()) count = *ki_entry_ptr; + uint64_t count_before = count; ++count; m_db_key_images_set.set(tokey_in.k_image, count); + LOG_PRINT_L2("tx pool: key image added: " << tokey_in.k_image << ", from tx " << get_transaction_hash(tx) << ", counter: " << count_before << " -> " << count); } } return false; @@ -828,11 +835,13 @@ namespace currency continue; } count = *ki_entry_ptr; + uint64_t count_before = count; --count; if (count) m_db_key_images_set.set(tokey_in.k_image, count); else m_db_key_images_set.erase(tokey_in.k_image); + LOG_PRINT_L2("tx pool: key image removed: " << tokey_in.k_image << ", from tx " << get_transaction_hash(tx) << ", counter: " << count_before << " -> " << count); } } return false; diff --git a/src/currency_core/tx_pool.h b/src/currency_core/tx_pool.h index d8dd4ed2..22dd9948 100644 --- a/src/currency_core/tx_pool.h +++ b/src/currency_core/tx_pool.h @@ -92,7 +92,7 @@ namespace currency bool have_tx(const crypto::hash &id)const; bool have_tx_keyimg_as_spent(const crypto::key_image& key_im)const; - bool have_tx_keyimges_as_spent(const transaction& tx)const; + bool have_tx_keyimges_as_spent(const transaction& tx, crypto::key_image* p_spent_ki = nullptr) const; const performnce_data& get_performnce_data() const { return m_performance_data; } diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index cfbcecc3..baa26fce 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -1595,8 +1595,8 @@ std::string daemon_backend::get_wallet_log_prefix(size_t wallet_id) const CRITICAL_REGION_LOCAL(m_wallets_lock); auto it = m_wallets.find(wallet_id); if (it == m_wallets.end()) - return std::string("[W:???id=") + epee::string_tools::num_to_string_fast(wallet_id) + "]"; + return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":???]"; - return std::string("[W:") + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]"; + return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":" + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]"; } diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 1629feff..32a4c764 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -571,7 +571,7 @@ bool MainWindow::update_wallet_status(const view::wallet_status_info& wsi) m_wallet_states->operator [](wsi.wallet_id) = wsi.wallet_state; std::string json_str; epee::serialization::store_t_to_json(wsi, json_str); - LOG_PRINT_L0("SENDING SIGNAL -> [update_wallet_status]:" << std::endl << json_str ); + LOG_PRINT_L0(get_wallet_log_prefix(wsi.wallet_id) + "SENDING SIGNAL -> [update_wallet_status]:" << std::endl << json_str ); QMetaObject::invokeMethod(this, "update_wallet_status", Qt::QueuedConnection, Q_ARG(QString, json_str.c_str())); return true; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 7c210431..f788d0d0 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1757,6 +1757,11 @@ namespace } } //---------------------------------------------------------------------------------------------------- +void wallet2::init_log_prefix() +{ + m_log_prefix = m_account.get_public_address_str().substr(0, 6); +} +//---------------------------------------------------------------------------------------------------- void wallet2::load_keys(const std::string& buff, const std::string& password) { wallet2::keys_file_data keys_file_data; @@ -1781,14 +1786,14 @@ void wallet2::load_keys(const std::string& buff, const std::string& password) WLT_LOG_L0("Wrong password for wallet " << string_encoding::convert_to_ansii(m_wallet_file)); tools::error::throw_wallet_ex(std::string(__FILE__ ":" STRINGIZE(__LINE__))); } - - m_log_prefix = m_account.get_public_address_str().substr(0, 6); + init_log_prefix(); } //---------------------------------------------------------------------------------------------------- void wallet2::assign_account(const currency::account_base& acc) { clear(); m_account = acc; + init_log_prefix(); } //---------------------------------------------------------------------------------------------------- void wallet2::generate(const std::wstring& path, const std::string& pass) @@ -1797,6 +1802,7 @@ void wallet2::generate(const std::wstring& path, const std::string& pass) m_wallet_file = path; m_password = pass; m_account.generate(); + init_log_prefix(); boost::system::error_code ignored_ec; THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file)); store(); @@ -1808,6 +1814,7 @@ void wallet2::restore(const std::wstring& path, const std::string& pass, const s m_wallet_file = path; m_password = pass; bool r = m_account.restore_keys_from_braindata(restore_key); + init_log_prefix(); THROW_IF_TRUE_WALLET_EX(!r, error::wallet_internal_error, epee::string_encoding::convert_to_ansii(m_wallet_file)); boost::system::error_code ignored_ec; THROW_IF_TRUE_WALLET_EX(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, epee::string_encoding::convert_to_ansii(m_wallet_file)); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 9efefcea..f8f0af05 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -599,6 +599,8 @@ private: void fill_transfer_details(const currency::transaction& tx, const tools::money_transfer2_details& td, tools::wallet_rpc::wallet_transfer_info_details& res_td) const; void print_source_entry(const currency::tx_source_entry& src) const; + void init_log_prefix(); + struct construct_tx_param { std::vector dsts;