[bug]: wallet stops syncing for good after a block arrives during a short postgres outage

オープン
#11,639 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, postgresql
領域
backend, databases

調査の方向性

Start with btcwallet's waddrmgr/db.go at PutSyncedTo and wallet/chainntfns.go at handleChainNotifications, then compare the notification path with syncWithChain at startup. Reproduce the reported PostgreSQL outage on regtest and trace how the wallet handles the missed height after the database returns. Done means syncing recovers without restarting lnd and synced_to_chain returns to true.

索引モデルが issue の本文から書いたものです。

説明

Pre-Submission Checklist
  • I have searched the existing issues and believe this is a new bug.
  • I am not asking a question about how to use lnd, but reporting a bug (otherwise open a discussion).
LND Version

Reproduced on:

  • master at 0cc5feb (0.21.99-beta, btcwallet v0.18.1)
  • v0.21.8-beta (production incident below)
  • v0.19.2-beta (via lightning-terminal v0.15.1-alpha)
LND Configuration
--bitcoin.regtest --bitcoin.node=bitcoind
--db.backend=postgres
--db.postgres.dsn=postgres://lnd:[email protected]:55432/lnd?sslmode=disable
--db.postgres.timeout=0
--noseedbackup --nolisten

Built with -tags "signrpc walletrpc chainrpc invoicesrpc kvdb_postgres".

Backend Version

bitcoind 29.0.0

Backend Configuration

bitcoind with RPC and ZMQ (zmqpubrawblock, zmqpubrawtx), regtest.

OS/Distribution

macOS 27.2 arm64 for the reproduction; Linux on Kubernetes for the incident.

Bug Details & Steps to Reproduce

If a block is connected while the postgres backend is unreachable, the wallet fails to store that block and never stores another one. lnd keeps running, but synced_to_chain stays false until lnd is restarted.

In one of our signet environments a 27 minute postgres restart left a node unsynced for 5.4 days. Every block after the outage logged:

[ERR] BTWL: Unable to process chain backend block connected notification: failed to store sync information <hash>: failed to fetch block hash for height <n-1>: block not found

Reproduction on regtest:

  1. Start lnd with --db.backend=postgres and mine a block. getinfo shows synced_to_chain: true.
  2. Stop postgres.
  3. Mine one block. lnd logs:
    [ERR] BTWL: Unable to process chain backend block connected notification: failed to connect to `user=lnd database=lnd`: ... connection refused
    
  4. Start postgres again. synced_to_chain is now false.
  5. Mine more blocks. Each one logs failed to store sync information ...: failed to fetch block hash for height <previous>: block not found, and synced_to_chain stays false.
  6. Restart lnd. The wallet rescans from the last stored block, catches up and reports synced_to_chain: true. New blocks are stored normally again.

Run on master 0cc5feb:

Step Height synced_to_chain store errors
baseline 341 true 0
block during outage 342
postgres back 342 false 0
one more block 343 false 1
two more blocks 345 false 3
after restart 345 true
one more block 346 true 0

Where it happens (btcwallet v0.18.1):

  • waddrmgr/db.go:2208 PutSyncedTo: once the birthday block is set, it requires the hash of height-1 to be stored and returns ErrBlockNotFound otherwise.
  • wallet/chainntfns.go:165-183 handleChainNotifications: the error is only logged. The ErrBlockNotFound case is skipped with a comment that the wallet will catch up when the rescan finishes, but only while !w.ChainSynced(). Here the wallet was synced, so no rescan is running and nothing fills the gap. The catch up only happens in syncWithChain at startup, which is why a restart fixes it.
Expected Behavior

After the database is back, the wallet should store the missed block (for example by retrying it, or by catching up from its last stored height, as syncWithChain does at startup) and continue syncing without a restart.

Debug Information

Full log of the master run available on request.

Environment

Related: an etcd outage of a few minutes crashes lnd with a nil pointer dereference in the same handler. Filed separately: #11640.

主要言語
Go
スター
8.2k
フォーク
2.3k
平均マージ
1日 11時間
マージ済み PR(30日)
103

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lightningnetwork/lnd のほかの issue

lightningnetwork/lnd の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。