From 7a9e3bea5fa6f7f2227bff3c813c8e02c7eddace Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sat, 25 Jul 2026 16:56:30 +0300 Subject: [PATCH] =?UTF-8?q?db=5Fsync:=20mc>pc=20guard=20with=20last=5Fpeer?= =?UTF-8?q?=5Fcount=20=E2=80=94=20detect=20stalled=20sync=20when=20pc=20do?= =?UTF-8?q?esn't=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db_sync.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/db_sync.c b/src/db_sync.c index 427a8685..95e96f13 100644 --- a/src/db_sync.c +++ b/src/db_sync.c @@ -39,6 +39,7 @@ struct SI_PEER { uint64_t node_id; uint32_t synced_pos; uint32_t verified_pos; + uint32_t last_peer_count; uint8_t sync_state; uint64_t sync_start_tb; }; @@ -1049,12 +1050,6 @@ static void db_handle_send_data(struct DB_SYNC_INSTANCE* si, uint64_t src, const } uint64_t lch8 = 0; if (mc > 0) db_chain_hash8_at(si, mc - 1, &lch8); - if (received == 0 && resp_count == 0) { - if (sp) { uint32_t nsp = mc > 0 ? mc - 1 : 0; if (sp->synced_pos < nsp) sp->synced_pos = nsp; sp->sync_state = 2; sp->sync_start_tb = 0; } - DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "sync [%s:%04llX] → SEND_DATA: 0 new records, skip SYNC_DONE (synced=%u)", - SI_SHRT(si), (unsigned long long)(src >> 16), sp ? sp->synced_pos : 0); - return; - } uint8_t sd[13]; sd[0] = DB_MSG_SYNC_DONE; memcpy(sd + 1, &mc, 4); memcpy(sd + 5, &lch8, 8); db_sync_send(si, src, sd, 13); @@ -1103,6 +1098,14 @@ static void db_handle_sync_done(struct DB_SYNC_INSTANCE* si, uint64_t src, const } if (mc > pc) { + if (sp && sp->synced_pos + 1 >= mc && sp->last_peer_count == pc) { + if (sp) sp->sync_state = 2; + DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, + "sync [%s:%04llX] ← SYNC_DONE: count diff my=%u peer=%u synced=%u — same pc, accept", + SI_SHRT(si), (unsigned long long)(src >> 16), mc, pc, sp ? sp->synced_pos : 0); + return; + } + if (sp) sp->last_peer_count = pc; DEBUG_INFO(DEBUG_CATEGORY_DB_SYNC, "sync [%s:%04llX] ← SYNC_DONE: count diff my=%u peer=%u — sending tail from=%u", SI_SHRT(si), (unsigned long long)(src >> 16), mc, pc, pc);