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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

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

83.05
/routing/payment_session_source.go
1
package routing
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/lightningnetwork/lnd/channeldb"
6
        "github.com/lightningnetwork/lnd/channeldb/models"
7
        "github.com/lightningnetwork/lnd/fn"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
        "github.com/lightningnetwork/lnd/routing/route"
10
        "github.com/lightningnetwork/lnd/tlv"
11
        "github.com/lightningnetwork/lnd/zpay32"
12
)
13

14
// A compile time assertion to ensure SessionSource meets the
15
// PaymentSessionSource interface.
16
var _ PaymentSessionSource = (*SessionSource)(nil)
17

18
// SessionSource defines a source for the router to retrieve new payment
19
// sessions.
20
type SessionSource struct {
21
        // GraphSessionFactory can be used to gain access to a Graph session.
22
        // If the backing DB allows it, this will mean that a read transaction
23
        // is being held during the use of the session.
24
        GraphSessionFactory GraphSessionFactory
25

26
        // SourceNode is the graph's source node.
27
        SourceNode *channeldb.LightningNode
28

29
        // GetLink is a method that allows querying the lower link layer
30
        // to determine the up to date available bandwidth at a prospective link
31
        // to be traversed. If the link isn't available, then a value of zero
32
        // should be returned. Otherwise, the current up to date knowledge of
33
        // the available bandwidth of the link should be returned.
34
        GetLink getLinkQuery
35

36
        // MissionControl is a shared memory of sorts that executions of payment
37
        // path finding use in order to remember which vertexes/edges were
38
        // pruned from prior attempts. During payment execution, errors sent by
39
        // nodes are mapped into a vertex or edge to be pruned. Each run will
40
        // then take into account this set of pruned vertexes/edges to reduce
41
        // route failure and pass on graph information gained to the next
42
        // execution.
43
        MissionControl MissionControlQuerier
44

45
        // PathFindingConfig defines global parameters that control the
46
        // trade-off in path finding between fees and probability.
47
        PathFindingConfig PathFindingConfig
48
}
49

50
// NewPaymentSession creates a new payment session backed by the latest prune
51
// view from Mission Control. An optional set of routing hints can be provided
52
// in order to populate additional edges to explore when finding a path to the
53
// payment's destination.
54
func (m *SessionSource) NewPaymentSession(p *LightningPayment,
55
        firstHopBlob fn.Option[tlv.Blob],
56
        trafficShaper fn.Option[TlvTrafficShaper]) (PaymentSession, error) {
12✔
57

12✔
58
        getBandwidthHints := func(graph Graph) (bandwidthHints, error) {
36✔
59
                return newBandwidthManager(
24✔
60
                        graph, m.SourceNode.PubKeyBytes, m.GetLink,
24✔
61
                        firstHopBlob, trafficShaper,
24✔
62
                )
24✔
63
        }
24✔
64

65
        session, err := newPaymentSession(
12✔
66
                p, m.SourceNode.PubKeyBytes, getBandwidthHints,
12✔
67
                m.GraphSessionFactory, m.MissionControl, m.PathFindingConfig,
12✔
68
        )
12✔
69
        if err != nil {
12✔
70
                return nil, err
×
71
        }
×
72

73
        return session, nil
12✔
74
}
75

76
// NewPaymentSessionEmpty creates a new paymentSession instance that is empty,
77
// and will be exhausted immediately. Used for failure reporting to
78
// missioncontrol for resumed payment we don't want to make more attempts for.
UNCOV
79
func (m *SessionSource) NewPaymentSessionEmpty() PaymentSession {
×
UNCOV
80
        return &paymentSession{
×
UNCOV
81
                empty: true,
×
UNCOV
82
        }
×
UNCOV
83
}
×
84

85
// RouteHintsToEdges converts a list of invoice route hints to an edge map that
86
// can be passed into pathfinding.
87
func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
88
        map[route.Vertex][]AdditionalEdge, error) {
23✔
89

23✔
90
        edges := make(map[route.Vertex][]AdditionalEdge)
23✔
91

23✔
92
        // Traverse through all of the available hop hints and include them in
23✔
93
        // our edges map, indexed by the public key of the channel's starting
23✔
94
        // node.
23✔
95
        for _, routeHint := range routeHints {
28✔
96
                // If multiple hop hints are provided within a single route
5✔
97
                // hint, we'll assume they must be chained together and sorted
5✔
98
                // in forward order in order to reach the target successfully.
5✔
99
                for i, hopHint := range routeHint {
10✔
100
                        // In order to determine the end node of this hint,
5✔
101
                        // we'll need to look at the next hint's start node. If
5✔
102
                        // we've reached the end of the hints list, we can
5✔
103
                        // assume we've reached the destination.
5✔
104
                        endNode := &channeldb.LightningNode{}
5✔
105
                        if i != len(routeHint)-1 {
5✔
106
                                endNode.AddPubKey(routeHint[i+1].NodeID)
×
107
                        } else {
5✔
108
                                targetPubKey, err := btcec.ParsePubKey(
5✔
109
                                        target[:],
5✔
110
                                )
5✔
111
                                if err != nil {
5✔
112
                                        return nil, err
×
113
                                }
×
114
                                endNode.AddPubKey(targetPubKey)
5✔
115
                        }
116

117
                        // Finally, create the channel edge from the hop hint
118
                        // and add it to list of edges corresponding to the node
119
                        // at the start of the channel.
120
                        edgePolicy := &models.CachedEdgePolicy{
5✔
121
                                ToNodePubKey: func() route.Vertex {
15✔
122
                                        return endNode.PubKeyBytes
10✔
123
                                },
10✔
124
                                ToNodeFeatures: lnwire.EmptyFeatureVector(),
125
                                ChannelID:      hopHint.ChannelID,
126
                                FeeBaseMSat: lnwire.MilliSatoshi(
127
                                        hopHint.FeeBaseMSat,
128
                                ),
129
                                FeeProportionalMillionths: lnwire.MilliSatoshi(
130
                                        hopHint.FeeProportionalMillionths,
131
                                ),
132
                                TimeLockDelta: hopHint.CLTVExpiryDelta,
133
                        }
134

135
                        edge := &PrivateEdge{
5✔
136
                                policy: edgePolicy,
5✔
137
                        }
5✔
138

5✔
139
                        v := route.NewVertex(hopHint.NodeID)
5✔
140
                        edges[v] = append(edges[v], edge)
5✔
141
                }
142
        }
143

144
        return edges, nil
23✔
145
}
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