@@ -44,21 +44,22 @@ namespace
44
44
{
45
45
using namespace std ::string_literals;
46
46
nlohmann::json resp;
47
- bool sync_ok = false ;
47
+ bool sync_ok = true ;
48
48
std::string resp_str = TO_STD_STR (resp_http.extract_string (true ).get ());
49
49
if (resp_http.status_code () != 200 )
50
50
{
51
- SPDLOG_ERROR (" Cannot reach the endpoint [{}]: {}" , g_timesync_endpoint);
51
+ SPDLOG_ERROR (" Cannot reach the endpoint [{}]: {}" , g_timesync_endpoint, resp_str );
52
52
}
53
53
else
54
54
{
55
55
resp = nlohmann::json::parse (resp_str);
56
56
int64_t epoch_ts = resp[" unixtime" ];
57
57
int64_t current_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
58
58
int64_t ts_diff = epoch_ts - current_ts;
59
- if (abs (ts_diff) < 60 )
59
+ if (abs (ts_diff) > 60 )
60
60
{
61
- sync_ok = true ;
61
+ SPDLOG_WARN (" Time sync failed! Actual: {}, System: {}, Diff: {}" , epoch_ts, current_ts, ts_diff);
62
+ sync_ok = false ;
62
63
}
63
64
}
64
65
return sync_ok;
@@ -82,7 +83,7 @@ namespace atomic_dex
82
83
int64_t m_timesync_clock_ts = std::chrono::duration_cast<std::chrono::seconds>(m_timesync_clock.time_since_epoch ()).count ();
83
84
int64_t now_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now ().time_since_epoch ()).count ();
84
85
int64_t ts_diff = now_ts - m_timesync_clock_ts;
85
- if (abs (ts_diff) >= 60 )
86
+ if (abs (ts_diff) > 300 )
86
87
{
87
88
fetch_timesync_status ();
88
89
m_timesync_clock = std::chrono::high_resolution_clock::now ();
@@ -91,21 +92,28 @@ namespace atomic_dex
91
92
92
93
void timesync_checker_service::fetch_timesync_status ()
93
94
{
95
+ SPDLOG_INFO (" Checking system time is in sync..." );
94
96
if (is_timesync_fetching)
95
97
{
98
+ SPDLOG_WARN (" Already checking timesync, returning" );
96
99
return ;
97
100
}
98
101
is_timesync_fetching = true ;
99
102
emit isTimesyncFetchingChanged ();
100
103
async_fetch_timesync ()
101
104
.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
+ }
104
113
})
105
114
.then (&handle_exception_pplx_task);
106
115
is_timesync_fetching = false ;
107
116
emit isTimesyncFetchingChanged ();
108
-
109
117
}
110
118
111
119
bool timesync_checker_service::get_timesync_info () const
@@ -115,4 +123,5 @@ namespace atomic_dex
115
123
116
124
} // namespace atomic_dex
117
125
126
+
118
127
0 commit comments