• 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

3.75
/channeldb/migration30/test_utils.go
1
package migration30
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "math/rand"
7
        "time"
8

9
        "github.com/btcsuite/btcd/btcec/v2"
10
        "github.com/btcsuite/btcd/btcutil"
11
        "github.com/btcsuite/btcd/chaincfg/chainhash"
12
        "github.com/btcsuite/btcd/wire"
13
        lnwire "github.com/lightningnetwork/lnd/channeldb/migration/lnwire21"
14
        mig25 "github.com/lightningnetwork/lnd/channeldb/migration25"
15
        mig26 "github.com/lightningnetwork/lnd/channeldb/migration26"
16
        mig "github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
17
        "github.com/lightningnetwork/lnd/keychain"
18
        "github.com/lightningnetwork/lnd/kvdb"
19
        "github.com/lightningnetwork/lnd/shachain"
20
)
21

22
var (
23
        testChainHash = chainhash.Hash{1, 2, 3}
24
        testChanType  = mig25.SingleFunderTweaklessBit
25

26
        // testOurIndex and testTheirIndex are artificial indexes that're saved
27
        // to db during test setup. They are different from indexes populated
28
        // from the actual migration process so we can check whether a new
29
        // revocation log is overwritten or not.
30
        testOurIndex   = uint32(100)
31
        testTheirIndex = uint32(200)
32

33
        // dummyInput is used in our commit tx.
34
        dummyInput = &wire.TxIn{
35
                PreviousOutPoint: wire.OutPoint{
36
                        Hash:  chainhash.Hash{},
37
                        Index: 0xffffffff,
38
                },
39
                Sequence: 0xffffffff,
40
        }
41

42
        // htlcScript is the PkScript used in the HTLC output. This script
43
        // corresponds to revocation preimage2.
44
        htlcScript = []byte{
45
                0x0, 0x20, 0x3d, 0x51, 0x66, 0xda, 0x39, 0x93,
46
                0x7b, 0x49, 0xaf, 0x2, 0xf2, 0x2f, 0x90, 0x52,
47
                0x8e, 0x45, 0x24, 0x34, 0x8f, 0xd8, 0x76, 0x7,
48
                0x5a, 0xfc, 0x52, 0x8d, 0x68, 0xdd, 0xbc, 0xce,
49
                0x3e, 0x5d,
50
        }
51

52
        // toLocalScript is the PkScript used in to-local output.
53
        toLocalScript = []byte{
54
                0x0, 0x14, 0xc6, 0x9, 0x62, 0xab, 0x60, 0xbe,
55
                0x40, 0xd, 0xab, 0x31, 0xc, 0x13, 0x14, 0x15,
56
                0x93, 0xe6, 0xa2, 0x94, 0xe4, 0x2a,
57
        }
58

59
        // preimage1 defines a revocation preimage, generated from itest.
60
        preimage1 = []byte{
61
                0x95, 0xb4, 0x7c, 0x5a, 0x2b, 0xfd, 0x6f, 0xf4,
62
                0x70, 0x8, 0xc, 0x70, 0x82, 0x36, 0xc8, 0x5,
63
                0x88, 0x16, 0xaf, 0x29, 0xb5, 0x8, 0xfd, 0x5a,
64
                0x40, 0x28, 0x24, 0xc, 0x2a, 0x7f, 0x96, 0xcd,
65
        }
66

67
        // commitTx1 is the tx saved in the first old revocation.
68
        commitTx1 = &wire.MsgTx{
69
                Version: 2,
70
                // Add a dummy input.
71
                TxIn: []*wire.TxIn{dummyInput},
72
                TxOut: []*wire.TxOut{
73
                        {
74
                                Value:    990_950,
75
                                PkScript: toLocalScript,
76
                        },
77
                },
78
        }
79

80
        // logHeight1 is the CommitHeight used by oldLog1.
81
        logHeight1 = uint64(0)
82

83
        // localBalance1 is the LocalBalance used in oldLog1.
84
        localBalance1 = lnwire.MilliSatoshi(990_950_000)
85

86
        // remoteBalance1 is the RemoteBalance used in oldLog1.
87
        remoteBalance1 = lnwire.MilliSatoshi(0)
88

89
        // oldLog1 defines an old revocation that has no HTLCs.
90
        oldLog1 = mig.ChannelCommitment{
91
                CommitHeight:    logHeight1,
92
                LocalLogIndex:   0,
93
                LocalHtlcIndex:  0,
94
                RemoteLogIndex:  0,
95
                RemoteHtlcIndex: 0,
96
                LocalBalance:    localBalance1,
97
                RemoteBalance:   remoteBalance1,
98
                CommitTx:        commitTx1,
99
        }
100

101
        // newLog1 is the new version of oldLog1 in the case were we don't want
102
        // to store any balance data.
103
        newLog1 = RevocationLog{
104
                OurOutputIndex:   0,
105
                TheirOutputIndex: OutputIndexEmpty,
106
                CommitTxHash:     commitTx1.TxHash(),
107
        }
108

109
        // newLog1WithAmts is the new version of oldLog1 in the case were we do
110
        // want to store balance data.
111
        newLog1WithAmts = RevocationLog{
112
                OurOutputIndex:   0,
113
                TheirOutputIndex: OutputIndexEmpty,
114
                CommitTxHash:     commitTx1.TxHash(),
115
                OurBalance:       &localBalance1,
116
                TheirBalance:     &remoteBalance1,
117
        }
118

119
        // preimage2 defines the second revocation preimage used in the test,
120
        // generated from itest.
121
        preimage2 = []byte{
122
                0xac, 0x60, 0x7a, 0x59, 0x9, 0xd6, 0x11, 0xb2,
123
                0xf5, 0x6e, 0xaa, 0xc6, 0xb9, 0x0, 0x12, 0xdc,
124
                0xf0, 0x89, 0x58, 0x90, 0x8a, 0xa2, 0xc6, 0xfc,
125
                0xf1, 0x2, 0x74, 0x87, 0x30, 0x51, 0x5e, 0xea,
126
        }
127

128
        // commitTx2 is the tx saved in the second old revocation.
129
        commitTx2 = &wire.MsgTx{
130
                Version: 2,
131
                // Add a dummy input.
132
                TxIn: []*wire.TxIn{dummyInput},
133
                TxOut: []*wire.TxOut{
134
                        {
135
                                Value:    100_000,
136
                                PkScript: htlcScript,
137
                        },
138
                        {
139
                                Value:    888_800,
140
                                PkScript: toLocalScript,
141
                        },
142
                },
143
        }
144

145
        // rHash is the payment hash used in the htlc below.
146
        rHash = [32]byte{
147
                0x42, 0x5e, 0xd4, 0xe4, 0xa3, 0x6b, 0x30, 0xea,
148
                0x21, 0xb9, 0xe, 0x21, 0xc7, 0x12, 0xc6, 0x49,
149
                0xe8, 0x21, 0x4c, 0x29, 0xb7, 0xea, 0xf6, 0x80,
150
                0x89, 0xd1, 0x3, 0x9c, 0x6e, 0x55, 0x38, 0x4c,
151
        }
152

153
        // htlc defines an HTLC that's saved in the old revocation log.
154
        htlc = mig.HTLC{
155
                RHash:         rHash,
156
                Amt:           lnwire.MilliSatoshi(100_000_000),
157
                RefundTimeout: 489,
158
                OutputIndex:   0,
159
                Incoming:      false,
160
                OnionBlob:     bytes.Repeat([]byte{0xff}, 1366),
161
                HtlcIndex:     0,
162
                LogIndex:      0,
163
        }
164

165
        // logHeight2 is the CommitHeight used by oldLog2.
166
        logHeight2 = uint64(1)
167

168
        // localBalance2 is the LocalBalance used in oldLog2.
169
        localBalance2 = lnwire.MilliSatoshi(888_800_000)
170

171
        // remoteBalance2 is the RemoteBalance used in oldLog2.
172
        remoteBalance2 = lnwire.MilliSatoshi(0)
173

174
        // oldLog2 defines an old revocation that has one HTLC.
175
        oldLog2 = mig.ChannelCommitment{
176
                CommitHeight:    logHeight2,
177
                LocalLogIndex:   1,
178
                LocalHtlcIndex:  1,
179
                RemoteLogIndex:  0,
180
                RemoteHtlcIndex: 0,
181
                LocalBalance:    localBalance2,
182
                RemoteBalance:   remoteBalance2,
183
                CommitTx:        commitTx2,
184
                Htlcs:           []mig.HTLC{htlc},
185
        }
186

187
        // newLog2 is the new version of the oldLog2 in the case were we don't
188
        // want to store any balance data.
189
        newLog2 = RevocationLog{
190
                OurOutputIndex:   1,
191
                TheirOutputIndex: OutputIndexEmpty,
192
                CommitTxHash:     commitTx2.TxHash(),
193
                HTLCEntries: []*HTLCEntry{
194
                        {
195
                                RHash:         rHash,
196
                                RefundTimeout: 489,
197
                                OutputIndex:   0,
198
                                Incoming:      false,
199
                                Amt:           btcutil.Amount(100_000),
200
                        },
201
                },
202
        }
203

204
        // newLog2WithAmts is the new version of oldLog2 in the case were we do
205
        // want to store balance data.
206
        newLog2WithAmts = RevocationLog{
207
                OurOutputIndex:   1,
208
                TheirOutputIndex: OutputIndexEmpty,
209
                CommitTxHash:     commitTx2.TxHash(),
210
                OurBalance:       &localBalance2,
211
                TheirBalance:     &remoteBalance2,
212
                HTLCEntries: []*HTLCEntry{
213
                        {
214
                                RHash:         rHash,
215
                                RefundTimeout: 489,
216
                                OutputIndex:   0,
217
                                Incoming:      false,
218
                                Amt:           btcutil.Amount(100_000),
219
                        },
220
                },
221
        }
222

223
        // newLog3 defines an revocation log that's been created after v0.15.0.
224
        newLog3 = mig.ChannelCommitment{
225
                CommitHeight:    logHeight2 + 1,
226
                LocalLogIndex:   1,
227
                LocalHtlcIndex:  1,
228
                RemoteLogIndex:  0,
229
                RemoteHtlcIndex: 0,
230
                LocalBalance:    lnwire.MilliSatoshi(888_800_000),
231
                RemoteBalance:   0,
232
                CommitTx:        commitTx2,
233
                Htlcs:           []mig.HTLC{htlc},
234
        }
235

236
        // The following public keys are taken from the itest results.
237
        localMusigKey, _ = btcec.ParsePubKey([]byte{
238
                0x2,
239
                0xda, 0x42, 0xa4, 0x4a, 0x6b, 0x42, 0xfe, 0xcb,
240
                0x2f, 0x7e, 0x35, 0x89, 0x99, 0xdd, 0x43, 0xba,
241
                0x4b, 0xf1, 0x9c, 0xf, 0x18, 0xef, 0x9, 0x83,
242
                0x35, 0x31, 0x59, 0xa4, 0x3b, 0xde, 0xa, 0xde,
243
        })
244
        localRevocationBasePoint, _ = btcec.ParsePubKey([]byte{
245
                0x2,
246
                0x6, 0x16, 0xd1, 0xb1, 0x4f, 0xee, 0x11, 0x86,
247
                0x55, 0xfe, 0x31, 0x66, 0x6f, 0x43, 0x1, 0x80,
248
                0xa8, 0xa7, 0x5c, 0x2, 0x92, 0xe5, 0x7c, 0x4,
249
                0x31, 0xa6, 0xcf, 0x43, 0xb6, 0xdb, 0xe6, 0x10,
250
        })
251
        localPaymentBasePoint, _ = btcec.ParsePubKey([]byte{
252
                0x2,
253
                0x88, 0x65, 0x16, 0xc2, 0x37, 0x3f, 0xc5, 0x16,
254
                0x62, 0x71, 0x0, 0xdd, 0x4d, 0x43, 0x28, 0x43,
255
                0x32, 0x91, 0x75, 0xcc, 0xd8, 0x81, 0xb6, 0xb0,
256
                0xd8, 0x96, 0x78, 0xad, 0x18, 0x3b, 0x16, 0xe1,
257
        })
258
        localDelayBasePoint, _ = btcec.ParsePubKey([]byte{
259
                0x2,
260
                0xea, 0x41, 0x48, 0x11, 0x2, 0x59, 0xe3, 0x5c,
261
                0x51, 0x15, 0x90, 0x25, 0x4a, 0x61, 0x5, 0x51,
262
                0xb3, 0x8, 0xe9, 0xd5, 0xf, 0xc6, 0x91, 0x25,
263
                0x14, 0xd2, 0xcf, 0xc8, 0xc5, 0x5b, 0xd9, 0x88,
264
        })
265
        localHtlcBasePoint, _ = btcec.ParsePubKey([]byte{
266
                0x3,
267
                0xfa, 0x1f, 0x6, 0x3a, 0xa4, 0x75, 0x2e, 0x74,
268
                0x3e, 0x55, 0x9, 0x20, 0x6e, 0xf6, 0xa8, 0xe1,
269
                0xd7, 0x61, 0x50, 0x75, 0xa8, 0x34, 0x15, 0xc3,
270
                0x6b, 0xdc, 0xb0, 0xbf, 0xaa, 0x66, 0xd7, 0xa7,
271
        })
272

273
        remoteMultiSigKey, _ = btcec.ParsePubKey([]byte{
274
                0x2,
275
                0x2b, 0x88, 0x7c, 0x6a, 0xf8, 0xb3, 0x51, 0x61,
276
                0xd3, 0x1c, 0xf1, 0xe4, 0x43, 0xc2, 0x8c, 0x5e,
277
                0xfa, 0x8e, 0xb5, 0xe9, 0xd0, 0x14, 0xb5, 0x33,
278
                0x6a, 0xcc, 0xd, 0x11, 0x42, 0xb8, 0x4b, 0x7d,
279
        })
280
        remoteRevocationBasePoint, _ = btcec.ParsePubKey([]byte{
281
                0x2,
282
                0x6c, 0x39, 0xa3, 0x6d, 0x93, 0x69, 0xac, 0x14,
283
                0x1f, 0xbb, 0x4, 0x86, 0x3, 0x82, 0x5, 0xe2,
284
                0xcb, 0xb0, 0x62, 0x41, 0xa, 0x93, 0x3, 0x6c,
285
                0x8d, 0xc0, 0x42, 0x4d, 0x9e, 0x51, 0x9b, 0x36,
286
        })
287
        remotePaymentBasePoint, _ = btcec.ParsePubKey([]byte{
288
                0x3,
289
                0xab, 0x74, 0x1e, 0x83, 0x48, 0xe3, 0xb5, 0x6,
290
                0x25, 0x1c, 0x80, 0xe7, 0xf2, 0x3e, 0x7d, 0xb7,
291
                0x7a, 0xc7, 0xd, 0x6, 0x3b, 0xbc, 0x74, 0x96,
292
                0x8e, 0x9b, 0x2d, 0xd1, 0x42, 0x71, 0xa5, 0x2a,
293
        })
294
        remoteDelayBasePoint, _ = btcec.ParsePubKey([]byte{
295
                0x2,
296
                0x4b, 0xdd, 0x52, 0x46, 0x1b, 0x50, 0x89, 0xb9,
297
                0x49, 0x4, 0xf2, 0xd2, 0x98, 0x7d, 0x51, 0xa1,
298
                0xa6, 0x3f, 0x9b, 0xd0, 0x40, 0x7c, 0x93, 0x74,
299
                0x3b, 0x8c, 0x4d, 0x63, 0x32, 0x90, 0xa, 0xca,
300
        })
301
        remoteHtlcBasePoint, _ = btcec.ParsePubKey([]byte{
302
                0x3,
303
                0x5b, 0x8f, 0x4a, 0x71, 0x4c, 0x2e, 0x71, 0x14,
304
                0x86, 0x1f, 0x30, 0x96, 0xc0, 0xd4, 0x11, 0x76,
305
                0xf8, 0xc3, 0xfc, 0x7, 0x2d, 0x15, 0x99, 0x55,
306
                0x8, 0x69, 0xf6, 0x1, 0xa2, 0xcd, 0x6b, 0xa7,
307
        })
308

309
        // withAmtData if set, will result in the amount data of the revoked
310
        // commitment transactions also being stored in the new revocation log.
311
        // The value of this variable is set randomly in the init function of
312
        // this package.
313
        withAmtData bool
314
)
315

