sweeptimelock: make start CSV timeout+channels configurable

pull/91/head
Oliver Gugger 6 months ago
parent 3044d9f796
commit 5bc49376a3
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -239,7 +239,7 @@ func sweepTimeLock(extendedKey *hdkeychain.ExtendedKey, apiURL string,
), input.DeriveRevocationPubkey( ), input.DeriveRevocationPubkey(
target.revocationBasePoint, target.revocationBasePoint,
target.commitPoint, target.commitPoint,
), target.lockScript, maxCsvTimeout, ), target.lockScript, 0, maxCsvTimeout,
) )
if err != nil { if err != nil {
log.Errorf("Could not create matching script for %s "+ log.Errorf("Could not create matching script for %s "+
@ -346,14 +346,14 @@ func pubKeyFromHex(pubKeyHex string) (*btcec.PublicKey, error) {
} }
func bruteForceDelay(delayPubkey, revocationPubkey *btcec.PublicKey, func bruteForceDelay(delayPubkey, revocationPubkey *btcec.PublicKey,
targetScript []byte, maxCsvTimeout uint16) (int32, []byte, []byte, targetScript []byte, startCsvTimeout, maxCsvTimeout uint16) (int32,
error) { []byte, []byte, error) {
if len(targetScript) != 34 { if len(targetScript) != 34 {
return 0, nil, nil, fmt.Errorf("invalid target script: %s", return 0, nil, nil, fmt.Errorf("invalid target script: %s",
targetScript) targetScript)
} }
for i := uint16(0); i <= maxCsvTimeout; i++ { for i := startCsvTimeout; i <= maxCsvTimeout; i++ {
s, err := input.CommitScriptToSelf( s, err := input.CommitScriptToSelf(
uint32(i), delayPubkey, revocationPubkey, uint32(i), delayPubkey, revocationPubkey,
) )

@ -136,15 +136,15 @@ func (c *sweepTimeLockManualCommand) Execute(_ *cobra.Command, _ []string) error
return sweepTimeLockManual( return sweepTimeLockManual(
extendedKey, c.APIURL, c.SweepAddr, c.TimeLockAddr, extendedKey, c.APIURL, c.SweepAddr, c.TimeLockAddr,
remoteRevPoint, c.MaxCsvLimit, c.MaxNumChansTotal, remoteRevPoint, 0, c.MaxCsvLimit, 0, c.MaxNumChansTotal,
c.MaxNumChanUpdates, c.Publish, c.FeeRate, c.MaxNumChanUpdates, c.Publish, c.FeeRate,
) )
} }
func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string, func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey, sweepAddr, timeLockAddr string, remoteRevPoint *btcec.PublicKey,
maxCsvTimeout, maxNumChannels uint16, maxNumChanUpdates uint64, startCsvTimeout, maxCsvTimeout, startNumChannels, maxNumChannels uint16,
publish bool, feeRate uint32) error { maxNumChanUpdates uint64, publish bool, feeRate uint32) error {
// First of all, we need to parse the lock addr and make sure we can // First of all, we need to parse the lock addr and make sure we can
// brute force the script with the information we have. If not, we can't // 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,
delayDesc *keychain.KeyDescriptor delayDesc *keychain.KeyDescriptor
commitPoint *btcec.PublicKey commitPoint *btcec.PublicKey
) )
for i := uint16(0); i < maxNumChannels; i++ { for i := startNumChannels; i < maxNumChannels; i++ {
csvTimeout, script, scriptHash, commitPoint, delayDesc, err = tryKey( csvTimeout, script, scriptHash, commitPoint, delayDesc, err = tryKey(
baseKey, remoteRevPoint, maxCsvTimeout, lockScript, baseKey, remoteRevPoint, startCsvTimeout, maxCsvTimeout,
uint32(i), maxNumChanUpdates, lockScript, uint32(i), maxNumChanUpdates,
) )
if err == nil { if err == nil {
@ -305,7 +305,7 @@ func sweepTimeLockManual(extendedKey *hdkeychain.ExtendedKey, apiURL string,
} }
func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey, func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
maxCsvTimeout uint16, lockScript []byte, idx uint32, startCsvTimeout, maxCsvTimeout uint16, lockScript []byte, idx uint32,
maxNumChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey, maxNumChanUpdates uint64) (int32, []byte, []byte, *btcec.PublicKey,
*keychain.KeyDescriptor, error) { *keychain.KeyDescriptor, error) {
@ -338,7 +338,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
// points and CSV values. // points and CSV values.
csvTimeout, script, scriptHash, commitPoint, err := bruteForceDelayPoint( csvTimeout, script, scriptHash, commitPoint, err := bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot, lockScript, delayPrivKey.PubKey(), remoteRevPoint, revRoot, lockScript,
maxCsvTimeout, maxNumChanUpdates, startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
) )
if err == nil { if err == nil {
return csvTimeout, script, scriptHash, commitPoint, return csvTimeout, script, scriptHash, commitPoint,
@ -403,7 +403,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint( csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot2, lockScript, delayPrivKey.PubKey(), remoteRevPoint, revRoot2, lockScript,
maxCsvTimeout, maxNumChanUpdates, startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
) )
if err == nil { if err == nil {
return csvTimeout, script, scriptHash, commitPoint, return csvTimeout, script, scriptHash, commitPoint,
@ -444,7 +444,7 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint( csvTimeout, script, scriptHash, commitPoint, err = bruteForceDelayPoint(
delayPrivKey.PubKey(), remoteRevPoint, revRoot3, lockScript, delayPrivKey.PubKey(), remoteRevPoint, revRoot3, lockScript,
maxCsvTimeout, maxNumChanUpdates, startCsvTimeout, maxCsvTimeout, maxNumChanUpdates,
) )
if err == nil { if err == nil {
return csvTimeout, script, scriptHash, commitPoint, return csvTimeout, script, scriptHash, commitPoint,
@ -462,8 +462,8 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey, func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
revRoot *shachain.RevocationProducer, lockScript []byte, revRoot *shachain.RevocationProducer, lockScript []byte,
maxCsvTimeout uint16, maxChanUpdates uint64) (int32, []byte, []byte, startCsvTimeout, maxCsvTimeout uint16, maxChanUpdates uint64) (int32,
*btcec.PublicKey, error) { []byte, []byte, *btcec.PublicKey, error) {
for i := uint64(0); i < maxChanUpdates; i++ { for i := uint64(0); i < maxChanUpdates; i++ {
revPreimage, err := revRoot.AtIndex(i) revPreimage, err := revRoot.AtIndex(i)
@ -475,7 +475,7 @@ func bruteForceDelayPoint(delayBase, revBase *btcec.PublicKey,
csvTimeout, script, scriptHash, err := bruteForceDelay( csvTimeout, script, scriptHash, err := bruteForceDelay(
input.TweakPubKey(delayBase, commitPoint), input.TweakPubKey(delayBase, commitPoint),
input.DeriveRevocationPubkey(revBase, commitPoint), input.DeriveRevocationPubkey(revBase, commitPoint),
lockScript, maxCsvTimeout, lockScript, startCsvTimeout, maxCsvTimeout,
) )
if err != nil { if err != nil {

@ -86,7 +86,7 @@ func TestSweepTimeLockManual(t *testing.T) {
revPubKey, _ := btcec.ParsePubKey(revPubKeyBytes) revPubKey, _ := btcec.ParsePubKey(revPubKeyBytes)
_, _, _, _, _, err = tryKey( _, _, _, _, _, err = tryKey(
baseKey, revPubKey, defaultCsvLimit, lockScript, baseKey, revPubKey, 0, defaultCsvLimit, lockScript,
tc.keyIndex, 500, tc.keyIndex, 500,
) )
require.NoError(t, err) require.NoError(t, err)

Loading…
Cancel
Save