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

lightningnetwork / lnd / 14388908780

10 Apr 2025 07:39PM UTC coverage: 56.811% (-12.3%) from 69.08%
14388908780

Pull #9702

github

web-flow
Merge f006bbf4d into b732525a9
Pull Request #9702: multi: make payment address mandatory

28 of 42 new or added lines in 11 files covered. (66.67%)

23231 existing lines in 283 files now uncovered.

107286 of 188846 relevant lines covered (56.81%)

22749.28 hits per line

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

0.0
/lnrpc/routerrpc/router_server_deprecated.go
1
package routerrpc
2

3
import (
4
        "context"
5
        "encoding/hex"
6
        "errors"
7
        "fmt"
8

9
        "github.com/lightningnetwork/lnd/lnrpc"
10
        "github.com/lightningnetwork/lnd/lnwire"
11
        "github.com/lightningnetwork/lnd/routing/route"
12
)
13

14
// legacyTrackPaymentServer is a wrapper struct that transforms a stream of main
15
// rpc payment structs into the legacy PaymentStatus format.
16
type legacyTrackPaymentServer struct {
17
        Router_TrackPaymentServer
18
}
19

20
// Send converts a Payment object and sends it as a PaymentStatus object on the
21
// embedded stream.
22
func (i *legacyTrackPaymentServer) Send(p *lnrpc.Payment) error {
×
23
        var state PaymentState
×
24
        switch p.Status {
×
25
        case lnrpc.Payment_IN_FLIGHT:
×
26
                state = PaymentState_IN_FLIGHT
×
27
        case lnrpc.Payment_SUCCEEDED:
×
28
                state = PaymentState_SUCCEEDED
×
29
        case lnrpc.Payment_FAILED:
×
30
                switch p.FailureReason {
×
31
                case lnrpc.PaymentFailureReason_FAILURE_REASON_NONE:
×
32
                        return fmt.Errorf("expected fail reason")
×
33

34
                case lnrpc.PaymentFailureReason_FAILURE_REASON_TIMEOUT:
×
35
                        state = PaymentState_FAILED_TIMEOUT
×
36

37
                case lnrpc.PaymentFailureReason_FAILURE_REASON_NO_ROUTE:
×
38
                        state = PaymentState_FAILED_NO_ROUTE
×
39

40
                case lnrpc.PaymentFailureReason_FAILURE_REASON_ERROR:
×
41
                        state = PaymentState_FAILED_ERROR
×
42

43
                case lnrpc.PaymentFailureReason_FAILURE_REASON_INCORRECT_PAYMENT_DETAILS:
×
44
                        state = PaymentState_FAILED_INCORRECT_PAYMENT_DETAILS
×
45

46
                case lnrpc.PaymentFailureReason_FAILURE_REASON_INSUFFICIENT_BALANCE:
×
47
                        state = PaymentState_FAILED_INSUFFICIENT_BALANCE
×
48

49
                default:
×
50
                        return fmt.Errorf("unknown failure reason %v",
×
51
                                p.FailureReason)
×
52
                }
53
        default:
×
54
                return fmt.Errorf("unknown state %v", p.Status)
×
55
        }
56

57
        preimage, err := hex.DecodeString(p.PaymentPreimage)
×
58
        if err != nil {
×
59
                return err
×
60
        }
×
61

62
        legacyState := PaymentStatus{
×
63
                State:    state,
×
64
                Preimage: preimage,
×
65
                Htlcs:    p.Htlcs,
×
66
        }
×
67

×
68
        return i.Router_TrackPaymentServer.Send(&legacyState)
×
69
}
70

71
// TrackPayment returns a stream of payment state updates. The stream is
72
// closed when the payment completes.
73
func (s *Server) TrackPayment(request *TrackPaymentRequest,
74
        stream Router_TrackPaymentServer) error {
×
75

×
76
        legacyStream := legacyTrackPaymentServer{
×
77
                Router_TrackPaymentServer: stream,
×
78
        }
×
79
        return s.TrackPaymentV2(request, &legacyStream)
×
80
}
×
81

82
// SendPayment attempts to route a payment described by the passed
83
// PaymentRequest to the final destination. If we are unable to route the
84
// payment, or cannot find a route that satisfies the constraints in the
85
// PaymentRequest, then an error will be returned. Otherwise, the payment
86
// pre-image, along with the final route will be returned.
87
func (s *Server) SendPayment(request *SendPaymentRequest,
88
        stream Router_SendPaymentServer) error {
×
89

×
90
        if request.MaxParts > 1 {
×
91
                return errors.New("for multi-part payments, use SendPaymentV2")
×
92
        }
×
93

94
        legacyStream := legacyTrackPaymentServer{
×
95
                Router_TrackPaymentServer: stream,
×
96
        }
×
97
        return s.SendPaymentV2(request, &legacyStream)
×
98
}
99

100
// SendToRoute sends a payment through a predefined route. The response of this
101
// call contains structured error information.
102
func (s *Server) SendToRoute(ctx context.Context,
103
        req *SendToRouteRequest) (*SendToRouteResponse, error) {
×
104

×
105
        resp, err := s.SendToRouteV2(ctx, req)
×
106
        if err != nil {
×
107
                return nil, err
×
108
        }
×
109

110
        if resp == nil {
×
111
                return nil, nil
×
112
        }
×
113

114
        // Need to convert to legacy response message because proto identifiers
115
        // don't line up.
116
        legacyResp := &SendToRouteResponse{
×
117
                Preimage: resp.Preimage,
×
118
                Failure:  resp.Failure,
×
119
        }
×
120

×
121
        return legacyResp, nil
×
122
}
123

124
// QueryProbability returns the current success probability estimate for a
125
// given node pair and amount.
126
func (s *Server) QueryProbability(_ context.Context,
UNCOV
127
        req *QueryProbabilityRequest) (*QueryProbabilityResponse, error) {
×
UNCOV
128

×
UNCOV
129
        fromNode, err := route.NewVertexFromBytes(req.FromNode)
×
UNCOV
130
        if err != nil {
×
131
                return nil, err
×
132
        }
×
133

UNCOV
134
        toNode, err := route.NewVertexFromBytes(req.ToNode)
×
UNCOV
135
        if err != nil {
×
136
                return nil, err
×
137
        }
×
138

UNCOV
139
        amt := lnwire.MilliSatoshi(req.AmtMsat)
×
UNCOV
140

×
UNCOV
141
        // Compute the probability.
×
UNCOV
142
        var prob float64
×
UNCOV
143
        mc := s.cfg.RouterBackend.MissionControl
×
UNCOV
144
        capacity, err := s.cfg.RouterBackend.FetchAmountPairCapacity(
×
UNCOV
145
                fromNode, toNode, amt,
×
UNCOV
146
        )
×
UNCOV
147

×
UNCOV
148
        // If we cannot query the capacity this means that either we don't have
×
UNCOV
149
        // information available or that the channel fails min/maxHtlc
×
UNCOV
150
        // constraints, so we return a zero probability.
×
UNCOV
151
        if err != nil {
×
UNCOV
152
                log.Errorf("Cannot fetch capacity: %v", err)
×
UNCOV
153
        } else {
×
154
                prob = mc.GetProbability(fromNode, toNode, amt, capacity)
×
155
        }
×
156

UNCOV
157
        history := mc.GetPairHistorySnapshot(fromNode, toNode)
×
UNCOV
158

×
UNCOV
159
        return &QueryProbabilityResponse{
×
UNCOV
160
                Probability: prob,
×
UNCOV
161
                History:     toRPCPairData(&history),
×
UNCOV
162
        }, nil
×
163
}
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