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

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

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

77.78
/channeldb/migration29/migration.go
1
package migration29
2

3
import (
4
        "bytes"
5

6
        "github.com/btcsuite/btcd/wire"
7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
var (
11
        // outpointBucket is the bucket that stores the set of outpoints we
12
        // know about.
13
        outpointBucket = []byte("outpoint-bucket")
14

15
        // chanIDBucket is the bucket that stores the set of ChannelID's we
16
        // know about.
17
        chanIDBucket = []byte("chan-id-bucket")
18
)
19

20
// MigrateChanID populates the ChannelID index by using the set of outpoints
21
// retrieved from the outpoint bucket.
22
func MigrateChanID(tx kvdb.RwTx) error {
1✔
23
        log.Info("Populating ChannelID index")
1✔
24

1✔
25
        // First we'll retrieve the set of outpoints we know about.
1✔
26
        ops, err := fetchOutPoints(tx)
1✔
27
        if err != nil {
1✔
28
                return err
×
29
        }
×
30

31
        return populateChanIDIndex(tx, ops)
1✔
32
}
33

34
// fetchOutPoints loops through the outpointBucket and returns each stored
35
// outpoint.
36
func fetchOutPoints(tx kvdb.RwTx) ([]*wire.OutPoint, error) {
1✔
37
        var ops []*wire.OutPoint
1✔
38

1✔
39
        bucket := tx.ReadBucket(outpointBucket)
1✔
40

1✔
41
        err := bucket.ForEach(func(k, _ []byte) error {
3✔
42
                var op wire.OutPoint
2✔
43
                r := bytes.NewReader(k)
2✔
44
                if err := readOutpoint(r, &op); err != nil {
2✔
45
                        return err
×
46
                }
×
47

48
                ops = append(ops, &op)
2✔
49
                return nil
2✔
50
        })
51
        if err != nil {
1✔
52
                return nil, err
×
53
        }
×
54

55
        return ops, nil
1✔
56
}
57

58
// populateChanIDIndex uses the set of retrieved outpoints and populates the
59
// ChannelID index.
60
func populateChanIDIndex(tx kvdb.RwTx, ops []*wire.OutPoint) error {
1✔
61
        bucket := tx.ReadWriteBucket(chanIDBucket)
1✔
62

1✔
63
        for _, op := range ops {
3✔
64
                chanID := NewChanIDFromOutPoint(op)
2✔
65

2✔
66
                if err := bucket.Put(chanID[:], []byte{}); err != nil {
2✔
67
                        return err
×
68
                }
×
69
        }
70

71
        return nil
1✔
72
}
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