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

3
import (
4
        "encoding/binary"
5
        "io"
6

7
        "github.com/lightningnetwork/lnd/channeldb"
8
        "github.com/lightningnetwork/lnd/lnwallet/chainfee"
9
        "github.com/lightningnetwork/lnd/watchtower/blob"
10
        "github.com/lightningnetwork/lnd/watchtower/wtpolicy"
11
)
12

13
// SessionIDSize is 33-bytes; it is a serialized, compressed public key.
14
const SessionIDSize = 33
15

16
// UnknownElementType is an alias for channeldb.UnknownElementType.
17
type UnknownElementType = channeldb.UnknownElementType
18

19
// SessionID is created from the remote public key of a client, and serves as a
20
// unique identifier and authentication for sending state updates.
21
type SessionID [SessionIDSize]byte
22

23
// TowerID is a unique 64-bit identifier allocated to each unique watchtower.
24
// This allows the client to conserve on-disk space by not needing to always
25
// reference towers by their pubkey.
26
type TowerID uint64
27

28
// Bytes encodes a TowerID into an 8-byte slice in big-endian byte order.
29
func (id TowerID) Bytes() []byte {
×
30
        var buf [8]byte
×
31
        binary.BigEndian.PutUint64(buf[:], uint64(id))
×
32
        return buf[:]
×
33
}
×
34

35
// ClientSession encapsulates a SessionInfo returned from a successful
36
// session negotiation, and also records the tower and ephemeral secret used for
37
// communicating with the tower.
38
type ClientSession struct {
39
        // ID is the client's public key used when authenticating with the
40
        // tower.
41
        ID SessionID
42
        ClientSessionBody
43
}
44

45
// CSessionStatus is a bit-field representing the possible statuses of
46
// ClientSessions.
47
type CSessionStatus uint8
48

49
type ClientSessionBody struct {
50
        // SeqNum is the next unallocated sequence number that can be sent to
51
        // the tower.
52
        SeqNum uint16
53

54
        // TowerLastApplied the last last-applied the tower has echoed back.
55
        TowerLastApplied uint16
56

57
        // TowerID is the unique, db-assigned identifier that references the
58
        // Tower with which the session is negotiated.
59
        TowerID TowerID
60

61
        // KeyIndex is the index of key locator used to derive the client's
62
        // session key so that it can authenticate with the tower to update its
63
        // session. In order to rederive the private key, the key locator should
64
        // use the keychain.KeyFamilyTowerSession key family.
65
        KeyIndex uint32
66

67
        // Policy holds the negotiated session parameters.
68
        Policy wtpolicy.Policy
69

70
        // Status indicates the current state of the ClientSession.
71
        Status CSessionStatus
72

73
        // RewardPkScript is the pkscript that the tower's reward will be
74
        // deposited to if a sweep transaction confirms and the sessions
75
        // specifies a reward output.
76
        RewardPkScript []byte
77
}
78

79
// Encode writes a ClientSessionBody to the passed io.Writer.
80
func (s *ClientSessionBody) Encode(w io.Writer) error {
×
81
        return WriteElements(w,
×
82
                s.SeqNum,
×
83
                s.TowerLastApplied,
×
84
                uint64(s.TowerID),
×
85
                s.KeyIndex,
×
86
                uint8(s.Status),
×
87
                s.Policy,
×
88
                s.RewardPkScript,
×
89
        )
×
90
}
×
91

92
// Decode reads a ClientSessionBody from the passed io.Reader.
93
func (s *ClientSessionBody) Decode(r io.Reader) error {
×
94
        var (
×
95
                towerID uint64
×
96
                status  uint8
×
97
        )
×
98
        err := ReadElements(r,
×
99
                &s.SeqNum,
×
100
                &s.TowerLastApplied,
×
101
                &towerID,
×
102
                &s.KeyIndex,
×
103
                &status,
×
104
                &s.Policy,
×
105
                &s.RewardPkScript,
×
106
        )
×
107
        if err != nil {
×
108
                return err
×
109
        }
×
110

111
        s.TowerID = TowerID(towerID)
×
112
        s.Status = CSessionStatus(status)
×
113

×
114
        return nil
×
115
}
116

