diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index dada57fe..ad847c47 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -145,8 +145,8 @@ namespace tools bool r = m_http_client.connect(u.host, std::to_string(u.port), m_connection_timeout); if (r) { - *m_plast_daemon_is_disconnected = false; - m_last_success_interract_time = time(nullptr); + m_pdiganostic_info->last_daemon_is_disconnected = false; + m_pdiganostic_info->last_success_interract_time = time(nullptr); } return r; } @@ -177,11 +177,11 @@ namespace tools return tools::get_transfer_address(adr_str, addr, payment_id, this); } //------------------------------------------------------------------------------------------------------------------------------ - void default_http_core_proxy::set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected) - { - CRITICAL_REGION_LOCAL(m_lock); - m_plast_daemon_is_disconnected = plast_daemon_is_disconnected ? plast_daemon_is_disconnected : &m_last_daemon_is_disconnected_stub; - } +// void default_http_core_proxy::set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected) +// { +// CRITICAL_REGION_LOCAL(m_lock); +// 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) { @@ -190,8 +190,8 @@ namespace tools return true; } //------------------------------------------------------------------------------------------------------------------------------ - default_http_core_proxy::default_http_core_proxy() :m_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected_stub), - m_last_success_interract_time(0), + default_http_core_proxy::default_http_core_proxy(): //:m_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected_stub), + //m_last_success_interract_time(0), m_connection_timeout(WALLET_RCP_CONNECTION_TIMEOUT), m_attempts_count(WALLET_RCP_COUNT_ATTEMNTS) { diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index 0bba7db6..cded9d06 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -69,11 +69,11 @@ namespace tools if (ret) { - m_last_success_interract_time = time(nullptr); - *m_plast_daemon_is_disconnected = false; + m_pdiganostic_info->last_success_interract_time = time(nullptr); + m_pdiganostic_info->last_daemon_is_disconnected = false; } else - *m_plast_daemon_is_disconnected = true; + m_pdiganostic_info->last_daemon_is_disconnected = true; return ret; } @@ -124,15 +124,13 @@ namespace tools //------------------------------------------------------------------------------------------------------------------------------ virtual time_t get_last_success_interract_time() override { - return m_last_success_interract_time; + return m_pdiganostic_info->last_success_interract_time; } epee::critical_section m_lock; epee::net_utils::http::http_simple_client m_http_client; std::string m_daemon_address; - std::atomic m_last_success_interract_time; - std::atomic *m_plast_daemon_is_disconnected; - std::atomic m_last_daemon_is_disconnected_stub; + unsigned int m_connection_timeout; size_t m_attempts_count; diff --git a/src/wallet/core_rpc_proxy.h b/src/wallet/core_rpc_proxy.h index 184e8a4b..b8d2e303 100644 --- a/src/wallet/core_rpc_proxy.h +++ b/src/wallet/core_rpc_proxy.h @@ -11,6 +11,15 @@ namespace tools { + struct proxy_diagnostic_info + { + proxy_diagnostic_info():is_busy(false), last_success_interract_time(0), last_daemon_is_disconnected(0) + {} + std::atomic is_busy; + std::atomic last_success_interract_time; + std::atomic last_daemon_is_disconnected; + }; + /* wrapper to core api (rpc/direct call) */ @@ -44,10 +53,18 @@ namespace tools virtual bool call_COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN(const currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::request& req, currency::COMMAND_RPC_GET_CURRENT_CORE_TX_EXPIRATION_MEDIAN::response& res){ return false; } virtual bool call_COMMAND_RPC_GET_POOL_INFO(const currency::COMMAND_RPC_GET_POOL_INFO::request& req, currency::COMMAND_RPC_GET_POOL_INFO::response& res) { return false; } + i_core_proxy() + { + m_pdiganostic_info.reset(new proxy_diagnostic_info()); + } virtual bool check_connection(){ return false; } virtual time_t get_last_success_interract_time() { return 0; } + 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; } + protected: + std::shared_ptr m_pdiganostic_info; }; } diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 29f5744c..ee1cc254 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -467,10 +467,12 @@ public: { bool is_online; bool last_daemon_is_disconnected; + bool is_server_busy; uint64_t last_proxy_communicate_timestamp; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(is_online) + KV_SERIALIZE(is_server_busy) KV_SERIALIZE(last_daemon_is_disconnected) KV_SERIALIZE(last_proxy_communicate_timestamp) END_KV_SERIALIZE_MAP() diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index f1cf1a96..f4e78ff1 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1370,9 +1370,11 @@ void wallet2::pull_blocks(size_t& blocks_added, std::atomic& stop) if (res.status == API_RETURN_CODE_BUSY) { WLT_LOG_L1("Core is busy, pull cancelled"); + m_core_proxy->get_editable_proxy_diagnostic_info()->is_busy = true; stop = true; return; } + m_core_proxy->get_editable_proxy_diagnostic_info()->is_busy = false; THROW_IF_TRUE_WALLET_EX(res.status != API_RETURN_CODE_OK, error::get_blocks_error, res.status); THROW_IF_TRUE_WALLET_EX(get_blockchain_current_size() && get_blockchain_current_size() <= res.start_height && res.start_height != m_minimum_height, error::wallet_internal_error, "wrong daemon response: m_start_height=" + std::to_string(res.start_height) + @@ -1500,6 +1502,7 @@ void wallet2::refresh() void wallet2::refresh(size_t & blocks_fetched) { bool received_money = false; + m_stop = false; refresh(blocks_fetched, received_money, m_stop); } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 0faa603a..d0c6e896 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -56,8 +56,7 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), m_rpc_proxy(new tools::default_http_core_proxy()), #endif - m_last_daemon_height(0), - m_last_daemon_is_disconnected(false), + m_last_daemon_height(0), m_wallet_id_counter(0), m_ui_opt(AUTO_VAL_INIT(m_ui_opt)), m_remote_node_mode(false), @@ -272,7 +271,6 @@ bool wallets_manager::init(view::i_view* pview_handler) { m_remote_node_mode = true; auto proxy_ptr = new tools::default_http_core_proxy(); - proxy_ptr->set_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected); proxy_ptr->set_connectivity(HTTP_PROXY_TIMEOUT, HTTP_PROXY_ATTEMPTS_COUNT); m_rpc_proxy.reset(proxy_ptr); m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node)); @@ -706,7 +704,8 @@ void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.stop_for_refresh = false; wo.plast_daemon_height = &m_last_daemon_height; wo.plast_daemon_network_state = &m_last_daemon_network_state; - wo.plast_daemon_is_disconnected = &m_last_daemon_is_disconnected; + //wo.plast_daemon_is_disconnected = &(m_rpc_proxy->get_proxy_diagnostic_info().last_daemon_is_disconnected; + wo.m_pproxy_diagnostig_info = m_rpc_proxy->get_proxy_diagnostic_info(); wo.pview = m_pview; wo.has_related_alias_in_unconfirmed = false; wo.rpc_wrapper.reset(new tools::wallet_rpc_server(*wo.w.unlocked_get().get())); @@ -1361,7 +1360,9 @@ bool wallets_manager::get_is_remote_daemon_connected() { if (!m_remote_node_mode) return true; - if (m_last_daemon_is_disconnected) + if (m_pproxy_diganostic_info->last_daemon_is_disconnected) + return false; + if (m_pproxy_diganostic_info->is_busy) return false; if (time(nullptr) - m_rpc_proxy->get_last_success_interract_time() > DAEMON_IDLE_UPDATE_TIME_MS * 2) return false; @@ -1372,7 +1373,8 @@ std::string wallets_manager::get_connectivity_status() { view::general_connectivity_info gci = AUTO_VAL_INIT(gci); gci.is_online = get_is_remote_daemon_connected(); - gci.last_daemon_is_disconnected = m_last_daemon_is_disconnected; + gci.last_daemon_is_disconnected = m_pproxy_diganostic_info->last_daemon_is_disconnected; + gci.is_server_busy = m_pproxy_diganostic_info->is_busy; gci.last_proxy_communicate_timestamp = m_rpc_proxy->get_last_success_interract_time(); return epee::serialization::store_t_to_json(gci); } @@ -1798,7 +1800,7 @@ void wallets_manager::wallet_vs_options::worker_func() try { wsi.wallet_state = view::wallet_status_info::wallet_state_ready; - if (plast_daemon_is_disconnected && plast_daemon_is_disconnected->load()) + if (m_pproxy_diagnostig_info->last_daemon_is_disconnected.load()) { std::this_thread::sleep_for(std::chrono::milliseconds(1000)); continue; diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index dd2797ca..739ab15e 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -69,7 +69,8 @@ public: std::atomic last_wallet_synch_height; std::atomic* plast_daemon_height; std::atomic* plast_daemon_network_state; - std::atomic* plast_daemon_is_disconnected; + //std::atomic* plast_daemon_is_disconnected; + std::shared_ptr m_pproxy_diagnostig_info; std::atomic has_related_alias_in_unconfirmed; std::atomic need_to_update_wallet_info; std::atomic long_refresh_in_progress; @@ -192,7 +193,8 @@ private: bool m_use_deffered_global_outputs; std::atomic m_last_daemon_height; std::atomic m_last_daemon_network_state; - std::atomic m_last_daemon_is_disconnected; + std::shared_ptr m_pproxy_diganostic_info; + //std::atomic m_last_daemon_is_disconnected; // std::atomic m_last_wallet_synch_height; std::atomic m_wallet_id_counter; std::atomic m_dont_save_wallet_at_stop;