From b837c889dc082ade322abd15b583a030a0feaa34 Mon Sep 17 00:00:00 2001 From: ziggie Date: Thu, 29 May 2025 10:16:22 +0200 Subject: [PATCH 1/3] itest: add disconnect test Add a connect/disconnect test when the peers both started up with the rbf coop close feature. --- itest/list_on_test.go | 4 ++++ itest/lnd_coop_close_rbf_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index 7263b2451a3..5dacc0b1cf2 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -699,6 +699,10 @@ var allTestCases = []*lntest.TestCase{ Name: "rbf coop close", TestFunc: testCoopCloseRbf, }, + { + Name: "rbf coop close disconnect", + TestFunc: testRBFCoopCloseDisconnect, + }, { Name: "bump fee low budget", TestFunc: testBumpFeeLowBudget, diff --git a/itest/lnd_coop_close_rbf_test.go b/itest/lnd_coop_close_rbf_test.go index 87033464844..5f8b15d4054 100644 --- a/itest/lnd_coop_close_rbf_test.go +++ b/itest/lnd_coop_close_rbf_test.go @@ -131,3 +131,25 @@ func testCoopCloseRbf(ht *lntest.HarnessTest) { aliceClosingTxid := ht.WaitForChannelCloseEvent(aliceCloseStream) ht.AssertTxInBlock(block, aliceClosingTxid) } + +// testRBFCoopCloseDisconnect tests that when a node disconnects that the node +// is properly disconnected. +func testRBFCoopCloseDisconnect(ht *lntest.HarnessTest) { + rbfCoopFlags := []string{"--protocol.rbf-coop-close"} + + // To kick things off, we'll create two new nodes, then fund them with + // enough coins to make a 50/50 channel. + cfgs := [][]string{rbfCoopFlags, rbfCoopFlags} + params := lntest.OpenChannelParams{ + Amt: btcutil.Amount(1000000), + PushAmt: btcutil.Amount(1000000 / 2), + } + _, nodes := ht.CreateSimpleNetwork(cfgs, params) + alice, bob := nodes[0], nodes[1] + + // Make sure the nodes are connected. + ht.AssertConnected(alice, bob) + + // Disconnect Bob from Alice. + ht.DisconnectNodes(alice, bob) +} From e593c9d266643aea85c27d3290164b0821d3d0f4 Mon Sep 17 00:00:00 2001 From: ziggie Date: Thu, 29 May 2025 10:17:35 +0200 Subject: [PATCH 2/3] brontide: fix peer disconnection issue In case when the rbf coop close feature was active we would not properly disconnect the peer. --- peer/brontide.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/peer/brontide.go b/peer/brontide.go index 17e9bc40901..43dbcb41934 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -3804,18 +3804,28 @@ func (p *Brontide) chanFlushEventSentinel(chanCloser *chancloser.RbfChanCloser, // We'll wait until the channel enters the ChannelFlushing state. We // exit after a success loop. As after the first RBF iteration, the // channel will always be flushed. - for newState := range newStateChan { - if _, ok := newState.(*chancloser.ChannelFlushing); ok { - peerLog.Infof("ChannelPoint(%v): rbf coop "+ - "close is awaiting a flushed state, "+ - "registering with link..., ", - channel.ChannelPoint()) - - // Request the link to send the event once the channel - // is flushed. We only need this event sent once, so we - // can exit now. - link.OnFlushedOnce(sendChanFlushed) + for { + select { + case newState, ok := <-newStateChan: + if !ok { + return + } + + if _, ok := newState.(*chancloser.ChannelFlushing); ok { + peerLog.Infof("ChannelPoint(%v): rbf coop "+ + "close is awaiting a flushed state, "+ + "registering with link..., ", + channel.ChannelPoint()) + // Request the link to send the event once the + // channel is flushed. We only need this event + // sent once, so we can exit now. + link.OnFlushedOnce(sendChanFlushed) + + return + } + + case <-p.cg.Done(): return } } From 329c571d5a7e259ee1b03752ce3210fb9c3c10d1 Mon Sep 17 00:00:00 2001 From: ziggie Date: Wed, 28 May 2025 14:24:00 +0200 Subject: [PATCH 3/3] docs: add release notes --- docs/release-notes/release-notes-0.19.1.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/release-notes-0.19.1.md b/docs/release-notes/release-notes-0.19.1.md index 72ea90d41ff..c49ccfd346e 100644 --- a/docs/release-notes/release-notes-0.19.1.md +++ b/docs/release-notes/release-notes-0.19.1.md @@ -27,6 +27,10 @@ - Fixed [a case](https://github.com/lightningnetwork/lnd/pull/9854) where the `BumpFee` doesn't give an error response. +- Fixed [a case](https://github.com/lightningnetwork/lnd/pull/9872) where a + peer would not disconnect properly when both peers supported the new + "rbf-coop-close" feature leaving the peer connection in a borked state. + # New Features ## Functional Enhancements @@ -83,3 +87,4 @@ * Elle Mouton * Yong Yu +* Ziggie