117
// WriteElements serializes a variadic list of elements into the given
118
// io.Writer.
119
func WriteElements(w io.Writer, elements ...interface{}) error {
×
120
        for _, element := range elements {
×
121
                if err := WriteElement(w, element); err != nil {
×
122
                        return err
×
123
                }
×
124
        }
125

126
        return nil
×
127
}
128

129
// WriteElement serializes a single element into the provided io.Writer.
130
func WriteElement(w io.Writer, element interface{}) error {
×
131
        err := channeldb.WriteElement(w, element)
×
132
        switch {
×
133
        // Known to channeldb codec.
134
        case err == nil:
×
135
                return nil
×
136

137
        // Fail if error is not UnknownElementType.
138
        default:
×
139
                if _, ok := err.(UnknownElementType); !ok {
×
140
                        return err
×
141
                }
×
142
        }
143

144
        // Process any wtdb-specific extensions to the codec.
145
        switch e := element.(type) {
×
146
        case SessionID:
×
147
                if _, err := w.Write(e[:]); err != nil {
×
148
                        return err
×
149
                }
×
150

151
        case blob.BreachHint:
×
152
                if _, err := w.Write(e[:]); err != nil {
×
153
                        return err
×
154
                }
×
155

156
        case wtpolicy.Policy:
×
157
                return channeldb.WriteElements(w,
×
158
                        uint16(e.BlobType),
×
159
                        e.MaxUpdates,
×
160
                        e.RewardBase,
×
161
                        e.RewardRate,
×
162
                        uint64(e.SweepFeeRate),
×
163
                )
×
164

165
        // Type is still unknown to wtdb extensions, fail.
166
        default:
×
167
                return channeldb.NewUnknownElementType(
×
168
                        "WriteElement", element,
×
169
                )
×
170
        }
171

172
        return nil
×
173
}
174

175
// ReadElements deserializes the provided io.Reader into a variadic list of
176
// target elements.
177
func ReadElements(r io.Reader, elements ...interface{}) error {
×
178
        for _, element := range elements {
×
179
                if err := ReadElement(r, element); err != nil {
×
180
                        return err
×
181
                }
×
182
        }
183

184
        return nil
×
185
}
186

187
// ReadElement deserializes a single element from the provided io.Reader.
188
func ReadElement(r io.Reader, element interface{}) error {
×
189
        err := channeldb.ReadElement(r, element)
×
190
        switch {
×
191
        // Known to channeldb codec.
192
        case err == nil:
×
193
                return nil
×
194

195
        // Fail if error is not UnknownElementType.
196
        default:
×
197
                if _, ok := err.(UnknownElementType); !ok {
×
198
                        return err
×
199
                }
×
200
        }
201

202
        // Process any wtdb-specific extensions to the codec.
203
        switch e := element.(type) {
×
204
        case *SessionID:
×
205
                if _, err := io.ReadFull(r, e[:]); err != nil {
×
206
                        return err
×
207
                }
×
208

209
        case *blob.BreachHint:
×
210
                if _, err := io.ReadFull(r, e[:]); err != nil {
×
211
                        return err
×
212
                }
×
213

214
        case *wtpolicy.Policy:
×
215
                var (
×
216
                        blobType     uint16
×
217
                        sweepFeeRate uint64
×
218
                )
×
219
                err := channeldb.ReadElements(r,
×
220
                        &blobType,
×
221
                        &e.MaxUpdates,
×
222
                        &e.RewardBase,
×
223
                        &e.RewardRate,
×
224
                        &sweepFeeRate,
×
225
                )
×
226
                if err != nil {
×
227
                        return err
×
228
                }
×
229

230
                e.BlobType = blob.Type(blobType)
×
231
                e.SweepFeeRate = chainfee.SatPerKWeight(sweepFeeRate)
×
232

233
        // Type is still unknown to wtdb extensions, fail.
234
        default:
×
235
                return channeldb.NewUnknownElementType(
×
236
                        "ReadElement", element,
×
237
                )
×
238
        }
239

240
        return nil
×
241
}
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