• 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
/watchtower/wtdb/migration3/client_db.go
1
package migration3
2

3
import (
4
        "bytes"
5
        "encoding/binary"
6
        "errors"
7

8
        "github.com/lightningnetwork/lnd/kvdb"
9
        "github.com/lightningnetwork/lnd/tlv"
10
)
11

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

18
        // cChanDBID is a key used in the cChanDetailsBkt to store the
19
        // db-assigned-id of a channel.
20
        cChanDBID = []byte("client-channel-db-id")
21

22
        // cChanIDIndexBkt is a top-level bucket storing:
23
        //    db-assigned-id -> channel-ID
24
        cChanIDIndexBkt = []byte("client-channel-id-index")
25

26
        // cChannelSummary is a key used in cChanDetailsBkt to store the encoded
27
        // body of ClientChanSummary.
28
        cChannelSummary = []byte("client-channel-summary")
29

30
        // ErrUninitializedDB signals that top-level buckets for the database
31
        // have not been initialized.
32
        ErrUninitializedDB = errors.New("db not initialized")
33

34
        // ErrCorruptChanDetails signals that the clients channel detail's
35
        // on-disk structure deviates from what is expected.
36
        ErrCorruptChanDetails = errors.New("channel details corrupted")
37

38
        byteOrder = binary.BigEndian
39
)
40

41
// MigrateChannelIDIndex adds a new channel ID index to the tower client db.
42
// This index is a mapping from db-assigned ID (a uint64 encoded using BigSize
43
// encoding) to real channel ID (32 bytes). This mapping will allow us to
44
// persist channel pointers with fewer bytes in the future.
45
func MigrateChannelIDIndex(tx kvdb.RwTx) error {
×
46
        log.Infof("Migrating the tower client db to add a new channel ID " +
×
47
                "index which stores a mapping from db-assigned ID to real " +
×
48
                "channel ID")
×
49

×
50
        // Create a new top-level bucket for the new index.
×
51
        indexBkt, err := tx.CreateTopLevelBucket(cChanIDIndexBkt)
×
52
        if err != nil {
×
53
                return err
×
54
        }
×
55

56
        // Get the top-level channel-details bucket. The keys of this bucket
57
        // are the real channel IDs.
58
        chanDetailsBkt := tx.ReadWriteBucket(cChanDetailsBkt)
×
59
        if chanDetailsBkt == nil {
×
60
                return ErrUninitializedDB
×
61
        }
×
62

63
        // Iterate over the keys of the channel-details bucket.
64
        return chanDetailsBkt.ForEach(func(chanID, _ []byte) error {
×
65
                // Ask the db for a new, unique, ID for the index bucket.
×
66
                nextSeq, err := indexBkt.NextSequence()
×
67
                if err != nil {
×
68
                        return err
×
69
                }
×
70

71
                // Encode the sequence number using BigSize encoding.
72
                var newIndex bytes.Buffer
×
73
                err = tlv.WriteVarInt(&newIndex, nextSeq, &[8]byte{})
×
74
                if err != nil {
×
75
                        return err
×
76
                }
×
77

78
                // Add the mapping from the db-assigned ID to the channel ID
79
                // to the new index.
80
                newIndexBytes := newIndex.Bytes()
×
81
                err = indexBkt.Put(newIndexBytes, chanID)
×
82
                if err != nil {
×
83
                        return err
×
84
                }
×
85

86
                chanDetails := chanDetailsBkt.NestedReadWriteBucket(chanID)
×
87
                if chanDetails == nil {
×
88
                        return ErrCorruptChanDetails
×
89
                }
×
90

91
                // Here we ensure that the channel-details bucket includes a
92
                // channel summary. The only reason we do this is so that we can
93
                // simulate a migration fail in a test to ensure that a
94
                // migration fail results in an untouched db.
95
                chanSummaryBytes := chanDetails.Get(cChannelSummary)
×
96
                if chanSummaryBytes == nil {
×
97
                        return ErrCorruptChanDetails
×
98
                }
×
99

100
                // In the channel-details sub-bucket for this channel, add the
101
                // new DB-assigned ID for this channel under the cChanDBID key.
102
                return chanDetails.Put(cChanDBID, newIndexBytes)
×
103
        })
104
}
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