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

lightningnetwork / lnd / 13035292482

29 Jan 2025 03:59PM UTC coverage: 49.3% (-9.5%) from 58.777%
13035292482

Pull #9456

github

mohamedawnallah
docs: update release-notes-0.19.0.md

In this commit, we warn users about the removal
of RPCs `SendToRoute`, `SendToRouteSync`, `SendPayment`,
and `SendPaymentSync` in the next release 0.20.
Pull Request #9456: lnrpc+docs: deprecate warning `SendToRoute`, `SendToRouteSync`, `SendPayment`, and `SendPaymentSync` in Release 0.19

100634 of 204126 relevant lines covered (49.3%)

1.54 hits per line

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

0.0
/channeldb/migration26/migration.go
1
package migration26
2

3
import (
4
        "fmt"
5

6
        mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
7
        "github.com/lightningnetwork/lnd/kvdb"
8
)
9

10
var (
11
        // openChanBucket stores all the currently open channels. This bucket
12
        // has a second, nested bucket which is keyed by a node's ID. Within
13
        // that node ID bucket, all attributes required to track, update, and
14
        // close a channel are stored.
15
        openChannelBucket = []byte("open-chan-bucket")
16

17
        // ErrNoChanDBExists is returned when a channel bucket hasn't been
18
        // created.
19
        ErrNoChanDBExists = fmt.Errorf("channel db has not yet been created")
20

21
        // ErrNoActiveChannels  is returned when there is no active (open)
22
        // channels within the database.
23
        ErrNoActiveChannels = fmt.Errorf("no active channels exist")
24

25
        // ErrChannelNotFound is returned when we attempt to locate a channel
26
        // for a specific chain, but it is not found.
27
        ErrChannelNotFound = fmt.Errorf("channel not found")
28
)
29

30
// MigrateBalancesToTlvRecords migrates the balance fields into tlv records. It
31
// does so by first reading a list of open channels, then rewriting the channel
32
// info with the updated tlv stream.
33
func MigrateBalancesToTlvRecords(tx kvdb.RwTx) error {
×
34
        log.Infof("Migrating local and remote balances into tlv records...")
×
35

×
36
        openChanBucket := tx.ReadWriteBucket(openChannelBucket)
×
37

×
38
        // If no bucket is found, we can exit early.
×
39
        if openChanBucket == nil {
×
40
                return nil
×
41
        }
×
42

43
        // Read a list of open channels.
44
        channels, err := findOpenChannels(openChanBucket)
×
45
        if err != nil {
×
46
                return err
×
47
        }
×
48

49
        // Migrate the balances.
50
        for _, c := range channels {
×
51
                if err := migrateBalances(tx, c); err != nil {
×
52
                        return err
×
53
                }
×
54
        }
55

56
        return err
×
57
}
58

59
// findOpenChannels finds all open channels.
60
func findOpenChannels(openChanBucket kvdb.RBucket) ([]*OpenChannel, error) {
×
61
        channels := []*OpenChannel{}
×
62

×
63
        // readChannel is a helper closure that reads the channel info from the
×
64
        // channel bucket.
×
65
        readChannel := func(chainBucket kvdb.RBucket, cp []byte) error {
×
66
                c := &OpenChannel{}
×
67

×
68
                // Read the sub-bucket level 3.
×
69
                chanBucket := chainBucket.NestedReadBucket(
×
70
                        cp,
×
71
                )
×
72
                if chanBucket == nil {
×
73
                        log.Errorf("unable to read bucket for chanPoint=%x", cp)
×
74
                        return nil
×
75
                }
×
76

77
                // Get the old channel info.
78
                if err := FetchChanInfo(chanBucket, c, true); err != nil {
×
79
                        return fmt.Errorf("unable to fetch chan info: %w", err)
×
80
                }
×
81

82
                channels = append(channels, c)
×
83

×
84
                return nil
×
85
        }
86

87
        // Iterate the root bucket.
88
        err := openChanBucket.ForEach(func(nodePub, v []byte) error {
×
89
                // Ensure that this is a key the same size as a pubkey, and
×
90
                // also that it leads directly to a bucket.
×
91
                if len(nodePub) != 33 || v != nil {
×
92
                        return nil
×
93
                }
×
94

95
                // Read the sub-bucket level 1.
96
                nodeChanBucket := openChanBucket.NestedReadBucket(nodePub)
×
97
                if nodeChanBucket == nil {
×
98
                        log.Errorf("no bucket for node %x", nodePub)
×
99
                        return nil
×
100
                }
×
101

102
                // Iterate the bucket.
103
                return nodeChanBucket.ForEach(func(chainHash, _ []byte) error {
×
104
                        // Read the sub-bucket level 2.
×
105
                        chainBucket := nodeChanBucket.NestedReadBucket(
×
106
                                chainHash,
×
107
                        )
×
108
                        if chainBucket == nil {
×
109
                                log.Errorf("unable to read bucket for chain=%x",
×
110
                                        chainHash)
×
111
                                return nil
×
112
                        }
×
113

114
                        // Iterate the bucket.
115
                        return chainBucket.ForEach(func(cp, _ []byte) error {
×
116
                                return readChannel(chainBucket, cp)
×
117
                        })
×
118
                })
119
        })
120

121
        if err != nil {
×
122
                return nil, err
×
123
        }
×
124

125
        return channels, nil
×
126
}
127

128
// migrateBalances creates a new tlv stream which adds two more records to hold
129
// the balances info.
130
func migrateBalances(tx kvdb.RwTx, c *OpenChannel) error {
×
131
        // Get the bucket.
×
132
        chanBucket, err := mig25.FetchChanBucket(tx, &c.OpenChannel)
×
133
        if err != nil {
×
134
                return err
×
135
        }
×
136

137
        // Update the channel info. There isn't much to do here as the
138
        // `PutChanInfo` will read the values from `c.InitialLocalBalance` and
139
        // `c.InitialRemoteBalance` then create the new tlv stream as
140
        // requested.
141
        if err := PutChanInfo(chanBucket, c, false); err != nil {
×
142
                return fmt.Errorf("unable to put chan info: %w", err)
×
143
        }
×
144

145
        return nil
×
146
}
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