diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index d8cf287635e09d3650be3ca81fdad18b7b19f911..9f33ceb43426103c5366a31d6dfa1311cee1a71f 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -588,27 +588,30 @@ json_object *s_net_sync_status(dap_chain_net_t *a_net) { json_object *l_jobj_chain = json_object_new_object(); json_object *l_jobj_chain_status = NULL; json_object *l_jobj_percent = NULL; - if (PVT(a_net)->state == NET_STATE_OFFLINE) { - l_jobj_chain_status = json_object_new_string("not synced"); - l_jobj_percent = json_object_new_string(" - %"); - } else if (PVT(a_net)->state == NET_STATE_ONLINE) { - l_jobj_chain_status = json_object_new_string("synced"); - l_jobj_percent = json_object_new_string(" - %"); - } else { - if (PVT(a_net)->sync_context.cur_chain && PVT(a_net)->sync_context.cur_chain->id.uint64 == l_chain->id.uint64) { - l_jobj_chain_status = json_object_new_string("sync in process"); - double l_percent = l_chain->callback_count_atom(l_chain) ? + double l_percent = l_chain->callback_count_atom(l_chain) ? (double) (l_chain->callback_count_atom(l_chain) * 100) / l_chain->atom_num_last : 0; - if (l_percent > 100) - l_percent = 100; - char *l_percent_str = dap_strdup_printf("%.3f", l_percent); - l_jobj_percent = json_object_new_string(l_percent_str); - DAP_DELETE(l_percent_str); - } else { + if (l_percent > 100) + l_percent = 100; + char *l_percent_str = dap_strdup_printf("%.3f", l_percent); + switch (PVT(a_net)->state) { + case NET_STATE_OFFLINE: + case NET_STATE_LINKS_PREPARE: + case NET_STATE_LINKS_ESTABLISHED: + case NET_STATE_LINKS_CONNECTING: l_jobj_chain_status = json_object_new_string("not synced"); l_jobj_percent = json_object_new_string(" - %"); - } + break; + case NET_STATE_SYNC_CHAINS: + l_jobj_chain_status = PVT(a_net)->sync_context.cur_chain->id.uint64 == l_chain->id.uint64 ? + json_object_new_string("sync in process") : json_object_new_string("not synced"); + l_jobj_percent = json_object_new_string(l_percent_str); + break; + case NET_STATE_ONLINE: + l_jobj_chain_status = json_object_new_string("synced"); + l_jobj_percent = json_object_new_string(l_percent_str); + break; } + DAP_DELETE(l_percent_str); json_object *l_jobj_current = json_object_new_uint64(l_chain->callback_count_atom(l_chain)); json_object *l_jobj_total = json_object_new_uint64(l_chain->atom_num_last); json_object_object_add(l_jobj_chain, "status", l_jobj_chain_status); @@ -2376,6 +2379,8 @@ static void s_ch_in_pkt_callback(dap_stream_ch_t *a_ch, uint8_t a_type, const vo a_type, a_data_size, NODE_ADDR_FP_ARGS_S(a_ch->stream->node)); dap_chain_net_t *l_net = a_arg; dap_chain_net_pvt_t *l_net_pvt = PVT(l_net); + if (l_net_pvt->state == NET_STATE_LINKS_ESTABLISHED) + l_net_pvt->state = NET_STATE_SYNC_CHAINS; switch (a_type) { case DAP_CHAIN_CH_PKT_TYPE_CHAIN_SUMMARY: