From 0d6712a08027738f4eb68d661e6454647b71e697 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?=
 <alexander.lysikov@demlabs.net>
Date: Fri, 6 Mar 2020 23:45:34 +0500
Subject: [PATCH] fixed start item for node synchronization in case of
 global_db truncated

---
 dap_chain_node_client.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dap_chain_node_client.c b/dap_chain_node_client.c
index ca52649e4f..3ac5e2c326 100644
--- a/dap_chain_node_client.c
+++ b/dap_chain_node_client.c
@@ -286,8 +286,13 @@ static void s_ch_chain_callback_notify_packet_in(dap_stream_ch_chain_t* a_ch_cha
                 // Get log diff
                 if(a_pkt_type == DAP_STREAM_CH_CHAIN_PKT_TYPE_SYNCED_GLOBAL_DB) {
                     a_ch_chain->request_last_ts = dap_db_log_get_last_id();
+                    uint64_t l_start_item = l_request->id_start;
+                    // If the current global_db has been truncated, but the remote node has not known this
+                    if(l_request->id_start > a_ch_chain->request_last_ts){
+                        l_start_item = 0;
+                    }
                     //dap_list_t *l_list = dap_db_log_get_list(l_request->id_start + 1);
-                    dap_db_log_list_t *l_db_log = dap_db_log_list_start(l_request->id_start + 1);
+                    dap_db_log_list_t *l_db_log = dap_db_log_list_start(l_start_item + 1);
                     if(l_db_log) {
                         // Add it to outgoing list
                         //l_list->prev = a_ch_chain->request_global_db_trs;
-- 
GitLab