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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

26.0
/lnwallet/errors.go
1
package lnwallet
2

3
import (
4
        "errors"
5
        "fmt"
6

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/btcsuite/btcd/chaincfg/chainhash"
9
        "github.com/lightningnetwork/lnd/lnwire"
10
)
11

12
// ReservationError wraps certain errors returned during channel reservation
13
// that can be sent across the wire to the remote peer. Errors not being
14
// ReservationErrors will not be sent to the remote in case of a failed channel
15
// reservation, as they may contain private information.
16
type ReservationError struct {
17
        error
18
}
19

20
// A compile time check to ensure ReservationError implements the error
21
// interface.
22
var _ error = (*ReservationError)(nil)
23

24
// ErrZeroCapacity returns an error indicating the funder attempted to put zero
25
// funds into the channel.
26
func ErrZeroCapacity() ReservationError {
×
27
        return ReservationError{
×
28
                errors.New("zero channel funds"),
×
29
        }
×
30
}
×
31

32
// ErrChainMismatch returns an error indicating that the initiator tried to
33
// open a channel for an unknown chain.
34
func ErrChainMismatch(knownChain,
35
        unknownChain *chainhash.Hash) ReservationError {
×
36
        return ReservationError{
×
37
                fmt.Errorf("unknown chain=%v, supported chain=%v",
×
38
                        unknownChain, knownChain),
×
39
        }
×
40
}
×
41

42
// ErrFunderBalanceDust returns an error indicating the initial balance of the
43
// funder is considered dust at the current commitment fee.
44
func ErrFunderBalanceDust(commitFee, funderBalance,
45
        minBalance int64) ReservationError {
3✔
46
        return ReservationError{
3✔
47
                fmt.Errorf("funder balance too small (%v) with fee=%v sat, "+
3✔
48
                        "minimum=%v sat required", funderBalance,
3✔
49
                        commitFee, minBalance),
3✔
50
        }
3✔
51
}
3✔
52

53
// ErrCsvDelayTooLarge returns an error indicating that the CSV delay was to
54
// large to be accepted, along with the current max.
UNCOV
55
func ErrCsvDelayTooLarge(remoteDelay, maxDelay uint16) ReservationError {
×
UNCOV
56
        return ReservationError{
×
UNCOV
57
                fmt.Errorf("CSV delay too large: %v, max is %v",
×
UNCOV
58
                        remoteDelay, maxDelay),
×
UNCOV
59
        }
×
UNCOV
60
}
×
61

62
// ErrChanReserveTooSmall returns an error indicating that the channel reserve
63
// the remote is requiring is too small to be accepted.
UNCOV
64
func ErrChanReserveTooSmall(reserve, dustLimit btcutil.Amount) ReservationError {
×
UNCOV
65
        return ReservationError{
×
UNCOV
66
                fmt.Errorf("channel reserve of %v sat is too small, min is %v "+
×
UNCOV
67
                        "sat", int64(reserve), int64(dustLimit)),
×
UNCOV
68
        }
×
UNCOV
69
}
×
70

71
// ErrChanReserveTooLarge returns an error indicating that the chan reserve the
72
// remote is requiring, is too large to be accepted.
73
func ErrChanReserveTooLarge(reserve,
UNCOV
74
        maxReserve btcutil.Amount) ReservationError {
×
UNCOV
75
        return ReservationError{
×
UNCOV
76
                fmt.Errorf("channel reserve is too large: %v sat, max "+
×
UNCOV
77
                        "is %v sat", int64(reserve), int64(maxReserve)),
×
UNCOV
78
        }
×
UNCOV
79
}
×
80

81
// ErrNonZeroPushAmount is returned by a remote peer that receives a
82
// FundingOpen request for a channel with non-zero push amount while
83
// they have 'rejectpush' enabled.
UNCOV
84
func ErrNonZeroPushAmount() ReservationError {
×
UNCOV
85
        return ReservationError{errors.New("non-zero push amounts are disabled")}
×
UNCOV
86
}
×
87

88
// ErrMinHtlcTooLarge returns an error indicating that the MinHTLC value the
89
// remote required is too large to be accepted.
90
func ErrMinHtlcTooLarge(minHtlc,
91
        maxMinHtlc lnwire.MilliSatoshi) ReservationError {
×
92
        return ReservationError{
×
93
                fmt.Errorf("minimum HTLC value is too large: %v, max is %v",
×
94
                        minHtlc, maxMinHtlc),
×
95
        }
×
96
}
×
97

98
// ErrMaxHtlcNumTooLarge returns an error indicating that the 'max HTLCs in
99
// flight' value the remote required is too large to be accepted.
100
func ErrMaxHtlcNumTooLarge(maxHtlc, maxMaxHtlc uint16) ReservationError {
×
101
        return ReservationError{
×
102
                fmt.Errorf("maxHtlcs is too large: %d, max is %d",
×
103
                        maxHtlc, maxMaxHtlc),
×
104
        }
×
105
}
×
106

