@@ -167,6 +167,7 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
167167 startNumChannelsTotal uint16
168168 maxNumChannelsTotal = c .MaxNumChannelsTotal
169169 remoteRevocationBasePoint = c .RemoteRevocationBasePoint
170+ multiSigIdx uint32
170171 )
171172
172173 // We either support specifying the remote revocation base point
@@ -193,14 +194,13 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
193194 }
194195
195196 remoteCfg := backupChan .RemoteChanCfg
197+ localCfg := backupChan .LocalChanCfg
196198 remoteRevocationBasePoint = remoteCfg .RevocationBasePoint .PubKey
197199
198200 startCsvLimit = remoteCfg .CsvDelay
199201 maxCsvLimit = startCsvLimit + 1
200202
201- delayPath , err := lnd .ParsePath (
202- backupChan .LocalChanCfg .DelayBasePoint .Path ,
203- )
203+ delayPath , err := lnd .ParsePath (localCfg .DelayBasePoint .Path )
204204 if err != nil {
205205 return fmt .Errorf ("error parsing delay path: %w" , err )
206206 }
@@ -210,6 +210,16 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
210210
211211 startNumChannelsTotal = uint16 (delayPath [4 ])
212212 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 ]
213223
214224 case c .ChannelBackup != "" && c .RemoteRevocationBasePoint != "" :
215225 return errors .New ("cannot use both --frombackup and " +
@@ -230,16 +240,17 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
230240
231241 return sweepTimeLockManual (
232242 extendedKey , c .APIURL , c .SweepAddr , c .TimeLockAddr ,
233- remoteRevPoint , startCsvLimit , maxCsvLimit ,
243+ remoteRevPoint , multiSigIdx , startCsvLimit , maxCsvLimit ,
234244 startNumChannelsTotal , maxNumChannelsTotal ,
235245 c .MaxNumChanUpdates , c .Publish , c .FeeRate ,
236246 )
237247}
238248
239249func sweepTimeLockManual (extendedKey * hdkeychain.ExtendedKey , apiURL string ,
240250 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 {
243254
244255 log .Debugf ("Starting to brute force the time lock script, using: " +
245256 "remote_rev_base_point=%x, start_csv_limit=%d, " +
@@ -301,9 +312,13 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
301312 commitPoint * btcec.PublicKey
302313 )
303314 for i := startNumChannels ; i < maxNumChannels ; i ++ {
315+ if multiSigIdx == 0 {
316+ multiSigIdx = uint32 (i )
317+ }
318+
304319 csvTimeout , script , scriptHash , commitPoint , delayDesc , err = tryKey (
305320 baseKey , remoteRevPoint , startCsvTimeout , maxCsvTimeout ,
306- lockScript , uint32 (i ), maxNumChanUpdates ,
321+ lockScript , uint32 (i ), multiSigIdx , maxNumChanUpdates ,
307322 )
308323
309324 if err == nil {
@@ -413,9 +428,9 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
413428}
414429
415430func 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 ) {
419434
420435 // The easy part first, let's derive the delay base point.
421436 delayPath := []uint32 {
@@ -495,7 +510,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
495510 // Now we try the same with the new revocation producer format.
496511 multiSigPath := []uint32 {
497512 lnd .HardenedKey (uint32 (keychain .KeyFamilyMultiSig )),
498- 0 , idx ,
513+ 0 , multiSigIdx ,
499514 }
500515 multiSigPrivKey , err := lnd .PrivKeyFromPath (baseKey , multiSigPath )
501516 if err != nil {
0 commit comments