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

lightningnetwork / lnd / 12583319996

02 Jan 2025 01:38PM UTC coverage: 57.522% (-1.1%) from 58.598%
12583319996

Pull #9361

github

starius
fn/ContextGuard: use context.AfterFunc to wait

Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
Pull Request #9361: fn: optimize context guard

102587 of 178344 relevant lines covered (57.52%)

24734.33 hits per line

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

63.46
/lnwire/update_fulfill_htlc.go
1
package lnwire
2

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

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

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

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

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

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

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

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

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

51
// Decode deserializes a serialized UpdateFulfillHTLC message stored in the passed
52
// io.Reader observing the specified protocol version.
53
//
54
// This is part of the lnwire.Message interface.
55
func (c *UpdateFulfillHTLC) Decode(r io.Reader, pver uint32) error {
1,060✔
56
        // msgExtraData is a temporary variable used to read the message extra
1,060✔
57
        // data field from the reader.
1,060✔
58
        var msgExtraData ExtraOpaqueData
1,060✔
59

1,060✔
60
        if err := ReadElements(r,
1,060✔
61
                &c.ChanID,
1,060✔
62
                &c.ID,
1,060✔
63
                c.PaymentPreimage[:],
1,060✔
64
                &msgExtraData,
1,060✔
65
        ); err != nil {
1,064✔
66
                return err
4✔
67
        }
4✔
68

69
        // Extract custom records from the extra data field.
70
        customRecords, _, extraData, err := ParseAndExtractCustomRecords(
1,056✔
71
                msgExtraData,
1,056✔
72
        )
1,056✔
73
        if err != nil {
1,069✔
74
                return err
13✔
75
        }
13✔
76

77
        c.CustomRecords = customRecords
1,043✔
78
        c.ExtraData = extraData
1,043✔
79

1,043✔
80
        return nil
1,043✔
81
}
82

83
// Encode serializes the target UpdateFulfillHTLC into the passed io.Writer
84
// observing the protocol version specified.
85
//
86
// This is part of the lnwire.Message interface.
87
func (c *UpdateFulfillHTLC) Encode(w *bytes.Buffer, pver uint32) error {
1,502✔
88
        if err := WriteChannelID(w, c.ChanID); err != nil {
1,502✔
89
                return err
×
90
        }
×
91

92
        if err := WriteUint64(w, c.ID); err != nil {
1,502✔
93
                return err
×
94
        }
×
95

96
        if err := WriteBytes(w, c.PaymentPreimage[:]); err != nil {
1,502✔
97
                return err
×
98
        }
×
99

100
        // Combine the custom records and the extra data, then encode the
101
        // result as a byte slice.
102
        extraData, err := MergeAndEncode(nil, c.ExtraData, c.CustomRecords)
1,502✔
103
        if err != nil {
1,502✔
104
                return err
×
105
        }
×
106

107
        return WriteBytes(w, extraData)
1,502✔
108
}
109

110
// MsgType returns the integer uniquely identifying this message type on the
111
// wire.
112
//
113
// This is part of the lnwire.Message interface.
114
func (c *UpdateFulfillHTLC) MsgType() MessageType {
1,758✔
115
        return MsgUpdateFulfillHTLC
1,758✔
116
}
1,758✔
117

118
// TargetChanID returns the channel id of the link for which this message is
119
// intended.
120
//
121
// NOTE: Part of peer.LinkUpdater interface.
122
func (c *UpdateFulfillHTLC) TargetChanID() ChannelID {
×
123
        return c.ChanID
×
124
}
×
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