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

lightningnetwork / lnd / 13236757158

10 Feb 2025 08:39AM UTC coverage: 57.649% (-1.2%) from 58.815%
13236757158

Pull #9493

github

ziggie1984
lncli: for some cmds we don't replace the data of the response.

For some cmds it is not very practical to replace the json output
because we might pipe it into other commands. For example when
creating the route we want to pipe it into sendtoRoute.
Pull Request #9493: For some lncli cmds we should not replace the content with other data

0 of 9 new or added lines in 2 files covered. (0.0%)

19535 existing lines in 252 files now uncovered.

103517 of 179563 relevant lines covered (57.65%)

24878.49 hits per line

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

73.91
/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 {
2,302✔
118
        // msgExtraData is a temporary variable used to read the message extra
2,302✔
119
        // data field from the reader.
2,302✔
120
        var msgExtraData ExtraOpaqueData
2,302✔
121

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

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

2,294✔
137
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
2,294✔
138
                msgExtraData, &blindingRecord,
2,294✔
139
        )
2,294✔
140
        if err != nil {
2,325✔
141
                return err
31✔
142
        }
31✔
143

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

149
        c.CustomRecords = customRecords
2,263✔
150
        c.ExtraData = extraData
2,263✔
151

2,263✔
152
        return nil
2,263✔
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,336✔
160
        if err := WriteChannelID(w, c.ChanID); err != nil {
3,336✔
161
                return err
×
162
        }
×
163

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

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

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

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

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

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

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

197
        return WriteBytes(w, extraData)
3,335✔
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 {
4,273✔
205
        return MsgUpdateAddHTLC
4,273✔
206
}
4,273✔
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.
UNCOV
212
func (c *UpdateAddHTLC) TargetChanID() ChannelID {
×
UNCOV
213
        return c.ChanID
×
UNCOV
214
}
×
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