@@ -44,21 +44,22 @@ namespace
4444 {
4545 using namespace std ::string_literals;
4646 nlohmann::json resp;
47- bool sync_ok = false ;
47+ bool sync_ok = true ;
4848 std::string resp_str = TO_STD_STR (resp_http.extract_string (true ).get ());
4949 if (resp_http.status_code () != 200 )
5050 {
51- SPDLOG_ERROR (" Cannot reach the endpoint [{}]: {}" , g_timesync_endpoint);
51+ SPDLOG_ERROR (" Cannot reach the endpoint [{}]: {}" , g_timesync_endpoint, resp_str );
5252 }
5353 else
5454 {
5555 resp = nlohmann::json::parse (resp_str);
5656 int64_t epoch_ts = resp[" unixtime" ];
5757 int64_t current_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
5858 int64_t ts_diff = epoch_ts - current_ts;
59- if (abs (ts_diff) < 60 )
59+ if (abs (ts_diff) > 60 )
6060 {
61- sync_ok = true ;
61+ SPDLOG_WARN (" Time sync failed! Actual: {}, System: {}, Diff: {}" , epoch_ts, current_ts, ts_diff);
62+ sync_ok = false ;
6263 }
6364 }
6465 return sync_ok;
@@ -82,7 +83,7 @@ namespace atomic_dex
8283 int64_t m_timesync_clock_ts = std::chrono::duration_cast<std::chrono::seconds>(m_timesync_clock.time_since_epoch ()).count ();
8384 int64_t now_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
8485 int64_t ts_diff = now_ts - m_timesync_clock_ts;
85- if (abs (ts_diff) >= 60 )
86+ if (abs (ts_diff) > 300 )
8687 {
8788 fetch_timesync_status ();
8889 m_timesync_clock = std::chrono::high_resolution_clock::now ();
@@ -91,21 +92,28 @@ namespace atomic_dex
9192
9293 void timesync_checker_service::fetch_timesync_status ()
9394 {
95+ SPDLOG_INFO (" Checking system time is in sync..." );
9496 if (is_timesync_fetching)
9597 {
98+ SPDLOG_WARN (" Already checking timesync, returning" );
9699 return ;
97100 }
98101 is_timesync_fetching = true ;
99102 emit isTimesyncFetchingChanged ();
100103 async_fetch_timesync ()
101104 .then ([this ](web::http::http_response resp) {
102- this ->m_timesync_status = get_timesync_info_rpc (resp);
103- emit timesyncInfoChanged ();
105+ bool is_timesync_ok = get_timesync_info_rpc (resp);
106+ SPDLOG_INFO (" System time is in sync: {}" , is_timesync_ok);
107+
108+ if (is_timesync_ok != *m_timesync_status)
109+ {
110+ this ->m_timesync_status = is_timesync_ok;
111+ emit timesyncInfoChanged ();
112+ }
104113 })
105114 .then (&handle_exception_pplx_task);
106115 is_timesync_fetching = false ;
107116 emit isTimesyncFetchingChanged ();
108-
109117 }
110118
111119 bool timesync_checker_service::get_timesync_info () const
@@ -115,4 +123,5 @@ namespace atomic_dex
115123
116124} // namespace atomic_dex
117125
126+
118127
0 commit comments