diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a38a381..1f9284ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,8 @@ else() set(DEBUG_FLAGS "-g3 -O0") endif() set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable") - if(NOT APPLE) + + if(NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android")) set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto") endif() #if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW) diff --git a/src/common/error_codes.h b/src/common/error_codes.h index f8ad7898..2878c300 100644 --- a/src/common/error_codes.h +++ b/src/common/error_codes.h @@ -21,6 +21,7 @@ #define API_RETURN_CODE_WRONG_PASSWORD "WRONG_PASSWORD" #define API_RETURN_CODE_WALLET_WRONG_ID "WALLET_WRONG_ID" #define API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED "WALLET_WATCH_ONLY_NOT_SUPPORTED" +#define API_RETURN_CODE_WALLET_AUDITABLE_NOT_SUPPORTED "WALLET_AUDITABLE_NOT_SUPPORTED" #define API_RETURN_CODE_FILE_NOT_FOUND "FILE_NOT_FOUND" #define API_RETURN_CODE_ALREADY_EXISTS "ALREADY_EXISTS" #define API_RETURN_CODE_CANCELED "CANCELED" diff --git a/src/common/util.h b/src/common/util.h index 6b683082..0c5b0bb1 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -23,6 +23,12 @@ #include #endif +#ifdef NDEBUG + #define BUILD_TYPE "Release" +#else + #define BUILD_TYPE "Debug" +#endif + namespace tools { std::string get_host_computer_name(); 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/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 084112d6..ef8e0ff9 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -187,7 +187,6 @@ namespace plain_wallet epee::static_helpers::set_or_call_on_destruct(true, static_destroy_handler); - std::cout << "[INIT PLAIN_WALLET_INSTANCE]" << ENDL; std::shared_ptr ptr(new plain_wallet_instance()); set_bundle_working_dir(working_dir); @@ -208,13 +207,15 @@ namespace plain_wallet } ptr->gwm.set_use_deffered_global_outputs(true); - + if(!ptr->gwm.start()) { LOG_ERROR("Failed to start wallets_manager"); return GENERAL_INTERNAL_ERRROR_INIT; } + LOG_PRINT_L0("[INIT PLAIN_WALLET_INSTANCE] Ver:" << PROJECT_VERSION_LONG << "(" << BUILD_TYPE << ")"); + std::string wallets_folder = get_wallets_folder(); boost::system::error_code ec; boost::filesystem::create_directories(wallets_folder, ec); 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..b78ea372 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1339,6 +1339,8 @@ void wallet2::pull_blocks(size_t& blocks_added, std::atomic& stop) req.minimum_height = get_wallet_minimum_height(); if (is_auditable()) req.need_global_indexes = true; + if (req.minimum_height > m_height_of_start_sync) + m_height_of_start_sync = req.minimum_height; m_chain.get_short_chain_history(req.block_ids); bool r = m_core_proxy->call_COMMAND_RPC_GET_BLOCKS_DIRECT(req, res); @@ -1370,9 +1372,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 +1504,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..095d1ed9 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), @@ -68,6 +67,7 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), { #ifndef MOBILE_WALLET_BUILD m_offers_service.set_disabled(true); + m_pproxy_diganostic_info = m_rpc_proxy->get_proxy_diagnostic_info(); #endif //m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service); } @@ -272,10 +272,10 @@ 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)); + m_pproxy_diganostic_info = m_rpc_proxy->get_proxy_diagnostic_info(); } if(!command_line::has_arg(m_vm, arg_disable_logs_init)) @@ -706,7 +706,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())); @@ -852,6 +853,13 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st w->load(path, password); if (w->is_watch_only() && !w->is_auditable()) return API_RETURN_CODE_WALLET_WATCH_ONLY_NOT_SUPPORTED; +#ifndef MOBILE_WALLET_BUILD + //disable auditable wallets for now in mobile wallet + if (w->is_auditable()) + { + return API_RETURN_CODE_WALLET_AUDITABLE_NOT_SUPPORTED; + } +#endif w->get_recent_transfers_history(owr.recent_history.history, 0, txs_to_return, owr.recent_history.total_history_items); //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history); @@ -1055,6 +1063,13 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: { bool auditable_watch_only = restore_key.find(':') != std::string::npos; w->restore(path, password, restore_key, auditable_watch_only); +#ifndef MOBILE_WALLET_BUILD + //disable auditable wallets for now in mobile wallet + if (w->is_auditable()) + { + return API_RETURN_CODE_WALLET_AUDITABLE_NOT_SUPPORTED; + } +#endif owr.seed = w->get_account().get_seed_phrase(); } catch (const tools::error::file_exists&) @@ -1361,7 +1376,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 +1389,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 +1816,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..ccd054e6 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;