From 44c81625830abf67de99b0451e0a1b53d124fda7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 12 May 2026 21:07:10 +0000 Subject: [PATCH] Bound sync loops in lightning-transaction-sync If we start syncing from an electrum or esplora server and find that the chain moved during our sync, we reset and start fresh. However, if that happens repeatedly, we probably shouldn't just spin forever. Here we give up after ten attempts and just hope we can sync properly later. --- lightning-transaction-sync/src/electrum.rs | 7 ++++++- lightning-transaction-sync/src/esplora.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lightning-transaction-sync/src/electrum.rs b/lightning-transaction-sync/src/electrum.rs index 9d643f48511..f2fc656beea 100644 --- a/lightning-transaction-sync/src/electrum.rs +++ b/lightning-transaction-sync/src/electrum.rs @@ -96,7 +96,12 @@ impl ElectrumSyncClient { let mut tip_header = tip_notification.header; let mut tip_height = tip_notification.height as u32; - loop { + for i in 0..100 { + if i >= 10 { + log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts."); + break; + } + let pending_registrations = self.queue.lock().unwrap().process_queues(&mut sync_state); let tip_is_new = Some(tip_header.block_hash()) != sync_state.last_sync_hash; diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs index 7d3550d65b1..5a540c81bd7 100644 --- a/lightning-transaction-sync/src/esplora.rs +++ b/lightning-transaction-sync/src/esplora.rs @@ -100,7 +100,12 @@ impl EsploraSyncClient { let mut tip_hash = maybe_await!(self.client.get_tip_hash())?; - loop { + for i in 0..100 { + if i >= 10 { + log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts."); + break; + } + let pending_registrations = self.queue.lock().unwrap().process_queues(&mut sync_state); let tip_is_new = Some(tip_hash) != sync_state.last_sync_hash;