[bug]: btcd backend: closed channels stay in the graph after a websocket reconnect, so peers ban the node for outdated gossip

Aperta
#11,517 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Start with routing/chainview/btcd.go and trace how the chain filter is loaded and restored after an RPC websocket reconnect; the issue also points to rpcclient.reregisterNtfns in infrastructure.go. Use the linked reproduction bundle to confirm the failure after the proxy reconnect. Done means closed channels are removed from the graph after reconnect, and the issue’s question about cleanup of already stale graph edges is addressed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Background

Main impact: peers ban the node for gossiping outdated channels. A node on
the btcd backend keeps its own closed channels in its graph and keeps
announcing them. Peers on lnd with gossip banning (#9009) reply with
outdated channel announcement. After enough of these, they ban the node for
48h and disconnect it if they share no channel with it. The node cannot fix
this by itself. Each restart and each new peer starts the same cycle again.

Why the channels stay: with bitcoin.node=btcd, a short drop of the
lnd↔btcd websocket makes lnd miss the spends of all channels that exist at
that moment. When one of these channels closes later, lnd lists it in
closedchannels, but its edge stays in the channel graph. An lnd restart does
not remove it.

We found this on a production node that ran on btcd before we moved it to
bitcoind. 126 of its own channels were still in its graph, and 125 of them
were closed on chain. About 60% of all closes from the btcd period stayed in
the graph. After the move to bitcoind, all 52 later closes were removed from
the graph correctly. Peers still banned the node after the move, because the
old stale edges stay in the graph.

Your environment
  • lnd: v0.21.3-beta and v0.21.6-beta (Docker images lightninglabs/lnd)
  • backend: btcd v0.26.0 (built from source)
  • OS: Linux containers (Docker Compose v2)
  • production node: btcd backend, later moved to bitcoind
Steps to reproduce

Repro bundle: https://gist.github.com/bufo24/67812acc91add20c1d1c8cd57f76f5eb

git clone https://gist.github.com/67812acc91add20c1d1c8cd57f76f5eb.git lnd-btcd-repro
cd lnd-btcd-repro && bash run.sh

Set LND_IMAGE=<image> to test another build. Exit code 1 means the bug
reproduced. Requirements: Docker Compose v2, bash, jq.

Topology: alice, bob (lnd) → socat proxy → btcd. A proxy restart drops
all lnd↔btcd websockets and btcd keeps running. (In our tests, a btcd restart
in regtest lost the chain, so we use the proxy.)

  1. Control: open alice→bob, close, mine 6 blocks. The edge is removed
    (GRPH: Block … closed 1 channels).
  2. Open alice→bob. Restart the proxy. All 4 lnd rpcclients log
    Reestablished connection to RPC server. Close the channel, mine 6 blocks.
  3. Restart alice.
Expected behavior

After step 2, the closed channel is removed from alice's graph, the same as
in the control case.

Actual behavior
RESULT[control]: closed channel 122045790748672 was REMOVED from the graph
alice has 4 btcd connections: ... (all through the proxy)
alice logged 4 'Reestablished connection to RPC server' lines
RESULT[after-reconnect]: closed channel 135239930281984 is STILL IN THE GRAPH (closedchannels lists it as closed)
RESULT[after-lnd-restart]: closed channel 135239930281984 is STILL IN THE GRAPH

lnd logs no closed 1 channels for the block with the close. After the
restart, Prune tip for Channel Graph: height=135 is already after the spend,
so the startup sync does not rescan it. Same result on v0.21.3 and v0.21.6,
in 3 of 3 runs.

Cause
  • routing/chainview/btcd.go sends the watched outpoints to btcd with
    LoadTxFilter. It finds spends from the server-filtered
    OnFilteredBlockConnected notifications. It does not set
    OnClientConnected.
  • btcd stores the tx filter per websocket client (rpcwebsocket.go,
    wsClient.filterData). A new connection has no filter, so
    filteredblockconnected has no matched transactions.
  • rpcclient.reregisterNtfns (infrastructure.go) re-sends notifyblocks,
    notifynewtx, notifyspent and notifyreceived, but not loadtxfilter.
  • New channels call UpdateFilter, which adds only their own outpoints. So
    only the channels that exist at the reconnect are lost.
  • The graph builder still moves the prune tip forward for each block, so
    syncGraphWithChain never rescans the missed spends. Zombie pruning skips
    the node's own channels, so nothing else removes them.
Possible fix
  • On reconnect, reload the full chainFilter with LoadTxFilter(reload=true)
    from an OnClientConnected handler, or
  • match each connected block against the local chainFilter instead of
    relying on the server-side filter.

Question: will a fix also clean up the stale channels that already exist,
or only prevent new ones?
A fix in the chain view only prevents new stale
channels. Affected nodes keep the old edges, so they keep gossiping them and
keep getting banned, also after a backend change (as in our case). A cleanup
could, for example, check the node's own graph edges against the
closed-channel records, or against the chain, at startup.

Workaround

lncli abandonchannel --chan_point <txid:idx> --i_know_what_i_am_doing for
each channel that is closed on chain but still in the graph. In the repro
(KEEP=1 ./run.sh), this removes the stale edge.

Lingua principale
Go
Stelle
8.2k
Fork
2.3k
Merge medio
1g 11h
PR unite (30g)
103

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lightningnetwork/lnd

Tutte le issue di lightningnetwork/lnd

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.