forked from lthn/blockchain
Merge branch 'wallet_busy_core' into develop
This commit is contained in:
commit
b11b4f19b0
11 changed files with 79 additions and 28 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@
|
|||
#include <dbghelp.h>
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define BUILD_TYPE "Release"
|
||||
#else
|
||||
#define BUILD_TYPE "Debug"
|
||||
#endif
|
||||
|
||||
namespace tools
|
||||
{
|
||||
std::string get_host_computer_name();
|
||||
|
|
|
|||
|
|
@ -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<bool> *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<bool> *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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<time_t> m_last_success_interract_time;
|
||||
std::atomic<bool> *m_plast_daemon_is_disconnected;
|
||||
std::atomic<bool> m_last_daemon_is_disconnected_stub;
|
||||
|
||||
unsigned int m_connection_timeout;
|
||||
size_t m_attempts_count;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<bool> is_busy;
|
||||
std::atomic<time_t> last_success_interract_time;
|
||||
std::atomic<bool> 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<const proxy_diagnostic_info> get_proxy_diagnostic_info() const { return m_pdiganostic_info; }
|
||||
std::shared_ptr<proxy_diagnostic_info> 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<proxy_diagnostic_info> m_pdiganostic_info;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<plain_wallet_instance> 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);
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -1339,6 +1339,8 @@ void wallet2::pull_blocks(size_t& blocks_added, std::atomic<bool>& 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<bool>& 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);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ public:
|
|||
std::atomic<uint64_t> last_wallet_synch_height;
|
||||
std::atomic<uint64_t>* plast_daemon_height;
|
||||
std::atomic<uint64_t>* plast_daemon_network_state;
|
||||
std::atomic<bool>* plast_daemon_is_disconnected;
|
||||
//std::atomic<bool>* plast_daemon_is_disconnected;
|
||||
std::shared_ptr<const tools::proxy_diagnostic_info> m_pproxy_diagnostig_info;
|
||||
std::atomic<bool> has_related_alias_in_unconfirmed;
|
||||
std::atomic<bool> need_to_update_wallet_info;
|
||||
std::atomic<bool> long_refresh_in_progress;
|
||||
|
|
@ -192,7 +193,8 @@ private:
|
|||
bool m_use_deffered_global_outputs;
|
||||
std::atomic<uint64_t> m_last_daemon_height;
|
||||
std::atomic<uint64_t> m_last_daemon_network_state;
|
||||
std::atomic<bool> m_last_daemon_is_disconnected;
|
||||
std::shared_ptr<const tools::proxy_diagnostic_info> m_pproxy_diganostic_info;
|
||||
//std::atomic<bool> m_last_daemon_is_disconnected;
|
||||
// std::atomic<uint64_t> m_last_wallet_synch_height;
|
||||
std::atomic<uint64_t> m_wallet_id_counter;
|
||||
std::atomic<bool> m_dont_save_wallet_at_stop;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue