From 5995c0ca7f226b33be606286d7360b8455a22b7e Mon Sep 17 00:00:00 2001 From: sowle Date: Thu, 6 Jun 2019 16:21:26 +0300 Subject: [PATCH 1/4] time sync issues detection first impl --- src/common/util.cpp | 37 +++++- src/common/util.h | 3 + .../currency_protocol_handler.h | 8 ++ .../currency_protocol_handler.inl | 122 +++++++++++++++--- 4 files changed, 153 insertions(+), 17 deletions(-) diff --git a/src/common/util.cpp b/src/common/util.cpp index b2198312..aa0ef880 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -21,6 +21,7 @@ using namespace epee; #include #endif +#include namespace tools { @@ -588,4 +589,38 @@ std::string get_nix_version_display_string() return static_cast(in.tellg()); } -} + int64_t get_ntp_time(const std::string& host_name) + { + try + { + boost::asio::io_service io_service; + boost::asio::ip::udp::resolver resolver(io_service); + boost::asio::ip::udp::resolver::query query(boost::asio::ip::udp::v4(), host_name, "ntp"); + boost::asio::ip::udp::endpoint receiver_endpoint = *resolver.resolve(query); + boost::asio::ip::udp::socket socket(io_service); + socket.open(boost::asio::ip::udp::v4()); + + boost::array send_buf = { 010, 0, 0, 0, 0, 0, 0, 0, 0 }; + socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint); + + boost::array recv_buf; + boost::asio::ip::udp::endpoint sender_endpoint; + size_t len = socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint); + + time_t time_recv = ntohl((time_t)recv_buf[4]); + time_recv -= 2208988800U; //Unix time starts from 01/01/1970 == 2208988800U + return time_recv; + } + catch (const std::exception& e) + { + LOG_PRINT_L2("get_ntp_time(): exception: " << e.what()); + return 0; + } + catch (...) + { + return 0; + } + } + + +} // namespace tools diff --git a/src/common/util.h b/src/common/util.h index 11374f8c..e6989acf 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -333,4 +333,7 @@ namespace tools static std::function m_handler; static std::function m_fatal_handler; }; + + + int64_t get_ntp_time(const std::string& host_name); } diff --git a/src/currency_protocol/currency_protocol_handler.h b/src/currency_protocol/currency_protocol_handler.h index 795354fc..a03d6cf3 100644 --- a/src/currency_protocol/currency_protocol_handler.h +++ b/src/currency_protocol/currency_protocol_handler.h @@ -66,7 +66,10 @@ namespace currency uint64_t get_max_seen_height(); virtual size_t get_synchronized_connections_count(); virtual size_t get_synchronizing_connections_count(); + int64_t get_net_time_delta_median(); + bool add_time_delta_and_check_time_sync(int64_t delta); + bool get_last_time_sync_difference(int64_t& last_median2local_time_difference, int64_t& last_ntp2local_time_difference); // returns true if differences in allowed bounds private: //----------------- commands handlers ---------------------------------------------- @@ -108,6 +111,11 @@ namespace currency std::thread m_relay_que_thread; std::atomic m_want_stop; + std::deque m_time_deltas; + std::mutex m_time_deltas_lock; + int64_t m_last_median2local_time_difference; + int64_t m_last_ntp2local_time_difference; + template bool post_notify(typename t_parametr::request& arg, currency_connection_context& context) { diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index e4eebf74..15155716 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -12,26 +12,27 @@ namespace currency //----------------------------------------------------------------------------------------------------------------------- template - t_currency_protocol_handler::t_currency_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint* p_net_layout):m_core(rcore), - m_p2p(p_net_layout), - m_syncronized_connections_count(0), - m_synchronized(false), - m_have_been_synchronized(false), - m_max_height_seen(0), - m_core_inital_height(0), - m_want_stop(false) - - + t_currency_protocol_handler::t_currency_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint* p_net_layout) + : m_core(rcore) + , m_p2p(p_net_layout) + , m_syncronized_connections_count(0) + , m_synchronized(false) + , m_have_been_synchronized(false) + , m_max_height_seen(0) + , m_core_inital_height(0) + , m_want_stop(false) + , m_last_median2local_time_difference(0) + , m_last_ntp2local_time_difference(0) { if(!m_p2p) m_p2p = &m_p2p_stub; } //----------------------------------------------------------------------------------------------------------------------- - template - t_currency_protocol_handler::~t_currency_protocol_handler() - { - deinit(); - } + template + t_currency_protocol_handler::~t_currency_protocol_handler() + { + deinit(); + } //----------------------------------------------------------------------------------------------------------------------- template bool t_currency_protocol_handler::init(const boost::program_options::variables_map& vm) @@ -121,7 +122,12 @@ namespace currency if(context.m_state == currency_connection_context::state_befor_handshake && !is_inital) return true; - context.m_time_delta = m_core.get_blockchain_storage().get_core_runtime_config().get_core_time() - hshd.core_time; + uint64_t local_time = m_core.get_blockchain_storage().get_core_runtime_config().get_core_time(); + context.m_time_delta = local_time - hshd.core_time; + + // for outgoing connections -- check time difference + if (!context.m_is_income) + add_time_delta_and_check_time_sync(context.m_time_delta); if(context.m_state == currency_connection_context::state_synchronizing) return true; @@ -751,6 +757,90 @@ namespace currency return epee::misc_utils::median(deltas); } //------------------------------------------------------------------------------------------------------------------------ + #define TIME_SYNC_DELTA_RING_BUFFER_SIZE 8 + #define TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE (60 * 5) // max acceptable difference between time delta median among peers and local time (seconds) + #define TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE (60 * 5) // max acceptable difference between NTP time and local time (seconds) + #define TIME_SYNC_NTP_SERVERS { "time.google.com", "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org" } + #define TIME_SYNC_NTP_ATTEMPTS_COUNT 3 // max number of attempts when getting time from NTP server + + static int64_t get_ntp_time() + { + static const std::vector ntp_servers TIME_SYNC_NTP_SERVERS; + + for (size_t att = 0; att < TIME_SYNC_NTP_ATTEMPTS_COUNT; ++att) + { + size_t i = 0; + crypto::generate_random_bytes(sizeof(i), &i); + const std::string& ntp_server = ntp_servers[i % ntp_servers.size()]; + LOG_PRINT_L3("NTP: trying to get time from " << ntp_server); + int64_t time = tools::get_ntp_time(ntp_server); + if (time > 0) + { + LOG_PRINT_L2("NTP: " << ntp_server << " responded with " << time << " (" << epee::misc_utils::get_time_str_v2(time) << ")"); + return time; + } + LOG_PRINT_L2("NTP: cannot get time from " << ntp_server); + } + + return 0; // smth went wrong + } + + template + bool t_currency_protocol_handler::add_time_delta_and_check_time_sync(int64_t time_delta) + { + std::unique_lock lk(m_time_deltas_lock); + + m_time_deltas.push_back(time_delta); + while (m_time_deltas.size() > TIME_SYNC_DELTA_RING_BUFFER_SIZE) + m_time_deltas.pop_front(); + + if (m_time_deltas.size() < TIME_SYNC_DELTA_RING_BUFFER_SIZE) + return true; // not enough data + + std::vector time_deltas_copy(m_time_deltas.begin(), m_time_deltas.end()); + + int64_t m_last_median2local_time_difference = epee::misc_utils::median(time_deltas_copy); + LOG_PRINT_MAGENTA("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ")", LOG_LEVEL_2); + if (std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE) + { + int64_t ntp_time = get_ntp_time(); + if (ntp_time == 0) + { + // error geting ntp time + LOG_PRINT_RED("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ") but NTP servers did not respond", LOG_LEVEL_0); + return false; + } + + // got ntp time correctly + // update local time, because getting ntp time could be time consuming + uint64_t local_time_2 = m_core.get_blockchain_storage().get_core_runtime_config().get_core_time(); + int64_t m_last_ntp2local_time_difference = local_time_2 - ntp_time; + if (std::abs(m_last_ntp2local_time_difference) > TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE) + { + // local time is out of sync + LOG_PRINT_RED("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << "), NTP time difference is " << + m_last_ntp2local_time_difference << " (max is " << TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE << ")", LOG_LEVEL_0); + return false; + } + + // NTP time is OK + LOG_PRINT_YELLOW("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << "), NTP time difference is " << + m_last_ntp2local_time_difference << " (max is " << TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE << ")", LOG_LEVEL_1); + } + + return true; + } + //------------------------------------------------------------------------------------------------------------------------ + template + bool t_currency_protocol_handler::get_last_time_sync_difference(int64_t& last_median2local_time_difference, int64_t& last_ntp2local_time_difference) + { + std::unique_lock lk(m_time_deltas_lock); + last_median2local_time_difference = m_last_median2local_time_difference; + last_ntp2local_time_difference = m_last_ntp2local_time_difference; + + return !(std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE && std::abs(m_last_ntp2local_time_difference) > TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE); + } + //------------------------------------------------------------------------------------------------------------------------ template int t_currency_protocol_handler::handle_response_chain_entry(int command, NOTIFY_RESPONSE_CHAIN_ENTRY::request& arg, currency_connection_context& context) { From be51d8ecd7b99510b88b89af51429196c4e7a335 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 7 Jun 2019 11:07:51 +0300 Subject: [PATCH 2/4] time sync issues detection: WIP --- src/currency_core/currency_core.cpp | 9 +++++++- src/currency_core/currency_core.h | 3 +++ .../currency_protocol_handler.inl | 23 ++++++++++++++----- .../currency_protocol_handler_common.h | 10 ++++++++ src/daemon/daemon.cpp | 1 + src/daemon/daemon_commands_handler.h | 5 ++-- src/rpc/core_rpc_server.cpp | 6 ++++- 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/currency_core/currency_core.cpp b/src/currency_core/currency_core.cpp index 0e4e66c4..24473ff0 100644 --- a/src/currency_core/currency_core.cpp +++ b/src/currency_core/currency_core.cpp @@ -32,10 +32,12 @@ namespace currency m_blockchain_storage(m_mempool), m_miner(this, m_blockchain_storage), m_miner_address(boost::value_initialized()), - m_starter_message_showed(false) + m_starter_message_showed(false), + m_stop_handler(nullptr) { set_currency_protocol(pprotocol); } + //----------------------------------------------------------------------------------- void core::set_currency_protocol(i_currency_protocol* pprotocol) { if(pprotocol) @@ -46,6 +48,11 @@ namespace currency m_mempool.set_protocol(m_pprotocol); } //----------------------------------------------------------------------------------- + void core::set_stop_handler(i_stop_handler *handler) + { + m_stop_handler = handler; + } + //----------------------------------------------------------------------------------- bool core::set_checkpoints(checkpoints&& chk_pts) { return m_blockchain_storage.set_checkpoints(std::move(chk_pts)); diff --git a/src/currency_core/currency_core.h b/src/currency_core/currency_core.h index 158c6302..b27b07fb 100644 --- a/src/currency_core/currency_core.h +++ b/src/currency_core/currency_core.h @@ -81,6 +81,8 @@ namespace currency size_t get_alternative_blocks_count(); void set_currency_protocol(i_currency_protocol* pprotocol); + void set_stop_handler(i_stop_handler *handler); + i_stop_handler* get_stop_handler() const { return m_stop_handler; } bool set_checkpoints(checkpoints&& chk_pts); bool get_pool_transactions(std::list& txs); @@ -138,6 +140,7 @@ namespace currency blockchain_storage m_blockchain_storage; tx_memory_pool m_mempool; i_currency_protocol* m_pprotocol; + i_stop_handler* m_stop_handler; critical_section m_incoming_tx_lock; miner m_miner; account_public_address m_miner_address; diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 15155716..990cf163 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -127,7 +127,19 @@ namespace currency // for outgoing connections -- check time difference if (!context.m_is_income) - add_time_delta_and_check_time_sync(context.m_time_delta); + { + if (!add_time_delta_and_check_time_sync(context.m_time_delta)) + { + // serious time sync problem detected + std::shared_ptr ish(m_core.get_stop_handler()); + if (ish != nullptr) + { + // this is a daemon -- stop immediately + ish->stop_handling(); + return true; + } + } + } if(context.m_state == currency_connection_context::state_synchronizing) return true; @@ -679,8 +691,7 @@ namespace currency { std::list local_que; { - std::unique_lock lk(m_relay_que_lock); - //m_relay_que_cv.wait(lk); + CRITICAL_REGION_LOCAL(m_relay_que_lock); local_que.swap(m_relay_que); } if (local_que.size()) @@ -788,7 +799,7 @@ namespace currency template bool t_currency_protocol_handler::add_time_delta_and_check_time_sync(int64_t time_delta) { - std::unique_lock lk(m_time_deltas_lock); + CRITICAL_REGION_LOCAL(m_time_deltas_lock); m_time_deltas.push_back(time_delta); while (m_time_deltas.size() > TIME_SYNC_DELTA_RING_BUFFER_SIZE) @@ -834,7 +845,7 @@ namespace currency template bool t_currency_protocol_handler::get_last_time_sync_difference(int64_t& last_median2local_time_difference, int64_t& last_ntp2local_time_difference) { - std::unique_lock lk(m_time_deltas_lock); + CRITICAL_REGION_LOCAL(m_time_deltas_lock); last_median2local_time_difference = m_last_median2local_time_difference; last_ntp2local_time_difference = m_last_ntp2local_time_difference; @@ -896,7 +907,7 @@ namespace currency { #ifdef ASYNC_RELAY_MODE { - std::unique_lock lk(m_relay_que_lock); + CRITICAL_REGION_LOCAL(m_relay_que_lock); m_relay_que.push_back(AUTO_VAL_INIT(relay_que_entry())); m_relay_que.back().first = arg; m_relay_que.back().second = exclude_context; diff --git a/src/currency_protocol/currency_protocol_handler_common.h b/src/currency_protocol/currency_protocol_handler_common.h index ccbd88b2..3a71f4dd 100644 --- a/src/currency_protocol/currency_protocol_handler_common.h +++ b/src/currency_protocol/currency_protocol_handler_common.h @@ -36,4 +36,14 @@ namespace currency } }; + + /************************************************************************/ + /* */ + /************************************************************************/ + struct i_stop_handler + { + virtual void stop_handling() = 0; + }; + + } diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index b90a4c3a..a9ddf296 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -167,6 +167,7 @@ int main(int argc, char* argv[]) cprotocol.set_p2p_endpoint(&p2psrv); ccore.set_currency_protocol(&cprotocol); daemon_cmmands_handler dch(p2psrv, rpc_server); + ccore.set_stop_handler(&dch); //ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&offers_service); std::shared_ptr stratum_server_ptr; if (stratum_enabled) diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 6770d0f1..7a69a085 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -20,7 +20,7 @@ PUSH_WARNINGS DISABLE_VS_WARNINGS(4100) -class daemon_cmmands_handler +class daemon_cmmands_handler : public currency::i_stop_handler { typedef nodetool::node_server > srv_type; srv_type& m_srv; @@ -75,7 +75,8 @@ public: return true; } - void stop_handling() + // interface currency::i_stop_handler + virtual void stop_handling() override { m_cmd_binder.stop_handling(); } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index d28de566..d78b0a00 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -116,7 +116,11 @@ namespace currency //conditional values if (req.flags&COMMAND_RPC_GET_INFO_FLAG_NET_TIME_DELTA_MEDIAN) - res.net_time_delta_median = m_p2p.get_payload_object().get_net_time_delta_median(); + { + int64_t last_median2local_time_diff, last_ntp2local_time_diff; + if (!m_p2p.get_payload_object().get_last_time_sync_difference(last_median2local_time_diff, last_ntp2local_time_diff)) + res.net_time_delta_median = 1; + } if (req.flags&COMMAND_RPC_GET_INFO_FLAG_CURRENT_NETWORK_HASHRATE_50) res.current_network_hashrate_50 = m_core.get_blockchain_storage().get_current_hashrate(50); if (req.flags&COMMAND_RPC_GET_INFO_FLAG_CURRENT_NETWORK_HASHRATE_350) From 403f21130bc18c3b1c95c1a3ba41087e4831fd88 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 7 Jun 2019 15:15:14 +0300 Subject: [PATCH 3/4] time sync issues detection: --disable-stop-if-time-out-of-sync option added + various fixes --- src/common/command_line.cpp | 4 +++- src/common/command_line.h | 1 + src/currency_protocol/currency_protocol_handler.inl | 5 +++-- src/daemon/daemon.cpp | 8 ++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 73178ce8..0aefbc17 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -25,5 +25,7 @@ namespace command_line const arg_descriptor arg_show_details = { "currency-details", "Display currency details" }; const arg_descriptor arg_show_rpc_autodoc = { "show_rpc_autodoc", "Display rpc auto-generated documentation template" }; - const arg_descriptor arg_disable_upnp = { "disable-upnp", "Disable UPnP (enhances local network privacy)", false, true }; + const arg_descriptor arg_disable_upnp = { "disable-upnp", "Disable UPnP (enhances local network privacy)", false, true }; + + const arg_descriptor arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true }; } diff --git a/src/common/command_line.h b/src/common/command_line.h index e4a9c544..2dff6a3d 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -185,4 +185,5 @@ namespace command_line extern const arg_descriptor arg_show_details; extern const arg_descriptor arg_show_rpc_autodoc; extern const arg_descriptor arg_disable_upnp; + extern const arg_descriptor arg_disable_stop_if_time_out_of_sync; } diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 990cf163..6ba18e43 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -131,11 +131,12 @@ namespace currency if (!add_time_delta_and_check_time_sync(context.m_time_delta)) { // serious time sync problem detected - std::shared_ptr ish(m_core.get_stop_handler()); + i_stop_handler* ish(m_core.get_stop_handler()); if (ish != nullptr) { - // this is a daemon -- stop immediately + // this is daemon -- stop immediately ish->stop_handling(); + LOG_ERROR(ENDL << ENDL << "Serious time sync problem detected, daemon will stop immediately" << ENDL << ENDL); return true; } } diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index a9ddf296..2e15932e 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -81,6 +81,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, command_line::arg_console); command_line::add_arg(desc_cmd_sett, command_line::arg_show_details); command_line::add_arg(desc_cmd_sett, command_line::arg_show_rpc_autodoc); + command_line::add_arg(desc_cmd_sett, command_line::arg_disable_stop_if_time_out_of_sync); arg_market_disable.default_value = true; @@ -167,7 +168,10 @@ int main(int argc, char* argv[]) cprotocol.set_p2p_endpoint(&p2psrv); ccore.set_currency_protocol(&cprotocol); daemon_cmmands_handler dch(p2psrv, rpc_server); - ccore.set_stop_handler(&dch); + + if (!command_line::get_arg(vm, command_line::arg_disable_stop_if_time_out_of_sync)) + ccore.set_stop_handler(&dch); + //ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&offers_service); std::shared_ptr stratum_server_ptr; if (stratum_enabled) @@ -305,7 +309,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Deinitializing p2p..."); p2psrv.deinit(); - + ccore.set_stop_handler(nullptr); ccore.set_currency_protocol(NULL); cprotocol.set_p2p_endpoint(NULL); From 627f3c2c560d0c80559b64240a7616390a3d31dd Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 11 Jun 2019 18:24:16 +0300 Subject: [PATCH 4/4] time sync problems detection: final fixes --- src/currency_protocol/currency_protocol_handler.inl | 4 ++-- src/gui/qt-daemon/application/daemon_backend.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 6ba18e43..2f3225a1 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -811,7 +811,7 @@ namespace currency std::vector time_deltas_copy(m_time_deltas.begin(), m_time_deltas.end()); - int64_t m_last_median2local_time_difference = epee::misc_utils::median(time_deltas_copy); + m_last_median2local_time_difference = epee::misc_utils::median(time_deltas_copy); LOG_PRINT_MAGENTA("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ")", LOG_LEVEL_2); if (std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE) { @@ -826,7 +826,7 @@ namespace currency // got ntp time correctly // update local time, because getting ntp time could be time consuming uint64_t local_time_2 = m_core.get_blockchain_storage().get_core_runtime_config().get_core_time(); - int64_t m_last_ntp2local_time_difference = local_time_2 - ntp_time; + m_last_ntp2local_time_difference = local_time_2 - ntp_time; if (std::abs(m_last_ntp2local_time_difference) > TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE) { // local time is out of sync diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index ba7aee2a..bc2ae40c 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -461,7 +461,7 @@ bool daemon_backend::update_state_info() { view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); currency::COMMAND_RPC_GET_INFO::request req = AUTO_VAL_INIT(req); - req.flags = COMMAND_RPC_GET_INFO_FLAG_EXPIRATIONS_MEDIAN; + req.flags = COMMAND_RPC_GET_INFO_FLAG_EXPIRATIONS_MEDIAN | COMMAND_RPC_GET_INFO_FLAG_NET_TIME_DELTA_MEDIAN; currency::COMMAND_RPC_GET_INFO::response inf = AUTO_VAL_INIT(inf); if (!m_rpc_proxy->call_COMMAND_RPC_GET_INFO(req, inf)) {