From 1154deb47a3aa21d777985f1cdf17a3cab25e455 Mon Sep 17 00:00:00 2001 From: Navid Rahimi Date: Thu, 29 Jan 2026 20:11:06 +0000 Subject: [PATCH] src: add --auto-refresh-period flag to wallet-rpc --- src/wallet/wallet_rpc_server.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 77613482d8d..a26288f455e 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "include_base_utils.h" using namespace epee; @@ -135,6 +136,7 @@ namespace const command_line::arg_descriptor arg_rpc_max_connections_per_private_ip = {"rpc-max-connections-per-private-ip", "Max RPC connections per private and localhost IP permitted", DEFAULT_RPC_MAX_CONNECTIONS_PER_PRIVATE_IP}; const command_line::arg_descriptor arg_rpc_max_connections = {"rpc-max-connections", "Max RPC connections permitted", DEFAULT_RPC_MAX_CONNECTIONS}; const command_line::arg_descriptor arg_rpc_response_soft_limit = {"rpc-response-soft-limit", "Max response bytes that can be queued, enforced at next response attempt", DEFAULT_RPC_SOFT_LIMIT_SIZE}; + const command_line::arg_descriptor arg_auto_refresh_period = {"auto-refresh-period", "Period for auto-refreshing the wallet (seconds)", DEFAULT_AUTO_REFRESH_PERIOD}; constexpr const char default_rpc_username[] = "monero"; @@ -376,8 +378,15 @@ namespace tools assert(bool(http_login)); } // end auth enabled - m_auto_refresh_period.store(DEFAULT_AUTO_REFRESH_PERIOD, std::memory_order_relaxed); - const auto over_one_period_ago = std::chrono::steady_clock::now() - std::chrono::seconds(m_auto_refresh_period.load(std::memory_order_relaxed) * 2); + auto auto_refresh_period = command_line::get_arg(*m_vm, arg_auto_refresh_period); + if (auto_refresh_period > (std::numeric_limits::max()/2)) { + LOG_ERROR("Auto-refresh period exceeds safe limit (" << auto_refresh_period + << "). Using " << DEFAULT_AUTO_REFRESH_PERIOD); + auto_refresh_period = DEFAULT_AUTO_REFRESH_PERIOD; + } + m_auto_refresh_period.store(auto_refresh_period, std::memory_order_relaxed); + const auto over_one_period_ago = + std::chrono::steady_clock::now() - std::chrono::seconds(auto_refresh_period * 2); m_last_auto_refresh_time = over_one_period_ago; check_background_mining(); @@ -5135,6 +5144,7 @@ int main(int argc, char** argv) { command_line::add_arg(desc_params, arg_rpc_max_connections); command_line::add_arg(desc_params, arg_rpc_response_soft_limit); command_line::add_arg(hidden_options, daemonizer::arg_non_interactive); + command_line::add_arg(desc_params, arg_auto_refresh_period); daemonizer::init_options(hidden_options, desc_params); desc_params.add(hidden_options);