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

lightningnetwork / lnd / 16948521526

13 Aug 2025 08:27PM UTC coverage: 54.877% (-12.1%) from 66.929%
16948521526

Pull #10155

github

web-flow
Merge 61c0fecf6 into c6a9116e3
Pull Request #10155: Add missing invoice index for native sql

108941 of 198518 relevant lines covered (54.88%)

22023.66 hits per line

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

86.36
/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 {
40✔
45
        return r.String()
40✔
46
}
40✔
47

48
// String returns a human-readable FailureReason.
49
func (r FailureReason) String() string {
40✔
50
        switch r {
40✔
51
        case FailureReasonTimeout:
12✔
52
                return "timeout"
12✔
53
        case FailureReasonNoRoute:
8✔
54
                return "no_route"
8✔
55
        case FailureReasonError:
14✔
56
                return "error"
14✔
57
        case FailureReasonPaymentDetails:
2✔
58
                return "incorrect_payment_details"
2✔
59
        case FailureReasonInsufficientBalance:
×
60
                return "insufficient_balance"
×
61
        case FailureReasonCanceled:
4✔
62
                return "canceled"
4✔
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.
91
func (p *PaymentCreationInfo) String() string {
8✔
92
        return fmt.Sprintf("payment_id=%v, amount=%v, created_at=%v",
8✔
93
                p.PaymentIdentifier, p.Value, p.CreationTime)
8✔
94
}
8✔
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