• 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

0.0
/lncfg/healthcheck.go
1
package lncfg
2

3
import (
4
        "errors"
5
        "fmt"
6
        "time"
7
)
8

9
var (
10
        // MinHealthCheckInterval is the minimum interval we allow between
11
        // health checks.
12
        MinHealthCheckInterval = time.Minute
13

14
        // MinHealthCheckTimeout is the minimum timeout we allow for health
15
        // check calls.
16
        MinHealthCheckTimeout = time.Second
17

18
        // MinHealthCheckBackoff is the minimum back off we allow between health
19
        // check retries.
20
        MinHealthCheckBackoff = time.Second
21
)
22

23
// HealthCheckConfig contains the configuration for the different health checks
24
// the lnd runs.
25
//
26
//nolint:ll
27
type HealthCheckConfig struct {
28
        ChainCheck *CheckConfig `group:"chainbackend" namespace:"chainbackend"`
29

30
        DiskCheck *DiskCheckConfig `group:"diskspace" namespace:"diskspace"`
31

32
        TLSCheck *CheckConfig `group:"tls" namespace:"tls"`
33

34
        TorConnection *CheckConfig `group:"torconnection" namespace:"torconnection"`
35

36
        RemoteSigner *CheckConfig `group:"remotesigner" namespace:"remotesigner"`
37

38
        LeaderCheck *CheckConfig `group:"leader" namespace:"leader"`
39
}
40

41
// Validate checks the values configured for our health checks.
42
func (h *HealthCheckConfig) Validate() error {
×
43
        if err := h.ChainCheck.validate("chain backend"); err != nil {
×
44
                return err
×
45
        }
×
46

47
        if err := h.DiskCheck.validate("disk space"); err != nil {
×
48
                return err
×
49
        }
×
50

51
        if err := h.TLSCheck.validate("tls"); err != nil {
×
52
                return err
×
53
        }
×
54

55
        if h.DiskCheck.RequiredRemaining < 0 ||
×
56
                h.DiskCheck.RequiredRemaining >= 1 {
×
57

×
58
                return errors.New("disk required ratio must be in [0:1)")
×
59
        }
×
60

61
        if err := h.TorConnection.validate("tor connection"); err != nil {
×
62
                return err
×
63
        }
×
64

65
        return nil
×
66
}
67

68
type CheckConfig struct {
69
        Interval time.Duration `long:"interval" description:"How often to run a health check."`
70

71
        Attempts int `long:"attempts" description:"The number of calls we will make for the check before failing. Set this value to 0 to disable a check."`
72

73
        Timeout time.Duration `long:"timeout" description:"The amount of time we allow the health check to take before failing due to timeout."`
74

75
        Backoff time.Duration `long:"backoff" description:"The amount of time to back-off between failed health checks."`
76
}
77

78
// validate checks the values in a health check config entry if it is enabled.
79
func (c *CheckConfig) validate(name string) error {
×
80
        if c.Attempts == 0 {
×
81
                return nil
×
82
        }
×
83

84
        if c.Backoff < MinHealthCheckBackoff {
×
85
                return fmt.Errorf("%v backoff: %v below minimum: %v", name,
×
86
                        c.Backoff, MinHealthCheckBackoff)
×
87
        }
×
88

89
        if c.Timeout < MinHealthCheckTimeout {
×
90
                return fmt.Errorf("%v timeout: %v below minimum: %v", name,
×
91
                        c.Timeout, MinHealthCheckTimeout)
×
92
        }
×
93

94
        if c.Interval < MinHealthCheckInterval {
×
95
                return fmt.Errorf("%v interval: %v below minimum: %v", name,
×
96
                        c.Interval, MinHealthCheckInterval)
×
97
        }
×
98

99
        return nil
×
100
}
101

102
// DiskCheckConfig contains configuration for ensuring that our node has
103
// sufficient disk space.
104
type DiskCheckConfig struct {
105
        RequiredRemaining float64 `long:"diskrequired" description:"The minimum ratio of free disk space to total capacity that we allow before shutting lnd down safely."`
106

107
        *CheckConfig
108
}
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