316
// setupTestLogs takes care of creating the related buckets and inserts testing
317
// records.
318
func setupTestLogs(db kvdb.Backend, c *mig26.OpenChannel,
319
        oldLogs, newLogs []mig.ChannelCommitment) error {
×
320

×
321
        return kvdb.Update(db, func(tx kvdb.RwTx) error {
×
322
                // If the open channel is nil, only create the root
×
323
                // bucket and skip creating the channel bucket.
×
324
                if c == nil {
×
325
                        _, err := tx.CreateTopLevelBucket(openChannelBucket)
×
326
                        return err
×
327
                }
×
328

329
                // Create test buckets.
330
                chanBucket, err := mig25.CreateChanBucket(tx, &c.OpenChannel)
×
331
                if err != nil {
×
332
                        return err
×
333
                }
×
334

335
                // Save channel info.
336
                if err := mig26.PutChanInfo(chanBucket, c, false); err != nil {
×
337
                        return fmt.Errorf("PutChanInfo got %w", err)
×
338
                }
×
339

340
                // Save revocation state.
341
                if err := putChanRevocationState(chanBucket, c); err != nil {
×
342
                        return fmt.Errorf("putChanRevocationState got %w", err)
×
343
                }
×
344

345
                // Create old logs.
346
                err = writeOldRevocationLogs(chanBucket, oldLogs)
×
347
                if err != nil {
×
348
                        return fmt.Errorf("write old logs: %w", err)
×
349
                }
×
350

351
                // Create new logs.
352
                return writeNewRevocationLogs(chanBucket, newLogs, !withAmtData)
×
353
        }, func() {})
×
354
}
355

