Skip to content

Commit f8e67c0

Browse files
authored
Merge pull request #9872 from ziggie1984/fix-peer-connection
brontide: fix peer disconnection issue
2 parents e9692f8 + 329c571 commit f8e67c0

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

docs/release-notes/release-notes-0.19.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
- Fixed [a case](https://github.com/lightningnetwork/lnd/pull/9854) where the
2828
`BumpFee` doesn't give an error response.
2929

30+
- Fixed [a case](https://github.com/lightningnetwork/lnd/pull/9872) where a
31+
peer would not disconnect properly when both peers supported the new
32+
"rbf-coop-close" feature leaving the peer connection in a borked state.
33+
3034
# New Features
3135

3236
## Functional Enhancements
@@ -83,3 +87,4 @@
8387

8488
* Elle Mouton
8589
* Yong Yu
90+
* Ziggie

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ var allTestCases = []*lntest.TestCase{
699699
Name: "rbf coop close",
700700
TestFunc: testCoopCloseRbf,
701701
},
702+
{
703+
Name: "rbf coop close disconnect",
704+
TestFunc: testRBFCoopCloseDisconnect,
705+
},
702706
{
703707
Name: "bump fee low budget",
704708
TestFunc: testBumpFeeLowBudget,

itest/lnd_coop_close_rbf_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,25 @@ func testCoopCloseRbf(ht *lntest.HarnessTest) {
131131
aliceClosingTxid := ht.WaitForChannelCloseEvent(aliceCloseStream)
132132
ht.AssertTxInBlock(block, aliceClosingTxid)
133133
}
134+
135+
// testRBFCoopCloseDisconnect tests that when a node disconnects that the node
136+
// is properly disconnected.
137+
func testRBFCoopCloseDisconnect(ht *lntest.HarnessTest) {
138+
rbfCoopFlags := []string{"--protocol.rbf-coop-close"}
139+
140+
// To kick things off, we'll create two new nodes, then fund them with
141+
// enough coins to make a 50/50 channel.
142+
cfgs := [][]string{rbfCoopFlags, rbfCoopFlags}
143+
params := lntest.OpenChannelParams{
144+
Amt: btcutil.Amount(1000000),
145+
PushAmt: btcutil.Amount(1000000 / 2),
146+
}
147+
_, nodes := ht.CreateSimpleNetwork(cfgs, params)
148+
alice, bob := nodes[0], nodes[1]
149+
150+
// Make sure the nodes are connected.
151+
ht.AssertConnected(alice, bob)
152+
153+
// Disconnect Bob from Alice.
154+
ht.DisconnectNodes(alice, bob)
155+
}

peer/brontide.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,18 +3804,28 @@ func (p *Brontide) chanFlushEventSentinel(chanCloser *chancloser.RbfChanCloser,
38043804
// We'll wait until the channel enters the ChannelFlushing state. We
38053805
// exit after a success loop. As after the first RBF iteration, the
38063806
// channel will always be flushed.
3807-
for newState := range newStateChan {
3808-
if _, ok := newState.(*chancloser.ChannelFlushing); ok {
3809-
peerLog.Infof("ChannelPoint(%v): rbf coop "+
3810-
"close is awaiting a flushed state, "+
3811-
"registering with link..., ",
3812-
channel.ChannelPoint())
3813-
3814-
// Request the link to send the event once the channel
3815-
// is flushed. We only need this event sent once, so we
3816-
// can exit now.
3817-
link.OnFlushedOnce(sendChanFlushed)
3807+
for {
3808+
select {
3809+
case newState, ok := <-newStateChan:
3810+
if !ok {
3811+
return
3812+
}
3813+
3814+
if _, ok := newState.(*chancloser.ChannelFlushing); ok {
3815+
peerLog.Infof("ChannelPoint(%v): rbf coop "+
3816+
"close is awaiting a flushed state, "+
3817+
"registering with link..., ",
3818+
channel.ChannelPoint())
38183819

3820+
// Request the link to send the event once the
3821+
// channel is flushed. We only need this event
3822+
// sent once, so we can exit now.
3823+
link.OnFlushedOnce(sendChanFlushed)
3824+
3825+
return
3826+
}
3827+
3828+
case <-p.cg.Done():
38193829
return
38203830
}
38213831
}

0 commit comments

Comments
 (0)