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

lightningnetwork / lnd / 16802564426

07 Aug 2025 10:58AM UTC coverage: 57.437% (-9.5%) from 66.938%
16802564426

Pull #9871

github

web-flow
Merge 0e84b7dbb into 8a2128ba4
Pull Request #9871: Add `NoopAdd` HTLCs

48 of 147 new or added lines in 3 files covered. (32.65%)

28319 existing lines in 455 files now uncovered.

99037 of 172428 relevant lines covered (57.44%)

1.78 hits per line

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

50.0
/channeldb/payments.go
1
package channeldb
2

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

7
        "github.com/lightningnetwork/lnd/lntypes"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
)
10

11
// FailureReason encodes the reason a payment ultimately failed.
12
type FailureReason byte
13

14
const (
15
        // FailureReasonTimeout indicates that the payment did timeout before a
16
        // successful payment attempt was made.
17
        FailureReasonTimeout FailureReason = 0
18

19
        // FailureReasonNoRoute indicates no successful route to the
20
        // destination was found during path finding.
21
        FailureReasonNoRoute FailureReason = 1
22

23
        // FailureReasonError indicates that an unexpected error happened during
24
        // payment.
25
        FailureReasonError FailureReason = 2
26

27
        // FailureReasonPaymentDetails indicates that either the hash is unknown
28
        // or the final cltv delta or amount is incorrect.
29
        FailureReasonPaymentDetails FailureReason = 3
30

31
        // FailureReasonInsufficientBalance indicates that we didn't have enough
32
        // balance to complete the payment.
33
        FailureReasonInsufficientBalance FailureReason = 4
34

35
        // FailureReasonCanceled indicates that the payment was canceled by the
36
        // user.
37
        FailureReasonCanceled FailureReason = 5
38

39
        // TODO(joostjager): Add failure reasons for:
40
        // LocalLiquidityInsufficient, RemoteCapacityInsufficient.
41
)
42

43
// Error returns a human-readable error string for the FailureReason.
44
func (r FailureReason) Error() string {
3✔
45
        return r.String()
3✔
46
}
3✔
47

48
// String returns a human-readable FailureReason.
49
func (r FailureReason) String() string {
3✔
50
        switch r {
3✔
UNCOV
51
        case FailureReasonTimeout:
×
UNCOV
52
                return "timeout"
×
53
        case FailureReasonNoRoute:
3✔
54
                return "no_route"
3✔
UNCOV
55
        case FailureReasonError:
×
UNCOV
56
                return "error"
×
57
        case FailureReasonPaymentDetails:
3✔
58
                return "incorrect_payment_details"
3✔
59
        case FailureReasonInsufficientBalance:
3✔
60
                return "insufficient_balance"
3✔
UNCOV
61
        case FailureReasonCanceled:
×
UNCOV
62
                return "canceled"
×
63
        }
64

65
        return "unknown"
×
66
}
67

68
// PaymentCreationInfo is the information necessary to have ready when
69
// initiating a payment, moving it into state InFlight.
70
type PaymentCreationInfo struct {
71
        // PaymentIdentifier is the hash this payment is paying to in case of
72
        // non-AMP payments, and the SetID for AMP payments.
73
        PaymentIdentifier lntypes.Hash
74

75
        // Value is the amount we are paying.
76
        Value lnwire.MilliSatoshi
77

78
        // CreationTime is the time when this payment was initiated.
79
        CreationTime time.Time
80

81
        // PaymentRequest is the full payment request, if any.
82
        PaymentRequest []byte
83

84
        // FirstHopCustomRecords are the TLV records that are to be sent to the
85
        // first hop of this payment. These records will be transmitted via the
86
        // wire message only and therefore do not affect the onion payload size.
87
        FirstHopCustomRecords lnwire.CustomRecords
88
}
89

90
// String returns a human-readable description of the payment creation info.
UNCOV
91
func (p *PaymentCreationInfo) String() string {
×
UNCOV
92
        return fmt.Sprintf("payment_id=%v, amount=%v, created_at=%v",
×
UNCOV
93
                p.PaymentIdentifier, p.Value, p.CreationTime)
×
UNCOV
94
}
×
95

96
// PaymentsQuery represents a query to the payments database starting or ending
97
// at a certain offset index. The number of retrieved records can be limited.
98
type PaymentsQuery struct {
99
        // IndexOffset determines the starting point of the payments query and
100
        // is always exclusive. In normal order, the query starts at the next
101
        // higher (available) index compared to IndexOffset. In reversed order,
102
        // the query ends at the next lower (available) index compared to the
103
        // IndexOffset. In the case of a zero index_offset, the query will start
104
        // with the oldest payment when paginating forwards, or will end with
105
        // the most recent payment when paginating backwards.
106
        IndexOffset uint64
107

108
        // MaxPayments is the maximal number of payments returned in the
109
        // payments query.
110
        MaxPayments uint64
111

112
        // Reversed gives a meaning to the IndexOffset. If reversed is set to
113
        // true, the query will fetch payments with indices lower than the
114
        // IndexOffset, otherwise, it will return payments with indices greater
115
        // than the IndexOffset.
116
        Reversed bool
117

118
        // If IncludeIncomplete is true, then return payments that have not yet
119
        // fully completed. This means that pending payments, as well as failed
120
        // payments will show up if this field is set to true.
121
        IncludeIncomplete bool
122

123
        // CountTotal indicates that all payments currently present in the
124
        // payment index (complete and incomplete) should be counted.
125
        CountTotal bool
126

127
        // CreationDateStart, expressed in Unix seconds, if set, filters out
128
        // all payments with a creation date greater than or equal to it.
129
        CreationDateStart int64
130

131
        // CreationDateEnd, expressed in Unix seconds, if set, filters out all
132
        // payments with a creation date less than or equal to it.
133
        CreationDateEnd int64
134
}
135

136
// PaymentsResponse contains the result of a query to the payments database.
137
// It includes the set of payments that match the query and integers which
138
// represent the index of the first and last item returned in the series of
139
// payments. These integers allow callers to resume their query in the event
140
// that the query's response exceeds the max number of returnable events.
141
type PaymentsResponse struct {
142
        // Payments is the set of payments returned from the database for the
143
        // PaymentsQuery.
144
        Payments []*MPPayment
145

146
        // FirstIndexOffset is the index of the first element in the set of
147
        // returned MPPayments. Callers can use this to resume their query
148
        // in the event that the slice has too many events to fit into a single
149
        // response. The offset can be used to continue reverse pagination.
150
        FirstIndexOffset uint64
151

152
        // LastIndexOffset is the index of the last element in the set of
153
        // returned MPPayments. Callers can use this to resume their query
154
        // in the event that the slice has too many events to fit into a single
155
        // response. The offset can be used to continue forward pagination.
156
        LastIndexOffset uint64
157

158
        // TotalCount represents the total number of payments that are currently
159
        // stored in the payment database. This will only be set if the
160
        // CountTotal field in the query was set to true.
161
        TotalCount uint64
162
}
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