Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/timesync checker #2474

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ QtObject {

function coinIcon(ticker)
{
if (ticker.toLowerCase() == "smart chain")
{
return coin_icons_path + "smart_chain.png"
}
if (ticker.toLowerCase() == "avx")
{
return coin_icons_path + "avax.png"
}
if (ticker === "" || ticker === "All" || ticker===undefined)
{
return ""
Expand Down Expand Up @@ -458,7 +466,7 @@ QtObject {
}
if (sell_ticker_balance == 0)
{
return qsTr("%1 balance is zero").arg(selectedTicker)
return qsTr("Balance is zero!")
}
if (!isZhtlcReady(selectedTicker))
{
Expand Down
25 changes: 17 additions & 8 deletions src/core/atomicdex/services/sync/timesync.checker.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ namespace
{
using namespace std::string_literals;
nlohmann::json resp;
bool sync_ok = false;
bool sync_ok = true;
std::string resp_str = TO_STD_STR(resp_http.extract_string(true).get());
if (resp_http.status_code() != 200)
{
SPDLOG_ERROR("Cannot reach the endpoint [{}]: {}", g_timesync_endpoint);
SPDLOG_ERROR("Cannot reach the endpoint [{}]: {}", g_timesync_endpoint, resp_str);
}
else
{
resp = nlohmann::json::parse(resp_str);
int64_t epoch_ts = resp["unixtime"];
int64_t current_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
int64_t ts_diff = epoch_ts - current_ts;
if (abs(ts_diff) < 60)
if (abs(ts_diff) > 60)
{
sync_ok = true;
SPDLOG_WARN("Time sync failed! Actual: {}, System: {}, Diff: {}", epoch_ts, current_ts, ts_diff);
sync_ok = false;
}
}
return sync_ok;
Expand All @@ -82,7 +83,7 @@ namespace atomic_dex
int64_t m_timesync_clock_ts = std::chrono::duration_cast<std::chrono::seconds>(m_timesync_clock.time_since_epoch()).count();
int64_t now_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
int64_t ts_diff = now_ts - m_timesync_clock_ts;
if (abs(ts_diff) >= 60)
if (abs(ts_diff) > 300)
{
fetch_timesync_status();
m_timesync_clock = std::chrono::high_resolution_clock::now();
Expand All @@ -91,21 +92,28 @@ namespace atomic_dex

void timesync_checker_service::fetch_timesync_status()
{
SPDLOG_INFO("Checking system time is in sync...");
if (is_timesync_fetching)
{
SPDLOG_WARN("Already checking timesync, returning");
return;
}
is_timesync_fetching = true;
emit isTimesyncFetchingChanged();
async_fetch_timesync()
.then([this](web::http::http_response resp) {
this->m_timesync_status = get_timesync_info_rpc(resp);
emit timesyncInfoChanged();
bool is_timesync_ok = get_timesync_info_rpc(resp);
SPDLOG_INFO("System time is in sync: {}", is_timesync_ok);

if (is_timesync_ok != *m_timesync_status)
{
this->m_timesync_status = is_timesync_ok;
emit timesyncInfoChanged();
}
})
.then(&handle_exception_pplx_task);
is_timesync_fetching = false;
emit isTimesyncFetchingChanged();

}

bool timesync_checker_service::get_timesync_info() const
Expand All @@ -115,4 +123,5 @@ namespace atomic_dex

} // namespace atomic_dex



Loading