@@ -167,6 +167,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
167
167
startNumChannelsTotal uint16
168
168
maxNumChannelsTotal = c .MaxNumChannelsTotal
169
169
remoteRevocationBasePoint = c .RemoteRevocationBasePoint
170
+ multiSigIdx uint32
170
171
)
171
172
172
173
// We either support specifying the remote revocation base point
@@ -193,14 +194,13 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
193
194
}
194
195
195
196
remoteCfg := backupChan .RemoteChanCfg
197
+ localCfg := backupChan .LocalChanCfg
196
198
remoteRevocationBasePoint = remoteCfg .RevocationBasePoint .PubKey
197
199
198
200
startCsvLimit = remoteCfg .CsvDelay
199
201
maxCsvLimit = startCsvLimit + 1
200
202
201
- delayPath , err := lnd .ParsePath (
202
- backupChan .LocalChanCfg .DelayBasePoint .Path ,
203
- )
203
+ delayPath , err := lnd .ParsePath (localCfg .DelayBasePoint .Path )
204
204
if err != nil {
205
205
return fmt .Errorf ("error parsing delay path: %w" , err )
206
206
}
@@ -210,6 +210,16 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
210
210
211
211
startNumChannelsTotal = uint16 (delayPath [4 ])
212
212
maxNumChannelsTotal = startNumChannelsTotal + 1
213
+ multiSigKeyPath , err := lnd .ParsePath (localCfg .MultiSigKey .Path )
214
+ if err != nil {
215
+ return fmt .Errorf ("error parsing multisigkey path: %w" ,
216
+ err )
217
+ }
218
+ if len (multiSigKeyPath ) != 5 {
219
+ return fmt .Errorf ("invalid multisig path '%v'" ,
220
+ multiSigKeyPath )
221
+ }
222
+ multiSigIdx = multiSigKeyPath [4 ]
213
223
214
224
case c .ChannelBackup != "" && c .RemoteRevocationBasePoint != "" :
215
225
return errors .New ("cannot use both --frombackup and " +
@@ -230,16 +240,17 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
230
240
231
241
return sweepTimeLockManual (
232
242
extendedKey , c .APIURL , c .SweepAddr , c .TimeLockAddr ,
233
- remoteRevPoint , startCsvLimit , maxCsvLimit ,
243
+ remoteRevPoint , multiSigIdx , startCsvLimit , maxCsvLimit ,
234
244
startNumChannelsTotal , maxNumChannelsTotal ,
235
245
c .MaxNumChanUpdates , c .Publish , c .FeeRate ,
236
246
)
237
247
}
238
248
239
249
func sweepTimeLockManual (extendedKey * hdkeychain.ExtendedKey , apiURL string ,
240
250
sweepAddr , timeLockAddr string , remoteRevPoint * btcec.PublicKey ,
241
- startCsvTimeout , maxCsvTimeout , startNumChannels , maxNumChannels uint16 ,
242
- maxNumChanUpdates uint64 , publish bool , feeRate uint32 ) error {
251
+ multiSigIdx uint32 , startCsvTimeout , maxCsvTimeout , startNumChannels ,
252
+ maxNumChannels uint16 , maxNumChanUpdates uint64 , publish bool ,
253
+ feeRate uint32 ) error {
243
254
244
255
log .Debugf ("Starting to brute force the time lock script, using: " +
245
256
"remote_rev_base_point=%x, start_csv_limit=%d, " +
@@ -301,9 +312,13 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
301
312
commitPoint * btcec.PublicKey
302
313
)
303
314
for i := startNumChannels ; i < maxNumChannels ; i ++ {
315
+ if multiSigIdx == 0 {
316
+ multiSigIdx = uint32 (i )
317
+ }
318
+
304
319
csvTimeout , script , scriptHash , commitPoint , delayDesc , err = tryKey (
305
320
baseKey , remoteRevPoint , startCsvTimeout , maxCsvTimeout ,
306
- lockScript , uint32 (i ), maxNumChanUpdates ,
321
+ lockScript , uint32 (i ), multiSigIdx , maxNumChanUpdates ,
307
322
)
308
323
309
324
if err == nil {
@@ -413,9 +428,9 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
413
428
}
414
429
415
430
func tryKey (baseKey * hdkeychain.ExtendedKey , remoteRevPoint * btcec.PublicKey ,
416
- startCsvTimeout , maxCsvTimeout uint16 , lockScript []byte , idx uint32 ,
417
- maxNumChanUpdates uint64 ) (int32 , []byte , [] byte , * btcec. PublicKey ,
418
- * keychain.KeyDescriptor , error ) {
431
+ startCsvTimeout , maxCsvTimeout uint16 , lockScript []byte , idx ,
432
+ multiSigIdx uint32 , maxNumChanUpdates uint64 ) (int32 , []byte ,
433
+ [] byte , * btcec. PublicKey , * keychain.KeyDescriptor , error ) {
419
434
420
435
// The easy part first, let's derive the delay base point.
421
436
delayPath := []uint32 {
@@ -495,7 +510,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
495
510
// Now we try the same with the new revocation producer format.
496
511
multiSigPath := []uint32 {
497
512
lnd .HardenedKey (uint32 (keychain .KeyFamilyMultiSig )),
498
- 0 , idx ,
513
+ 0 , multiSigIdx ,
499
514
}
500
515
multiSigPrivKey , err := lnd .PrivKeyFromPath (baseKey , multiSigPath )
501
516
if err != nil {
0 commit comments