• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 11393106485

17 Oct 2024 09:10PM UTC coverage: 57.848% (-1.0%) from 58.81%
11393106485

Pull #9148

github

ProofOfKeags
lnwire: convert DynPropose and DynCommit to use typed tlv records
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

142 of 177 new or added lines in 4 files covered. (80.23%)

18983 existing lines in 242 files now uncovered.

99003 of 171143 relevant lines covered (57.85%)

36968.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/htlcswitch/linkfailure.go
1
package htlcswitch
2

3
import "github.com/go-errors/errors"
4

5
var (
6
        // ErrLinkShuttingDown signals that the link is shutting down.
7
        ErrLinkShuttingDown = errors.New("link shutting down")
8

9
        // ErrLinkFailedShutdown signals that a requested shutdown failed.
10
        ErrLinkFailedShutdown = errors.New("link failed to shutdown")
11
)
12

13
// errorCode encodes the possible types of errors that will make us fail the
14
// current link.
15
type errorCode uint8
16

17
const (
18
        // ErrInternalError indicates that something internal in the link
19
        // failed. In this case we will send a generic error to our peer.
20
        ErrInternalError errorCode = iota
21

22
        // ErrRemoteError indicates that our peer sent an error, prompting up
23
        // to fail the link.
24
        ErrRemoteError
25

26
        // ErrRemoteUnresponsive indicates that our peer took too long to
27
        // complete a commitment dance.
28
        ErrRemoteUnresponsive
29

30
        // ErrSyncError indicates that we failed synchronizing the state of the
31
        // channel with our peer.
32
        ErrSyncError
33

34
        // ErrInvalidUpdate indicates that the peer send us an invalid update.
35
        ErrInvalidUpdate
36

37
        // ErrInvalidCommitment indicates that the remote peer sent us an
38
        // invalid commitment signature.
39
        ErrInvalidCommitment
40

41
        // ErrInvalidRevocation indicates that the remote peer send us an
42
        // invalid revocation message.
43
        ErrInvalidRevocation
44

45
        // ErrRecoveryError the channel was unable to be resumed, we need the
46
        // remote party to force close the channel out on chain now as a
47
        // result.
48
        ErrRecoveryError
49

50
        // ErrCircuitError indicates a duplicate keystone error was hit in the
51
        // circuit map. This is non-fatal and will resolve itself (usually
52
        // within several minutes).
53
        ErrCircuitError
54
)
55

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

74
// LinkFailureError encapsulates an error that will make us fail the current
75
// link. It contains the necessary information needed to determine if we should
76
// force close the channel in the process, and if any error data should be sent
77
// to the peer.
78
type LinkFailureError struct {
79
        // code is the type of error this LinkFailureError encapsulates.
80
        code errorCode
81

82
        // FailureAction describes what we should do to fail the channel.
83
        FailureAction LinkFailureAction
84

85
        // PermanentFailure indicates whether this failure is permanent, and
86
        // the channel should not be attempted loaded again.
87
        PermanentFailure bool
88

89
        // Warning denotes if this is a non-terminal error that doesn't warrant
90
        // failing the channel all together.
91
        Warning bool
92

93
        // SendData is a byte slice that will be sent to the peer. If nil a
94
        // generic error will be sent.
95
        SendData []byte
96
}
97

98
// A compile time check to ensure LinkFailureError implements the error
99
// interface.
100
var _ error = (*LinkFailureError)(nil)
101

102
// Error returns a generic error for the LinkFailureError.
103
//
104
// NOTE: Part of the error interface.
UNCOV
105
func (e LinkFailureError) Error() string {
×
UNCOV
106
        switch e.code {
×
UNCOV
107
        case ErrInternalError:
×
UNCOV
108
                return "internal error"
×
UNCOV
109
        case ErrRemoteError:
×
UNCOV
110
                return "remote error"
×
111
        case ErrRemoteUnresponsive:
×
112
                return "remote unresponsive"
×
UNCOV
113
        case ErrSyncError:
×
UNCOV
114
                return "sync error"
×
UNCOV
115
        case ErrInvalidUpdate:
×
UNCOV
116
                return "invalid update"
×
117
        case ErrInvalidCommitment:
×
118
                return "invalid commitment"
×
119
        case ErrInvalidRevocation:
×
120
                return "invalid revocation"
×
UNCOV
121
        case ErrRecoveryError:
×
UNCOV
122
                return "unable to resume channel, recovery required"
×
123
        case ErrCircuitError:
×
124
                return "non-fatal circuit map error"
×
125
        default:
×
126
                return "unknown error"
×
127
        }
128
}
129

130
// ShouldSendToPeer indicates whether we should send an error to the peer if
131
// the link fails with this LinkFailureError.
UNCOV
132
func (e LinkFailureError) ShouldSendToPeer() bool {
×
UNCOV
133
        switch e.code {
×
134

135
        // Since sending an error can lead some nodes to force close the
136
        // channel, create a whitelist of the failures we want to send so that
137
        // newly added error codes aren't automatically sent to the remote peer.
138
        case
139
                ErrInternalError,
140
                ErrRemoteError,
141
                ErrSyncError,
142
                ErrInvalidUpdate,
143
                ErrInvalidCommitment,
144
                ErrInvalidRevocation,
UNCOV
145
                ErrRecoveryError:
×
UNCOV
146

×
UNCOV
147
                return true
×
148

149
        // In all other cases we will not attempt to send our peer an error.
150
        default:
×
151
                return false
×
152
        }
153
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc