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

3
import (
4
        "bytes"
5
        "errors"
6
        "fmt"
7

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

11
var (
12
        // cSessionBkt is a top-level bucket storing:
13
        //   session-id => cSessionBody -> encoded ClientSessionBody
14
        //              => cSessionCommits => seqnum -> encoded CommittedUpdate
15
        //              => cSessionAcks => seqnum -> encoded BackupID
16
        cSessionBkt = []byte("client-session-bucket")
17

18
        // cSessionBody is a sub-bucket of cSessionBkt storing only the body of
19
        // the ClientSession.
20
        cSessionBody = []byte("client-session-body")
21

22
        // cTowerIDToSessionIDIndexBkt is a top-level bucket storing:
23
        //         tower-id -> session-id -> 1
24
        cTowerIDToSessionIDIndexBkt = []byte(
25
                "client-tower-to-session-index-bucket",
26
        )
27

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

32
        // ErrClientSessionNotFound signals that the requested client session
33
        // was not found in the database.
34
        ErrClientSessionNotFound = errors.New("client session not found")
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

41
// MigrateTowerToSessionIndex constructs a new towerID-to-sessionID for the
42
// watchtower client DB.
43
func MigrateTowerToSessionIndex(tx kvdb.RwTx) error {
×
44
        log.Infof("Migrating the tower client db to add a " +
×
45
                "towerID-to-sessionID index")
×
46

×
47
        // First, we collect all the entries we want to add to the index.
×
48
        entries, err := getIndexEntries(tx)
×
49
        if err != nil {
×
50
                return err
×
51
        }
×
52

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

59
        // Finally, we add all the collected entries to the index.
60
        for towerID, sessions := range entries {
×
61
                // Create a sub-bucket using the tower ID.
×
62
                towerBkt, err := indexBkt.CreateBucketIfNotExists(
×
63
                        towerID.Bytes(),
×
64
                )
×
65
                if err != nil {
×
66
                        return err
×
67
                }
×
68

69
                for sessionID := range sessions {
×
70
                        err := addIndex(towerBkt, sessionID)
×
71
                        if err != nil {
×
72
                                return err
×
73
                        }
×
74
                }
75
        }
76

77
        return nil
×
78
}
79

80
// addIndex adds a new towerID-sessionID pair to the given bucket. The
81
// session ID is used as a key within the bucket and a value of []byte{1} is
82
// used for each session ID key.
83
func addIndex(towerBkt kvdb.RwBucket, sessionID SessionID) error {
×
84
        session := towerBkt.Get(sessionID[:])
×
85
        if session != nil {
×
86
                return fmt.Errorf("session %x duplicated", sessionID)
×
87
        }
×
88

89
        return towerBkt.Put(sessionID[:], []byte{1})
×
90
}
91

92
// getIndexEntries collects all the towerID-sessionID entries that need to be
93
// added to the new index.
94
func getIndexEntries(tx kvdb.RwTx) (map[TowerID]map[SessionID]bool, error) {
×
95
        sessions := tx.ReadBucket(cSessionBkt)
×
96
        if sessions == nil {
×
97
                return nil, ErrUninitializedDB
×
98
        }
×
99

100
        index := make(map[TowerID]map[SessionID]bool)
×
101
        err := sessions.ForEach(func(k, _ []byte) error {
×
102
                session, err := getClientSession(sessions, k)
×
103
                if err != nil {
×
104
                        return err
×
105
                }
×
106

107
                if index[session.TowerID] == nil {
×
108
                        index[session.TowerID] = make(map[SessionID]bool)
×
109
                }
×
110

111
                index[session.TowerID][session.ID] = true
×
112
                return nil
×
113
        })
114
        if err != nil {
×
115
                return nil, err
×
116
        }
×
117

118
        return index, nil
×
119
}
120

121
// getClientSession fetches the session with the given ID from the db.
122
func getClientSession(sessions kvdb.RBucket, idBytes []byte) (*ClientSession,
123
        error) {
×
124

×
125
        sessionBkt := sessions.NestedReadBucket(idBytes)
×
126
        if sessionBkt == nil {
×
127
                return nil, ErrClientSessionNotFound
×
128
        }
×
129

130
        // Should never have a sessionBkt without also having its body.
131
        sessionBody := sessionBkt.Get(cSessionBody)
×
132
        if sessionBody == nil {
×
133
                return nil, ErrCorruptClientSession
×
134
        }
×
135

136
        var session ClientSession
×
137
        copy(session.ID[:], idBytes)
×
138

×
139
        err := session.Decode(bytes.NewReader(sessionBody))
×
140
        if err != nil {
×
141
                return nil, err
×
142
        }
×
143

144
        return &session, nil
×
145
}
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