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

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

197
        return WriteBytes(w, extraData)
3,347✔
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,285✔
205
        return MsgUpdateAddHTLC
4,285✔
206
}
4,285✔
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