mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-13 06:29:07 +02:00
htlcswitch: add new LinkFailureAction enum
In this commit, we add a new LinkFailureAction enum to take over the old force close bool. Force closing isn't the only thing we might want to do when we decide to fail the link, so this is a prep refactoring for an upcoming change.
This commit is contained in:
parent
7dacf5edb9
commit
cb5fc71659
@ -1036,8 +1036,8 @@ func (l *channelLink) htlcManager() {
|
||||
// storing the transaction in the db.
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrSyncError,
|
||||
ForceClose: true,
|
||||
code: ErrSyncError,
|
||||
FailureAction: LinkFailureForceClose, // nolint:lll
|
||||
},
|
||||
"unable to synchronize channel "+
|
||||
"states: %v", err,
|
||||
@ -1077,8 +1077,8 @@ func (l *channelLink) htlcManager() {
|
||||
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrRecoveryError,
|
||||
ForceClose: false,
|
||||
code: ErrRecoveryError,
|
||||
FailureAction: LinkFailureForceNone,
|
||||
},
|
||||
"unable to synchronize channel "+
|
||||
"states: %v", err,
|
||||
@ -1782,8 +1782,8 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
if err := l.channel.ReceiveHTLCSettle(pre, idx); err != nil {
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrInvalidUpdate,
|
||||
ForceClose: true,
|
||||
code: ErrInvalidUpdate,
|
||||
FailureAction: LinkFailureForceClose,
|
||||
},
|
||||
"unable to handle upstream settle HTLC: %v", err,
|
||||
)
|
||||
@ -1947,9 +1947,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
}
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
code: ErrInvalidCommitment,
|
||||
ForceClose: true,
|
||||
SendData: sendData,
|
||||
code: ErrInvalidCommitment,
|
||||
FailureAction: LinkFailureForceClose,
|
||||
SendData: sendData,
|
||||
},
|
||||
"ChannelPoint(%v): unable to accept new "+
|
||||
"commitment: %v",
|
||||
|
@ -5457,8 +5457,9 @@ func TestChannelLinkFail(t *testing.T) {
|
||||
// If we expect the link to force close the channel in this
|
||||
// case, check that it happens. If not, make sure it does not
|
||||
// happen.
|
||||
require.Equal(
|
||||
t, test.shouldForceClose, linkErr.ForceClose, test.name,
|
||||
isForceCloseErr := (linkErr.FailureAction == LinkFailureForceClose)
|
||||
require.True(
|
||||
t, test.shouldForceClose == isForceCloseErr, test.name,
|
||||
)
|
||||
require.Equal(
|
||||
t, test.permanentFailure, linkErr.PermanentFailure,
|
||||
@ -6523,7 +6524,7 @@ func TestPipelineSettle(t *testing.T) {
|
||||
// ForceClose should be false.
|
||||
select {
|
||||
case linkErr := <-linkErrors:
|
||||
require.False(t, linkErr.ForceClose)
|
||||
require.False(t, linkErr.FailureAction == LinkFailureForceClose)
|
||||
case <-forwardChan:
|
||||
t.Fatal("packet was erroneously forwarded")
|
||||
}
|
||||
@ -6559,7 +6560,7 @@ func TestPipelineSettle(t *testing.T) {
|
||||
// ForceClose should be false.
|
||||
select {
|
||||
case linkErr := <-linkErrors:
|
||||
require.False(t, linkErr.ForceClose)
|
||||
require.False(t, linkErr.FailureAction == LinkFailureForceClose)
|
||||
case <-forwardChan:
|
||||
t.Fatal("packet was erroneously forwarded")
|
||||
}
|
||||
|
@ -53,6 +53,19 @@ const (
|
||||
ErrCircuitError
|
||||
)
|
||||
|
||||
// LinkFailureAction is an enum-like type that describes the action that should
|
||||
// be taken in response to a link failure.
|
||||
type LinkFailureAction uint8
|
||||
|
||||
const (
|
||||
// LinkFailureForceNone indicates no action is to be taken.
|
||||
LinkFailureForceNone LinkFailureAction = iota
|
||||
|
||||
// LinkFailureForceClose indicates that the channel should be force
|
||||
// closed.
|
||||
LinkFailureForceClose
|
||||
)
|
||||
|
||||
// LinkFailureError encapsulates an error that will make us fail the current
|
||||
// link. It contains the necessary information needed to determine if we should
|
||||
// force close the channel in the process, and if any error data should be sent
|
||||
@ -61,9 +74,8 @@ type LinkFailureError struct {
|
||||
// code is the type of error this LinkFailureError encapsulates.
|
||||
code errorCode
|
||||
|
||||
// ForceClose indicates whether we should force close the channel
|
||||
// because of this error.
|
||||
ForceClose bool
|
||||
// FailureAction describes what we should do to fail the channel.
|
||||
FailureAction LinkFailureAction
|
||||
|
||||
// PermanentFailure indicates whether this failure is permanent, and
|
||||
// the channel should not be attempted loaded again.
|
||||
|
@ -3094,11 +3094,10 @@ func (p *Brontide) handleLinkFailure(failure linkFailureReport) {
|
||||
// being applied.
|
||||
p.WipeChannel(&failure.chanPoint)
|
||||
|
||||
// If the error encountered was severe enough, we'll now force close the
|
||||
// channel to prevent reading it to the switch in the future.
|
||||
if failure.linkErr.ForceClose {
|
||||
p.log.Warnf("Force closing link(%v)",
|
||||
failure.shortChanID)
|
||||
// If the error encountered was severe enough, we'll now force close
|
||||
// the channel to prevent reading it to the switch in the future.
|
||||
if failure.linkErr.FailureAction == htlcswitch.LinkFailureForceClose {
|
||||
p.log.Warnf("Force closing link(%v)", failure.shortChanID)
|
||||
|
||||
closeTx, err := p.cfg.ChainArb.ForceCloseContract(
|
||||
failure.chanPoint,
|
||||
|
Loading…
x
Reference in New Issue
Block a user