• 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

82.46
/routing/additional_edge.go
1
package routing
2

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

7
        "github.com/lightningnetwork/lnd/channeldb/models"
8
        "github.com/lightningnetwork/lnd/lnwire"
9
        "github.com/lightningnetwork/lnd/routing/route"
10
)
11

12
var (
13
        // ErrNoPayLoadSizeFunc is returned when no payload size function is
14
        // definied.
15
        ErrNoPayLoadSizeFunc = errors.New("no payloadSizeFunc defined for " +
16
                "additional edge")
17
)
18

19
// AdditionalEdge is an interface which specifies additional edges which can
20
// be appended to an existing route. Compared to normal edges of a route they
21
// provide an explicit payload size function and are introduced because blinded
22
// paths differ in their payload structure.
23
type AdditionalEdge interface {
24
        // IntermediatePayloadSize returns the size of the payload for the
25
        // additional edge when being an intermediate hop in a route NOT the
26
        // final hop.
27
        IntermediatePayloadSize(amount lnwire.MilliSatoshi, expiry uint32,
28
                channelID uint64) uint64
29

30
        // EdgePolicy returns the policy of the additional edge.
31
        EdgePolicy() *models.CachedEdgePolicy
32

33
        // BlindedPayment returns the BlindedPayment that this additional edge
34
        // info was derived from. It will return nil if this edge was not
35
        // derived from a blinded route.
36
        BlindedPayment() *BlindedPayment
37
}
38

39
// PayloadSizeFunc defines the interface for the payload size function.
40
type PayloadSizeFunc func(amount lnwire.MilliSatoshi, expiry uint32,
41
        channelID uint64) uint64
42

43
// PrivateEdge implements the AdditionalEdge interface. As the name implies it
44
// is used for private route hints that the receiver adds for example to an
45
// invoice.
46
type PrivateEdge struct {
47
        policy *models.CachedEdgePolicy
48
}
49

50
// EdgePolicy return the policy of the PrivateEdge.
51
func (p *PrivateEdge) EdgePolicy() *models.CachedEdgePolicy {
19✔
52
        return p.policy
19✔
53
}
19✔
54

55
// IntermediatePayloadSize returns the sphinx payload size defined in BOLT04 if
56
// this edge were to be included in a route.
57
func (p *PrivateEdge) IntermediatePayloadSize(amount lnwire.MilliSatoshi,
58
        expiry uint32, channelID uint64) uint64 {
624✔
59

624✔
60
        hop := route.Hop{
624✔
61
                AmtToForward:     amount,
624✔
62
                OutgoingTimeLock: expiry,
624✔
63
        }
624✔
64

624✔
65
        return hop.PayloadSize(channelID)
624✔
66
}
624✔
67

68
// BlindedPayment is a no-op for a PrivateEdge since it is not associated with
69
// a blinded payment. This will thus return nil.
70
func (p *PrivateEdge) BlindedPayment() *BlindedPayment {
8✔
71
        return nil
8✔
72
}
8✔
73

74
// BlindedEdge implements the AdditionalEdge interface. Blinded hops are viewed
75
// as additional edges because they are appended at the end of a normal route.
76
type BlindedEdge struct {
77
        policy *models.CachedEdgePolicy
78

79
        // blindedPayment is the BlindedPayment that this blinded edge was
80
        // derived from.
81
        blindedPayment *BlindedPayment
82

83
        // hopIndex is the index of the hop in the blinded payment path that
84
        // this edge is associated with.
85
        hopIndex int
86
}
87

88
// NewBlindedEdge constructs a new BlindedEdge which packages the policy info
89
// for a specific hop within the given blinded payment path. The hop index
90
// should correspond to the hop within the blinded payment that this edge is
91
// associated with.
92
func NewBlindedEdge(policy *models.CachedEdgePolicy, payment *BlindedPayment,
93
        hopIndex int) (*BlindedEdge, error) {
7✔
94

7✔
95
        if payment == nil {
7✔
96
                return nil, fmt.Errorf("blinded payment cannot be nil for " +
×
97
                        "blinded edge")
×
98
        }
×
99

100
        if hopIndex < 0 || hopIndex >= len(payment.BlindedPath.BlindedHops) {
7✔
101
                return nil, fmt.Errorf("the hop index %d is outside the "+
×
102
                        "valid range between 0 and %d", hopIndex,
×
103
                        len(payment.BlindedPath.BlindedHops)-1)
×
104
        }
×
105

106
        return &BlindedEdge{
7✔
107
                policy:         policy,
7✔
108
                hopIndex:       hopIndex,
7✔
109
                blindedPayment: payment,
7✔
110
        }, nil
7✔
111
}
112

113
// EdgePolicy return the policy of the BlindedEdge.
114
func (b *BlindedEdge) EdgePolicy() *models.CachedEdgePolicy {
10✔
115
        return b.policy
10✔
116
}
10✔
117

118
// IntermediatePayloadSize returns the sphinx payload size defined in BOLT04 if
119
// this edge were to be included in a route.
120
func (b *BlindedEdge) IntermediatePayloadSize(_ lnwire.MilliSatoshi, _ uint32,
121
        _ uint64) uint64 {
6✔
122

6✔
123
        blindedPath := b.blindedPayment.BlindedPath
6✔
124

6✔
125
        hop := route.Hop{
6✔
126
                BlindingPoint: blindedPath.BlindingPoint,
6✔
127
                EncryptedData: blindedPath.BlindedHops[b.hopIndex].CipherText,
6✔
128
        }
6✔
129

6✔
130
        // For blinded paths the next chanID is in the encrypted data tlv.
6✔
131
        return hop.PayloadSize(0)
6✔
132
}
6✔
133

134
// BlindedPayment returns the blinded payment that this edge is associated
135
// with.
UNCOV
136
func (b *BlindedEdge) BlindedPayment() *BlindedPayment {
×
UNCOV
137
        return b.blindedPayment
×
UNCOV
138
}
×
139

140
// Compile-time constraints to ensure the PrivateEdge and the BlindedEdge
141
// implement the AdditionalEdge interface.
142
var _ AdditionalEdge = (*PrivateEdge)(nil)
143
var _ AdditionalEdge = (*BlindedEdge)(nil)
144

145
// defaultHopPayloadSize is the default payload size of a normal (not-blinded)
146
// hop in the route.
147
func defaultHopPayloadSize(amount lnwire.MilliSatoshi, expiry uint32,
148
        channelID uint64) uint64 {
615✔
149

615✔
150
        // The payload size of a cleartext intermediate hop is equal to the
615✔
151
        // payload size of a private edge therefore we reuse its size function.
615✔
152
        edge := PrivateEdge{}
615✔
153

615✔
154
        return edge.IntermediatePayloadSize(amount, expiry, channelID)
615✔
155
}
615✔
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