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

lightningnetwork / lnd / 15951470896

29 Jun 2025 04:23AM UTC coverage: 67.594% (-0.01%) from 67.606%
15951470896

Pull #9751

github

web-flow
Merge 599d9b051 into 6290edf14
Pull Request #9751: multi: update Go to 1.23.10 and update some packages

135088 of 199851 relevant lines covered (67.59%)

21909.44 hits per line

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

92.68
/lnwallet/chainfee/rates.go
1
package chainfee
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/blockchain"
7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/lntypes"
9
)
10

11
const (
12
        // FeePerKwFloor is the lowest fee rate in sat/kw that we should use for
13
        // estimating transaction fees before signing.
14
        FeePerKwFloor SatPerKWeight = 253
15

16
        // AbsoluteFeePerKwFloor is the lowest fee rate in sat/kw of a
17
        // transaction that we should ever _create_. This is the equivalent
18
        // of 1 sat/byte in sat/kw.
19
        AbsoluteFeePerKwFloor SatPerKWeight = 250
20
)
21

22
// SatPerVByte represents a fee rate in sat/vbyte.
23
type SatPerVByte btcutil.Amount
24

25
// FeePerKWeight converts the current fee rate from sat/vb to sat/kw.
26
func (s SatPerVByte) FeePerKWeight() SatPerKWeight {
22✔
27
        return SatPerKWeight(s * 1000 / blockchain.WitnessScaleFactor)
22✔
28
}
22✔
29

30
// FeePerKVByte converts the current fee rate from sat/vb to sat/kvb.
31
func (s SatPerVByte) FeePerKVByte() SatPerKVByte {
1✔
32
        return SatPerKVByte(s * 1000)
1✔
33
}
1✔
34

35
// String returns a human-readable string of the fee rate.
36
func (s SatPerVByte) String() string {
4✔
37
        return fmt.Sprintf("%v sat/vb", int64(s))
4✔
38
}
4✔
39

40
// SatPerKVByte represents a fee rate in sat/kb.
41
type SatPerKVByte btcutil.Amount
42

43
// FeeForVSize calculates the fee resulting from this fee rate and the given
44
// vsize in vbytes.
45
func (s SatPerKVByte) FeeForVSize(vbytes lntypes.VByte) btcutil.Amount {
234✔
46
        return btcutil.Amount(s) * btcutil.Amount(vbytes) / 1000
234✔
47
}
234✔
48

49
// FeePerKWeight converts the current fee rate from sat/kb to sat/kw.
50
func (s SatPerKVByte) FeePerKWeight() SatPerKWeight {
224✔
51
        return SatPerKWeight(s / blockchain.WitnessScaleFactor)
224✔
52
}
224✔
53

54
// String returns a human-readable string of the fee rate.
55
func (s SatPerKVByte) String() string {
3✔
56
        return fmt.Sprintf("%v sat/kvb", int64(s))
3✔
57
}
3✔
58

59
// SatPerKWeight represents a fee rate in sat/kw.
60
type SatPerKWeight btcutil.Amount
61

62
// NewSatPerKWeight creates a new fee rate in sat/kw.
63
func NewSatPerKWeight(fee btcutil.Amount, wu lntypes.WeightUnit) SatPerKWeight {
14✔
64
        return SatPerKWeight(fee.MulF64(1000 / float64(wu)))
14✔
65
}
14✔
66

67
// FeeForWeight calculates the fee resulting from this fee rate and the given
68
// weight in weight units (wu).
69
func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount {
229,263✔
70
        // The resulting fee is rounded down, as specified in BOLT#03.
229,263✔
71
        return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
229,263✔
72
}
229,263✔
73

74
// FeeForWeightRoundUp calculates the fee resulting from this fee rate and the
75
// given weight in weight units (wu), rounding up to the nearest satoshi.
76
func (s SatPerKWeight) FeeForWeightRoundUp(
77
        wu lntypes.WeightUnit) btcutil.Amount {
1✔
78

1✔
79
        return (btcutil.Amount(s)*btcutil.Amount(wu) + 999) / 1000
1✔
80
}
1✔
81

82
// FeeForVByte calculates the fee resulting from this fee rate and the given
83
// size in vbytes (vb).
84
func (s SatPerKWeight) FeeForVByte(vb lntypes.VByte) btcutil.Amount {
×
85
        return s.FeePerKVByte().FeeForVSize(vb)
×
86
}
×
87

88
// FeePerKVByte converts the current fee rate from sat/kw to sat/kb.
89
func (s SatPerKWeight) FeePerKVByte() SatPerKVByte {
535✔
90
        return SatPerKVByte(s * blockchain.WitnessScaleFactor)
535✔
91
}
535✔
92

93
// FeePerVByte converts the current fee rate from sat/kw to sat/vb.
94
func (s SatPerKWeight) FeePerVByte() SatPerVByte {
61✔
95
        return SatPerVByte(s * blockchain.WitnessScaleFactor / 1000)
61✔
96
}
61✔
97

98
// String returns a human-readable string of the fee rate.
99
func (s SatPerKWeight) String() string {
37✔
100
        return fmt.Sprintf("%v sat/kw", int64(s))
37✔
101
}
37✔
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