[bug]: incoming update_add_htlc after a reconnect with a persisted shutdown gets a warning and a disconnect
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 40/100
Research direction
Start in htlcswitch/link.go: resumeLink (around L4112-L4119) disables incoming adds right after reestablish, and the 'received add while link is flushing' check is around L4194-L4221. Run the reproducer TestAddAfterReconnectWithSavedShutdown from the issue (a new file such as htlcswitch/link_add_reconnect_test.go) with -v. Done when the saved=true case no longer produces a link failure or disconnect, while the saved=false case still behaves the same.
Written by the indexing model from the issue text.
Description
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
master 8cdbf85c0860 (2026-11-18), v0.21.8-beta and v0.20.8-beta
LND Configuration
Default.
Backend Version
None. The code runs inside lnd's own packages.
Backend Configuration
None.
OS/Distribution
Linux x86_64
Bug Details & Steps to Reproduce
On lnd master 8cdbf85c0860, after a reconnect with a persisted shutdown, resumeLink disables incoming adds right after the reestablish (link.go L4112-L4119), before the retransmitted shutdown can have reached the peer. An update_add_htlc that the peer sent before it read that shutdown then gets a warning and a disconnect ("received add while link is flushing", link.go L4194-L4221). Without the persisted shutdown, the same add is accepted. BOLT 2 says a node that has sent shutdown SHOULD fail to route any HTLC added after it.
Test, package htlcswitch. The link resumes with SyncStates set, as the peer sets it on a reconnection, with and without a persisted shutdown. The peer's channel_reestablish is delivered, then an update_add_htlc with its commitment signature:
// An incoming update_add_htlc after a reconnect, on a link whose shutdown was
// persisted, compared with the same link without a persisted shutdown.
package htlcswitch
import (
"bytes"
"strings"
"testing"
"time"
"github.com/btcsuite/btclog/v2"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
func addAfterReconnect(t *testing.T, savedShutdown bool) {
h, err := newSingleLinkTestHarness(t, 1_000_000, 10_000)
require.NoError(t, err)
link := h.aliceLink.(*channelLink)
failures := make(chan LinkFailureError, 1)
link.cfg.OnChannelFailure = func(_ lnwire.ChannelID,
_ lnwire.ShortChannelID, e LinkFailureError) {
failures <- e
}
// The link resumes with a channel_reestablish exchange, as the peer
// sets it up for a link on a reconnection.
logBuf := &bytes.Buffer{}
link.log = btclog.NewSLogger(btclog.NewDefaultHandler(
logBuf, btclog.WithNoTimestamp(),
))
link.cfg.SyncStates = true
if savedShutdown {
link.cfg.PreviouslySentShutdown = fn.Some(lnwire.Shutdown{
ChannelID: link.ChanID(),
Address: append([]byte{0x00, 0x14}, make([]byte, 20)...),
})
}
require.NoError(t, h.start())
sent := link.cfg.Peer.(*mockPeer).sentMsgs
var names []string
drain := func(wait time.Duration) {
for {
select {
case m := <-sent:
names = append(names, m.MsgType().String())
case <-time.After(wait):
return
}
}
}
// The peer's channel_reestablish, then an update_add_htlc that it sent
// before it read our shutdown.
bobSync, err := h.bobChannel.State().ChanSyncMsg()
require.NoError(t, err)
link.HandleChannelUpdate(bobSync)
drain(time.Second)
amt, timelock, hops := generateHops(
lnwire.NewMSatFromSatoshis(10_000), testStartingHeight, link,
)
blob, err := generateRoute(hops...)
require.NoError(t, err)
invoice, htlc, _, err := generatePayment(amt, amt, timelock, blob)
require.NoError(t, err)
require.NoError(t, link.cfg.Registry.(*mockInvoiceRegistry).AddInvoice(
t.Context(), *invoice, htlc.PaymentHash,
))
htlc.ID = 0
_, err = h.bobChannel.AddHTLC(htlc, nil)
require.NoError(t, err)
link.HandleChannelUpdate(htlc)
// The peer then signs, as it does after an add.
sigs, err := h.bobChannel.SignNextCommitment(t.Context())
require.NoError(t, err)
link.HandleChannelUpdate(&lnwire.CommitSig{
CommitSig: sigs.CommitSig, HtlcSigs: sigs.HtlcSigs,
})
select {
case e := <-failures:
t.Logf("shutdown saved=%v: link failure: %v, disconnect %v, "+
"warning %v", savedShutdown, e.Error(),
e.FailureAction == LinkFailureDisconnect, e.Warning)
for _, l := range strings.Split(logBuf.String(), "\n") {
if strings.Contains(l, "while link is flushing") {
t.Logf("shutdown saved=%v: link log: %s", savedShutdown, l)
}
}
case <-time.After(2 * time.Second):
t.Logf("shutdown saved=%v: no link failure", savedShutdown)
}
drain(time.Second)
t.Logf("shutdown saved=%v: link sent %v", savedShutdown, names)
}
func TestAddAfterReconnectWithSavedShutdown(t *testing.T) {
t.Run("no saved shutdown", func(t *testing.T) { addAfterReconnect(t, false) })
t.Run("saved shutdown", func(t *testing.T) { addAfterReconnect(t, true) })
}
Run go test -count=1 -run TestAddAfterReconnectWithSavedShutdown -v ./htlcswitch/. The output is the same on master, v0.21.8-beta and v0.20.8-beta:
link_add_reconnect_test.go:97: shutdown saved=false: no link failure
link_add_reconnect_test.go:100: shutdown saved=false: link sent [ChannelReestablish ChannelReady RevokeAndAck CommitSig]
link_add_reconnect_test.go:88: shutdown saved=true: link failure: invalid update, disconnect true, warning true
link_add_reconnect_test.go:93: shutdown saved=true: link log: [ERR]: failing link: received add while link is flushing with error: invalid update
link_add_reconnect_test.go:93: shutdown saved=true: link log: [ERR]: failed to process remote UpdateAddHTLC: received add while link is flushing
link_add_reconnect_test.go:100: shutdown saved=true: link sent [ChannelReestablish ChannelReady Shutdown]
Expected Behavior
The add is accepted and failed back, as BOLT 2 describes for HTLCs added after the node sent shutdown.
Debug Information
No response
Environment
No response
- 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