• 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

0.0
/watchtower/wtdb/migration2/client_db.go
1
package migration2
2

3
import (
4
        "errors"
5

6
        "github.com/lightningnetwork/lnd/kvdb"
7
)
8

9
var (
10
        // cChanSummaryBkt is a top-level bucket storing:
11
        //   channel-id -> encoded ClientChanSummary.
12
        cChanSummaryBkt = []byte("client-channel-summary-bucket")
13

14
        // cChanDetailsBkt is a top-level bucket storing:
15
        //   channel-id => cChannelSummary -> encoded ClientChanSummary.
16
        cChanDetailsBkt = []byte("client-channel-detail-bucket")
17

18
        // cChannelSummary is a key used in cChanDetailsBkt to store the encoded
19
        // body of ClientChanSummary.
20
        cChannelSummary = []byte("client-channel-summary")
21

22
        // ErrUninitializedDB signals that top-level buckets for the database
23
        // have not been initialized.
24
        ErrUninitializedDB = errors.New("db not initialized")
25

26
        // ErrCorruptChanSummary signals that the clients channel summary's
27
        // on-disk structure deviates from what is expected.
28
        ErrCorruptChanSummary = errors.New("channel summary corrupted")
29
)
30

31
// MigrateClientChannelDetails creates a new channel-details bucket that uses
32
// channel IDs as sub-buckets where the channel summaries are moved to from the
33
// channel summary bucket. If the migration is successful then the channel
34
// summary bucket is deleted.
UNCOV
35
func MigrateClientChannelDetails(tx kvdb.RwTx) error {
×
UNCOV
36
        log.Infof("Migrating the tower client db to move the channel " +
×
UNCOV
37
                "summaries to the new channel-details bucket")
×
UNCOV
38

×
UNCOV
39
        // Create the new top level cChanDetailsBkt.
×
UNCOV
40
        chanDetailsBkt, err := tx.CreateTopLevelBucket(cChanDetailsBkt)
×
UNCOV
41
        if err != nil {
×
42
                return err
×
43
        }
×
44

45
        // Get the top-level channel summaries bucket.
UNCOV
46
        chanSummaryBkt := tx.ReadWriteBucket(cChanSummaryBkt)
×
UNCOV
47
        if chanSummaryBkt == nil {
×
48
                return ErrUninitializedDB
×
49
        }
×
50

51
        // Iterate over the cChanSummaryBkt's keys. Each key is a channel-id.
52
        // For each of these, create a new sub-bucket with this key in
53
        // cChanDetailsBkt. In this sub-bucket, add the cChannelSummary key with
54
        // the encoded ClientChanSummary as the value.
UNCOV
55
        err = chanSummaryBkt.ForEach(func(chanID, summary []byte) error {
×
UNCOV
56
                // Force the migration to fail if the summary is empty. This
×
UNCOV
57
                // should never be the case, but it is added so that we can
×
UNCOV
58
                // force the migration to fail in a test so that we can test
×
UNCOV
59
                // that the db remains unaffected if a migration failure takes
×
UNCOV
60
                // place.
×
UNCOV
61
                if len(summary) == 0 {
×
UNCOV
62
                        return ErrCorruptChanSummary
×
UNCOV
63
                }
×
64

65
                // Create a new sub-bucket in the channel details bucket using
66
                // this channel ID.
UNCOV
67
                channelBkt, err := chanDetailsBkt.CreateBucket(chanID)
×
UNCOV
68
                if err != nil {
×
69
                        return err
×
70
                }
×
71

72
                // Add the encoded channel summary in the new bucket under the
73
                // channel-summary key.
UNCOV
74
                return channelBkt.Put(cChannelSummary, summary)
×
75
        })
UNCOV
76
        if err != nil {
×
UNCOV
77
                return err
×
UNCOV
78
        }
×
79

80
        // Now delete the cChanSummaryBkt from the DB.
UNCOV
81
        return tx.DeleteTopLevelBucket(cChanSummaryBkt)
×
82
}
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