1
0
Fork 0
forked from lthn/blockchain

added wallets_manager deinitialization before everyone dies

This commit is contained in:
cryptozoidberg 2020-05-14 19:23:17 +02:00
parent 1af8862202
commit 29aa2a25de
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 33 additions and 17 deletions

View file

@ -42,9 +42,22 @@ struct plain_wallet_instance
std::shared_ptr<plain_wallet_instance> ginstance_ptr;
#define GET_INSTANCE_PTR(ptr_name) \
auto ptr_name = std::atomic_load(&ginstance_ptr); \
if (!ptr_name) \
{ \
LOG_ERROR("Core already deinitialised or not initialized yet."); \
epee::json_rpc::response<view::api_responce_return_code, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response); \
ok_response.result.return_code = API_RETURN_CODE_UNINITIALIZED; \
return epee::serialization::store_t_to_json(ok_response); \
}
void deinit();
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([]()
{
std::cout << "[LEAVE HANDLER CALLED]" << ENDL;
std::cout << "[BEFORE DEINIT]" << ENDL;
deinit();
std::cout << "[AFTER DEINIT]" << ENDL;
});
namespace plain_wallet
@ -132,7 +145,11 @@ namespace plain_wallet
//wait other callers finish
local_ptr->gjobs_lock.lock();
local_ptr->gjobs_lock.unlock();
bool r = local_ptr->gwm.quick_stop_no_save();
std::cout << "[QUICK_STOP_NO_SAVE] return " << r;
//let's prepare wallet manager for quick shutdown
local_ptr.reset();
}
}
@ -252,16 +269,6 @@ namespace plain_wallet
return epee::serialization::store_t_to_json(ok_response);
}
#define GET_INSTANCE_PTR(ptr_name) \
auto ptr_name = std::atomic_load(&ginstance_ptr); \
if (!ptr_name) \
{ \
LOG_ERROR("Core already deinitialised or not initialized yet."); \
epee::json_rpc::response<view::api_responce_return_code, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response); \
ok_response.result.return_code = API_RETURN_CODE_UNINITIALIZED; \
return epee::serialization::store_t_to_json(ok_response); \
}
std::string get_connectivity_status()
{
GET_INSTANCE_PTR(inst_ptr);

View file

@ -56,7 +56,8 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub),
m_ui_opt(AUTO_VAL_INIT(m_ui_opt)),
m_remote_node_mode(false),
m_is_pos_allowed(false),
m_qt_logs_enbaled(false)
m_qt_logs_enbaled(false),
dont_save_wallet_at_stop(false)
{
#ifndef MOBILE_WALLET_BUILD
m_offers_service.set_disabled(true);
@ -87,6 +88,7 @@ wallets_manager::~wallets_manager()
{
TRY_ENTRY();
stop();
LOG_LEVEL_0("[~WALLETS_MANAGER] destroyed");
CATCH_ENTRY_NO_RETURN();
}
@ -297,12 +299,17 @@ bool wallets_manager::stop()
LOG_PRINT_L0("Waiting for backend main worker thread: " << m_main_worker_thread.get_id());
m_main_worker_thread.join();
}
return true;
}
bool wallets_manager::quick_stop_no_save() //stop without storing wallets
{
dont_save_wallet_at_stop = true;
return stop();
}
std::string wallets_manager::get_config_folder()
{
return m_data_dir;
@ -508,7 +515,8 @@ void wallets_manager::main_worker(const po::variables_map& m_vm)
wo.second.stop_for_refresh = true;
wo.second.w.unlocked_get()->stop();
wo.second.w->get()->store();
if(!dont_save_wallet_at_stop)
wo.second.w->get()->store();
}
catch (const std::exception& e)
{

View file

@ -71,7 +71,6 @@ public:
std::atomic<bool>* plast_daemon_is_disconnected;
std::atomic<bool> has_related_alias_in_unconfirmed;
std::atomic<bool> need_to_update_wallet_info;
std::atomic<bool> long_refresh_in_progress;
epee::critical_section long_refresh_in_progress_lock; //secure wallet state and prevent from long wait while long refresh is in work
@ -90,6 +89,7 @@ public:
bool init(int argc, char* argv[], view::i_view* pview_handler);
bool start();
bool stop();
bool quick_stop_no_save(); //stop without storing wallets
bool send_stop_signal();
std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr);
std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr);
@ -184,6 +184,7 @@ private:
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> dont_save_wallet_at_stop;
std::string m_data_dir;
view::gui_options m_ui_opt;