[bug]: btcd backend: closed channels stay in the graph after a websocket reconnect, so peers ban the node for outdated gossip
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- backend, networking
Research direction
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.
Written by the indexing model from the issue text.
Description
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.)
- Control: open alice→bob, close, mine 6 blocks. The edge is removed
(GRPH: Block … closed 1 channels). - Open alice→bob. Restart the proxy. All 4 lnd rpcclients log
Reestablished connection to RPC server. Close the channel, mine 6 blocks. - 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.gosends the watched outpoints to btcd with
LoadTxFilter. It finds spends from the server-filtered
OnFilteredBlockConnectednotifications. It does not set
OnClientConnected.- btcd stores the tx filter per websocket client (
rpcwebsocket.go,
wsClient.filterData). A new connection has no filter, so
filteredblockconnectedhas no matched transactions. rpcclient.reregisterNtfns(infrastructure.go) re-sendsnotifyblocks,
notifynewtx,notifyspentandnotifyreceived, but notloadtxfilter.- 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
syncGraphWithChainnever rescans the missed spends. Zombie pruning skips
the node's own channels, so nothing else removes them.
Possible fix
- On reconnect, reload the full
chainFilterwithLoadTxFilter(reload=true)
from anOnClientConnectedhandler, or - match each connected block against the local
chainFilterinstead 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.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
lightningnetwork/lnd#11674 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day