Misc. network related

- Add interface for bytes sent/received
- Allow wallet refresh while daemon is not synchronized
- emit success boolean for refreshed()
- don't call refreshThreadFunc (we don't need it)
- lower rpc timeout from 3m30s (?!) to 10 seconds
This commit is contained in:
thotbot 2021-07-03 23:16:06 +02:00 committed by wowario
parent 1ed861bff8
commit e60954b619
No known key found for this signature in database
GPG Key ID: 793504B449C69220
5 changed files with 32 additions and 32 deletions

View File

@ -274,3 +274,4 @@ void TransactionHistoryImpl::refresh()
} }
} // namespace } // namespace
}

View File

@ -65,8 +65,8 @@ namespace {
static const int MAX_REFRESH_INTERVAL_MILLIS = 1000 * 60 * 1; static const int MAX_REFRESH_INTERVAL_MILLIS = 1000 * 60 * 1;
// Default refresh interval when connected to remote node // Default refresh interval when connected to remote node
static const int DEFAULT_REMOTE_NODE_REFRESH_INTERVAL_MILLIS = 1000 * 10; static const int DEFAULT_REMOTE_NODE_REFRESH_INTERVAL_MILLIS = 1000 * 10;
// Connection timeout 20 sec // Connection timeout 10 sec
static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 20; static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 10;
std::string get_default_ringdb_path(cryptonote::network_type nettype) std::string get_default_ringdb_path(cryptonote::network_type nettype)
{ {
@ -434,10 +434,6 @@ WalletImpl::WalletImpl(NetworkType nettype, uint64_t kdf_rounds)
m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS; m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS;
m_refreshThread = boost::thread([this] () {
this->refreshThreadFunc();
});
} }
WalletImpl::~WalletImpl() WalletImpl::~WalletImpl()
@ -1082,7 +1078,7 @@ uint64_t WalletImpl::daemonBlockChainHeight() const
if(m_wallet->light_wallet()) { if(m_wallet->light_wallet()) {
return m_wallet->get_light_wallet_scanned_block_height(); return m_wallet->get_light_wallet_scanned_block_height();
} }
if (!m_is_connected) if (!m_is_connected && m_synchronized)
return 0; return 0;
std::string err; std::string err;
uint64_t result = m_wallet->get_daemon_blockchain_height(err); uint64_t result = m_wallet->get_daemon_blockchain_height(err);
@ -1101,7 +1097,7 @@ uint64_t WalletImpl::daemonBlockChainTargetHeight() const
if(m_wallet->light_wallet()) { if(m_wallet->light_wallet()) {
return m_wallet->get_light_wallet_blockchain_height(); return m_wallet->get_light_wallet_blockchain_height();
} }
if (!m_is_connected) if (!m_is_connected && m_synchronized)
return 0; return 0;
std::string err; std::string err;
uint64_t result = m_wallet->get_daemon_blockchain_target_height(err); uint64_t result = m_wallet->get_daemon_blockchain_target_height(err);
@ -2565,14 +2561,12 @@ void WalletImpl::refreshThreadFunc()
void WalletImpl::doRefresh() void WalletImpl::doRefresh()
{ {
bool success = true;
bool rescan = m_refreshShouldRescan.exchange(false); bool rescan = m_refreshShouldRescan.exchange(false);
// synchronizing async and sync refresh calls // synchronizing async and sync refresh calls
boost::lock_guard<boost::mutex> guarg(m_refreshMutex2); boost::lock_guard<boost::mutex> guarg(m_refreshMutex2);
do try { do try {
LOG_PRINT_L3(__FUNCTION__ << ": doRefresh, rescan = "<<rescan); LOG_PRINT_L3(__FUNCTION__ << ": doRefresh, rescan = "<<rescan);
// Syncing daemon and refreshing wallet simultaneously is very resource intensive.
// Disable refresh if wallet is disconnected or daemon isn't synced.
if (m_wallet->light_wallet() || daemonSynced()) {
if(rescan) if(rescan)
m_wallet->rescan_blockchain(false); m_wallet->rescan_blockchain(false);
m_wallet->refresh(trustedDaemon()); m_wallet->refresh(trustedDaemon());
@ -2586,16 +2580,15 @@ void WalletImpl::doRefresh()
m_history->refresh(); m_history->refresh();
} }
m_wallet->find_and_save_rings(false); m_wallet->find_and_save_rings(false);
} else {
LOG_PRINT_L3(__FUNCTION__ << ": skipping refresh - daemon is not synced");
}
} catch (const std::exception &e) { } catch (const std::exception &e) {
success = false;
setStatusError(e.what()); setStatusError(e.what());
break; break;
}while(!rescan && (rescan=m_refreshShouldRescan.exchange(false))); // repeat if not rescanned and rescan was requested }while(!rescan && (rescan=m_refreshShouldRescan.exchange(false))); // repeat if not rescanned and rescan was requested
m_is_connected = success;
if (m_wallet2Callback->getListener()) { if (m_wallet2Callback->getListener()) {
m_wallet2Callback->getListener()->refreshed(); m_wallet2Callback->getListener()->refreshed(success);
} }
} }
@ -2658,8 +2651,14 @@ void WalletImpl::pendingTxPostProcess(PendingTransactionImpl * pending)
bool WalletImpl::doInit(const string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit, bool ssl) bool WalletImpl::doInit(const string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit, bool ssl)
{ {
if (!m_wallet->init(daemon_address, m_daemon_login, proxy_address, upper_transaction_size_limit)) if (!m_wallet->init(daemon_address,
m_daemon_login,
proxy_address,
upper_transaction_size_limit,
trustedDaemon(),
ssl ? epee::net_utils::ssl_support_t::e_ssl_support_autodetect : epee::net_utils::ssl_support_t::e_ssl_support_disabled)) {
return false; return false;
}
// in case new wallet, this will force fast-refresh (pulling hashes instead of blocks) // in case new wallet, this will force fast-refresh (pulling hashes instead of blocks)
// If daemon isn't synced a calculated block height will be used instead // If daemon isn't synced a calculated block height will be used instead

View File

@ -479,7 +479,7 @@ struct WalletListener
/** /**
* @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously * @brief refreshed - called when wallet refreshed by background thread or explicitly refreshed by calling "refresh" synchronously
*/ */
virtual void refreshed() = 0; virtual void refreshed(bool success) = 0;
/** /**
* @brief called by device if the action is required * @brief called by device if the action is required

View File

@ -51,7 +51,7 @@ using namespace epee;
namespace tools namespace tools
{ {
static const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30); static const std::chrono::seconds rpc_timeout = std::chrono::seconds(10);
NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex) NodeRPCProxy::NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex)
: m_http_client(http_client) : m_http_client(http_client)

View File

@ -235,7 +235,7 @@ private:
friend class wallet_keys_unlocker; friend class wallet_keys_unlocker;
friend class wallet_device_callback; friend class wallet_device_callback;
public: public:
static constexpr const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30); static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(10);
enum RefreshType { enum RefreshType {
RefreshFull, RefreshFull,