• 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

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

17
type (
18
        // BlindingPointTlvType is the type for ephemeral pubkeys used in
19
        // route blinding.
20
        BlindingPointTlvType = tlv.TlvType0
21

22
        // BlindingPointRecord holds an optional blinding point on update add
23
        // htlc.
24
        //nolint:lll
25
        BlindingPointRecord = tlv.OptionalRecordT[BlindingPointTlvType, *btcec.PublicKey]
26
)
27

28
// UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an
29
// HTLC to his remote commitment transaction. In addition to information
30
// detailing the value, the ID, expiry, and the onion blob is also included
31
// which allows Bob to derive the next hop in the route. The HTLC added by this
32
// message is to be added to the remote node's "pending" HTLCs.  A subsequent
33
// CommitSig message will move the pending HTLC to the newly created commitment
34
// transaction, marking them as "staged".
35
type UpdateAddHTLC struct {
36
        // ChanID is the particular active channel that this UpdateAddHTLC is
37
        // bound to.
38
        ChanID ChannelID
39

40
        // ID is the identification server for this HTLC. This value is
41
        // explicitly included as it allows nodes to survive single-sided
42
        // restarts. The ID value for this sides starts at zero, and increases
43
        // with each offered HTLC.
44
        ID uint64
45

46
        // Amount is the amount of millisatoshis this HTLC is worth.
47
        Amount MilliSatoshi
48

49
        // PaymentHash is the payment hash to be included in the HTLC this
50
        // request creates. The pre-image to this HTLC must be revealed by the
51
        // upstream peer in order to fully settle the HTLC.
52
        PaymentHash [32]byte
53

54
        // Expiry is the number of blocks after which this HTLC should expire.
55
        // It is the receiver's duty to ensure that the outgoing HTLC has a
56
        // sufficient expiry value to allow her to redeem the incoming HTLC.
57
        Expiry uint32
58

59
        // OnionBlob is the raw serialized mix header used to route an HTLC in
60
        // a privacy-preserving manner. The mix header is defined currently to
61
        // be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
62
        // body).  First the receiving node should use the groupElement, and
63
        // its current onion key to derive a shared secret with the source.
64
        // Once the shared secret has been derived, the headerMAC should be
65
        // checked FIRST. Note that the MAC only covers the routingInfo field.
66
        // If the MAC matches, and the shared secret is fresh, then the node
67
        // should strip off a layer of encryption, exposing the next hop to be
68
        // used in the subsequent UpdateAddHTLC message.
69
        OnionBlob [OnionPacketSize]byte
70

71
        // BlindingPoint is the ephemeral pubkey used to optionally blind the
72
        // next hop for this htlc.
73
        BlindingPoint BlindingPointRecord
74

75
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
76
        // intended for inclusion in the ExtraData field of the UpdateAddHTLC
77
        // message.
78
        CustomRecords CustomRecords
79

80
        // ExtraData is the set of data that was appended to this message to
81
        // fill out the full maximum transport message size. These fields can
82
        // be used to specify optional data such as custom TLV fields.
83
        ExtraData ExtraOpaqueData
84
}
85

86
// NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.
87
func NewUpdateAddHTLC() *UpdateAddHTLC {
×
88
        return &UpdateAddHTLC{}
×
89
}
×
90

91
// A compile time check to ensure UpdateAddHTLC implements the lnwire.Message
92
// interface.
93
var _ Message = (*UpdateAddHTLC)(nil)
94

95
// Decode deserializes a serialized UpdateAddHTLC message stored in the passed
96
// io.Reader observing the specified protocol version.
97
//
98
// This is part of the lnwire.Message interface.
99
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
7,857✔
100
        // msgExtraData is a temporary variable used to read the message extra
7,857✔
101
        // data field from the reader.
7,857✔
102
        var msgExtraData ExtraOpaqueData
7,857✔
103

7,857✔
104
        if err := ReadElements(r,
7,857✔
105
                &c.ChanID,
7,857✔
106
                &c.ID,
7,857✔
107
                &c.Amount,
7,857✔
108
                c.PaymentHash[:],
7,857✔
109
                &c.Expiry,
7,857✔
110
                c.OnionBlob[:],
7,857✔
111
                &msgExtraData,
7,857✔
112
        ); err != nil {
7,864✔
113
                return err
7✔
114
        }
7✔
115

116
        // Extract TLV records from the extra data field.
117
        blindingRecord := c.BlindingPoint.Zero()
7,850✔
118

7,850✔
119
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
7,850✔
120
                msgExtraData, &blindingRecord,
7,850✔
121
        )
7,850✔
122
        if err != nil {
7,857✔
123
                return err
7✔
124
        }
7✔
125

126
        // Assign the parsed records back to the message.
127
        if parsed.Contains(blindingRecord.TlvType()) {
7,899✔
128
                c.BlindingPoint = tlv.SomeRecordT(blindingRecord)
56✔
129
        }
56✔
130

131
        c.CustomRecords = customRecords
7,843✔
132
        c.ExtraData = extraData
7,843✔
133

7,843✔
134
        return nil
7,843✔
135
}
136

137
// Encode serializes the target UpdateAddHTLC into the passed io.Writer
138
// observing the protocol version specified.
139
//
140
// This is part of the lnwire.Message interface.
141
func (c *UpdateAddHTLC) Encode(w *bytes.Buffer, pver uint32) error {
8,344✔
142
        if err := WriteChannelID(w, c.ChanID); err != nil {
8,344✔
143
                return err
×
144
        }
×
145

146
        if err := WriteUint64(w, c.ID); err != nil {
8,344✔
147
                return err
×
148
        }
×
149

150
        if err := WriteMilliSatoshi(w, c.Amount); err != nil {
8,344✔
151
                return err
×
152
        }
×
153

154
        if err := WriteBytes(w, c.PaymentHash[:]); err != nil {
8,344✔
155
                return err
×
156
        }
×
157

158
        if err := WriteUint32(w, c.Expiry); err != nil {
8,344✔
159
                return err
×
160
        }
×
161

162
        if err := WriteBytes(w, c.OnionBlob[:]); err != nil {
8,344✔
163
                return err
×
164
        }
×
165

166
        // Only include blinding point in extra data if present.
167
        var records []tlv.RecordProducer
8,344✔
168
        c.BlindingPoint.WhenSome(
8,344✔
169
                func(b tlv.RecordT[BlindingPointTlvType, *btcec.PublicKey]) {
8,401✔
170
                        records = append(records, &b)
57✔
171
                },
57✔
172
        )
173

174
        extraData, err := MergeAndEncode(records, c.ExtraData, c.CustomRecords)
8,344✔
175
        if err != nil {
8,345✔
176
                return err
1✔
177
        }
1✔
178

179
        return WriteBytes(w, extraData)
8,343✔
180
}
181

182
// MsgType returns the integer uniquely identifying this message type on the
183
// wire.
184
//
185
// This is part of the lnwire.Message interface.
186
func (c *UpdateAddHTLC) MsgType() MessageType {
11,363✔
187
        return MsgUpdateAddHTLC
11,363✔
188
}
11,363✔
189

190
// TargetChanID returns the channel id of the link for which this message is
191
// intended.
192
//
193
// NOTE: Part of peer.LinkUpdater interface.
UNCOV
194
func (c *UpdateAddHTLC) TargetChanID() ChannelID {
×
UNCOV
195
        return c.ChanID
×
UNCOV
196
}
×
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