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

lightningnetwork / lnd / 13566028875

27 Feb 2025 12:09PM UTC coverage: 49.396% (-9.4%) from 58.748%
13566028875

Pull #9555

github

ellemouton
graph/db: populate the graph cache in Start instead of during construction

In this commit, we move the graph cache population logic out of the
ChannelGraph constructor and into its Start method instead.
Pull Request #9555: graph: extract cache from CRUD [6]

34 of 54 new or added lines in 4 files covered. (62.96%)

27464 existing lines in 436 files now uncovered.

101095 of 204664 relevant lines covered (49.4%)

1.54 hits per line

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

55.56
/contractcourt/config.go
1
package contractcourt
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
)
8

9
const (
10
        // MinBudgetValue is the minimal budget that we allow when configuring
11
        // the budget used in sweeping outputs. The actual budget can be lower
12
        // if the user decides to NOT set this value.
13
        //
14
        // NOTE: This value is chosen so the linear fee function can increase
15
        // at least 1 sat/kw per block.
16
        MinBudgetValue btcutil.Amount = 1008
17

18
        // MinBudgetRatio is the minimal ratio that we allow when configuring
19
        // the budget ratio used in sweeping outputs.
20
        MinBudgetRatio = 0.001
21

22
        // DefaultBudgetRatio defines a default budget ratio to be used when
23
        // sweeping inputs. This is a large value, which is fine as the final
24
        // fee rate is capped at the max fee rate configured.
25
        DefaultBudgetRatio = 0.5
26
)
27

28
// BudgetConfig is a struct that holds the configuration when offering outputs
29
// to the sweeper.
30
//
31
//nolint:ll
32
type BudgetConfig struct {
33
        ToLocal      btcutil.Amount `long:"tolocal" description:"The amount in satoshis to allocate as the budget to pay fees when sweeping the to_local output. If set, the budget calculated using the ratio (if set) will be capped at this value."`
34
        ToLocalRatio float64        `long:"tolocalratio" description:"The ratio of the value in to_local output to allocate as the budget to pay fees when sweeping it."`
35

36
        AnchorCPFP      btcutil.Amount `long:"anchorcpfp" description:"The amount in satoshis to allocate as the budget to pay fees when CPFPing a force close tx using the anchor output. If set, the budget calculated using the ratio (if set) will be capped at this value."`
37
        AnchorCPFPRatio float64        `long:"anchorcpfpratio" description:"The ratio of a special value to allocate as the budget to pay fees when CPFPing a force close tx using the anchor output. The special value is the sum of all time-sensitive HTLCs on this commitment subtracted by their budgets."`
38

39
        DeadlineHTLC      btcutil.Amount `long:"deadlinehtlc" description:"The amount in satoshis to allocate as the budget to pay fees when sweeping a time-sensitive (first-level) HTLC. If set, the budget calculated using the ratio (if set) will be capped at this value."`
40
        DeadlineHTLCRatio float64        `long:"deadlinehtlcratio" description:"The ratio of the value in a time-sensitive (first-level) HTLC to allocate as the budget to pay fees when sweeping it."`
41

42
        NoDeadlineHTLC      btcutil.Amount `long:"nodeadlinehtlc" description:"The amount in satoshis to allocate as the budget to pay fees when sweeping a non-time-sensitive (second-level) HTLC. If set, the budget calculated using the ratio (if set) will be capped at this value."`
43
        NoDeadlineHTLCRatio float64        `long:"nodeadlinehtlcratio" description:"The ratio of the value in a non-time-sensitive (second-level) HTLC to allocate as the budget to pay fees when sweeping it."`
44
}
45

