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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

66.67
/lnwire/update_add_htlc.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcec/v2"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
const (
12
        // OnionPacketSize is the size of the serialized Sphinx onion packet
13
        // included in each UpdateAddHTLC message. The breakdown of the onion
14
        // packet is as follows: 1-byte version, 33-byte ephemeral public key
15
        // (for ECDH), 1300-bytes of per-hop data, and a 32-byte HMAC over the
16
        // entire packet.
17
        OnionPacketSize = 1366
18

19
        // ExperimentalEndorsementType is the TLV type used for a custom
20
        // record that sets an experimental endorsement value.
21
        ExperimentalEndorsementType tlv.Type = 106823
22

23
        // ExperimentalUnendorsed is the value that the experimental endorsement
24
        // field contains when a htlc is not endorsed.
25
        ExperimentalUnendorsed = 0
26

27
        // ExperimentalEndorsed is the value that the experimental endorsement
28
        // field contains when a htlc is endorsed. We're using a single byte
29
        // to represent our endorsement value, but limit the value to using
30
        // the first three bits (max value = 00000111). Interpreted as a uint8
31
        // (an alias for byte in go), we can just define this constant as 7.
32
        ExperimentalEndorsed = 7
33
)
34

35
type (
36
        // BlindingPointTlvType is the type for ephemeral pubkeys used in
37
        // route blinding.
38
        BlindingPointTlvType = tlv.TlvType0
39

40
        // BlindingPointRecord holds an optional blinding point on update add
41
        // htlc.
42
        //nolint:ll
43
        BlindingPointRecord = tlv.OptionalRecordT[BlindingPointTlvType, *btcec.PublicKey]
44
)
45

46
// UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an
47
// HTLC to his remote commitment transaction. In addition to information
48
// detailing the value, the ID, expiry, and the onion blob is also included
49
// which allows Bob to derive the next hop in the route. The HTLC added by this
50
// message is to be added to the remote node's "pending" HTLCs.  A subsequent
51
// CommitSig message will move the pending HTLC to the newly created commitment
52
// transaction, marking them as "staged".
53
type UpdateAddHTLC struct {
54
        // ChanID is the particular active channel that this UpdateAddHTLC is
55
        // bound to.
56
        ChanID ChannelID
57

58
        // ID is the identification server for this HTLC. This value is
59
        // explicitly included as it allows nodes to survive single-sided
60
        // restarts. The ID value for this sides starts at zero, and increases
61
        // with each offered HTLC.
62
        ID uint64
63

64
        // Amount is the amount of millisatoshis this HTLC is worth.
65
        Amount MilliSatoshi
66

67
        // PaymentHash is the payment hash to be included in the HTLC this
68
        // request creates. The pre-image to this HTLC must be revealed by the
69
        // upstream peer in order to fully settle the HTLC.
70
        PaymentHash [32]byte
71

72
        // Expiry is the number of blocks after which this HTLC should expire.
73
        // It is the receiver's duty to ensure that the outgoing HTLC has a
74
        // sufficient expiry value to allow her to redeem the incoming HTLC.
75
        Expiry uint32
76

77
        // OnionBlob is the raw serialized mix header used to route an HTLC in
78
        // a privacy-preserving manner. The mix header is defined currently to
79
        // be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
80
        // body).  First the receiving node should use the groupElement, and
81
        // its current onion key to derive a shared secret with the source.
82
        // Once the shared secret has been derived, the headerMAC should be
83
        // checked FIRST. Note that the MAC only covers the routingInfo field.
84
        // If the MAC matches, and the shared secret is fresh, then the node
85
        // should strip off a layer of encryption, exposing the next hop to be
86
        // used in the subsequent UpdateAddHTLC message.
87
        OnionBlob [OnionPacketSize]byte
88

89
        // BlindingPoint is the ephemeral pubkey used to optionally blind the
90
        // next hop for this htlc.
91
        BlindingPoint BlindingPointRecord
92

93
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
94
        // intended for inclusion in the ExtraData field of the UpdateAddHTLC
95
        // message.
96
        CustomRecords CustomRecords
97

98
        // ExtraData is the set of data that was appended to this message to
99
        // fill out the full maximum transport message size. These fields can
100
        // be used to specify optional data such as custom TLV fields.
101
        ExtraData ExtraOpaqueData
102
}
103

104
// NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.
105
func NewUpdateAddHTLC() *UpdateAddHTLC {
×
106
        return &UpdateAddHTLC{}
×
107
}
×
108

109
// A compile time check to ensure UpdateAddHTLC implements the lnwire.Message
110
// interface.
111
var _ Message = (*UpdateAddHTLC)(nil)
112

113
// Decode deserializes a serialized UpdateAddHTLC message stored in the passed
114
// io.Reader observing the specified protocol version.
115
//
116
// This is part of the lnwire.Message interface.
117
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
3✔
118
        // msgExtraData is a temporary variable used to read the message extra
3✔
119
        // data field from the reader.
3✔
120
        var msgExtraData ExtraOpaqueData
3✔
121

3✔
122
        if err := ReadElements(r,
3✔
123
                &c.ChanID,
3✔
124
                &c.ID,
3✔
125
                &c.Amount,
3✔
126
                c.PaymentHash[:],
3✔
127
                &c.Expiry,
3✔
128
                c.OnionBlob[:],
3✔
129
                &msgExtraData,
3✔
130
        ); err != nil {
3✔
UNCOV
131
                return err
×
UNCOV
132
        }
×
133

134
        // Extract TLV records from the extra data field.
135
        blindingRecord := c.BlindingPoint.Zero()
3✔
136

3✔
137
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
3✔
138
                msgExtraData, &blindingRecord,
3✔
139
        )
3✔
140
        if err != nil {
3✔
UNCOV
141
                return err
×
UNCOV
142
        }
×
143

144
        // Assign the parsed records back to the message.
145
        if parsed.Contains(blindingRecord.TlvType()) {
6✔
146
                c.BlindingPoint = tlv.SomeRecordT(blindingRecord)
3✔
147
        }
3✔
148

149
        c.CustomRecords = customRecords
3✔
150
        c.ExtraData = extraData
3✔
151

3✔
152
        return nil
3✔
153
}
154

155
// Encode serializes the target UpdateAddHTLC into the passed io.Writer
156
// observing the protocol version specified.
157
//
158
// This is part of the lnwire.Message interface.
159
func (c *UpdateAddHTLC) Encode(w *bytes.Buffer, pver uint32) error {
3✔
160
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
161
                return err
×
162
        }
×
163

164
        if err := WriteUint64(w, c.ID); err != nil {
3✔
165
                return err
×
166
        }
×
167

168
        if err := WriteMilliSatoshi(w, c.Amount); err != nil {
3✔
169
                return err
×
170
        }
×
171

172
        if err := WriteBytes(w, c.PaymentHash[:]); err != nil {
3✔
173
                return err
×
174
        }
×
175

176
        if err := WriteUint32(w, c.Expiry); err != nil {
3✔
177
                return err
×
178
        }
×
179

180
        if err := WriteBytes(w, c.OnionBlob[:]); err != nil {
3✔
181
                return err
×
182
        }
×
183

184
        // Only include blinding point in extra data if present.
185
        var records []tlv.RecordProducer
3✔
186
        c.BlindingPoint.WhenSome(
3✔
187
                func(b tlv.RecordT[BlindingPointTlvType, *btcec.PublicKey]) {
6✔
188
                        records = append(records, &b)
3✔
189
                },
3✔
190
        )
191

192
        extraData, err := MergeAndEncode(records, c.ExtraData, c.CustomRecords)
3✔
193
        if err != nil {
3✔
UNCOV
194
                return err
×
UNCOV
195
        }
×
196

197
        return WriteBytes(w, extraData)
3✔
198
}
199

200
// MsgType returns the integer uniquely identifying this message type on the
201
// wire.
202
//
203
// This is part of the lnwire.Message interface.
204
func (c *UpdateAddHTLC) MsgType() MessageType {
3✔
205
        return MsgUpdateAddHTLC
3✔
206
}
3✔
207

208
// TargetChanID returns the channel id of the link for which this message is
209
// intended.
210
//
211
// NOTE: Part of peer.LinkUpdater interface.
212
func (c *UpdateAddHTLC) TargetChanID() ChannelID {
3✔
213
        return c.ChanID
3✔
214
}
3✔
215

216
// SerializedSize returns the serialized size of the message in bytes.
217
//
218
// This is part of the lnwire.SizeableMessage interface.
219
func (c *UpdateAddHTLC) SerializedSize() (uint32, error) {
×
220
        return MessageSerializedSize(c)
×
221
}
×
222

223
// A compile time check to ensure UpdateAddHTLC implements the
224
// lnwire.SizeableMessage interface.
225
var _ SizeableMessage = (*UpdateAddHTLC)(nil)
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