Skip to content

Bound sync loops in lightning-transaction-sync#4612

Open
TheBlueMatt wants to merge 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-esplora-sync-timeout
Open

Bound sync loops in lightning-transaction-sync#4612
TheBlueMatt wants to merge 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-05-esplora-sync-timeout

Conversation

@TheBlueMatt
Copy link
Copy Markdown
Collaborator

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.

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented May 12, 2026

I've assigned @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Comment thread lightning-transaction-sync/src/electrum.rs Outdated
Comment thread lightning-transaction-sync/src/esplora.rs
@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented May 12, 2026

Review Summary

Issues found: 1 (new)

  1. lightning-transaction-sync/src/electrum.rs:100-103 — After breaking out of the loop at 10 attempts ("Giving up"), execution falls through to the "Finished transaction sync" log and returns Ok(()), making it look like sync completed normally. Same issue in esplora.rs.

Previously flagged issues (not repeated)

  • electrum.rs:100 — Compile error (_ vs i) — now resolved in current diff.
  • esplora.rs:107 — Dead upper bound (0..100 with break at 10) — still present.

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.
@TheBlueMatt TheBlueMatt force-pushed the 2026-05-esplora-sync-timeout branch from 9db7e55 to 44c8162 Compare May 12, 2026 21:40
Comment on lines +100 to +103
if i >= 10 {
log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts.");
break;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After break-ing here, execution falls through to the "Finished transaction sync at tip …" log message (and Ok(())), which is misleading — sync didn't actually finish, it gave up. Same issue in esplora.rs.

Consider either:

  • Adding an early return Ok(()) (or return Err(...)) right here so the "Finished" log is skipped, or
  • Guarding the "Finished" log with a check (e.g., if !sync_state.pending_sync).

@ldk-reviews-bot ldk-reviews-bot requested a review from tankyleo May 12, 2026 21:49
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.12%. Comparing base (946ee09) to head (44c8162).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #4612    +/-   ##
========================================
  Coverage   86.11%   86.12%            
========================================
  Files         157      157            
  Lines      108841   108944   +103     
  Branches   108841   108944   +103     
========================================
+ Hits        93725    93823    +98     
- Misses      12497    12500     +3     
- Partials     2619     2621     +2     
Flag Coverage Δ
tests 86.12% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

for i in 0..100 {
if i >= 10 {
log_debug!(self.logger, "Giving up trying to do transaction sync after 10 attempts.");
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like claude I'm thinking we return Err early here instead of breaking ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants