diff --git a/contrib/epee/include/misc_helpers.h b/contrib/epee/include/misc_helpers.h index 8c5aba18..dd3067c8 100644 --- a/contrib/epee/include/misc_helpers.h +++ b/contrib/epee/include/misc_helpers.h @@ -77,7 +77,7 @@ /// @details Useful within a dtor - but only if nested within another try block /// (since we can still potentially throw here). See NESTED_*ENTRY() /// @todo Exception dispatcher class -#define CATCH_ENTRY_NO_RETURN(location, custom_code) } \ +#define CATCH_ENTRY_NO_RETURN_CUSTOM(location, custom_code) } \ catch(const std::exception& ex) \ { \ (void)(ex); \ @@ -90,6 +90,7 @@ custom_code; \ } +#define CATCH_ENTRY_NO_RETURN() CATCH_ENTRY_NO_RETURN_CUSTOM(LOCATION_SS, (void)0) #define CATCH_ENTRY_WITH_FORWARDING_EXCEPTION() } \ catch(const std::exception& ex) \ @@ -108,7 +109,7 @@ #define NESTED_TRY_ENTRY() try { TRY_ENTRY(); #define NESTED_CATCH_ENTRY(location) \ - CATCH_ENTRY_NO_RETURN(location, {}); \ + CATCH_ENTRY_NO_RETURN_CUSTOM(location, {}); \ } catch (...) {} diff --git a/src/common/db_backend_lmdb.cpp b/src/common/db_backend_lmdb.cpp index b02a8fe7..69122969 100644 --- a/src/common/db_backend_lmdb.cpp +++ b/src/common/db_backend_lmdb.cpp @@ -11,8 +11,8 @@ #define BUF_SIZE 1024 -#define CHECK_AND_ASSERT_MESS_LMDB_DB(rc, ret, mess) CHECK_AND_ASSERT_MES(res == MDB_SUCCESS, ret, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess); -#define CHECK_AND_ASSERT_THROW_MESS_LMDB_DB(rc, mess) CHECK_AND_ASSERT_THROW_MES(res == MDB_SUCCESS, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess); +#define CHECK_AND_ASSERT_MESS_LMDB_DB(rc, ret, mess) CHECK_AND_ASSERT_MES(rc == MDB_SUCCESS, ret, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess); +#define CHECK_AND_ASSERT_THROW_MESS_LMDB_DB(rc, mess) CHECK_AND_ASSERT_THROW_MES(rc == MDB_SUCCESS, "[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess); #define ASSERT_MES_AND_THROW_LMDB(rc, mess) ASSERT_MES_AND_THROW("[DB ERROR]:(" << rc << ")" << mdb_strerror(rc) << ", [message]: " << mess); #undef LOG_DEFAULT_CHANNEL diff --git a/src/currency_core/bc_offers_service.cpp b/src/currency_core/bc_offers_service.cpp index 44e1de3e..59064632 100644 --- a/src/currency_core/bc_offers_service.cpp +++ b/src/currency_core/bc_offers_service.cpp @@ -31,8 +31,10 @@ namespace bc_services //------------------------------------------------------------------ bc_offers_service::~bc_offers_service() { + TRY_ENTRY(); if (!m_deinitialized) deinit(); + CATCH_ENTRY_NO_RETURN(); } //------------------------------------------------------------------ bool bc_offers_service::init(const std::string& config_folder, const boost::program_options::variables_map& vm) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index f9716bd1..56705fc7 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -87,7 +87,7 @@ namespace currency bool pos, const pos_entry& pe) { - uint64_t block_reward; + uint64_t block_reward = 0; if (!get_block_reward(pos, median_size, current_block_size, already_generated_coins, block_reward, height)) { LOG_ERROR("Block is too big"); @@ -1525,14 +1525,16 @@ namespace currency bool is_out_to_acc(const account_keys& acc, const txout_to_key& out_key, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk); + if (!derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk)) + return false; return pk == out_key.key; } //--------------------------------------------------------------- bool is_out_to_acc(const account_keys& acc, const txout_multisig& out_multisig, const crypto::key_derivation& derivation, size_t output_index) { crypto::public_key pk; - derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk); + if (!derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk)) + return false; auto it = std::find(out_multisig.keys.begin(), out_multisig.keys.end(), pk); if (out_multisig.keys.end() == it) return false; @@ -1593,7 +1595,8 @@ namespace currency bool lookup_acc_outs(const account_keys& acc, const transaction& tx, const crypto::public_key& tx_pub_key, std::vector& outs, uint64_t& money_transfered, crypto::key_derivation& derivation) { money_transfered = 0; - generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation); + bool r = generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation); + CHECK_AND_ASSERT_MES(r, false, "unable to generate derivation from tx_pub = " << tx_pub_key << " * view_sec, invalid tx_pub?"); if (is_coinbase(tx) && get_block_height(tx) == 0 && tx_pub_key == ggenesis_tx_pub_key) { diff --git a/src/currency_core/miner.cpp b/src/currency_core/miner.cpp index ff2579e2..005c274c 100644 --- a/src/currency_core/miner.cpp +++ b/src/currency_core/miner.cpp @@ -56,13 +56,16 @@ namespace currency m_current_hash_rate(0), m_last_hr_merge_time(0), m_hashes(0), - m_config(AUTO_VAL_INIT(m_config)) + m_config(AUTO_VAL_INIT(m_config)), + m_mine_address{} { } //----------------------------------------------------------------------------------------------------- miner::~miner() { + TRY_ENTRY(); stop(); + CATCH_ENTRY_NO_RETURN(); } //----------------------------------------------------------------------------------------------------- bool miner::set_block_template(const block& bl, const wide_difficulty_type& di, uint64_t height) diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index dab77d8b..0bddba44 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -677,8 +677,7 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str try { w->load(path, password); - w->get_recent_transfers_history(owr.recent_history.history, 0, 0); - owr.recent_history.total_history_items = w->get_recent_transfers_total_count(); + w->get_recent_transfers_history(owr.recent_history.history, 0, 100, owr.recent_history.total_history_items); //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history); //workaround for missed fee @@ -716,7 +715,7 @@ std::string daemon_backend::get_recent_transfers(size_t wallet_id, uint64_t offs return API_RETURN_CODE_CORE_BUSY; } - w->get()->get_recent_transfers_history(tr_hist.history, offset, count); + w->get()->get_recent_transfers_history(tr_hist.history, offset, count, tr_hist.total_history_items); //workaround for missed fee for (auto & he : tr_hist.history) { diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 29ff8705..c57fa524 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -80,7 +80,8 @@ namespace nodetool m_ip_address{}, m_last_stat_request_time{}, m_use_only_priority_peers(false), - m_peer_livetime{} + m_peer_livetime{}, + m_debug_requests_enabled(false) {} diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index c70b45d7..34d930de 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -100,9 +100,9 @@ namespace nodetool if (m_offline_mode) return false; - //@#@ workaround + //@#@ temporary workaround return true; - +#if 0 CRITICAL_REGION_LOCAL(m_blocked_ips_lock); auto it = m_blocked_ips.find(addr); if(it == m_blocked_ips.end()) @@ -114,6 +114,7 @@ namespace nodetool return true; } return false; +#endif } //----------------------------------------------------------------------------------- template diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 87532a6a..1cc11544 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -716,7 +716,8 @@ bool simple_wallet::list_recent_transfers(const std::vector& args) { std::vector unconfirmed; std::vector recent; - m_wallet->get_recent_transfers_history(recent, 0, 0); + uint64_t total = 0; + m_wallet->get_recent_transfers_history(recent, 0, 0, total); m_wallet->get_unconfirmed_transfers(unconfirmed); //workaround for missed fee @@ -741,7 +742,8 @@ bool simple_wallet::list_recent_transfers_ex(const std::vector& arg { std::vector unconfirmed; std::vector recent; - m_wallet->get_recent_transfers_history(recent, 0, 0); + uint64_t total = 0; + m_wallet->get_recent_transfers_history(recent, 0, 0, total); m_wallet->get_unconfirmed_transfers(unconfirmed); //workaround for missed fee stringstream ss; @@ -1274,7 +1276,7 @@ bool simple_wallet::print_address(const std::vector &args/* = std:: bool simple_wallet::show_seed(const std::vector &args) { success_msg_writer() << "Here's your wallet's seed phrase. Write it down and keep in a safe place."; - success_msg_writer(true) << "Anyone who knows the following 25 words can access you wallet:"; + success_msg_writer(true) << "Anyone who knows the following 25 words can access your wallet:"; std::cout << m_wallet->get_account().get_restore_braindata() << std::endl << std::flush; return true; } @@ -1282,7 +1284,7 @@ bool simple_wallet::show_seed(const std::vector &args) bool simple_wallet::spendkey(const std::vector &args) { message_writer(epee::log_space::console_color_red, true, std::string()) - << "WARNING! Anyone who knows the following secret key can access you wallet and spend your coins."; + << "WARNING! Anyone who knows the following secret key can access your wallet and spend your coins."; const account_keys& keys = m_wallet->get_account().get_keys(); std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_spend_secret_key) << std::endl; @@ -1294,7 +1296,7 @@ bool simple_wallet::spendkey(const std::vector &args) bool simple_wallet::viewkey(const std::vector &args) { message_writer(epee::log_space::console_color_yellow, false, std::string()) - << "WARNING! Anyone who knows the following secret key can view you wallet (but can not spend your coins)."; + << "WARNING! Anyone who knows the following secret key can view your wallet (but can not spend your coins)."; const account_keys& keys = m_wallet->get_account().get_keys(); std::cout << "secret: " << epee::string_tools::pod_to_hex(keys.m_view_secret_key) << std::endl; diff --git a/src/version.h.in b/src/version.h.in index bd46ad58..bdce3708 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "4" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 71 +#define PROJECT_VERSION_BUILD_NO 72 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2d411e68..68779858 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2119,7 +2119,7 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(!data_file.fail(), "failed to open binary wallet file for saving: " << tmp_file_path.string()); data_file << header_buff << keys_buff; - WLT_LOG_L0("Storing to " << tmp_file_path.string() << " ..."); + WLT_LOG_L0("Storing to temporary file " << tmp_file_path.string() << " ..."); r = tools::portble_serialize_obj_to_stream(*this, data_file); if (!r) @@ -2132,15 +2132,39 @@ void wallet2::store(const std::wstring& path_to_save, const std::string& passwor data_file.flush(); data_file.close(); + WLT_LOG_L1("Stored successfully to temporary file " << tmp_file_path.string()); + // for the sake of safety perform a double-renaming: wallet file -> old tmp, new tmp -> wallet file, remove old tmp boost::filesystem::path tmp_old_file_path = boost::filesystem::path(path_to_save); tmp_old_file_path += L".oldtmp_" + std::to_wstring(ts); if (boost::filesystem::is_regular_file(path_to_save)) + { boost::filesystem::rename(path_to_save, tmp_old_file_path); + WLT_LOG_L1("Renamed: " << ascii_path_to_save << " -> " << tmp_old_file_path.string()); + } + boost::filesystem::rename(tmp_file_path, path_to_save); - boost::filesystem::remove(tmp_old_file_path); + WLT_LOG_L1("Renamed: " << tmp_file_path.string() << " -> " << ascii_path_to_save); + + if (boost::filesystem::remove(tmp_old_file_path)) + { + WLT_LOG_L1("Removed temporary file: " << tmp_old_file_path.string()); + } + + bool path_to_save_exists = boost::filesystem::is_regular_file(path_to_save); + bool tmp_file_path_exists = boost::filesystem::is_regular_file(tmp_file_path); + bool tmp_old_file_path_exists = boost::filesystem::is_regular_file(tmp_old_file_path); + if (path_to_save_exists && !tmp_file_path_exists && !tmp_old_file_path_exists) + { + WLT_LOG_L0("Wallet was successfully stored to " << ascii_path_to_save); + } + else + { + WLT_LOG_ERROR("Wallet stroing to " << ascii_path_to_save << " might not be successfull: path_to_save_exists=" << path_to_save_exists << ", tmp_file_path_exists=" << tmp_file_path_exists << ", tmp_old_file_path_exists=" << tmp_old_file_path_exists); + throw tools::error::wallet_common_error(LOCATION_STR, "Wallet file storing might not be successfull. Please make sure you have backed up your seed phrase and check log for details."); + } } //---------------------------------------------------------------------------------------------------- void wallet2::store_watch_only(const std::wstring& path_to_save, const std::string& password) const @@ -2558,7 +2582,7 @@ uint64_t wallet2::get_recent_transfers_total_count() return m_transfer_history.size(); } //---------------------------------------------------------------------------------------------------- -void wallet2::get_recent_transfers_history(std::vector& trs, size_t offset, size_t count) +void wallet2::get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total) { if (offset >= m_transfer_history.size()) return; @@ -2569,6 +2593,7 @@ void wallet2::get_recent_transfers_history(std::vector& offers, uint64_t amount) -{ - - for (uint64_t i = 0; i != amount; i++) - { - bc_services::offer_details od; - od.offer_type = rand() % 4; - od.amount_primary = rand(); - od.amount_target = rand(); - od.bonus = get_random_rext(10); - od.target = get_random_rext(10); - od.location_country = get_random_rext(6); - od.location_city = get_random_rext(10); - od.contacts = get_random_rext(20); - od.comment = get_random_rext(30); - od.payment_types = get_random_rext(10); - od.deal_option = get_random_rext(10); - od.category = get_random_rext(4); - od.expiration_time = 3; - - crypto::hash tx_id = crypto::rand(); - offers.push_back(bc_services::offer_details_ex()); - bc_services::offer_details_ex& odl = offers.back(); - static_cast(odl) = od; - odl.timestamp = m_core_runtime_config.get_core_time(); - odl.index_in_tx = 0; - odl.tx_hash = tx_id; - odl.stopped = false; - odl.fee = 10000; - } - return true; -} -//---------------------------------------------------------------------------------------------------- void wallet2::build_escrow_release_templates(crypto::hash multisig_id, uint64_t fee, currency::transaction& tx_release_template, diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 382bac78..e214f5a7 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -464,7 +464,7 @@ namespace tools currency::account_base& get_account() { return m_account; } const currency::account_base& get_account() const { return m_account; } - void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count); + void get_recent_transfers_history(std::vector& trs, size_t offset, size_t count, uint64_t& total); uint64_t get_recent_transfers_total_count(); void get_unconfirmed_transfers(std::vector& trs); void init(const std::string& daemon_address = "http://localhost:8080"); @@ -709,7 +709,6 @@ namespace tools bool reset_password(const std::string& pass); bool is_password_valid(const std::string& pass); bool get_actual_offers(std::list& offers); - bool get_fake_offers(std::list& offers, uint64_t amount); bool process_contract_info(wallet_public::wallet_transfer_info& wti, const std::vector& decrypted_attach); bool handle_proposal(wallet_public::wallet_transfer_info& wti, const bc_services::proposal_body& prop); void accept_proposal(const crypto::hash& contract_id, uint64_t b_acceptance_fee, currency::transaction* p_acceptance_tx = nullptr); diff --git a/tests/performance_tests/free_space_check.h b/tests/performance_tests/free_space_check.h index 9ab54e13..a4d4d21e 100644 --- a/tests/performance_tests/free_space_check.h +++ b/tests/performance_tests/free_space_check.h @@ -13,14 +13,14 @@ namespace fs = boost::filesystem; -std::string exec(const char* cmd) +std::string exec(const std::string& str) { std::array buffer; #if defined(WIN32) - std::unique_ptr pipe(_popen(cmd, "r"), _pclose); + std::unique_ptr pipe(_popen(str.c_str(), "r"), _pclose); #else - std::unique_ptr pipe(popen(cmd, "r"), pclose); + std::unique_ptr pipe(popen(str.c_str(), "r"), pclose); #endif if (!pipe) @@ -89,12 +89,13 @@ void free_space_check() bool r = false; #ifdef WIN32 - output = exec("dir"); + std::string command = "dir"; #else - output = exec("df -h"); + std::string command = "df -h && df -i"; #endif + output = exec(command); - LOG_PRINT_L0("test command output:" << std::endl << output); + LOG_PRINT_L0("test command " << command << ", output:" << std::endl << output); r = try_write_test_file(test_file_size); LOG_PRINT_L0("test file write: " << (r ? "OK" : "fail")); @@ -122,12 +123,9 @@ void free_space_check() } // free space is not ok! LOG_PRINT_YELLOW("1) fs::space() : available: " << si.available << ", free: " << si.free << ", capacity: " << si.capacity, LOG_LEVEL_0); -#ifdef WIN32 - output = exec("dir"); -#else - output = exec("df -h"); -#endif - LOG_PRINT_YELLOW(output, LOG_LEVEL_0); + + output = exec(command); + LOG_PRINT_YELLOW("executed command: " << command << ", output: " << std::endl << output, LOG_LEVEL_0); // try one again asap si = fs::space(current_path); diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 8c04a1bf..a490ad7b 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -27,6 +27,9 @@ int main(int argc, char** argv) epee::string_tools::set_module_name_and_folder(argv[0]); epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); + epee::log_space::log_singletone::add_logger(LOGGER_FILE, + epee::log_space::log_singletone::get_default_log_file().c_str(), + epee::log_space::log_singletone::get_default_log_folder().c_str()); //run_serialization_performance_test(); //return 1;