Skip to content

Commit b92bed8

Browse files
authored
Fix multisig path for sweeptimelockremote
1 parent d7d5ad9 commit b92bed8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cmd/chantools/sweeptimelockmanual.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -210,7 +211,16 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
210211

211212
startNumChannelsTotal = uint16(delayPath[4])
212213
maxNumChannelsTotal = startNumChannelsTotal + 1
213-
214+
multiSigKeyPath, err := lnd.ParsePath(
215+
backupChan.LocalChanCfg.MultiSigKey.Path,
216+
)
217+
if err != nil {
218+
return fmt.Errorf("error parsing multisigkey path: %w", err)
219+
}
220+
if len(multiSigKeyPath) != 5 {
221+
return fmt.Errorf("invalid delay path '%v'", multiSigKeyPath)
222+
}
223+
multiSigIdx = multiSigKeyPath[4]
214224
case c.ChannelBackup != "" && c.RemoteRevocationBasePoint != "":
215225
return errors.New("cannot use both --frombackup and " +
216226
"--remoterevbasepoint at the same time")
@@ -230,14 +240,14 @@ 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

239249
func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
240-
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey,
250+
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey, multiSigIdx uint32,
241251
startCsvTimeout, maxCsvTimeout, startNumChannels, maxNumChannels uint16,
242252
maxNumChanUpdates uint64, publish bool, feeRate uint32) error {
243253

@@ -302,7 +312,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
302312
)
303313
for i := startNumChannels; i < maxNumChannels; i++ {
304314
csvTimeout, script, scriptHash, commitPoint, delayDesc, err = tryKey(
305-
baseKey, remoteRevPoint, startCsvTimeout, maxCsvTimeout,
315+
baseKey, remoteRevPoint, multiSigIdx, startCsvTimeout, maxCsvTimeout,
306316
lockScript, uint32(i), maxNumChanUpdates,
307317
)
308318

@@ -413,7 +423,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
413423
}
414424

415425
func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
416-
startCsvTimeout, maxCsvTimeout uint16, lockScript []byte, idx uint32,
426+
multiSigIdx uint32, startCsvTimeout, maxCsvTimeout uint16, lockScript []byte, idx uint32,
417427
maxNumChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey,
418428
*keychain.KeyDescriptor, error) {
419429

@@ -491,11 +501,13 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
491501
keychain.KeyFamilyRevocationRoot,
492502
)), 0, idx,
493503
}
494-
504+
if multiSigIdx == 0 {
505+
multiSigIdx = idx
506+
}
495507
// Now we try the same with the new revocation producer format.
496508
multiSigPath := []uint32{
497509
lnd.HardenedKey(uint32(keychain.KeyFamilyMultiSig)),
498-
0, idx,
510+
0, multiSigIdx,
499511
}
500512
multiSigPrivKey, err := lnd.PrivKeyFromPath(baseKey, multiSigPath)
501513
if err != nil {

0 commit comments

Comments
 (0)