46
// Validate checks the budget configuration for any invalid values.
47
func (b *BudgetConfig) Validate() error {
3✔
48
        // Exit early if no budget config is set.
3✔
49
        if b == nil {
3✔
UNCOV
50
                return fmt.Errorf("no budget config set")
×
UNCOV
51
        }
×
52

53
        // Sanity check all fields.
54
        if b.ToLocal != 0 && b.ToLocal < MinBudgetValue {
3✔
UNCOV
55
                return fmt.Errorf("tolocal must be at least %v",
×
UNCOV
56
                        MinBudgetValue)
×
UNCOV
57
        }
×
58
        if b.ToLocalRatio != 0 && b.ToLocalRatio < MinBudgetRatio {
3✔
UNCOV
59
                return fmt.Errorf("tolocalratio must be at least %v",
×
UNCOV
60
                        MinBudgetRatio)
×
UNCOV
61
        }
×
62

63
        if b.AnchorCPFP != 0 && b.AnchorCPFP < MinBudgetValue {
3✔
UNCOV
64
                return fmt.Errorf("anchorcpfp must be at least %v",
×
UNCOV
65
                        MinBudgetValue)
×
UNCOV
66
        }
×
67
        if b.AnchorCPFPRatio != 0 && b.AnchorCPFPRatio < MinBudgetRatio {
3✔
UNCOV
68
                return fmt.Errorf("anchorcpfpratio must be at least %v",
×
UNCOV
69
                        MinBudgetRatio)
×
UNCOV
70
        }
×
71

72
        if b.DeadlineHTLC != 0 && b.DeadlineHTLC < MinBudgetValue {
3✔
UNCOV
73
                return fmt.Errorf("deadlinehtlc must be at least %v",
×
UNCOV
74
                        MinBudgetValue)
×
UNCOV
75
        }
×
76
        if b.DeadlineHTLCRatio != 0 && b.DeadlineHTLCRatio < MinBudgetRatio {
3✔
UNCOV
77
                return fmt.Errorf("deadlinehtlcratio must be at least %v",
×
UNCOV
78
                        MinBudgetRatio)
×
UNCOV
79
        }
×
80

81
        if b.NoDeadlineHTLC != 0 && b.NoDeadlineHTLC < MinBudgetValue {
3✔
UNCOV
82
                return fmt.Errorf("nodeadlinehtlc must be at least %v",
×
UNCOV
83
                        MinBudgetValue)
×
UNCOV
84
        }
×
85
        if b.NoDeadlineHTLCRatio != 0 &&
3✔
86
                b.NoDeadlineHTLCRatio < MinBudgetRatio {
3✔
UNCOV
87

×
UNCOV
88
                return fmt.Errorf("nodeadlinehtlcratio must be at least %v",
×
UNCOV
89
                        MinBudgetRatio)
×
UNCOV
90
        }
×
91

92
        return nil
3✔
93
}
94

95
// String returns a human-readable description of the budget configuration.
96
func (b *BudgetConfig) String() string {
3✔
97
        return fmt.Sprintf("tolocal=%v tolocalratio=%v anchorcpfp=%v "+
3✔
98
                "anchorcpfpratio=%v deadlinehtlc=%v deadlinehtlcratio=%v "+
3✔
99
                "nodeadlinehtlc=%v nodeadlinehtlcratio=%v",
3✔
100
                b.ToLocal, b.ToLocalRatio, b.AnchorCPFP, b.AnchorCPFPRatio,
3✔
101
                b.DeadlineHTLC, b.DeadlineHTLCRatio, b.NoDeadlineHTLC,
3✔
102
                b.NoDeadlineHTLCRatio)
3✔
103
}
3✔
104

105
// DefaultSweeperConfig returns the default configuration for the sweeper.
106
func DefaultBudgetConfig() *BudgetConfig {
3✔
107
        return &BudgetConfig{
3✔
108
                ToLocalRatio:        DefaultBudgetRatio,
3✔
109
                AnchorCPFPRatio:     DefaultBudgetRatio,
3✔
110
                DeadlineHTLCRatio:   DefaultBudgetRatio,
3✔
111
                NoDeadlineHTLCRatio: DefaultBudgetRatio,
3✔
112
        }
3✔
113
}
3✔
114

115
// calculateBudget takes an output value, a configured ratio and budget value,
116
// and returns the budget to use for sweeping the output. If the budget value
117
// is set, it will be used as cap.
118
func calculateBudget(value btcutil.Amount, ratio float64,
119
        max btcutil.Amount) btcutil.Amount {
3✔
120

3✔
121
        // If ratio is not set, using the default value.
3✔
122
        if ratio == 0 {
3✔
UNCOV
123
                ratio = DefaultBudgetRatio
×
UNCOV
124
        }
×
125

126
        budget := value.MulF64(ratio)
3✔
127

3✔
128
        log.Tracef("Calculated budget=%v using value=%v, ratio=%v, cap=%v",
3✔
129
                budget, value, ratio, max)
3✔
130

3✔
131
        if max != 0 && budget > max {
3✔
UNCOV
132
                log.Debugf("Calculated budget=%v is capped at %v", budget, max)
×
UNCOV
133
                return max
×
UNCOV
134
        }
×
135

136
        return budget
3✔
137
}
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