From b02fc0b5d850df5c4bec791aac8208bb6f814d29 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 31 Aug 2020 16:37:05 +0300 Subject: [PATCH] wallet: all free space checks removed completely --- src/common/command_line.cpp | 1 - src/common/command_line.h | 1 - src/simplewallet/simplewallet.cpp | 8 +--- src/simplewallet/simplewallet.h | 1 - src/wallet/wallet2.cpp | 64 +------------------------------ src/wallet/wallet2.h | 3 -- src/wallet/wallets_manager.cpp | 3 +- src/wallet/wallets_manager.h | 1 - 8 files changed, 3 insertions(+), 79 deletions(-) diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index a64970f1..92a59b61 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -31,7 +31,6 @@ namespace command_line const arg_descriptor arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true }; const arg_descriptor arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true }; - const arg_descriptor arg_disable_wallet_free_space_check = { "disable-wallet-free-space-check", "Disable checking for free space in wallet", false, true }; const arg_descriptor arg_enable_offers_service = { "enable-offers-service", "Enables marketplace feature", false, false}; const arg_descriptor arg_db_engine = { "db-engine", "Specify database engine for storage. May be \"lmdb\"(default) or \"mdbx\"", ARG_DB_ENGINE_LMDB, false }; diff --git a/src/common/command_line.h b/src/common/command_line.h index 4ad99a0d..f19a04ae 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -210,7 +210,6 @@ namespace command_line extern const arg_descriptor arg_disable_upnp; extern const arg_descriptor arg_disable_stop_if_time_out_of_sync; extern const arg_descriptor arg_disable_stop_on_low_free_space; - extern const arg_descriptor arg_disable_wallet_free_space_check; extern const arg_descriptor arg_enable_offers_service; extern const arg_descriptor arg_db_engine; extern const arg_descriptor arg_no_predownload; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 48cba3af..c37fef0a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -183,8 +183,7 @@ simple_wallet::simple_wallet() m_do_not_set_date(false), m_do_pos_mining(false), m_refresh_progress_reporter(*this), - m_offline_mode(false), - m_free_space_check_enabled(true) + m_offline_mode(false) { m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, _1), "start_mining - Start mining in daemon"); m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), "Stop mining in daemon"); @@ -370,7 +369,6 @@ void simple_wallet::handle_command_line(const boost::program_options::variables_ m_do_not_set_date = command_line::get_arg(vm, arg_dont_set_date); m_do_pos_mining = command_line::get_arg(vm, arg_do_pos_mining); m_restore_wallet = command_line::get_arg(vm, arg_restore_wallet); - m_free_space_check_enabled = !command_line::get_arg(vm, command_line::arg_disable_wallet_free_space_check); } //---------------------------------------------------------------------------------------------------- bool simple_wallet::try_connect_to_daemon() @@ -392,7 +390,6 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas m_wallet.reset(new tools::wallet2()); m_wallet->callback(this->shared_from_this()); m_wallet->set_do_rise_transfer(false); - m_wallet->set_free_space_check_enabled(m_free_space_check_enabled); try { m_wallet->generate(epee::string_encoding::utf8_to_wstring(m_wallet_file), password, create_auditable_wallet); @@ -432,7 +429,6 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st m_wallet.reset(new tools::wallet2()); m_wallet->callback(this->shared_from_this()); m_wallet->set_do_rise_transfer(true); - m_wallet->set_free_space_check_enabled(m_free_space_check_enabled); try { if (tracking_wallet) @@ -478,7 +474,6 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa m_wallet_file = wallet_file; m_wallet.reset(new tools::wallet2()); m_wallet->callback(shared_from_this()); - m_wallet->set_free_space_check_enabled(m_free_space_check_enabled); while (true) { @@ -1773,7 +1768,6 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_offline_mode); command_line::add_arg(desc_params, command_line::arg_log_file); command_line::add_arg(desc_params, command_line::arg_log_level); - command_line::add_arg(desc_params, command_line::arg_disable_wallet_free_space_check); tools::wallet_rpc_server::init_options(desc_params); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 6f60b0aa..8fc44fc9 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -166,7 +166,6 @@ namespace currency bool m_print_brain_wallet; bool m_do_pos_mining; bool m_offline_mode; - bool m_free_space_check_enabled; std::string m_restore_wallet; epee::console_handlers_binder m_cmd_binder; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e7391765..3ce28f9e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -52,8 +52,7 @@ namespace tools m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST), m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE), m_current_wallet_file_size(0), - m_use_deffered_global_outputs(false), - m_do_free_space_check(true) + m_use_deffered_global_outputs(false) { m_core_runtime_config = currency::get_default_core_runtime_config(); } @@ -2290,8 +2289,6 @@ void wallet2::generate(const std::wstring& path, const std::string& pass, bool a clear(); prepare_file_names(path); - check_for_free_space_and_throw_if_it_lacks(m_wallet_file); - m_password = pass; m_account.generate(auditable_wallet); init_log_prefix(); @@ -2341,8 +2338,6 @@ void wallet2::load(const std::wstring& wallet_, const std::string& password) clear(); prepare_file_names(wallet_); - check_for_free_space_and_throw_if_it_lacks(m_wallet_file); - m_password = password; std::string keys_buff; @@ -2419,8 +2414,6 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor { LOG_PRINT_L0("(before storing: pending_key_images: " << m_pending_key_images.size() << ", pki file elements: " << m_pending_key_images_file_container.size() << ", tx_keys: " << m_tx_keys.size() << ")"); - // check_for_free_space_and_throw_if_it_lacks(path_to_save); temporary disabled, wallet saving implemented in two-stage scheme to avoid data loss due to lack of space - std::string ascii_path_to_save = epee::string_encoding::convert_to_ansii(path_to_save); //prepare data @@ -2515,15 +2508,6 @@ void wallet2::set_use_deffered_global_outputs(bool use) m_use_deffered_global_outputs = use; } //---------------------------------------------------------------------------------------------------- -void wallet2::set_free_space_check_enabled(bool value) -{ - if (value != m_do_free_space_check) - { - WLT_LOG_L0("free space check " << (value ? "enabled" : "disabled")); - } - m_do_free_space_check = value; -} -//---------------------------------------------------------------------------------------------------- void wallet2::store_watch_only(const std::wstring& path_to_save, const std::string& password) const { WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(path_to_save != m_wallet_file, "trying to save watch-only wallet to the same wallet file!"); @@ -2572,52 +2556,6 @@ void wallet2::store_watch_only(const std::wstring& path_to_save, const std::stri wo.store(path_to_save, password); } //---------------------------------------------------------------------------------------------------- -void wallet2::check_for_free_space_and_throw_if_it_lacks(const std::wstring& wallet_filename, uint64_t exact_size_needed_if_known /* = UINT64_MAX */) -{ - namespace fs = boost::filesystem; - - if (!m_do_free_space_check) - return; - - try - { - fs::path wallet_file_path(wallet_filename); - fs::path base_path = wallet_file_path.parent_path(); - if (base_path.empty()) - base_path = fs::path("."); - WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(fs::is_directory(base_path), "directory does not exist: " << base_path.string()); - - uint64_t min_free_size = exact_size_needed_if_known; - if (min_free_size == UINT64_MAX) - { - // if exact size needed is unknown -- determine it as - // twice the original wallet file size or MINIMUM_REQUIRED_WALLET_FREE_SPACE_BYTES, which one is bigger - min_free_size = MINIMUM_REQUIRED_WALLET_FREE_SPACE_BYTES; - if (fs::is_regular_file(wallet_file_path)) - min_free_size = std::max(min_free_size, 2 * static_cast(fs::file_size(wallet_file_path))); - } - else - { - min_free_size += 1024 * 1024 * 10; // add a little for FS overhead and so - } - - fs::space_info si = fs::space(base_path); - WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(si.available > min_free_size, "free space at " << base_path.string() << " is too low: " << si.available << ", required minimum is: " << min_free_size); - } - catch (tools::error::wallet_common_error&) - { - throw; - } - catch (std::exception& e) - { - WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(false, "failed to determine free space: " << e.what()); - } - catch (...) - { - WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(false, "failed to determine free space: unknown exception"); - } -} -//---------------------------------------------------------------------------------------------------- uint64_t wallet2::unlocked_balance() const { uint64_t stub = 0; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4130af47..57883076 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -802,7 +802,6 @@ namespace tools uint64_t get_sync_progress(); uint64_t get_wallet_file_size()const; void set_use_deffered_global_outputs(bool use); - void set_free_space_check_enabled(bool value); private: @@ -922,7 +921,6 @@ private: void exception_handler(); void exception_handler() const; uint64_t get_minimum_allowed_fee_for_contract(const crypto::hash& ms_id); - void check_for_free_space_and_throw_if_it_lacks(const std::wstring& path, uint64_t exact_size_needed_if_known = UINT64_MAX); bool generate_packing_transaction_if_needed(currency::transaction& tx, uint64_t fake_outputs_number); bool store_unsigned_tx_to_file_and_reserve_transfers(const finalize_tx_param& ftp, const std::string& filename, std::string* p_unsigned_tx_blob_str = nullptr); void check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp); @@ -981,7 +979,6 @@ private: mutable uint64_t m_current_wallet_file_size; bool m_use_deffered_global_outputs; - bool m_do_free_space_check; //this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions friend class test_generator; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 828c88a7..e65cf6dd 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -63,8 +63,7 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), m_is_pos_allowed(false), m_qt_logs_enbaled(false), m_dont_save_wallet_at_stop(false), - m_use_deffered_global_outputs(false), - m_free_space_check_enabled(true) + m_use_deffered_global_outputs(false) { #ifndef MOBILE_WALLET_BUILD m_offers_service.set_disabled(true); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 3edfd7d8..ccd054e6 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -213,7 +213,6 @@ private: bool m_remote_node_mode; bool m_qt_logs_enbaled; - bool m_free_space_check_enabled; std::string m_qt_dev_tools; std::atomic m_is_pos_allowed;