107
// ErrMaxHtlcNumTooSmall returns an error indicating that the 'max HTLCs in
108
// flight' value the remote required is too small to be accepted.
109
func ErrMaxHtlcNumTooSmall(maxHtlc, minMaxHtlc uint16) ReservationError {
×
110
        return ReservationError{
×
111
                fmt.Errorf("maxHtlcs is too small: %d, min is %d",
×
112
                        maxHtlc, minMaxHtlc),
×
113
        }
×
114
}
×
115

116
// ErrMaxValueInFlightTooSmall returns an error indicating that the 'max HTLC
117
// value in flight' the remote required is too small to be accepted.
118
func ErrMaxValueInFlightTooSmall(maxValInFlight,
119
        minMaxValInFlight lnwire.MilliSatoshi) ReservationError {
×
120
        return ReservationError{
×
121
                fmt.Errorf("maxValueInFlight too small: %v, min is %v",
×
122
                        maxValInFlight, minMaxValInFlight),
×
123
        }
×
124
}
×
125

126
// ErrNumConfsTooLarge returns an error indicating that the number of
127
// confirmations required for a channel is too large.
UNCOV
128
func ErrNumConfsTooLarge(numConfs, maxNumConfs uint32) error {
×
UNCOV
129
        return ReservationError{
×
UNCOV
130
                fmt.Errorf("minimum depth of %d is too large, max is %d",
×
UNCOV
131
                        numConfs, maxNumConfs),
×
UNCOV
132
        }
×
UNCOV
133
}
×
134

135
// ErrChanTooSmall returns an error indicating that an incoming channel request
136
// was too small. We'll reject any incoming channels if they're below our
137
// configured value for the min channel size we'll accept.
138
func ErrChanTooSmall(chanSize, minChanSize btcutil.Amount) ReservationError {
3✔
139
        return ReservationError{
3✔
140
                fmt.Errorf("chan size of %v is below min chan size of %v",
3✔
141
                        chanSize, minChanSize),
3✔
142
        }
3✔
143
}
3✔
144

145
// ErrChanTooLarge returns an error indicating that an incoming channel request
146
// was too large. We'll reject any incoming channels if they're above our
147
// configured value for the max channel size we'll accept.
148
func ErrChanTooLarge(chanSize, maxChanSize btcutil.Amount) ReservationError {
3✔
149
        return ReservationError{
3✔
150
                fmt.Errorf("chan size of %v exceeds maximum chan size of %v",
3✔
151
                        chanSize, maxChanSize),
3✔
152
        }
3✔
153
}
3✔
154

155
// ErrInvalidDustLimit returns an error indicating that a proposed DustLimit
156
// was rejected.
157
func ErrInvalidDustLimit(dustLimit btcutil.Amount) ReservationError {
×
158
        return ReservationError{
×
159
                fmt.Errorf("dust limit %v is invalid", dustLimit),
×
160
        }
×
161
}
×
162

163
// ErrHtlcIndexAlreadyFailed is returned when the HTLC index has already been
164
// failed, but has not been committed by our commitment state.
165
type ErrHtlcIndexAlreadyFailed uint64
166

167
// Error returns a message indicating the index that had already been failed.
168
func (e ErrHtlcIndexAlreadyFailed) Error() string {
3✔
169
        return fmt.Sprintf("HTLC with ID %d has already been failed", e)
3✔
170
}
3✔
171

172
// ErrHtlcIndexAlreadySettled is returned when the HTLC index has already been
173
// settled, but has not been committed by our commitment state.
174
type ErrHtlcIndexAlreadySettled uint64
175

176
// Error returns a message indicating the index that had already been settled.
177
func (e ErrHtlcIndexAlreadySettled) Error() string {
×
178
        return fmt.Sprintf("HTLC with ID %d has already been settled", e)
×
179
}
×
180

181
// ErrInvalidSettlePreimage is returned when trying to settle an HTLC, but the
182
// preimage does not correspond to the payment hash.
183
type ErrInvalidSettlePreimage struct {
184
        preimage []byte
185
        rhash    []byte
186
}
187

188
// Error returns an error message with the offending preimage and intended
189
// payment hash.
190
func (e ErrInvalidSettlePreimage) Error() string {
3✔
191
        return fmt.Sprintf("Invalid payment preimage %x for hash %x",
3✔
192
                e.preimage, e.rhash)
3✔
193
}
3✔
194

195
// ErrUnknownHtlcIndex is returned when locally settling or failing an HTLC, but
196
// the HTLC index is not known to the channel. This typically indicates that the
197
// HTLC was already settled in a prior commitment.
198
type ErrUnknownHtlcIndex struct {
199
        chanID lnwire.ShortChannelID
200
        index  uint64
201
}
202

203
// Error returns an error logging the channel and HTLC index that was unknown.
204
func (e ErrUnknownHtlcIndex) Error() string {
×
205
        return fmt.Sprintf("No HTLC with ID %d in channel %v",
×
206
                e.index, e.chanID)
×
207
}
×
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