356
// createTestChannel creates an OpenChannel using the specified nodePub and
357
// outpoint. If any of the params is nil, a random value is populated.
358
func createTestChannel(nodePub *btcec.PublicKey) *mig26.OpenChannel {
×
359
        // Create a random private key that's used to provide randomness.
×
360
        priv, _ := btcec.NewPrivateKey()
×
361

×
362
        // If passed public key is nil, use the random public key.
×
363
        if nodePub == nil {
×
364
                nodePub = priv.PubKey()
×
365
        }
×
366

367
        // Create a random channel point.
368
        var op wire.OutPoint
×
369
        copy(op.Hash[:], priv.Serialize())
×
370

×
371
        testProducer := shachain.NewRevocationProducer(op.Hash)
×
372
        store, _ := createTestStore()
×
373

×
374
        localCfg := mig.ChannelConfig{
×
375
                ChannelConstraints: mig.ChannelConstraints{
×
376
                        DustLimit:        btcutil.Amount(354),
×
377
                        MaxAcceptedHtlcs: 483,
×
378
                        CsvDelay:         4,
×
379
                },
×
380
                MultiSigKey: keychain.KeyDescriptor{
×
381
                        KeyLocator: keychain.KeyLocator{
×
382
                                Family: 0,
×
383
                                Index:  0,
×
384
                        },
×
385
                        PubKey: localMusigKey,
×
386
                },
×
387
                RevocationBasePoint: keychain.KeyDescriptor{
×
388
                        KeyLocator: keychain.KeyLocator{
×
389
                                Family: 1,
×
390
                                Index:  0,
×
391
                        },
×
392
                        PubKey: localRevocationBasePoint,
×
393
                },
×
394
                HtlcBasePoint: keychain.KeyDescriptor{
×
395
                        KeyLocator: keychain.KeyLocator{
×
396
                                Family: 2,
×
397
                                Index:  0,
×
398
                        },
×
399
                        PubKey: localHtlcBasePoint,
×
400
                },
×
401
                PaymentBasePoint: keychain.KeyDescriptor{
×
402
                        KeyLocator: keychain.KeyLocator{
×
403
                                Family: 3,
×
404
                                Index:  0,
×
405
                        },
×
406
                        PubKey: localPaymentBasePoint,
×
407
                },
×
408
                DelayBasePoint: keychain.KeyDescriptor{
×
409
                        KeyLocator: keychain.KeyLocator{
×
410
                                Family: 4,
×
411
                                Index:  0,
×
412
                        },
×
413
                        PubKey: localDelayBasePoint,
×
414
                },
×
415
        }
×
416

×
417
        remoteCfg := mig.ChannelConfig{
×
418
                ChannelConstraints: mig.ChannelConstraints{
×
419
                        DustLimit:        btcutil.Amount(354),
×
420
                        MaxAcceptedHtlcs: 483,
×
421
                        CsvDelay:         4,
×
422
                },
×
423
                MultiSigKey: keychain.KeyDescriptor{
×
424
                        KeyLocator: keychain.KeyLocator{
×
425
                                Family: 0,
×
426
                                Index:  0,
×
427
                        },
×
428
                        PubKey: remoteMultiSigKey,
×
429
                },
×
430
                RevocationBasePoint: keychain.KeyDescriptor{
×
431
                        KeyLocator: keychain.KeyLocator{
×
432
                                Family: 0,
×
433
                                Index:  0,
×
434
                        },
×
435
                        PubKey: remoteRevocationBasePoint,
×
436
                },
×
437
                HtlcBasePoint: keychain.KeyDescriptor{
×
438
                        KeyLocator: keychain.KeyLocator{
×
439
                                Family: 0,
×
440
                                Index:  0,
×
441
                        },
×
442
                        PubKey: remoteHtlcBasePoint,
×
443
                },
×
444
                PaymentBasePoint: keychain.KeyDescriptor{
×
445
                        KeyLocator: keychain.KeyLocator{
×
446
                                Family: 0,
×
447
                                Index:  0,
×
448
                        },
×
449
                        PubKey: remotePaymentBasePoint,
×
450
                },
×
451
                DelayBasePoint: keychain.KeyDescriptor{
×
452
                        KeyLocator: keychain.KeyLocator{
×
453
                                Family: 0,
×
454
                                Index:  0,
×
455
                        },
×
456
                        PubKey: remoteDelayBasePoint,
×
457
                },
×
458
        }
×
459

×
460
        c := &mig26.OpenChannel{
×
461
                OpenChannel: mig25.OpenChannel{
×
462
                        OpenChannel: mig.OpenChannel{
×
463
                                ChainHash:       testChainHash,
×
464
                                IdentityPub:     nodePub,
×
465
                                FundingOutpoint: op,
×
466
                                LocalChanCfg:    localCfg,
×
467
                                RemoteChanCfg:   remoteCfg,
×
468
                                // Assign dummy values.
×
469
                                RemoteCurrentRevocation: nodePub,
×
470
                                RevocationProducer:      testProducer,
×
471
                                RevocationStore:         store,
×
472
                        },
×
473
                        ChanType: testChanType,
×
474
                },
×
475
        }
×
476

×
477
        return c
×
478
}
479

