wallet_rpc_server: chunk refresh to keep responding to RPC while refreshing
This commit is contained in:
parent
5bb2369b55
commit
23fde151ee
@ -3360,7 +3360,7 @@ std::shared_ptr<std::map<std::pair<uint64_t, uint64_t>, size_t>> wallet2::create
|
|||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool)
|
void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool, uint64_t max_blocks)
|
||||||
{
|
{
|
||||||
if (m_offline)
|
if (m_offline)
|
||||||
{
|
{
|
||||||
@ -3452,7 +3452,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
|
|||||||
update_pool_state(process_pool_txs, true);
|
update_pool_state(process_pool_txs, true);
|
||||||
|
|
||||||
bool first = true, last = false;
|
bool first = true, last = false;
|
||||||
while(m_run.load(std::memory_order_relaxed))
|
while(m_run.load(std::memory_order_relaxed) && blocks_fetched < max_blocks)
|
||||||
{
|
{
|
||||||
uint64_t next_blocks_start_height;
|
uint64_t next_blocks_start_height;
|
||||||
std::vector<cryptonote::block_complete_entry> next_blocks;
|
std::vector<cryptonote::block_complete_entry> next_blocks;
|
||||||
|
@ -974,7 +974,7 @@ private:
|
|||||||
bool is_deprecated() const;
|
bool is_deprecated() const;
|
||||||
void refresh(bool trusted_daemon);
|
void refresh(bool trusted_daemon);
|
||||||
void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched);
|
void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched);
|
||||||
void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool = true);
|
void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool = true, uint64_t max_blocks = std::numeric_limits<uint64_t>::max());
|
||||||
bool refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok);
|
bool refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok);
|
||||||
|
|
||||||
void set_refresh_type(RefreshType refresh_type) { m_refresh_type = refresh_type; }
|
void set_refresh_type(RefreshType refresh_type) { m_refresh_type = refresh_type; }
|
||||||
|
@ -60,6 +60,7 @@ using namespace epee;
|
|||||||
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
|
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"
|
||||||
|
|
||||||
#define DEFAULT_AUTO_REFRESH_PERIOD 20 // seconds
|
#define DEFAULT_AUTO_REFRESH_PERIOD 20 // seconds
|
||||||
|
#define REFRESH_INFICATIVE_BLOCK_CHUNK_SIZE 256 // just to split refresh in separate calls to play nicer with other threads
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -139,12 +140,17 @@ namespace tools
|
|||||||
return true;
|
return true;
|
||||||
if (boost::posix_time::microsec_clock::universal_time() < m_last_auto_refresh_time + boost::posix_time::seconds(m_auto_refresh_period))
|
if (boost::posix_time::microsec_clock::universal_time() < m_last_auto_refresh_time + boost::posix_time::seconds(m_auto_refresh_period))
|
||||||
return true;
|
return true;
|
||||||
|
uint64_t blocks_fetched = 0;
|
||||||
try {
|
try {
|
||||||
if (m_wallet) m_wallet->refresh(m_wallet->is_trusted_daemon());
|
bool received_money = false;
|
||||||
|
if (m_wallet) m_wallet->refresh(m_wallet->is_trusted_daemon(), 0, blocks_fetched, received_money, true, REFRESH_INFICATIVE_BLOCK_CHUNK_SIZE);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
LOG_ERROR("Exception at while refreshing, what=" << ex.what());
|
LOG_ERROR("Exception at while refreshing, what=" << ex.what());
|
||||||
}
|
}
|
||||||
m_last_auto_refresh_time = boost::posix_time::microsec_clock::universal_time();
|
// if we got the max amount of blocks, do not set the last refresh time, we did only part of the refresh and will
|
||||||
|
// continue asap, and only set the last refresh time once the refresh is actually finished
|
||||||
|
if (blocks_fetched < REFRESH_INFICATIVE_BLOCK_CHUNK_SIZE)
|
||||||
|
m_last_auto_refresh_time = boost::posix_time::microsec_clock::universal_time();
|
||||||
return true;
|
return true;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
m_net_server.add_idle_handler([this](){
|
m_net_server.add_idle_handler([this](){
|
||||||
|
Loading…
Reference in New Issue
Block a user