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

lightningnetwork / lnd / 12199391122

06 Dec 2024 01:10PM UTC coverage: 49.807% (-9.1%) from 58.933%
12199391122

push

github

web-flow
Merge pull request #9337 from Guayaba221/patch-1

chore: fix typo in ruby.md

100137 of 201051 relevant lines covered (49.81%)

2.07 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 {
4✔
48
        // Exit early if no budget config is set.
4✔
49
        if b == nil {
4✔
50
                return fmt.Errorf("no budget config set")
×
51
        }
×
52

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

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

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

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

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

92
        return nil
4✔
93
}
94

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

105
// DefaultSweeperConfig returns the default configuration for the sweeper.
106
func DefaultBudgetConfig() *BudgetConfig {
4✔
107
        return &BudgetConfig{
4✔
108
                ToLocalRatio:        DefaultBudgetRatio,
4✔
109
                AnchorCPFPRatio:     DefaultBudgetRatio,
4✔
110
                DeadlineHTLCRatio:   DefaultBudgetRatio,
4✔
111
                NoDeadlineHTLCRatio: DefaultBudgetRatio,
4✔
112
        }
4✔
113
}
4✔
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 {
4✔
120

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

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

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

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

136
        return budget
4✔
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