• 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

34.69
/htlcswitch/hodl/flags.go
1
package hodl
2

3
import "fmt"
4

5
// MaskNone represents the empty Mask, in which no breakpoints are
6
// active.
7
const MaskNone = Mask(0)
8

9
type (
10
        // Flag represents a single breakpoint where an HTLC should be dropped
11
        // during forwarding. Flags can be composed into a Mask to express more
12
        // complex combinations.
13
        Flag uint32
14

15
        // Mask is a bitvector combining multiple Flags that can be queried to
16
        // see which breakpoints are active.
17
        Mask uint32
18
)
19

20
const (
21
        // ExitSettle drops an incoming ADD for which we are the exit node,
22
        // before processing in the link.
23
        ExitSettle Flag = 1 << iota
24

25
        // AddIncoming drops an incoming ADD before processing if we are not
26
        // the exit node.
27
        AddIncoming
28

29
        // SettleIncoming drops an incoming SETTLE before processing if we
30
        // are not the exit node.
31
        SettleIncoming
32

33
        // FailIncoming drops an incoming FAIL before processing if we are
34
        // not the exit node.
35
        FailIncoming
36

37
        // TODO(conner): add  modes for switch breakpoints
38

39
        // AddOutgoing drops an outgoing ADD before it is added to the
40
        // in-memory commitment state of the link.
41
        AddOutgoing
42

43
        // SettleOutgoing drops an SETTLE before it is added to the
44
        // in-memory commitment state of the link.
45
        SettleOutgoing
46

47
        // FailOutgoing drops an outgoing FAIL before is is added to the
48
        // in-memory commitment state of the link.
49
        FailOutgoing
50

51
        // Commit drops all HTLC after any outgoing circuits have been
52
        // opened, but before the in-memory commitment state is persisted.
53
        Commit
54

55
        // BogusSettle attempts to settle back any incoming HTLC for which we
56
        // are the exit node with a bogus preimage.
57
        BogusSettle
58
)
59

60
// String returns a human-readable identifier for a given Flag.
61
func (f Flag) String() string {
111✔
62
        switch f {
111✔
63
        case ExitSettle:
107✔
64
                return "ExitSettle"
107✔
65
        case AddIncoming:
×
66
                return "AddIncoming"
×
67
        case SettleIncoming:
×
68
                return "SettleIncoming"
×
69
        case FailIncoming:
×
70
                return "FailIncoming"
×
71
        case AddOutgoing:
×
72
                return "AddOutgoing"
×
73
        case SettleOutgoing:
×
74
                return "SettleOutgoing"
×
75
        case FailOutgoing:
×
76
                return "FailOutgoing"
×
77
        case Commit:
4✔
78
                return "Commit"
4✔
79
        case BogusSettle:
×
80
                return "BogusSettle"
×
81
        default:
×
82
                return "UnknownHodlFlag"
×
83
        }
84
}
85

86
// Warning generates a warning message to log if a particular breakpoint is
87
// triggered during execution.
88
func (f Flag) Warning() string {
111✔
89
        var msg string
111✔
90
        switch f {
111✔
91
        case ExitSettle:
107✔
92
                msg = "will not attempt to settle ADD with sender"
107✔
93
        case AddIncoming:
×
94
                msg = "will not attempt to forward ADD to switch"
×
95
        case SettleIncoming:
×
96
                msg = "will not attempt to forward SETTLE to switch"
×
97
        case FailIncoming:
×
98
                msg = "will not attempt to forward FAIL to switch"
×
99
        case AddOutgoing:
×
100
                msg = "will not update channel state with downstream ADD"
×
101
        case SettleOutgoing:
×
102
                msg = "will not update channel state with downstream SETTLE"
×
103
        case FailOutgoing:
×
104
                msg = "will not update channel state with downstream FAIL"
×
105
        case Commit:
4✔
106
                msg = "will not commit pending channel updates"
4✔
107
        case BogusSettle:
×
108
                msg = "will settle HTLC with bogus preimage"
×
109
        default:
×
110
                msg = "incorrect hodl flag usage"
×
111
        }
112

113
        return fmt.Sprintf("%s mode enabled -- %s", f, msg)
111✔
114
}
115

116
// Mask returns the Mask consisting solely of this Flag.
117
func (f Flag) Mask() Mask {
5✔
118
        return Mask(f)
5✔
119
}
5✔
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