Skip to content

Commit 5bc4937

Browse files
committed
sweeptimelock: make start CSV timeout+channels configurable
1 parent 3044d9f commit 5bc4937

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

cmd/chantools/sweeptimelock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
239239
), input.DeriveRevocationPubkey(
240240
target.revocationBasePoint,
241241
target.commitPoint,
242-
), target.lockScript, maxCsvTimeout,
242+
), target.lockScript, 0, maxCsvTimeout,
243243
)
244244
if err != nil {
245245
log.Errorf("Could not create matching script for %s "+
@@ -346,14 +346,14 @@ func pubKeyFromHex(pubKeyHex string) (*btcec.PublicKey, error) {
346346
}
347347

348348
func bruteForceDelay(delayPubkey, revocationPubkey *btcec.PublicKey,
349-
targetScript []byte, maxCsvTimeout uint16) (int32, []byte, []byte,
350-
error) {
349+
targetScript []byte, startCsvTimeout, maxCsvTimeout uint16) (int32,
350+
[]byte, []byte, error) {
351351

352352
if len(targetScript) != 34 {
353353
return 0, nil, nil, fmt.Errorf("invalid target script: %s",
354354
targetScript)
355355
}
356-
for i := uint16(0); i <= maxCsvTimeout; i++ {
356+
for i := startCsvTimeout; i <= maxCsvTimeout; i++ {
357357
s, err := input.CommitScriptToSelf(
358358
uint32(i), delayPubkey, revocationPubkey,
359359
)

cmd/chantools/sweeptimelockmanual.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
136136

137137
return sweepTimeLockManual(
138138
extendedKey, c.APIURL, c.SweepAddr, c.TimeLockAddr,
139-
remoteRevPoint, c.MaxCsvLimit, c.MaxNumChansTotal,
139+
remoteRevPoint, 0, c.MaxCsvLimit, 0, c.MaxNumChansTotal,
140140
c.MaxNumChanUpdates, c.Publish, c.FeeRate,
141141
)
142142
}
143143

144144
func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
145145
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey,
146-
maxCsvTimeout, maxNumChannels uint16, maxNumChanUpdates uint64,
147-
publish bool, feeRate uint32) error {
146+
startCsvTimeout, maxCsvTimeout, startNumChannels, maxNumChannels uint16,
147+
maxNumChanUpdates uint64, publish bool, feeRate uint32) error {
148148

149149
// First of all, we need to parse the lock addr and make sure we can
150150
// brute force the script with the information we have. If not, we can't
@@ -179,10 +179,10 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
179179
delayDesc *keychain.KeyDescriptor
180180
commitPoint *btcec.PublicKey
181181
)
182-
for i := uint16(0); i < maxNumChannels; i++ {
182+
for i := startNumChannels; i < maxNumChannels; i++ {
183183
csvTimeout, script, scriptHash, commitPoint, delayDesc, err = tryKey(
184-
baseKey, remoteRevPoint, maxCsvTimeout, lockScript,
185-
uint32(i), maxNumChanUpdates,
184+
baseKey, remoteRevPoint, startCsvTimeout, maxCsvTimeout,
185+
lockScript, uint32(i), maxNumChanUpdates,
186186
)
187187

188188
if err == nil {
@@ -305,7 +305,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
305305
}
306306

307307
func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
308-
maxCsvTimeout uint16, lockScript []byte, idx uint32,
308+
startCsvTimeout, maxCsvTimeout uint16, lockScript []byte, idx uint32,
309309
maxNumChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey,
310310
*keychain.KeyDescriptor, error) {
311311

@@ -338,7 +338,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
338338
// points and CSV values.
339339
csvTimeout, script, scriptHash, commitPoint, err := bruteForceDelayPoint(
340340
delayPrivKey.PubKey(), remoteRevPoint, revRoot, lockScript,
341-
maxCsvTimeout, maxNumChanUpdates,
341+
startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
342342
)
343343
if err == nil {
344344
return csvTimeout, script, scriptHash, commitPoint,
@@ -403,7 +403,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
403403

404404
csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
405405
delayPrivKey.PubKey(), remoteRevPoint, revRoot2, lockScript,
406-
maxCsvTimeout, maxNumChanUpdates,
406+
startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
407407
)
408408
if err == nil {
409409
return csvTimeout, script, scriptHash, commitPoint,
@@ -444,7 +444,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
444444

445445
csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
446446
delayPrivKey.PubKey(), remoteRevPoint, revRoot3, lockScript,
447-
maxCsvTimeout, maxNumChanUpdates,
447+
startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
448448
)
449449
if err == nil {
450450
return csvTimeout, script, scriptHash, commitPoint,
@@ -462,8 +462,8 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
462462

463463
func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
464464
revRoot *shachain.RevocationProducer, lockScript []byte,
465-
maxCsvTimeout uint16, maxChanUpdates uint64) (int32, []byte, []byte,
466-
*btcec.PublicKey, error) {
465+
startCsvTimeout, maxCsvTimeout uint16, maxChanUpdates uint64) (int32,
466+
[]byte, []byte, *btcec.PublicKey, error) {
467467

468468
for i := uint64(0); i < maxChanUpdates; i++ {
469469
revPreimage, err := revRoot.AtIndex(i)
@@ -475,7 +475,7 @@ func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
475475
csvTimeout, script, scriptHash, err := bruteForceDelay(
476476
input.TweakPubKey(delayBase, commitPoint),
477477
input.DeriveRevocationPubkey(revBase, commitPoint),
478-
lockScript, maxCsvTimeout,
478+
lockScript, startCsvTimeout, maxCsvTimeout,
479479
)
480480

481481
if err != nil {

cmd/chantools/sweeptimelockmanual_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestSweepTimeLockManual(t *testing.T) {
8686
revPubKey, _ := btcec.ParsePubKey(revPubKeyBytes)
8787

8888
_, _, _, _, _, err = tryKey(
89-
baseKey, revPubKey, defaultCsvLimit, lockScript,
89+
baseKey, revPubKey, 0, defaultCsvLimit, lockScript,
9090
tc.keyIndex, 500,
9191
)
9292
require.NoError(t, err)

0 commit comments

Comments
 (0)