• 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/migration6/client_db.go
1
package migration6
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
        // cSessionBkt is a top-level bucket storing:
14
        //   session-id => cSessionBody -> encoded ClientSessionBody
15
        //                 => cSessionDBID -> db-assigned-id
16
        //              => cSessionCommits => seqnum -> encoded CommittedUpdate
17
        //              => cSessionAcks => seqnum -> encoded BackupID
18
        cSessionBkt = []byte("client-session-bucket")
19

20
        // cSessionDBID is a key used in the cSessionBkt to store the
21
        // db-assigned-id of a session.
22
        cSessionDBID = []byte("client-session-db-id")
23

24
        // cSessionIDIndexBkt is a top-level bucket storing:
25
        //    db-assigned-id -> session-id
26
        cSessionIDIndexBkt = []byte("client-session-id-index")
27

28
        // cSessionBody is a sub-bucket of cSessionBkt storing only the body of
29
        // the ClientSession.
30
        cSessionBody = []byte("client-session-body")
31

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

36
        // ErrCorruptClientSession signals that the client session's on-disk
37
        // structure deviates from what is expected.
38
        ErrCorruptClientSession = errors.New("client session corrupted")
39

40
        byteOrder = binary.BigEndian
41
)
42

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

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

58
        // Get the existing top-level sessions bucket.
59
        sessionsBkt := tx.ReadWriteBucket(cSessionBkt)
×
60
        if sessionsBkt == nil {
×
61
                return ErrUninitializedDB
×
62
        }
×
63

64
        // Iterate over the sessions bucket where each key is a session-ID.
65
        return sessionsBkt.ForEach(func(sessionID, _ []byte) error {
×
66
                // Ask the DB for a new, unique, id for the index bucket.
×
67
                nextSeq, err := indexBkt.NextSequence()
×
68
                if err != nil {
×
69
                        return err
×
70
                }
×
71

72
                newIndex, err := writeBigSize(nextSeq)
×
73
                if err != nil {
×
74
                        return err
×
75
                }
×
76

77
                // Add the new db-assigned-ID to real-session-ID pair to the
78
                // new index bucket.
79
                err = indexBkt.Put(newIndex, sessionID)
×
80
                if err != nil {
×
81
                        return err
×
82
                }
×
83

84
                // Get the sub-bucket for this specific session ID.
85
                sessionBkt := sessionsBkt.NestedReadWriteBucket(sessionID)
×
86
                if sessionBkt == nil {
×
87
                        return ErrCorruptClientSession
×
88
                }
×
89

90
                // Here we ensure that the session bucket includes a session
91
                // body. The only reason we do this is so that we can simulate
92
                // a migration fail in a test to ensure that a migration fail
93
                // results in an untouched db.
94
                sessionBodyBytes := sessionBkt.Get(cSessionBody)
×
95
                if sessionBodyBytes == nil {
×
96
                        return ErrCorruptClientSession
×
97
                }
×
98

99
                // Add the db-assigned ID of the session to the session under
100
                // the cSessionDBID key.
101
                return sessionBkt.Put(cSessionDBID, newIndex)
×
102
        })
103
}
104

105
// writeBigSize will encode the given uint64 as a BigSize byte slice.
106
func writeBigSize(i uint64) ([]byte, error) {
×
107
        var b bytes.Buffer
×
108
        err := tlv.WriteVarInt(&b, i, &[8]byte{})
×
109
        if err != nil {
×
110
                return nil, err
×
111
        }
×
112

113
        return b.Bytes(), nil
×
114
}
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