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

lightningnetwork / lnd / 12293715361

12 Dec 2024 09:38AM UTC coverage: 57.483% (+7.9%) from 49.538%
12293715361

Pull #9348

github

ziggie1984
github: update goveralls tool

The goverall tool had a bug regarding the module versioning of
golang packages see also
https://github.com/mattn/goveralls/pull/222 for more background.
Goveralls is wrapped by another library to make it available for
github actions. So the relevant PR which is referenced here in
LND is:
https://github.com/shogo82148/actions-goveralls/pull/521.
Pull Request #9348: github: update goveralls tool

101897 of 177264 relevant lines covered (57.48%)

24982.4 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/fn/v2"
6
        "github.com/lightningnetwork/lnd/graph/db/models"
7
        "github.com/lightningnetwork/lnd/htlcswitch"
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 *models.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[htlcswitch.AuxTrafficShaper]) (PaymentSession,
57
        error) {
12✔
58

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

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

74
        return session, nil
12✔
75
}
76

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

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

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

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

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

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

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

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