480
// writeOldRevocationLogs saves an old revocation log to db.
481
func writeOldRevocationLogs(chanBucket kvdb.RwBucket,
482
        oldLogs []mig.ChannelCommitment) error {
×
483

×
484
        // Don't bother continue if the logs are empty.
×
485
        if len(oldLogs) == 0 {
×
486
                return nil
×
487
        }
×
488

489
        logBucket, err := chanBucket.CreateBucketIfNotExists(
×
490
                revocationLogBucketDeprecated,
×
491
        )
×
492
        if err != nil {
×
493
                return err
×
494
        }
×
495

496
        for _, c := range oldLogs {
×
497
                if err := putOldRevocationLog(logBucket, &c); err != nil {
×
498
                        return err
×
499
                }
×
500
        }
501
        return nil
×
502
}
503

504
// writeNewRevocationLogs saves a new revocation log to db.
505
func writeNewRevocationLogs(chanBucket kvdb.RwBucket,
506
        oldLogs []mig.ChannelCommitment, noAmtData bool) error {
×
507

×
508
        // Don't bother continue if the logs are empty.
×
509
        if len(oldLogs) == 0 {
×
510
                return nil
×
511
        }
×
512

513
        logBucket, err := chanBucket.CreateBucketIfNotExists(
×
514
                revocationLogBucket,
×
515
        )
×
516
        if err != nil {
×
517
                return err
×
518
        }
×
519

520
        for _, c := range oldLogs {
×
521
                // NOTE: we just blindly write the output indexes to db here
×
522
                // whereas normally, we would find the correct indexes from the
×
523
                // old commit tx. We do this intentionally so we can
×
524
                // distinguish a newly created log from an already saved one.
×
525
                err := putRevocationLog(
×
526
                        logBucket, &c, testOurIndex, testTheirIndex, noAmtData,
×
527
                )
×
528
                if err != nil {
×
529
                        return err
×
530
                }
×
531
        }
532
        return nil
×
533
}
534

535
// createTestStore creates a revocation store and always saves the above
536
// defined two preimages into the store.
537
func createTestStore() (shachain.Store, error) {
×
538
        var p chainhash.Hash
×
539
        copy(p[:], preimage1)
×
540

×
541
        testStore := shachain.NewRevocationStore()
×
542
        if err := testStore.AddNextEntry(&p); err != nil {
×
543
                return nil, err
×
544
        }
×
545

546
        copy(p[:], preimage2)
×
547
        if err := testStore.AddNextEntry(&p); err != nil {
×
548
                return nil, err
×
549
        }
×
550

551
        return testStore, nil
×
552
}
553

554
// createNotStarted will setup a situation where we haven't started the
555
// migration for the channel. We use the legacy to denote whether to simulate a
556
// node with v0.15.0.
557
func createNotStarted(cdb kvdb.Backend, c *mig26.OpenChannel,
558
        legacy bool) error {
×
559

×
560
        var newLogs []mig.ChannelCommitment
×
561

×
562
        // Create test logs.
×
563
        oldLogs := []mig.ChannelCommitment{oldLog1, oldLog2}
×
564

×
565
        // Add a new log if the node is running with v0.15.0.
×
566
        if !legacy {
×
567
                newLogs = []mig.ChannelCommitment{newLog3}
×
568
        }
×
569
        return setupTestLogs(cdb, c, oldLogs, newLogs)
×
570
}
571

