Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet refresh improvements #8941

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,7 @@ std::shared_ptr<std::map<std::pair<uint64_t, uint64_t>, size_t>> wallet2::create
return cache;
}
//----------------------------------------------------------------------------------------------------
void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool, bool try_incremental)
void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool, uint64_t max_blocks, bool try_incremental)
{
if (m_offline)
{
Expand Down Expand Up @@ -3996,7 +3996,7 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
// infer when we get an incoming output

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;
std::vector<cryptonote::block_complete_entry> next_blocks;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ namespace tools
bool is_deprecated() const;
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, bool& received_money, bool check_pool = true, bool try_incremental = 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 try_incremental = true);
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; }
Expand Down
14 changes: 11 additions & 3 deletions src/wallet/wallet_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using namespace epee;
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.rpc"

#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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was inficative (not a word) meant to be indicative? Even indicative seems like an odd name choice, it's more like a default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was. IIRC that value is only respected by monerod if the blocks aren't too big, so it's only indicative. Maybe "max" would have been better.
I won't bother changing it here since it's a copy of the master patch, which is already merged.


#define CHECK_MULTISIG_ENABLED() \
do \
Expand All @@ -79,6 +80,7 @@ namespace
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", "Restricts to view-only commands", false};
const command_line::arg_descriptor<std::string> arg_wallet_dir = {"wallet-dir", "Directory for newly created wallets"};
const command_line::arg_descriptor<bool> arg_prompt_for_password = {"prompt-for-password", "Prompts for password when not provided", false};
const command_line::arg_descriptor<bool> arg_no_initial_sync = {"no-initial-sync", "Skips the initial sync before listening for connections", false};

constexpr const char default_rpc_username[] = "monero";

Expand Down Expand Up @@ -152,11 +154,14 @@ namespace tools
uint64_t blocks_fetched = 0;
try {
bool received_money = false;
if (m_wallet) m_wallet->refresh(m_wallet->is_trusted_daemon(), 0, blocks_fetched, received_money, true, true);
if (m_wallet) m_wallet->refresh(m_wallet->is_trusted_daemon(), 0, blocks_fetched, received_money, true, REFRESH_INFICATIVE_BLOCK_CHUNK_SIZE, true);
} catch (const std::exception& ex) {
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;
}, 1000);
m_net_server.add_idle_handler([this](){
Expand Down Expand Up @@ -4554,6 +4559,7 @@ class t_daemon
const auto password_file = command_line::get_arg(vm, arg_password_file);
const auto prompt_for_password = command_line::get_arg(vm, arg_prompt_for_password);
const auto password_prompt = prompt_for_password ? password_prompter : nullptr;
const auto no_initial_sync = command_line::get_arg(vm, arg_no_initial_sync);

if(!wallet_file.empty() && !from_json.empty())
{
Expand Down Expand Up @@ -4622,7 +4628,8 @@ class t_daemon

try
{
wal->refresh(wal->is_trusted_daemon());
if (!no_initial_sync)
wal->refresh(wal->is_trusted_daemon());
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -4733,6 +4740,7 @@ int main(int argc, char** argv) {
command_line::add_arg(desc_params, arg_wallet_dir);
command_line::add_arg(desc_params, arg_prompt_for_password);
command_line::add_arg(desc_params, arg_rpc_client_secret_key);
command_line::add_arg(desc_params, arg_no_initial_sync);

daemonizer::init_options(hidden_options, desc_params);
desc_params.add(hidden_options);
Expand Down