From 644557d44d1473a38727879f7188a41383b31928 Mon Sep 17 00:00:00 2001 From: Doyle Date: Wed, 18 Dec 2019 16:22:44 +1100 Subject: [PATCH] Stop endlessly asking the user for password after refreshing --- src/simplewallet/simplewallet.cpp | 14 +++++++++++--- src/simplewallet/simplewallet.h | 2 ++ src/wallet/wallet2.cpp | 3 +-- src/wallet/wallet2.h | 8 +++++++- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 5dbcf6500..f0a50eb50 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -4999,15 +4999,23 @@ boost::optional simple_wallet::on_get_password(const char // can't ask for password from a background thread if (!m_in_manual_refresh.load(std::memory_order_relaxed)) { - message_writer(console_color_red, false) << boost::format(tr("Password needed %s")) % reason; - m_cmd_binder.print_prompt(); + crypto::hash tx_pool_checksum = m_wallet->get_long_poll_tx_pool_checksum(); + if (m_password_asked_on_height != m_wallet->get_blockchain_current_height() || + m_password_asked_on_checksum != tx_pool_checksum) + { + m_password_asked_on_height = m_wallet->get_blockchain_current_height(); + m_password_asked_on_checksum = tx_pool_checksum; + + message_writer(console_color_red, false) << boost::format(tr("Password needed %s")) % reason; + m_cmd_binder.print_prompt(); + } return boost::none; } #ifdef HAVE_READLINE rdln::suspend_readline pause_readline; #endif - std::string msg = tr("Enter password"); + std::string msg = tr("Enter password "); if (reason && *reason) msg += reason; auto pwd_container = tools::password_container::prompt(false, msg.c_str()); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 064c63ba8..9e42dadc4 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -426,6 +426,8 @@ namespace cryptonote uint32_t m_current_subaddress_account; bool m_long_payment_id_support; + std::atomic m_password_asked_on_height; + crypto::hash m_password_asked_on_checksum; // MMS mms::message_store& get_message_store() const { return m_wallet->get_message_store(); }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 2964d19a2..d4852e94d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2899,8 +2899,7 @@ void wallet2::update_pool_state(bool refreshed) std::vector tx_hashes; { std::lock_guard lock(m_long_poll_tx_pool_cache_mutex); - tx_hashes = std::move(m_long_poll_tx_pool_cache); - m_long_poll_tx_pool_cache.clear(); + tx_hashes = m_long_poll_tx_pool_cache; } auto keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]() { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 9469eebef..135de3a4f 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1337,6 +1337,12 @@ private: bool import_key_images(signed_tx_set & signed_tx, size_t offset=0, bool only_selected_transfers=false); crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const; + crypto::hash get_long_poll_tx_pool_checksum() const + { + std::lock_guard lock(m_long_poll_tx_pool_cache_mutex); + return m_long_poll_tx_pool_checksum; + }; + // long_poll_pool_state is blocking and does NOT return to the caller until // the daemon detects a change in the contents of the txpool by comparing // our last tx pool checksum with theirs. @@ -1674,7 +1680,7 @@ private: std::recursive_mutex m_long_poll_mutex; epee::net_utils::http::http_simple_client m_long_poll_client; - std::mutex m_long_poll_tx_pool_cache_mutex; + mutable std::mutex m_long_poll_tx_pool_cache_mutex; std::vector m_long_poll_tx_pool_cache; crypto::hash m_long_poll_tx_pool_checksum = {};