Skip to content

Commit 9b4fce1

Browse files
committed
Merge branch 'v0-16-3-branch-7711' into v0-16-3-branch
2 parents fcbe684 + ddf551f commit 9b4fce1

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed
+14-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
# Release Notes
22

3-
## Mempool
3+
## Mempool Optimizations
44

5-
Optimized [mempool
6-
management](https://github.com/lightningnetwork/lnd/pull/7681) to lower the CPU
7-
usage.
5+
* Optimized [mempool
6+
management](https://github.com/lightningnetwork/lnd/pull/7681) to lower the
7+
CPU usage.
88

99
## Bug Fixes
1010

1111
* [Re-encrypt/regenerate](https://github.com/lightningnetwork/lnd/pull/7705)
1212
all macaroon DB root keys on `ChangePassword`/`GenerateNewRootKey`
1313
respectively.
1414

15+
## Channel Link Bug Fix
16+
17+
* If we detect the remote link is inactive, [we'll now tear down the
18+
connection](https://github.com/lightningnetwork/lnd/pull/7711) in addition to
19+
stopping the link's statemachine. If we're persistently connected with the
20+
peer, then this'll force a reconnect, which may restart things and help avoid
21+
certain force close scenarios.
22+
1523
# Contributors (Alphabetical Order)
24+
1625
* Elle Mouton
26+
* Olaoluwa Osuntokun
1727
* Yong Yu

htlcswitch/link.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,8 @@ func (l *channelLink) htlcManager() {
10361036
// storing the transaction in the db.
10371037
l.fail(
10381038
LinkFailureError{
1039-
code: ErrSyncError,
1040-
ForceClose: true,
1039+
code: ErrSyncError,
1040+
FailureAction: LinkFailureForceClose, //nolint:lll
10411041
},
10421042
"unable to synchronize channel "+
10431043
"states: %v", err,
@@ -1077,8 +1077,8 @@ func (l *channelLink) htlcManager() {
10771077

10781078
l.fail(
10791079
LinkFailureError{
1080-
code: ErrRecoveryError,
1081-
ForceClose: false,
1080+
code: ErrRecoveryError,
1081+
FailureAction: LinkFailureForceNone,
10821082
},
10831083
"unable to synchronize channel "+
10841084
"states: %v", err,
@@ -1239,8 +1239,13 @@ func (l *channelLink) htlcManager() {
12391239
}
12401240

12411241
case <-l.cfg.PendingCommitTicker.Ticks():
1242-
l.fail(LinkFailureError{code: ErrRemoteUnresponsive},
1243-
"unable to complete dance")
1242+
l.fail(
1243+
LinkFailureError{
1244+
code: ErrRemoteUnresponsive,
1245+
FailureAction: LinkFailureDisconnect,
1246+
},
1247+
"unable to complete dance",
1248+
)
12441249
return
12451250

12461251
// A message from the switch was just received. This indicates
@@ -1782,8 +1787,8 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
17821787
if err := l.channel.ReceiveHTLCSettle(pre, idx); err != nil {
17831788
l.fail(
17841789
LinkFailureError{
1785-
code: ErrInvalidUpdate,
1786-
ForceClose: true,
1790+
code: ErrInvalidUpdate,
1791+
FailureAction: LinkFailureForceClose,
17871792
},
17881793
"unable to handle upstream settle HTLC: %v", err,
17891794
)
@@ -1947,9 +1952,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
19471952
}
19481953
l.fail(
19491954
LinkFailureError{
1950-
code: ErrInvalidCommitment,
1951-
ForceClose: true,
1952-
SendData: sendData,
1955+
code: ErrInvalidCommitment,
1956+
FailureAction: LinkFailureForceClose,
1957+
SendData: sendData,
19531958
},
19541959
"ChannelPoint(%v): unable to accept new "+
19551960
"commitment: %v",

htlcswitch/link_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -5457,8 +5457,10 @@ func TestChannelLinkFail(t *testing.T) {
54575457
// If we expect the link to force close the channel in this
54585458
// case, check that it happens. If not, make sure it does not
54595459
// happen.
5460-
require.Equal(
5461-
t, test.shouldForceClose, linkErr.ForceClose, test.name,
5460+
isForceCloseErr := (linkErr.FailureAction ==
5461+
LinkFailureForceClose)
5462+
require.True(
5463+
t, test.shouldForceClose == isForceCloseErr, test.name,
54625464
)
54635465
require.Equal(
54645466
t, test.permanentFailure, linkErr.PermanentFailure,
@@ -6342,11 +6344,12 @@ func TestPendingCommitTicker(t *testing.T) {
63426344
// Assert that we get the expected link failure from Alice.
63436345
select {
63446346
case linkErr := <-linkErrs:
6345-
if linkErr.code != ErrRemoteUnresponsive {
6346-
t.Fatalf("error code mismatch, "+
6347-
"want: ErrRemoteUnresponsive, got: %v",
6348-
linkErr.code)
6349-
}
6347+
require.Equal(
6348+
t, linkErr.code, ErrRemoteUnresponsive,
6349+
fmt.Sprintf("error code mismatch, want: "+
6350+
"ErrRemoteUnresponsive, got: %v", linkErr.code),
6351+
)
6352+
require.Equal(t, linkErr.FailureAction, LinkFailureDisconnect)
63506353

63516354
case <-time.After(time.Second):
63526355
t.Fatalf("did not receive failure")
@@ -6523,7 +6526,7 @@ func TestPipelineSettle(t *testing.T) {
65236526
// ForceClose should be false.
65246527
select {
65256528
case linkErr := <-linkErrors:
6526-
require.False(t, linkErr.ForceClose)
6529+
require.False(t, linkErr.FailureAction == LinkFailureForceClose)
65276530
case <-forwardChan:
65286531
t.Fatal("packet was erroneously forwarded")
65296532
}
@@ -6559,7 +6562,7 @@ func TestPipelineSettle(t *testing.T) {
65596562
// ForceClose should be false.
65606563
select {
65616564
case linkErr := <-linkErrors:
6562-
require.False(t, linkErr.ForceClose)
6565+
require.False(t, linkErr.FailureAction == LinkFailureForceClose)
65636566
case <-forwardChan:
65646567
t.Fatal("packet was erroneously forwarded")
65656568
}

htlcswitch/linkfailure.go

+20-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ const (
5353
ErrCircuitError
5454
)
5555

56+
// LinkFailureAction is an enum-like type that describes the action that should
57+
// be taken in response to a link failure.
58+
type LinkFailureAction uint8
59+
60+
const (
61+
// LinkFailureForceNone indicates no action is to be taken.
62+
LinkFailureForceNone LinkFailureAction = iota
63+
64+
// LinkFailureForceClose indicates that the channel should be force
65+
// closed.
66+
LinkFailureForceClose
67+
68+
// LinkFailureDisconnect indicates that we should disconnect in an
69+
// attempt to recycle the connection. This can be useful if we think a
70+
// TCP connection or state machine is stalled.
71+
LinkFailureDisconnect
72+
)
73+
5674
// LinkFailureError encapsulates an error that will make us fail the current
5775
// link. It contains the necessary information needed to determine if we should
5876
// force close the channel in the process, and if any error data should be sent
@@ -61,9 +79,8 @@ type LinkFailureError struct {
6179
// code is the type of error this LinkFailureError encapsulates.
6280
code errorCode
6381

64-
// ForceClose indicates whether we should force close the channel
65-
// because of this error.
66-
ForceClose bool
82+
// FailureAction describes what we should do to fail the channel.
83+
FailureAction LinkFailureAction
6784

6885
// PermanentFailure indicates whether this failure is permanent, and
6986
// the channel should not be attempted loaded again.

peer/brontide.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -3094,11 +3094,10 @@ func (p *Brontide) handleLinkFailure(failure linkFailureReport) {
30943094
// being applied.
30953095
p.WipeChannel(&failure.chanPoint)
30963096

3097-
// If the error encountered was severe enough, we'll now force close the
3098-
// channel to prevent reading it to the switch in the future.
3099-
if failure.linkErr.ForceClose {
3100-
p.log.Warnf("Force closing link(%v)",
3101-
failure.shortChanID)
3097+
// If the error encountered was severe enough, we'll now force close
3098+
// the channel to prevent reading it to the switch in the future.
3099+
if failure.linkErr.FailureAction == htlcswitch.LinkFailureForceClose {
3100+
p.log.Warnf("Force closing link(%v)", failure.shortChanID)
31023101

31033102
closeTx, err := p.cfg.ChainArb.ForceCloseContract(
31043103
failure.chanPoint,
@@ -3143,6 +3142,13 @@ func (p *Brontide) handleLinkFailure(failure linkFailureReport) {
31433142
"remote peer: %v", err)
31443143
}
31453144
}
3145+
3146+
// If the failure action is disconnect, then we'll execute that now. If
3147+
// we had to send an error above, it was a sync call, so we expect the
3148+
// message to be flushed on the wire by now.
3149+
if failure.linkErr.FailureAction == htlcswitch.LinkFailureDisconnect {
3150+
p.Disconnect(fmt.Errorf("link requested disconnect"))
3151+
}
31463152
}
31473153

31483154
// tryLinkShutdown attempts to fetch a target link from the switch, calls

0 commit comments

Comments
 (0)