572
// createNotFinished will setup a situation where we have un-migrated logs and
573
// return the next migration height. We use the legacy to denote whether to
574
// simulate a node with v0.15.0.
575
func createNotFinished(cdb kvdb.Backend, c *mig26.OpenChannel,
576
        legacy bool) error {
×
577

×
578
        // Create test logs.
×
579
        oldLogs := []mig.ChannelCommitment{oldLog1, oldLog2}
×
580
        newLogs := []mig.ChannelCommitment{oldLog1}
×
581

×
582
        // Add a new log if the node is running with v0.15.0.
×
583
        if !legacy {
×
584
                newLogs = append(newLogs, newLog3)
×
585
        }
×
586
        return setupTestLogs(cdb, c, oldLogs, newLogs)
×
587
}
588

589
// createFinished will setup a situation where all the old logs have been
590
// migrated and return a nil. We use the legacy to denote whether to simulate a
591
// node with v0.15.0.
592
func createFinished(cdb kvdb.Backend, c *mig26.OpenChannel,
593
        legacy bool) error {
×
594

×
595
        // Create test logs.
×
596
        oldLogs := []mig.ChannelCommitment{oldLog1, oldLog2}
×
597
        newLogs := []mig.ChannelCommitment{oldLog1, oldLog2}
×
598

×
599
        // Add a new log if the node is running with v0.15.0.
×
600
        if !legacy {
×
601
                newLogs = append(newLogs, newLog3)
×
602
        }
×
603
        return setupTestLogs(cdb, c, oldLogs, newLogs)
×
604
}
605

606
func init() {
3✔
607
        rand.Seed(time.Now().Unix())
3✔
608
        if rand.Intn(2) == 0 {
6✔
609
                withAmtData = true
3✔
610
        }
3✔
611

612
        if withAmtData {
6✔
613
                newLog1 = newLog1WithAmts
3✔
614
                newLog2 = newLog2WithAmts
3✔
615
        }
3✔
616
}
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