wallet: reuse cached height when set after refresh

Refreshing sets cached height, which is otherwise got by calling
get_info. Since get_info is called upon needing to display a prompt
after a command has finished, it can be used to determine how much
time a given command took to run if the cache timeout lapses while
the command runs. Refreshing caches the height as a side effect, so
get_info will never be called as a result of displaying a prompt
after refreshing (and potentially leaking how much time it took to
process a set of transactions, therefore leaking whether we got
some monero in them).
This commit is contained in:
moneromooo-monero 2019-10-15 19:16:13 +00:00
parent 5956beaa15
commit e108330248
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
2 changed files with 11 additions and 0 deletions

View File

@ -77,6 +77,7 @@ void NodeRPCProxy::invalidate()
m_rpc_payment_seed_height = 0; m_rpc_payment_seed_height = 0;
m_rpc_payment_seed_hash = crypto::null_hash; m_rpc_payment_seed_hash = crypto::null_hash;
m_rpc_payment_next_seed_hash = crypto::null_hash; m_rpc_payment_next_seed_hash = crypto::null_hash;
m_height_time = 0;
} }
boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version) boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version)
@ -101,6 +102,7 @@ boost::optional<std::string> NodeRPCProxy::get_rpc_version(uint32_t &rpc_version
void NodeRPCProxy::set_height(uint64_t h) void NodeRPCProxy::set_height(uint64_t h)
{ {
m_height = h; m_height = h;
m_height_time = time(NULL);
} }
boost::optional<std::string> NodeRPCProxy::get_info() boost::optional<std::string> NodeRPCProxy::get_info()
@ -126,12 +128,20 @@ boost::optional<std::string> NodeRPCProxy::get_info()
m_target_height = resp_t.target_height; m_target_height = resp_t.target_height;
m_block_weight_limit = resp_t.block_weight_limit ? resp_t.block_weight_limit : resp_t.block_size_limit; m_block_weight_limit = resp_t.block_weight_limit ? resp_t.block_weight_limit : resp_t.block_size_limit;
m_get_info_time = now; m_get_info_time = now;
m_height_time = now;
} }
return boost::optional<std::string>(); return boost::optional<std::string>();
} }
boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height) boost::optional<std::string> NodeRPCProxy::get_height(uint64_t &height)
{ {
const time_t now = time(NULL);
if (now < m_height_time + 30) // re-cache every 30 seconds
{
height = m_height;
return boost::optional<std::string>();
}
auto res = get_info(); auto res = get_info();
if (res) if (res)
return res; return res;

View File

@ -97,6 +97,7 @@ private:
crypto::hash m_rpc_payment_seed_hash; crypto::hash m_rpc_payment_seed_hash;
crypto::hash m_rpc_payment_next_seed_hash; crypto::hash m_rpc_payment_next_seed_hash;
uint32_t m_rpc_payment_cookie; uint32_t m_rpc_payment_cookie;
time_t m_height_time;
}; };
} }