Skip to content
Snippets Groups Projects
Commit ee5ef6b7 authored by Roman Khlopkov's avatar Roman Khlopkov 🔜
Browse files

Merge branch 'bugfix-11834' into 'release-5.3'

Bugfix 11834

See merge request !1693
parents 590b72c6 2f881eeb
No related branches found
No related tags found
1 merge request!1693Bugfix 11834
Pipeline #41273 passed with stage
in 9 minutes and 32 seconds
...@@ -41,8 +41,10 @@ ...@@ -41,8 +41,10 @@
#include "dap_cert_file.h" #include "dap_cert_file.h"
#include "dap_chain_ch.h" #include "dap_chain_ch.h"
#include "dap_stream_ch_gossip.h" #include "dap_stream_ch_gossip.h"
#include "dap_notify_srv.h"
#include <uthash.h> #include <uthash.h>
#include <pthread.h> #include <pthread.h>
#include "json.h"
#define LOG_TAG "chain" #define LOG_TAG "chain"
...@@ -580,6 +582,19 @@ int dap_chain_save_all(dap_chain_t *l_chain) ...@@ -580,6 +582,19 @@ int dap_chain_save_all(dap_chain_t *l_chain)
return l_ret; return l_ret;
} }
//send chain load_progress data to notify socket
bool download_notify_callback(dap_chain_t* a_chain) {
json_object* l_chain_info = json_object_new_object();
json_object_object_add(l_chain_info, "class", json_object_new_string("chain_init"));
json_object_object_add(l_chain_info, "net", json_object_new_string(a_chain->net_name));
json_object_object_add(l_chain_info, "chain_id", json_object_new_uint64(a_chain->id.uint64));
json_object_object_add(l_chain_info, "load_progress", json_object_new_int(a_chain->load_progress));
dap_notify_server_send_mt(json_object_get_string(l_chain_info));
log_it(L_DEBUG, "Load progress: net_name: %s; chain_id: %d; download:%d%c", a_chain->net_name, a_chain->id.uint64, a_chain->load_progress, '%');
json_object_put(l_chain_info);
return true;
}
/** /**
* @brief dap_chain_load_all * @brief dap_chain_load_all
* @param l_chain * @param l_chain
...@@ -610,6 +625,7 @@ int dap_chain_load_all(dap_chain_t *a_chain) ...@@ -610,6 +625,7 @@ int dap_chain_load_all(dap_chain_t *a_chain)
uint64_t l_cell_id_uint64 = 0; uint64_t l_cell_id_uint64 = 0;
sscanf(l_filename, "%"DAP_UINT64_FORMAT_x".dchaincell", &l_cell_id_uint64); sscanf(l_filename, "%"DAP_UINT64_FORMAT_x".dchaincell", &l_cell_id_uint64);
dap_chain_cell_t *l_cell = dap_chain_cell_create_fill(a_chain, (dap_chain_cell_id_t){ .uint64 = l_cell_id_uint64 }); dap_chain_cell_t *l_cell = dap_chain_cell_create_fill(a_chain, (dap_chain_cell_id_t){ .uint64 = l_cell_id_uint64 });
dap_timerfd_t* l_download_notify_timer = dap_timerfd_start(5000, (dap_timerfd_callback_t)download_notify_callback, a_chain);
l_ret += dap_chain_cell_load(a_chain, l_cell); l_ret += dap_chain_cell_load(a_chain, l_cell);
if ( DAP_CHAIN_PVT(a_chain)->need_reorder ) { if ( DAP_CHAIN_PVT(a_chain)->need_reorder ) {
#ifdef DAP_OS_WINDOWS #ifdef DAP_OS_WINDOWS
...@@ -629,6 +645,8 @@ int dap_chain_load_all(dap_chain_t *a_chain) ...@@ -629,6 +645,8 @@ int dap_chain_load_all(dap_chain_t *a_chain)
DAP_DELETE(l_filename_backup); DAP_DELETE(l_filename_backup);
#endif #endif
} }
dap_timerfd_delete_unsafe(l_download_notify_timer);
download_notify_callback(a_chain);
} }
} }
closedir(l_dir); closedir(l_dir);
......
...@@ -439,7 +439,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) ...@@ -439,7 +439,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell)
uint64_t q = 0; uint64_t q = 0;
if (a_chain->is_mapped) { if (a_chain->is_mapped) {
a_cell->map_pos = a_cell->map + sizeof(dap_chain_cell_file_header_t); a_cell->map_pos = a_cell->map + sizeof(dap_chain_cell_file_header_t);
for ( uint64_t l_el_size = 0; l_pos < l_size; ++q, l_pos += l_el_size + sizeof(uint64_t) ) { for ( uint64_t l_el_size = 0; l_pos < l_size; ++q, l_pos += l_el_size + sizeof(uint64_t), a_chain->load_progress = (int)((double)l_pos/l_size * 100 + 0.5)) {
size_t space_left = (size_t)( a_cell->map_end - a_cell->map_pos ); size_t space_left = (size_t)( a_cell->map_end - a_cell->map_pos );
if ( space_left < sizeof(uint64_t) || (space_left - sizeof(uint64_t)) < *(uint64_t*)a_cell->map_pos ) if ( space_left < sizeof(uint64_t) || (space_left - sizeof(uint64_t)) < *(uint64_t*)a_cell->map_pos )
if ( s_cell_map_new_volume(a_cell, l_pos) ) if ( s_cell_map_new_volume(a_cell, l_pos) )
...@@ -468,6 +468,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) ...@@ -468,6 +468,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell)
break; break;
} }
l_pos += sizeof(uint64_t) + ( l_read = fread((void*)l_element, 1, l_el_size, a_cell->file_storage) ); l_pos += sizeof(uint64_t) + ( l_read = fread((void*)l_element, 1, l_el_size, a_cell->file_storage) );
a_chain->load_progress = (int)((double)l_pos/l_size * 100 + 0.5);
if (l_read != l_el_size) { if (l_read != l_el_size) {
log_it(L_ERROR, "Read only %lu of %zu bytes, stop cell loading", l_read, l_el_size); log_it(L_ERROR, "Read only %lu of %zu bytes, stop cell loading", l_read, l_el_size);
DAP_DELETE(l_element); DAP_DELETE(l_element);
......
...@@ -140,6 +140,7 @@ typedef struct dap_chain { ...@@ -140,6 +140,7 @@ typedef struct dap_chain {
char *net_name; char *net_name;
bool is_datum_pool_proc; bool is_datum_pool_proc;
bool is_mapped; bool is_mapped;
atomic_int load_progress;
// Nested cells (hashtab by cell_id) // Nested cells (hashtab by cell_id)
dap_chain_cell_t *cells; dap_chain_cell_t *cells;
dap_chain_cell_id_t active_cell_id; dap_chain_cell_id_t active_cell_id;
......
...@@ -1599,12 +1599,12 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply) ...@@ -1599,12 +1599,12 @@ static int s_cli_dag(int argc, char ** argv, void **a_str_reply)
break; break;
} }
if ( l_event ){ if ( l_event ) {
char buf[DAP_TIME_STR_SIZE];
json_object_object_add(json_obj_event,"Event hash", json_object_new_string(l_event_hash_str)); json_object_object_add(json_obj_event,"Event hash", json_object_new_string(l_event_hash_str));
// Round info // Round info
if ((l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) && l_round_item) { if ((l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) && l_round_item) {
char buf[DAP_TIME_STR_SIZE];
json_object_object_add(json_obj_event,"Round info", json_object_new_string(" ")); json_object_object_add(json_obj_event,"Round info", json_object_new_string(" "));
json_object_object_add(json_obj_event,"tsigns reject", json_object_new_uint64(l_round_item->round_info.reject_count)); json_object_object_add(json_obj_event,"tsigns reject", json_object_new_uint64(l_round_item->round_info.reject_count));
json_object_object_add(json_obj_event,"ts_update", json_object_new_string(buf)); json_object_object_add(json_obj_event,"ts_update", json_object_new_string(buf));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment