• 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

64.0
/lnwire/update_fail_htlc.go
1
package lnwire
2

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

8
// OpaqueReason is an opaque encrypted byte slice that encodes the exact
9
// failure reason and additional some supplemental data. The contents of this
10
// slice can only be decrypted by the sender of the original HTLC.
11
type OpaqueReason []byte
12

13
// UpdateFailHTLC is sent by Alice to Bob in order to remove a previously added
14
// HTLC. Upon receipt of an UpdateFailHTLC the HTLC should be removed from the
15
// next commitment transaction, with the UpdateFailHTLC propagated backwards in
16
// the route to fully undo the HTLC.
17
type UpdateFailHTLC struct {
18
        // ChanID is the particular active channel that this
19
        // UpdateFailHTLC is bound to.
20
        ChanID ChannelID
21

22
        // ID references which HTLC on the remote node's commitment transaction
23
        // has timed out.
24
        ID uint64
25

26
        // Reason is an onion-encrypted blob that details why the HTLC was
27
        // failed. This blob is only fully decryptable by the initiator of the
28
        // HTLC message.
29
        Reason OpaqueReason
30

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

37
// A compile time check to ensure UpdateFailHTLC implements the lnwire.Message
38
// interface.
39
var _ Message = (*UpdateFailHTLC)(nil)
40

41
// Decode deserializes a serialized UpdateFailHTLC message stored in the passed
42
// io.Reader observing the specified protocol version.
43
//
44
// This is part of the lnwire.Message interface.
45
func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
570✔
46
        return ReadElements(r,
570✔
47
                &c.ChanID,
570✔
48
                &c.ID,
570✔
49
                &c.Reason,
570✔
50
                &c.ExtraData,
570✔
51
        )
570✔
52
}
570✔
53

54
// Encode serializes the target UpdateFailHTLC into the passed io.Writer observing
55
// the protocol version specified.
56
//
57
// This is part of the lnwire.Message interface.
58
func (c *UpdateFailHTLC) Encode(w *bytes.Buffer, pver uint32) error {
792✔
59
        if err := WriteChannelID(w, c.ChanID); err != nil {
792✔
60
                return err
×
61
        }
×
62

63
        if err := WriteUint64(w, c.ID); err != nil {
792✔
64
                return err
×
65
        }
×
66

67
        if err := WriteOpaqueReason(w, c.Reason); err != nil {
792✔
68
                return err
×
69
        }
×
70

71
        return WriteBytes(w, c.ExtraData)
792✔
72
}
73

74
// MsgType returns the integer uniquely identifying this message type on the
75
// wire.
76
//
77
// This is part of the lnwire.Message interface.
78
func (c *UpdateFailHTLC) MsgType() MessageType {
930✔
79
        return MsgUpdateFailHTLC
930✔
80
}
930✔
81

82
// TargetChanID returns the channel id of the link for which this message is
83
// intended.
84
//
85
// NOTE: Part of peer.LinkUpdater interface.
86
func (c *UpdateFailHTLC) TargetChanID() ChannelID {
×
87
        return c.ChanID
×
88
}
×
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