• 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

78.95
/lnwire/msat.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
const (
12
        // mSatScale is a value that's used to scale satoshis to milli-satoshis, and
13
        // the other way around.
14
        mSatScale uint64 = 1000
15

16
        // MaxMilliSatoshi is the maximum number of msats that can be expressed
17
        // in this data type.
18
        MaxMilliSatoshi = ^MilliSatoshi(0)
19
)
20

21
// MilliSatoshi are the native unit of the Lightning Network. A milli-satoshi
22
// is simply 1/1000th of a satoshi. There are 1000 milli-satoshis in a single
23
// satoshi. Within the network, all HTLC payments are denominated in
24
// milli-satoshis. As milli-satoshis aren't deliverable on the native
25
// blockchain, before settling to broadcasting, the values are rounded down to
26
// the nearest satoshi.
27
type MilliSatoshi uint64
28

29
// NewMSatFromSatoshis creates a new MilliSatoshi instance from a target amount
30
// of satoshis.
31
func NewMSatFromSatoshis(sat btcutil.Amount) MilliSatoshi {
3✔
32
        return MilliSatoshi(uint64(sat) * mSatScale)
3✔
33
}
3✔
34

35
// ToBTC converts the target MilliSatoshi amount to its corresponding value
36
// when expressed in BTC.
UNCOV
37
func (m MilliSatoshi) ToBTC() float64 {
×
UNCOV
38
        sat := m.ToSatoshis()
×
UNCOV
39
        return sat.ToBTC()
×
UNCOV
40
}
×
41

42
// ToSatoshis converts the target MilliSatoshi amount to satoshis. Simply, this
43
// sheds a factor of 1000 from the mSAT amount in order to convert it to SAT.
44
func (m MilliSatoshi) ToSatoshis() btcutil.Amount {
3✔
45
        return btcutil.Amount(uint64(m) / mSatScale)
3✔
46
}
3✔
47

48
// String returns the string representation of the mSAT amount.
49
func (m MilliSatoshi) String() string {
3✔
50
        return fmt.Sprintf("%v mSAT", uint64(m))
3✔
51
}
3✔
52

53
// TODO(roasbeef): extend with arithmetic operations?
54

55
// Record returns a TLV record that can be used to encode/decode a MilliSatoshi
56
// to/from a TLV stream.
57
func (m *MilliSatoshi) Record() tlv.Record {
3✔
58
        return tlv.MakeDynamicRecord(
3✔
59
                0, m, tlv.SizeBigSize(m), encodeMilliSatoshis,
3✔
60
                decodeMilliSatoshis,
3✔
61
        )
3✔
62
}
3✔
63

64
func encodeMilliSatoshis(w io.Writer, val interface{}, buf *[8]byte) error {
3✔
65
        if v, ok := val.(*MilliSatoshi); ok {
6✔
66
                bigSize := uint64(*v)
3✔
67

3✔
68
                return tlv.EBigSize(w, &bigSize, buf)
3✔
69
        }
3✔
70

71
        return tlv.NewTypeForEncodingErr(val, "lnwire.MilliSatoshi")
×
72
}
73

74
func decodeMilliSatoshis(r io.Reader, val interface{}, buf *[8]byte,
75
        l uint64) error {
3✔
76

3✔
77
        if v, ok := val.(*MilliSatoshi); ok {
6✔
78
                var bigSize uint64
3✔
79
                err := tlv.DBigSize(r, &bigSize, buf, l)
3✔
80
                if err != nil {
3✔
UNCOV
81
                        return err
×
UNCOV
82
                }
×
83

84
                *v = MilliSatoshi(bigSize)
3✔
85

3✔
86
                return nil
3✔
87
        }
88

89
        return tlv.NewTypeForDecodingErr(val, "lnwire.MilliSatoshi", l, l)
×
90
}
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