• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 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,
UNCOV
319
        oldLogs, newLogs []mig.ChannelCommitment) error {
×
UNCOV
320

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

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

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

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

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

351
                // Create new logs.
UNCOV
352
                return writeNewRevocationLogs(chanBucket, newLogs, !withAmtData)
×
UNCOV
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.
UNCOV
358
func createTestChannel(nodePub *btcec.PublicKey) *mig26.OpenChannel {
×
UNCOV
359
        // Create a random private key that's used to provide randomness.
×
UNCOV
360
        priv, _ := btcec.NewPrivateKey()
×
UNCOV
361

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

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

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

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

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

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

×
UNCOV
477
        return c
×
478
}
479

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

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

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

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

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

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

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

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

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

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

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

UNCOV
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,
UNCOV
558
        legacy bool) error {
×
UNCOV
559

×
UNCOV
560
        var newLogs []mig.ChannelCommitment
×
UNCOV
561

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

×
UNCOV
565
        // Add a new log if the node is running with v0.15.0.
×
UNCOV
566
        if !legacy {
×
567
                newLogs = []mig.ChannelCommitment{newLog3}
×
568
        }
×
UNCOV
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,
UNCOV
576
        legacy bool) error {
×
UNCOV
577

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

×
UNCOV
582
        // Add a new log if the node is running with v0.15.0.
×
UNCOV
583
        if !legacy {
×
UNCOV
584
                newLogs = append(newLogs, newLog3)
×
UNCOV
585
        }
×
UNCOV
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,
UNCOV
593
        legacy bool) error {
×
UNCOV
594

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

×
UNCOV
599
        // Add a new log if the node is running with v0.15.0.
×
UNCOV
600
        if !legacy {
×
UNCOV
601
                newLogs = append(newLogs, newLog3)
×
UNCOV
602
        }
×
UNCOV
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