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

lightningnetwork / lnd / 19080946931

04 Nov 2025 07:47PM UTC coverage: 66.65% (+0.009%) from 66.641%
19080946931

Pull #10340

github

web-flow
Merge c364eae9c into 4131a8e58
Pull Request #10340: graph: fix zombie chan pruning

9 of 25 new or added lines in 1 file covered. (36.0%)

291 existing lines in 18 files now uncovered.

137293 of 205990 relevant lines covered (66.65%)

21217.79 hits per line

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

67.44
/lnwire/error.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "io"
7
)
8

9
var (
10
        // ErrParsingExtraTLVBytes is returned when we attempt to parse
11
        // extra opaque bytes as a TLV stream, but the parsing fails due to
12
        // and invalid TLV stream.
13
        ErrParsingExtraTLVBytes = fmt.Errorf("error parsing extra TLV bytes")
14
)
15

16
// FundingError represents a set of errors that can be encountered and sent
17
// during the funding workflow.
18
type FundingError uint8
19

20
const (
21
        // ErrMaxPendingChannels is returned by remote peer when the number of
22
        // active pending channels exceeds their maximum policy limit.
23
        ErrMaxPendingChannels FundingError = 1
24

25
        // ErrChanTooLarge is returned by a remote peer that receives a
26
        // FundingOpen request for a channel that is above their current
27
        // soft-limit.
28
        ErrChanTooLarge FundingError = 2
29
)
30

31
// String returns a human readable version of the target FundingError.
32
func (e FundingError) String() string {
7✔
33
        switch e {
7✔
34
        case ErrMaxPendingChannels:
7✔
35
                return "Number of pending channels exceed maximum"
7✔
36
        case ErrChanTooLarge:
×
37
                return "channel too large"
×
38
        default:
×
39
                return "unknown error"
×
40
        }
41
}
42

43
// Error returns the human readable version of the target FundingError.
44
//
45
// NOTE: Satisfies the Error interface.
46
func (e FundingError) Error() string {
7✔
47
        return e.String()
7✔
48
}
7✔
49

50
// ErrorData is a set of bytes associated with a particular sent error. A
51
// receiving node SHOULD only print out data verbatim if the string is composed
52
// solely of printable ASCII characters. For reference, the printable character
53
// set includes byte values 32 through 127 inclusive.
54
type ErrorData []byte
55

56
// Error represents a generic error bound to an exact channel. The message
57
// format is purposefully general in order to allow expression of a wide array
58
// of possible errors. Each Error message is directed at a particular open
59
// channel referenced by ChannelPoint.
60
type Error struct {
61
        // ChanID references the active channel in which the error occurred
62
        // within. If the ChanID is all zeros, then this error applies to the
63
        // entire established connection.
64
        ChanID ChannelID
65

66
        // Data is the attached error data that describes the exact failure
67
        // which caused the error message to be sent.
68
        Data ErrorData
69
}
70

71
// NewError creates a new Error message.
72
func NewError() *Error {
×
73
        return &Error{}
×
74
}
×
75

76
// A compile time check to ensure Error implements the lnwire.Message
77
// interface.
78
var _ Message = (*Error)(nil)
79

80
// A compile time check to ensure Error implements the lnwire.SizeableMessage
81
// interface.
82
var _ SizeableMessage = (*Error)(nil)
83

84
// Error returns the string representation to Error.
85
//
86
// NOTE: Satisfies the error interface.
87
func (c *Error) Error() string {
38✔
88
        errMsg := "non-ascii data"
38✔
89
        if isASCII(c.Data) {
76✔
90
                errMsg = string(c.Data)
38✔
91
        }
38✔
92

93
        return fmt.Sprintf("chan_id=%v, err=%v", c.ChanID, errMsg)
38✔
94
}
95

96
// Decode deserializes a serialized Error message stored in the passed
97
// io.Reader observing the specified protocol version.
98
//
99
// This is part of the lnwire.Message interface.
100
func (c *Error) Decode(r io.Reader, pver uint32) error {
116✔
101
        return ReadElements(r,
116✔
102
                &c.ChanID,
116✔
103
                &c.Data,
116✔
104
        )
116✔
105
}
116✔
106

107
// Encode serializes the target Error into the passed io.Writer observing the
108
// protocol version specified.
109
//
110
// This is part of the lnwire.Message interface.
111
func (c *Error) Encode(w *bytes.Buffer, pver uint32) error {
108✔
112
        if err := WriteBytes(w, c.ChanID[:]); err != nil {
108✔
113
                return err
×
114
        }
×
115

116
        return WriteErrorData(w, c.Data)
108✔
117
}
118

119
// MsgType returns the integer uniquely identifying an Error message on the
120
// wire.
121
//
122
// This is part of the lnwire.Message interface.
123
func (c *Error) MsgType() MessageType {
109✔
124
        return MsgError
109✔
125
}
109✔
126

127
// SerializedSize returns the serialized size of the message in bytes.
128
//
129
// This is part of the lnwire.SizeableMessage interface.
UNCOV
130
func (c *Error) SerializedSize() (uint32, error) {
×
UNCOV
131
        return MessageSerializedSize(c)
×
UNCOV
132
}
×
133

134
// isASCII is a helper method that checks whether all bytes in `data` would be
135
// printable ASCII characters if interpreted as a string.
136
func isASCII(data []byte) bool {
83✔
137
        for _, c := range data {
829✔
138
                if c < 32 || c > 126 {
746✔
139
                        return false
×
140
                }
×
141
        }
142
        return true
83✔
143
}
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