• 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

29.17
/lncfg/sweeper.go
1
package lncfg
2

3
import (
4
        "fmt"
5
        "time"
6

7
        "github.com/lightningnetwork/lnd/contractcourt"
8
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
9
        "github.com/lightningnetwork/lnd/sweep"
10
)
11

12
const (
13
        // MaxFeeRateFloor is the smallest config value allowed for the max fee
14
        // rate in sat/vb.
15
        MaxFeeRateFloor chainfee.SatPerVByte = 100
16

17
        // MaxAllowedFeeRate is the largest fee rate in sat/vb that we allow
18
        // when configuring the MaxFeeRate.
19
        MaxAllowedFeeRate = 10_000
20
)
21

22
//nolint:ll
23
type Sweeper struct {
24
        BatchWindowDuration time.Duration        `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input." hidden:"true"`
25
        MaxFeeRate          chainfee.SatPerVByte `long:"maxfeerate" description:"Maximum fee rate in sat/vb that the sweeper is allowed to use when sweeping funds, the fee rate derived from budgets are capped at this value. Setting this value too low can result in transactions not being confirmed in time, causing HTLCs to expire hence potentially losing funds."`
26

27
        NoDeadlineConfTarget uint32 `long:"nodeadlineconftarget" description:"The conf target to use when sweeping non-time-sensitive outputs. This is useful for sweeping outputs that are not time-sensitive, and can be swept at a lower fee rate."`
28

29
        Budget *contractcourt.BudgetConfig `group:"sweeper.budget" namespace:"budget" long:"budget" description:"An optional config group that's used for the automatic sweep fee estimation. The Budget config gives options to limits ones fee exposure when sweeping unilateral close outputs and the fee rate calculated from budgets is capped at sweeper.maxfeerate. Check the budget config options for more details."`
30
}
31

32
// Validate checks the values configured for the sweeper.
33
func (s *Sweeper) Validate() error {
×
34
        if s.BatchWindowDuration < 0 {
×
35
                return fmt.Errorf("batchwindowduration must be positive")
×
36
        }
×
37

38
        // We require the max fee rate to be at least 100 sat/vbyte.
39
        if s.MaxFeeRate < MaxFeeRateFloor {
×
40
                return fmt.Errorf("maxfeerate must be >= 100 sat/vb")
×
41
        }
×
42

43
        // We require the max fee rate to be no greater than 10_000 sat/vbyte.
44
        if s.MaxFeeRate > MaxAllowedFeeRate {
×
45
                return fmt.Errorf("maxfeerate must be <= 10000 sat/vb")
×
46
        }
×
47

48
        // Make sure the conf target is at least 144 blocks (1 day).
49
        if s.NoDeadlineConfTarget < 144 {
×
50
                return fmt.Errorf("nodeadlineconftarget must be at least 144")
×
51
        }
×
52

53
        // Validate the budget configuration.
54
        if err := s.Budget.Validate(); err != nil {
×
55
                return fmt.Errorf("invalid budget config: %w", err)
×
56
        }
×
57

58
        return nil
×
59
}
60

61
// DefaultSweeperConfig returns the default configuration for the sweeper.
62
func DefaultSweeperConfig() *Sweeper {
1✔
63
        return &Sweeper{
1✔
64
                MaxFeeRate:           sweep.DefaultMaxFeeRate,
1✔
65
                NoDeadlineConfTarget: uint32(sweep.DefaultDeadlineDelta),
1✔
66
                Budget:               contractcourt.DefaultBudgetConfig(),
1✔
67
        }
1✔
68
}
1✔
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