diff options
author | xiphon <xiphon@protonmail.com> | 2020-11-17 23:15:36 +0000 |
---|---|---|
committer | xiphon <xiphon@protonmail.com> | 2020-11-23 12:24:01 +0000 |
commit | af4fb4729ed09139a1a48038fcfcf7da64092a58 (patch) | |
tree | fce96e24c6e993e70642a7b366f9ea2ee6cb4645 | |
parent | Merge pull request #6997 (diff) | |
download | monero-af4fb4729ed09139a1a48038fcfcf7da64092a58.tar.xz |
rpc: skip non-synced bootstrap daemons in --no-sync mode too
-rw-r--r-- | src/rpc/bootstrap_daemon.cpp | 10 | ||||
-rw-r--r-- | src/rpc/bootstrap_daemon.h | 3 | ||||
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 25 |
3 files changed, 21 insertions, 17 deletions
diff --git a/src/rpc/bootstrap_daemon.cpp b/src/rpc/bootstrap_daemon.cpp index 6a0833f19..2fdd28406 100644 --- a/src/rpc/bootstrap_daemon.cpp +++ b/src/rpc/bootstrap_daemon.cpp @@ -45,12 +45,12 @@ namespace cryptonote return host + ":" + m_http_client.get_port(); } - boost::optional<uint64_t> bootstrap_daemon::get_height() + boost::optional<std::pair<uint64_t, uint64_t>> bootstrap_daemon::get_height() { - cryptonote::COMMAND_RPC_GET_HEIGHT::request req; - cryptonote::COMMAND_RPC_GET_HEIGHT::response res; + cryptonote::COMMAND_RPC_GET_INFO::request req; + cryptonote::COMMAND_RPC_GET_INFO::response res; - if (!invoke_http_json("/getheight", req, res)) + if (!invoke_http_json("/getinfo", req, res)) { return boost::none; } @@ -60,7 +60,7 @@ namespace cryptonote return boost::none; } - return res.height; + return {{res.height, res.target_height}}; } bool bootstrap_daemon::handle_result(bool success, const std::string &status) diff --git a/src/rpc/bootstrap_daemon.h b/src/rpc/bootstrap_daemon.h index bedc255b5..d54042b11 100644 --- a/src/rpc/bootstrap_daemon.h +++ b/src/rpc/bootstrap_daemon.h @@ -2,6 +2,7 @@ #include <functional> #include <map> +#include <utility> #include <boost/optional/optional.hpp> #include <boost/thread/mutex.hpp> @@ -27,7 +28,7 @@ namespace cryptonote bool rpc_payment_enabled); std::string address() const noexcept; - boost::optional<uint64_t> get_height(); + boost::optional<std::pair<uint64_t, uint64_t>> get_height(); bool handle_result(bool success, const std::string &status); template <class t_request, class t_response> diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 9b08971cd..5ef0c8979 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1987,34 +1987,37 @@ namespace cryptonote } auto current_time = std::chrono::system_clock::now(); - if (!m_p2p.get_payload_object().no_sync() && - current_time - m_bootstrap_height_check_time > std::chrono::seconds(30)) // update every 30s + if (current_time - m_bootstrap_height_check_time > std::chrono::seconds(30)) // update every 30s { { boost::upgrade_to_unique_lock<boost::shared_mutex> lock(upgrade_lock); m_bootstrap_height_check_time = current_time; } - boost::optional<uint64_t> bootstrap_daemon_height = m_bootstrap_daemon->get_height(); - if (!bootstrap_daemon_height) + boost::optional<std::pair<uint64_t, uint64_t>> bootstrap_daemon_height_info = m_bootstrap_daemon->get_height(); + if (!bootstrap_daemon_height_info) { MERROR("Failed to fetch bootstrap daemon height"); return false; } - uint64_t target_height = m_core.get_target_blockchain_height(); - if (*bootstrap_daemon_height < target_height) + const uint64_t bootstrap_daemon_height = bootstrap_daemon_height_info->first; + const uint64_t bootstrap_daemon_target_height = bootstrap_daemon_height_info->second; + if (bootstrap_daemon_height < bootstrap_daemon_target_height) { MINFO("Bootstrap daemon is out of sync"); return m_bootstrap_daemon->handle_result(false, {}); } - uint64_t top_height = m_core.get_current_blockchain_height(); - m_should_use_bootstrap_daemon = top_height + 10 < *bootstrap_daemon_height; - MINFO((m_should_use_bootstrap_daemon ? "Using" : "Not using") << " the bootstrap daemon (our height: " << top_height << ", bootstrap daemon's height: " << *bootstrap_daemon_height << ")"); + if (!m_p2p.get_payload_object().no_sync()) + { + uint64_t top_height = m_core.get_current_blockchain_height(); + m_should_use_bootstrap_daemon = top_height + 10 < bootstrap_daemon_height; + MINFO((m_should_use_bootstrap_daemon ? "Using" : "Not using") << " the bootstrap daemon (our height: " << top_height << ", bootstrap daemon's height: " << bootstrap_daemon_height << ")"); - if (!m_should_use_bootstrap_daemon) - return false; + if (!m_should_use_bootstrap_daemon) + return false; + } } if (mode == invoke_http_mode::JON) |