Browse Source

db_sync: mc>pc guard with last_peer_count — detect stalled sync when pc doesn't change

topo_upd
Evgeny 2 months ago
parent
commit
7a9e3bea5f
  1. 15
      src/db_sync.c

15
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);

Loading…
Cancel
Save