Skip to content

Commit 44c8162

Browse files
committed
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.
1 parent 783c280 commit 44c8162

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lightning-transaction-sync/src/electrum.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ impl<L: Logger> ElectrumSyncClient<L> {
9696
let mut tip_header = tip_notification.header;
9797
let mut tip_height = tip_notification.height as u32;
9898

99-
loop {
99+
for i in 0..100 {
100+
if i >= 10 {
101+
log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts.");
102+
break;
103+
}
104+
100105
let pending_registrations = self.queue.lock().unwrap().process_queues(&mut sync_state);
101106
let tip_is_new = Some(tip_header.block_hash()) != sync_state.last_sync_hash;
102107

lightning-transaction-sync/src/esplora.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ impl<L: Logger> EsploraSyncClient<L> {
100100

101101
let mut tip_hash = maybe_await!(self.client.get_tip_hash())?;
102102

103-
loop {
103+
for i in 0..100 {
104+
if i >= 10 {
105+
log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts.");
106+
break;
107+
}
108+
104109
let pending_registrations = self.queue.lock().unwrap().process_queues(&mut sync_state);
105110
let tip_is_new = Some(tip_hash) != sync_state.last_sync_hash;
106111

0 commit comments

Comments
 (0)