diff --git a/dap_chain_global_db.h b/dap_chain_global_db.h index 381b3ac9687fc144c12e8f8c3835436982dfd8d8..30f5095af9ac42563ff98925ae76e8a7e03e2a4c 100755 --- a/dap_chain_global_db.h +++ b/dap_chain_global_db.h @@ -11,7 +11,7 @@ #define GROUP_LOCAL_HISTORY "global.history" -#define GROUP_LOCAL_NODE_LAST_TS "local.node.last_ts" +#define GROUP_LOCAL_NODE_LAST_ID "local.node.last_id" #define GROUP_LOCAL_GENERAL "local.general" typedef struct dap_global_db_obj { diff --git a/dap_chain_global_db_hist.c b/dap_chain_global_db_hist.c index 8d63d2c949dc5f3ec942aa31400cbf09bf2f2508..1b3062b558d0e90d76d2a1239a6179fbcf83bab7 100755 --- a/dap_chain_global_db_hist.c +++ b/dap_chain_global_db_hist.c @@ -75,7 +75,9 @@ uint8_t* dap_db_log_pack(dap_global_db_obj_t *a_obj, size_t *a_data_size_out) // add record - read record if(l_rec.type == 'a'){ l_obj = (dap_store_obj_t*) dap_chain_global_db_obj_get(l_keys[i], l_rec.group); - l_obj->id = a_obj->id; + // l_obj may be NULL, if this record has been deleted but it is present in history + if(l_obj) + l_obj->id = a_obj->id; } // delete record - save only key for record else if(l_rec.type == 'd') { // //section=strdup("kelvin_nodes"); diff --git a/dap_chain_global_db_remote.c b/dap_chain_global_db_remote.c index 605ddcf8f07402973658bb2a32e6bc196aa9e674..34e3de72f1ff8a854ec2ecdee689fb4b32cff50c 100755 --- a/dap_chain_global_db_remote.c +++ b/dap_chain_global_db_remote.c @@ -32,31 +32,31 @@ uint64_t dap_db_get_cur_node_addr(void) } /** - * Set last timestamp for remote node + * Set last id for remote node */ -bool dap_db_log_set_last_timestamp_remote(uint64_t a_node_addr, time_t a_timestamp) +bool dap_db_log_set_last_id_remote(uint64_t a_node_addr, uint64_t a_id) { dap_global_db_obj_t l_objs; l_objs.key = dap_strdup_printf("%lld", a_node_addr); - l_objs.value = (uint8_t*) &a_timestamp; - l_objs.value_len = sizeof(time_t); - bool l_ret = dap_chain_global_db_gr_save(&l_objs, 1, GROUP_LOCAL_NODE_LAST_TS); + l_objs.value = (uint8_t*) &a_id; + l_objs.value_len = sizeof(uint64_t); + bool l_ret = dap_chain_global_db_gr_save(&l_objs, 1, GROUP_LOCAL_NODE_LAST_ID); DAP_DELETE(l_objs.key); - log_it( L_NOTICE, "Node 0x%016X set last synced timestamp %llu",a_timestamp); + log_it( L_NOTICE, "Node 0x%016X set last synced timestamp %llu",a_id); return l_ret; } /** - * Get last timestamp for remote node + * Get last id for remote node */ -time_t dap_db_log_get_last_timestamp_remote(uint64_t a_node_addr) +uint64_t dap_db_log_get_last_id_remote(uint64_t a_node_addr) { char *l_node_addr_str = dap_strdup_printf("%lld", a_node_addr); size_t l_timestamp_len = 0; uint8_t *l_timestamp = dap_chain_global_db_gr_get((const char*) l_node_addr_str, &l_timestamp_len, - GROUP_LOCAL_NODE_LAST_TS); - time_t l_ret_timestamp = 0; - if(l_timestamp && l_timestamp_len == sizeof(time_t)) + GROUP_LOCAL_NODE_LAST_ID); + uint64_t l_ret_timestamp = 0; + if(l_timestamp && l_timestamp_len == sizeof(uint64_t)) memcpy(&l_ret_timestamp, l_timestamp, l_timestamp_len); DAP_DELETE(l_node_addr_str); DAP_DELETE(l_timestamp); diff --git a/dap_chain_global_db_remote.h b/dap_chain_global_db_remote.h index 0a0f3b6fa89a867866e3cc5ac2b167dba4c83fd3..2453611dc84e875cf38d5c01f75911e67a935891 100755 --- a/dap_chain_global_db_remote.h +++ b/dap_chain_global_db_remote.h @@ -9,8 +9,8 @@ bool dap_db_set_cur_node_addr(uint64_t a_address); // Get addr for current node uint64_t dap_db_get_cur_node_addr(void); -// Set last timestamp for remote node -bool dap_db_log_set_last_timestamp_remote(uint64_t a_node_addr, time_t a_timestamp); -// Get last timestamp for remote node -time_t dap_db_log_get_last_timestamp_remote(uint64_t a_node_addr); +// Set last id for remote node +bool dap_db_log_set_last_id_remote(uint64_t a_node_addr, uint64_t a_id); +// Get last id for remote node +uint64_t dap_db_log_get_last_id_remote(uint64_t a_node_addr);