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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

45.71
/lnwire/update_fulfill_htlc.go
1
package lnwire
2

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

7
        "pgregory.net/rapid"
8
)
9

10
// UpdateFulfillHTLC is sent by Alice to Bob when she wishes to settle a
11
// particular HTLC referenced by its HTLCKey within a specific active channel
12
// referenced by ChannelPoint.  A subsequent CommitSig message will be sent by
13
// Alice to "lock-in" the removal of the specified HTLC, possible containing a
14
// batch signature covering several settled HTLC's.
15
type UpdateFulfillHTLC struct {
16
        // ChanID references an active channel which holds the HTLC to be
17
        // settled.
18
        ChanID ChannelID
19

20
        // ID denotes the exact HTLC stage within the receiving node's
21
        // commitment transaction to be removed.
22
        ID uint64
23

24
        // PaymentPreimage is the R-value preimage required to fully settle an
25
        // HTLC.
26
        PaymentPreimage [32]byte
27

28
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
29
        // intended for inclusion in the ExtraData field.
30
        CustomRecords CustomRecords
31

32
        // ExtraData is the set of data that was appended to this message to
33
        // fill out the full maximum transport message size. These fields can
34
        // be used to specify optional data such as custom TLV fields.
35
        ExtraData ExtraOpaqueData
36
}
37

38
// NewUpdateFulfillHTLC returns a new empty UpdateFulfillHTLC.
39
func NewUpdateFulfillHTLC(chanID ChannelID, id uint64,
40
        preimage [32]byte) *UpdateFulfillHTLC {
×
41

×
42
        return &UpdateFulfillHTLC{
×
43
                ChanID:          chanID,
×
44
                ID:              id,
×
45
                PaymentPreimage: preimage,
×
46
        }
×
47
}
×
48

49
// A compile time check to ensure UpdateFulfillHTLC implements the lnwire.Message
50
// interface.
51
var _ Message = (*UpdateFulfillHTLC)(nil)
52

53
// A compile time check to ensure UpdateFulfillHTLC implements the lnwire.SizeableMessage
54
// interface.
55
var _ SizeableMessage = (*UpdateFulfillHTLC)(nil)
56

57
// Decode deserializes a serialized UpdateFulfillHTLC message stored in the passed
58
// io.Reader observing the specified protocol version.
59
//
60
// This is part of the lnwire.Message interface.
61
func (c *UpdateFulfillHTLC) Decode(r io.Reader, pver uint32) error {
3✔
62
        // msgExtraData is a temporary variable used to read the message extra
3✔
63
        // data field from the reader.
3✔
64
        var msgExtraData ExtraOpaqueData
3✔
65

3✔
66
        if err := ReadElements(r,
3✔
67
                &c.ChanID,
3✔
68
                &c.ID,
3✔
69
                c.PaymentPreimage[:],
3✔
70
                &msgExtraData,
3✔
71
        ); err != nil {
3✔
UNCOV
72
                return err
×
UNCOV
73
        }
×
74

75
        // Extract custom records from the extra data field.
76
        customRecords, _, extraData, err := ParseAndExtractCustomRecords(
3✔
77
                msgExtraData,
3✔
78
        )
3✔
79
        if err != nil {
3✔
UNCOV
80
                return err
×
UNCOV
81
        }
×
82

83
        c.CustomRecords = customRecords
3✔
84
        c.ExtraData = extraData
3✔
85

3✔
86
        return nil
3✔
87
}
88

89
// Encode serializes the target UpdateFulfillHTLC into the passed io.Writer
90
// observing the protocol version specified.
91
//
92
// This is part of the lnwire.Message interface.
93
func (c *UpdateFulfillHTLC) Encode(w *bytes.Buffer, pver uint32) error {
3✔
94
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
95
                return err
×
96
        }
×
97

98
        if err := WriteUint64(w, c.ID); err != nil {
3✔
99
                return err
×
100
        }
×
101

102
        if err := WriteBytes(w, c.PaymentPreimage[:]); err != nil {
3✔
103
                return err
×
104
        }
×
105

106
        // Combine the custom records and the extra data, then encode the
107
        // result as a byte slice.
108
        extraData, err := MergeAndEncode(nil, c.ExtraData, c.CustomRecords)
3✔
109
        if err != nil {
3✔
110
                return err
×
111
        }
×
112

113
        return WriteBytes(w, extraData)
3✔
114
}
115

116
// MsgType returns the integer uniquely identifying this message type on the
117
// wire.
118
//
119
// This is part of the lnwire.Message interface.
120
func (c *UpdateFulfillHTLC) MsgType() MessageType {
3✔
121
        return MsgUpdateFulfillHTLC
3✔
122
}
3✔
123

124
// SerializedSize returns the serialized size of the message in bytes.
125
//
126
// This is part of the lnwire.SizeableMessage interface.
NEW
127
func (c *UpdateFulfillHTLC) SerializedSize() (uint32, error) {
×
NEW
128
        return MessageSerializedSize(c)
×
NEW
129
}
×
130

131
// TargetChanID returns the channel id of the link for which this message is
132
// intended.
133
//
134
// NOTE: Part of peer.LinkUpdater interface.
135
func (c *UpdateFulfillHTLC) TargetChanID() ChannelID {
3✔
136
        return c.ChanID
3✔
137
}
3✔
138

139
// A compile time check to ensure UpdateFulfillHTLC implements the TestMessage interface.
140
var _ TestMessage = (*UpdateFulfillHTLC)(nil)
141

142
// RandTestMessage populates the message with random data suitable for testing.
143
// It uses the rapid testing framework to generate random values.
144
//
145
// This is part of the TestMessage interface.
NEW
146
func (c *UpdateFulfillHTLC) RandTestMessage(t *rapid.T) Message {
×
NEW
147
        msg := &UpdateFulfillHTLC{
×
NEW
148
                ChanID:          RandChannelID(t),
×
NEW
149
                ID:              rapid.Uint64().Draw(t, "id"),
×
NEW
150
                PaymentPreimage: RandPaymentPreimage(t),
×
NEW
151
        }
×
NEW
152

×
NEW
153
        cr, ignoreRecords := RandCustomRecords(t, nil, true)
×
NEW
154
        msg.CustomRecords = cr
×
NEW
155

×
NEW
156
        randData := RandExtraOpaqueData(t, ignoreRecords)
×
NEW
157
        if len(randData) > 0 {
×
NEW
158
                msg.ExtraData = randData
×
NEW
159
        }
×
160

NEW
161
        return msg
×
162
}
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