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

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

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

70.83
/lnwire/stfu.go
1
package lnwire
2

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

8
// Stfu is a message that is sent to lock the channel state prior to some other
9
// interactive protocol where channel updates need to be paused.
10
type Stfu struct {
11
        // ChanID identifies which channel needs to be frozen.
12
        ChanID ChannelID
13

14
        // Initiator is a byte that identifies whether we are the initiator of
15
        // this process.
16
        Initiator bool
17

18
        // ExtraData is the set of data that was appended to this message to
19
        // fill out the full maximum transport message size. These fields can
20
        // be used to specify optional data such as custom TLV fields.
21
        ExtraData ExtraOpaqueData
22
}
23

24
// A compile time check to ensure Stfu implements the lnwire.Message interface.
25
var _ Message = (*Stfu)(nil)
26

27
// Encode serializes the target Stfu into the passed io.Writer.
28
// Serialization will observe the rules defined by the passed protocol version.
29
//
30
// This is a part of the lnwire.Message interface.
31
func (s *Stfu) Encode(w *bytes.Buffer, _ uint32) error {
115✔
32
        if err := WriteChannelID(w, s.ChanID); err != nil {
115✔
33
                return err
×
34
        }
×
35

36
        if err := WriteBool(w, s.Initiator); err != nil {
115✔
37
                return err
×
38
        }
×
39

40
        return WriteBytes(w, s.ExtraData)
115✔
41
}
42

43
// Decode deserializes the serialized Stfu stored in the passed io.Reader
44
// into the target Stfu using the deserialization rules defined by the
45
// passed protocol version.
46
//
47
// This is a part of the lnwire.Message interface.
48
func (s *Stfu) Decode(r io.Reader, _ uint32) error {
133✔
49
        if err := ReadElements(
133✔
50
                r, &s.ChanID, &s.Initiator, &s.ExtraData,
133✔
51
        ); err != nil {
136✔
52
                return err
3✔
53
        }
3✔
54

55
        // This is required to pass the fuzz test round trip equality check.
56
        if len(s.ExtraData) == 0 {
183✔
57
                s.ExtraData = nil
53✔
58
        }
53✔
59

60
        return nil
130✔
61
}
62

63
// MsgType returns the MessageType code which uniquely identifies this message
64
// as a Stfu on the wire.
65
//
66
// This is part of the lnwire.Message interface.
67
func (s *Stfu) MsgType() MessageType {
119✔
68
        return MsgStfu
119✔
69
}
119✔
70

71
// A compile time check to ensure Stfu implements the
72
// lnwire.LinkUpdater interface.
73
var _ LinkUpdater = (*Stfu)(nil)
74

75
// TargetChanID returns the channel id of the link for which this message is
76
// intended.
77
//
78
// NOTE: Part of peer.LinkUpdater interface.
79
func (s *Stfu) TargetChanID() ChannelID {
×
80
        return s.ChanID
×
81
}
×
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