chainntnfs: retry failed historical rescans in the backends

Open
#11,234 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
62/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
backend

Research direction

Start in the chainntnfs package to understand how request sets track in-flight scans after #11183, then read the three backends named in the issue: bitcoindnotify/bitcoind.go, btcdnotify/btcd.go, neutrinonotify/neutrino.go, focusing on where historical conf/spend rescans fail and the TODO(wilmer) retry markers. Done means every failure path eventually calls UpdateConfDetails or UpdateSpendDetails (with backoff until notifier quit), non-retryable errors like pruned blocks are logged without spinning, and TestTxNotifierAsyncModelProperty's FailScan action drops the liveness carve-out and passes.

Written by the indexing model from the issue text.

Description

When a historical conf or spend rescan fails, all three chain notifier backends log the error and return without ever reporting back to the TxNotifier (bitcoindnotify/bitcoind.go, btcdnotify/btcd.go, neutrinonotify/neutrino.go, several of which still carry a TODO(wilmer): add retry logic if rescan fails?). Neutrino's GetUtxo path does the same for spends, and bitcoind's outpoint spend path returns early when the funding tx is found but unconfirmed.

Since #11183, a request set counts its in-flight scans, so a scan that never reports keeps the set in rescanPending for the life of the process. That's fail safe: the hint can't advance past the range that was never verified, and since the persisted hint's origin sits above that range, the next restart scans it again. Details found by any other scan, or at tip, are still dispatched. What we lose is the event itself for this run: a subscriber whose confirmation or spend only lies in the failed range won't be notified until lnd restarts.

In this issue, we want the backends to retry failed historical scans rather than dropping them. Roughly:

  • Retry the scan with backoff until it succeeds or the notifier quits, so UpdateConfDetails / UpdateSpendDetails is always eventually called and the pending count always unwinds.
  • Distinguish errors that won't resolve on retry (e.g. a pruned block bitcoind can't fetch) from transient RPC or peer errors, and log loudly for the former instead of spinning.
  • Cover the early-return paths that never report at all (bitcoind's unconfirmed funding tx case, btcd's RescanAsync spends, Neutrino's script spend rewind), since those also leave a pending scan behind.

The async state machine model added in #11183 (TestTxNotifierAsyncModelProperty) already has a FailScan action. Once retries exist, the model can treat a failed scan as delayed instead of lost, and drop the carve-out in its liveness check for requests with a failed scan.

Dominant language
Go
Stars
8.2k
Forks
2.3k
Avg merge
1d 11h
Merged PRs (30d)
103

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lightningnetwork/lnd

All issues in lightningnetwork/lnd

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.