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

lightningnetwork / lnd / 18914042383

29 Oct 2025 03:53PM UTC coverage: 54.594%. First build
18914042383

Pull #10089

github

web-flow
Merge 5a7e61d97 into e8a486fa6
Pull Request #10089: Onion message forwarding

93 of 590 new or added lines in 10 files covered. (15.76%)

110416 of 202249 relevant lines covered (54.59%)

21682.71 hits per line

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

66.67
/record/hop.go
1
package record
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/lightningnetwork/lnd/tlv"
6
)
7

8
const (
9
        // Onion Routing Packet types.
10

11
        // AmtOnionType is the type used in the onion to reference the amount to
12
        // send to the next hop.
13
        AmtOnionType tlv.Type = 2
14

15
        // LockTimeTLV is the type used in the onion to reference the CLTV
16
        // value that should be used for the next hop's HTLC.
17
        LockTimeOnionType tlv.Type = 4
18

19
        // NextHopOnionType is the type used in the onion to reference the ID
20
        // of the next hop.
21
        NextHopOnionType tlv.Type = 6
22

23
        // EncryptedDataOnionType is the type used to include encrypted data
24
        // provided by the receiver in the onion for use in blinded paths.
25
        EncryptedDataOnionType tlv.Type = 10
26

27
        // BlindingPointOnionType is the type used to include receiver provided
28
        // ephemeral keys in the onion that are used in blinded paths.
29
        BlindingPointOnionType tlv.Type = 12
30

31
        // MetadataOnionType is the type used in the onion for the payment
32
        // metadata.
33
        MetadataOnionType tlv.Type = 16
34

35
        // TotalAmtMsatBlindedType is the type used in the onion for the total
36
        // amount field that is included in the final hop for blinded payments.
37
        TotalAmtMsatBlindedType tlv.Type = 18
38

39
        // Onion Message Packet types.
40

41
        // ReplyPathType is the type used in the onion message to indicate the
42
        // blinded path to be used for replies.
43
        ReplyPathType tlv.Type = 2
44

45
        // EncryptedRecipientDataType is the type used in the onion message to
46
        // include encrypted data in the onion for use in blinded paths.
47
        EncryptedRecipientDataType tlv.Type = 4
48

49
        // InvoiceRequestType is the type used in the onion message to include
50
        // invoice requests.
51
        InvoiceRequestType tlv.Type = 64
52

53
        // InvoiceType is the type used in the onion message to include
54
        // invoices.
55
        InvoiceType tlv.Type = 66
56

57
        // InvoiceErrorType is the type used in the onion message to include
58
        // invoice errors.
59
        InvoiceErrorType tlv.Type = 68
60
)
61

62
// NewAmtToFwdRecord creates a tlv.Record that encodes the amount_to_forward
63
// (type 2) for an onion payload.
64
func NewAmtToFwdRecord(amt *uint64) tlv.Record {
869✔
65
        return tlv.MakeDynamicRecord(
869✔
66
                AmtOnionType, amt, func() uint64 {
1,160✔
67
                        return tlv.SizeTUint64(*amt)
291✔
68
                },
291✔
69
                tlv.ETUint64, tlv.DTUint64,
70
        )
71
}
72

73
// NewLockTimeRecord creates a tlv.Record that encodes the outgoing_cltv_value
74
// (type 4) for an onion payload.
75
func NewLockTimeRecord(lockTime *uint32) tlv.Record {
869✔
76
        return tlv.MakeDynamicRecord(
869✔
77
                LockTimeOnionType, lockTime, func() uint64 {
1,160✔
78
                        return tlv.SizeTUint32(*lockTime)
291✔
79
                },
291✔
80
                tlv.ETUint32, tlv.DTUint32,
81
        )
82
}
83

84
// NewNextHopIDRecord creates a tlv.Record that encodes the short_channel_id
85
// (type 6) for an onion payload.
86
func NewNextHopIDRecord(cid *uint64) tlv.Record {
611✔
87
        return tlv.MakePrimitiveRecord(NextHopOnionType, cid)
611✔
88
}
611✔
89

90
// NewEncryptedDataRecord creates a tlv.Record that encodes the encrypted_data
91
// (type 10) record for an onion payload.
92
func NewEncryptedDataRecord(data *[]byte) tlv.Record {
591✔
93
        return tlv.MakePrimitiveRecord(EncryptedDataOnionType, data)
591✔
94
}
591✔
95

96
// NewEncryptedRecipientDataRecord creates a tlv.Record that encodes the
97
// encrypted_data (type 4) record for an onion message payload.
NEW
98
func NewEncryptedRecipientDataRecord(data *[]byte) tlv.Record {
×
NEW
99
        return tlv.MakePrimitiveRecord(EncryptedRecipientDataType, data)
×
NEW
100
}
×
101

102
// NewReplyPathRecord creates a tlv.Record that encodes the reply_path (type 2)
103
// record for an onion message payload.
NEW
104
func NewReplyPathRecord(data *[]byte) tlv.Record {
×
NEW
105
        return tlv.MakePrimitiveRecord(ReplyPathType, data)
×
NEW
106
}
×
107

108
// NewInvoiceRequestRecord creates a tlv.Record that encodes the
109
// invoice_request (type 64) record for an onion message payload.
NEW
110
func NewInvoiceRequestRecord(data *[]byte) tlv.Record {
×
NEW
111
        return tlv.MakePrimitiveRecord(InvoiceRequestType, data)
×
NEW
112
}
×
113

114
// NewInvoiceRecord creates a tlv.Record that encodes the
115
// invoice (type 66) record for an onion message payload.
NEW
116
func NewInvoiceRecord(data *[]byte) tlv.Record {
×
NEW
117
        return tlv.MakePrimitiveRecord(InvoiceType, data)
×
NEW
118
}
×
119

120
// NewInvoiceErrorRecord creates a tlv.Record that encodes the
121
// invoice_error (type 68) record for an onion message payload.
NEW
122
func NewInvoiceErrorRecord(data *[]byte) tlv.Record {
×
NEW
123
        return tlv.MakePrimitiveRecord(InvoiceErrorType, data)
×
NEW
124
}
×
125

126
// NewBlindingPointRecord creates a tlv.Record that encodes the blinding_point
127
// (type 12) record for an onion payload.
128
func NewBlindingPointRecord(point **btcec.PublicKey) tlv.Record {
580✔
129
        return tlv.MakePrimitiveRecord(BlindingPointOnionType, point)
580✔
130
}
580✔
131

132
// NewMetadataRecord creates a tlv.Record that encodes the metadata (type 10)
133
// for an onion payload.
134
func NewMetadataRecord(metadata *[]byte) tlv.Record {
809✔
135
        return tlv.MakeDynamicRecord(
809✔
136
                MetadataOnionType, metadata,
809✔
137
                func() uint64 {
978✔
138
                        return uint64(len(*metadata))
169✔
139
                },
169✔
140
                tlv.EVarBytes, tlv.DVarBytes,
141
        )
142
}
143

144
// NewTotalAmtMsatBlinded creates a tlv.Record that encodes the
145
// total_amount_msat for the final an onion payload within a blinded route.
146
func NewTotalAmtMsatBlinded(amt *uint64) tlv.Record {
585✔
147
        return tlv.MakeDynamicRecord(
585✔
148
                TotalAmtMsatBlindedType, amt, func() uint64 {
596✔
149
                        return tlv.SizeTUint64(*amt)
11✔
150
                },
11✔
151
                tlv.ETUint64, tlv.DTUint64,
152
        )
153
}
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