mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 19:33:28 +01:00
Merge pull request #817
4b1c0d6
simplewallet: some background refresh threading fixes (moneromooo-monero)
This commit is contained in:
commit
cde9dce9c4
@ -77,6 +77,19 @@ typedef cryptonote::simple_wallet sw;
|
|||||||
|
|
||||||
#define DEFAULT_MIX 4
|
#define DEFAULT_MIX 4
|
||||||
|
|
||||||
|
#define LOCK_REFRESH_THREAD_SCOPE() \
|
||||||
|
bool auto_refresh_run = m_auto_refresh_run.load(std::memory_order_relaxed); \
|
||||||
|
m_auto_refresh_run.store(false, std::memory_order_relaxed); \
|
||||||
|
/* stop any background refresh, and take over */ \
|
||||||
|
m_wallet->stop(); \
|
||||||
|
boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex); \
|
||||||
|
m_auto_refresh_cond.notify_one(); \
|
||||||
|
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ \
|
||||||
|
m_auto_refresh_run.store(auto_refresh_run, std::memory_order_relaxed); \
|
||||||
|
if (auto_refresh_run) \
|
||||||
|
m_auto_refresh_thread = boost::thread([&]{wallet_refresh_thread();}); \
|
||||||
|
})
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const command_line::arg_descriptor<std::string> arg_wallet_file = {"wallet-file", sw::tr("Use wallet <arg>"), ""};
|
const command_line::arg_descriptor<std::string> arg_wallet_file = {"wallet-file", sw::tr("Use wallet <arg>"), ""};
|
||||||
@ -1614,6 +1627,7 @@ bool simple_wallet::save(const std::vector<std::string> &args)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
m_wallet->store();
|
m_wallet->store();
|
||||||
success_msg_writer() << tr("Wallet data saved");
|
success_msg_writer() << tr("Wallet data saved");
|
||||||
}
|
}
|
||||||
@ -1782,12 +1796,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
|
|||||||
if (!try_connect_to_daemon())
|
if (!try_connect_to_daemon())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool auto_refresh_run = m_auto_refresh_run.load(std::memory_order_relaxed);
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
m_auto_refresh_run.store(false, std::memory_order_relaxed);
|
|
||||||
// stop any background refresh, and take over
|
|
||||||
m_wallet->stop();
|
|
||||||
boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex);
|
|
||||||
m_auto_refresh_cond.notify_one();
|
|
||||||
|
|
||||||
if (reset)
|
if (reset)
|
||||||
m_wallet->rescan_blockchain(false);
|
m_wallet->rescan_blockchain(false);
|
||||||
@ -1800,13 +1809,13 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_in_manual_refresh.store(true, std::memory_order_relaxed);
|
m_in_manual_refresh.store(true, std::memory_order_relaxed);
|
||||||
|
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_in_manual_refresh.store(false, std::memory_order_relaxed);});
|
||||||
m_wallet->refresh(start_height, fetched_blocks);
|
m_wallet->refresh(start_height, fetched_blocks);
|
||||||
m_in_manual_refresh.store(false, std::memory_order_relaxed);
|
|
||||||
ok = true;
|
ok = true;
|
||||||
// Clear line "Height xxx of xxx"
|
// Clear line "Height xxx of xxx"
|
||||||
std::cout << "\r \r";
|
std::cout << "\r \r";
|
||||||
success_msg_writer(true) << tr("Refresh done, blocks received: ") << fetched_blocks;
|
success_msg_writer(true) << tr("Refresh done, blocks received: ") << fetched_blocks;
|
||||||
show_balance();
|
show_balance_unlocked();
|
||||||
}
|
}
|
||||||
catch (const tools::error::daemon_busy&)
|
catch (const tools::error::daemon_busy&)
|
||||||
{
|
{
|
||||||
@ -1847,8 +1856,6 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset)
|
|||||||
fail_msg_writer() << tr("refresh failed: ") << ss.str() << ". " << tr("Blocks received: ") << fetched_blocks;
|
fail_msg_writer() << tr("refresh failed: ") << ss.str() << ". " << tr("Blocks received: ") << fetched_blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_in_manual_refresh.store(false, std::memory_order_relaxed);
|
|
||||||
m_auto_refresh_run.store(auto_refresh_run, std::memory_order_relaxed);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -1868,15 +1875,24 @@ bool simple_wallet::refresh(const std::vector<std::string>& args)
|
|||||||
return refresh_main(start_height, false);
|
return refresh_main(start_height, false);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
|
bool simple_wallet::show_balance_unlocked()
|
||||||
{
|
{
|
||||||
success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance()) << ", "
|
success_msg_writer() << tr("Balance: ") << print_money(m_wallet->balance()) << ", "
|
||||||
<< tr("unlocked balance: ") << print_money(m_wallet->unlocked_balance());
|
<< tr("unlocked balance: ") << print_money(m_wallet->unlocked_balance());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
bool simple_wallet::show_balance(const std::vector<std::string>& args/* = std::vector<std::string>()*/)
|
||||||
|
{
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
show_balance_unlocked();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args)
|
bool simple_wallet::show_incoming_transfers(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
bool filter = false;
|
bool filter = false;
|
||||||
bool available = false;
|
bool available = false;
|
||||||
if (!args.empty())
|
if (!args.empty())
|
||||||
@ -1942,6 +1958,8 @@ bool simple_wallet::show_payments(const std::vector<std::string> &args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
message_writer() << boost::format("%68s%68s%12s%21s%16s") %
|
message_writer() << boost::format("%68s%68s%12s%21s%16s") %
|
||||||
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
|
tr("payment") % tr("transaction") % tr("height") % tr("amount") % tr("unlock time");
|
||||||
|
|
||||||
@ -2019,6 +2037,7 @@ bool simple_wallet::rescan_spent(const std::vector<std::string> &args)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
m_wallet->rescan_spent();
|
m_wallet->rescan_spent();
|
||||||
}
|
}
|
||||||
catch (const tools::error::daemon_busy&)
|
catch (const tools::error::daemon_busy&)
|
||||||
@ -2127,6 +2146,8 @@ bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::str
|
|||||||
if (!try_connect_to_daemon())
|
if (!try_connect_to_daemon())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
std::vector<std::string> local_args = args_;
|
std::vector<std::string> local_args = args_;
|
||||||
|
|
||||||
size_t fake_outs_count;
|
size_t fake_outs_count;
|
||||||
@ -2397,6 +2418,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// figure out what tx will be necessary
|
// figure out what tx will be necessary
|
||||||
@ -2786,6 +2808,8 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
|
|||||||
}
|
}
|
||||||
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
|
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
crypto::secret_key tx_key;
|
crypto::secret_key tx_key;
|
||||||
bool r = m_wallet->get_tx_key(txid, tx_key);
|
bool r = m_wallet->get_tx_key(txid, tx_key);
|
||||||
if (r)
|
if (r)
|
||||||
@ -2820,6 +2844,8 @@ bool simple_wallet::check_tx_key(const std::vector<std::string> &args_)
|
|||||||
}
|
}
|
||||||
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
|
crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
cryptonote::blobdata tx_key_data;
|
cryptonote::blobdata tx_key_data;
|
||||||
if(!epee::string_tools::parse_hexstr_to_binbuff(local_args[1], tx_key_data))
|
if(!epee::string_tools::parse_hexstr_to_binbuff(local_args[1], tx_key_data))
|
||||||
{
|
{
|
||||||
@ -2924,6 +2950,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCK_REFRESH_THREAD_SCOPE();
|
||||||
|
|
||||||
// optional in/out selector
|
// optional in/out selector
|
||||||
if (local_args.size() > 0) {
|
if (local_args.size() > 0) {
|
||||||
if (local_args[0] == "in" || local_args[0] == "incoming") {
|
if (local_args[0] == "in" || local_args[0] == "incoming") {
|
||||||
@ -3078,7 +3106,12 @@ bool simple_wallet::run()
|
|||||||
void simple_wallet::stop()
|
void simple_wallet::stop()
|
||||||
{
|
{
|
||||||
m_cmd_binder.stop_handling();
|
m_cmd_binder.stop_handling();
|
||||||
|
|
||||||
|
m_auto_refresh_run.store(false, std::memory_order_relaxed);
|
||||||
m_wallet->stop();
|
m_wallet->stop();
|
||||||
|
// make the background refresh thread quit
|
||||||
|
boost::unique_lock<boost::mutex> lock(m_auto_refresh_mutex);
|
||||||
|
m_auto_refresh_cond.notify_one();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||||
|
@ -114,6 +114,7 @@ namespace cryptonote
|
|||||||
bool stop_mining(const std::vector<std::string> &args);
|
bool stop_mining(const std::vector<std::string> &args);
|
||||||
bool save_bc(const std::vector<std::string>& args);
|
bool save_bc(const std::vector<std::string>& args);
|
||||||
bool refresh(const std::vector<std::string> &args);
|
bool refresh(const std::vector<std::string> &args);
|
||||||
|
bool show_balance_unlocked();
|
||||||
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
|
bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
|
||||||
bool show_incoming_transfers(const std::vector<std::string> &args);
|
bool show_incoming_transfers(const std::vector<std::string> &args);
|
||||||
bool show_payments(const std::vector<std::string> &args);
|
bool show_payments(const std::vector<std::string> &args);
|
||||||
|
Loading…
Reference in New Issue
Block a user