• 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

50.0
/lncfg/wtclient.go
1
package lncfg
2

3
import (
4
        "fmt"
5

6
        "github.com/lightningnetwork/lnd/watchtower/wtclient"
7
        "github.com/lightningnetwork/lnd/watchtower/wtpolicy"
8
)
9

10
// WtClient holds the configuration options for the daemon's watchtower client.
11
//
12
//nolint:ll
13
type WtClient struct {
14
        // Active determines whether a watchtower client should be created to
15
        // back up channel states with registered watchtowers.
16
        Active bool `long:"active" description:"Whether the daemon should use private watchtowers to back up revoked channel states."`
17

18
        // SweepFeeRate specifies the fee rate in sat/byte to be used when
19
        // constructing justice transactions sent to the tower.
20
        SweepFeeRate uint64 `long:"sweep-fee-rate" description:"Specifies the fee rate in sat/byte to be used when constructing justice transactions sent to the watchtower."`
21

22
        // SessionCloseRange is the range over which to choose a random number
23
        // of blocks to wait after the last channel of a session is closed
24
        // before sending the DeleteSession message to the tower server.
25
        SessionCloseRange uint32 `long:"session-close-range" description:"The range over which to choose a random number of blocks to wait after the last channel of a session is closed before sending the DeleteSession message to the tower server. Set to 1 for no delay."`
26

27
        // MaxTasksInMemQueue is the maximum number of back-up tasks that should
28
        // be queued in memory before overflowing to disk.
29
        MaxTasksInMemQueue uint64 `long:"max-tasks-in-mem-queue" description:"The maximum number of updates that should be queued in memory before overflowing to disk."`
30

31
        // MaxUpdates is the maximum number of updates to be backed up in a
32
        // single tower sessions.
33
        MaxUpdates uint16 `long:"max-updates" description:"The maximum number of updates to be backed up in a single session."`
34
}
35

36
// DefaultWtClientCfg returns the WtClient config struct with some default
37
// values populated.
38
func DefaultWtClientCfg() *WtClient {
1✔
39
        // The sweep fee rate used internally by the tower client is in sats/kw
1✔
40
        // but the config exposed to the user is in sats/byte, so we convert the
1✔
41
        // default here before exposing it to the user.
1✔
42
        sweepSatsPerVB := wtpolicy.DefaultSweepFeeRate.FeePerVByte()
1✔
43
        sweepFeeRate := uint64(sweepSatsPerVB)
1✔
44

1✔
45
        return &WtClient{
1✔
46
                SweepFeeRate:       sweepFeeRate,
1✔
47
                SessionCloseRange:  wtclient.DefaultSessionCloseRange,
1✔
48
                MaxTasksInMemQueue: wtclient.DefaultMaxTasksInMemQueue,
1✔
49
                MaxUpdates:         wtpolicy.DefaultMaxUpdates,
1✔
50
        }
1✔
51
}
1✔
52

53
// Validate ensures the user has provided a valid configuration.
54
//
55
// NOTE: Part of the Validator interface.
56
func (c *WtClient) Validate() error {
×
57
        if c.SweepFeeRate == 0 {
×
58
                return fmt.Errorf("sweep-fee-rate must be non-zero")
×
59
        }
×
60

61
        if c.MaxUpdates == 0 {
×
62
                return fmt.Errorf("max-updates must be non-zero")
×
63
        }
×
64

65
        if c.MaxTasksInMemQueue == 0 {
×
66
                return fmt.Errorf("max-tasks-in-mem-queue must be non-zero")
×
67
        }
×
68

69
        if c.SessionCloseRange == 0 {
×
70
                return fmt.Errorf("session-close-range must be non-zero")
×
71
        }
×
72

73
        return nil
×
74
}
75

76
// Compile-time constraint to ensure WtClient implements the Validator
77
// interface.
78
var _ Validator = (*WtClient)(nil)
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