Skip to content

Commit

Permalink
sweeptimelockmanual: add new test case with latest lnd
Browse files Browse the repository at this point in the history
  • Loading branch information
guggero committed Aug 21, 2024
1 parent bb9494a commit 2d40071
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
9 changes: 0 additions & 9 deletions cmd/chantools/sweeptimelockmanual.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,6 @@ func tryKey(baseKey *hdkeychain.ExtendedKey, remoteRevPoint *btcec.PublicKey,
}

// Now we try the same with the new revocation producer format.
multiSigPath = []uint32{
lnd.HardenedKey(uint32(keychain.KeyFamilyMultiSig)),
0, idx,
}
multiSigPrivKey, err = lnd.PrivKeyFromPath(baseKey, multiSigPath)
if err != nil {
return 0, nil, nil, nil, nil, err
}

revRoot3, err := lnd.ShaChainFromPath(
baseKey, revPath3, multiSigPrivKey.PubKey(),
)
Expand Down
27 changes: 24 additions & 3 deletions cmd/chantools/sweeptimelockmanual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

var sweepTimeLockManualCases = []struct {
baseKey string
rootKey string
basePath []uint32
keyIndex uint32
timeLockAddr string
remoteRevPubKey string
Expand Down Expand Up @@ -58,7 +60,7 @@ var sweepTimeLockManualCases = []struct {
// when already the old format was present, this leads to the situation
// where the idx for the shachain root (revocation root) is equal to
// the delay basepoint index. Normally when starting a node after
// lnd with the version v0.13.0-beta onwords, the index is always
// lnd with the version v0.13.0-beta onwards, the index is always
// +1 compared to the delay basepoint index.
baseKey: "tprv8e3Mee42NcUd2MbwxBCJyEEhvKa8KqjiDR76M7ym4DJSfZ" +
"kfDyA46XZeA4kTj8YKktWrjGBDThxxcL4HBF89jDKseu24XtugVMNsm3GhHwK",
Expand All @@ -67,6 +69,16 @@ var sweepTimeLockManualCases = []struct {
"rhetju2srseqrh",
remoteRevPubKey: "0341692a025ad552c62689a630ff24d9439e3752d8e0ac5cb4" +
"1b5e71ab2bd46d0f",
}, {
// Anchor channel with lnd 0.18.x-beta.
rootKey: "tprv8ZgxMBicQKsPdRiEUwMA71fkU9XoiPakhuSAEGCfcpgZxraB" +
"eXKCfJSVo2SMAAEENrZU6x4V5gu5at6cpnasaf9oSrUh72zXaEdWDgSFVEf",
basePath: []uint32{lnd.HardenedKey(1017), lnd.HardenedKey(1)},
keyIndex: 3,
timeLockAddr: "bcrt1qqm2u8pyqjc8akatdyap5qsjh7z4fuytwaehsjndt93e50l0" +
"sup4qa2384v",
remoteRevPubKey: "028a2199d9c64f21b59c01a5d5429fbe78b8709f0270deaf91" +
"578f682b87a12796",
}}

func TestSweepTimeLockManual(t *testing.T) {
Expand All @@ -79,8 +91,17 @@ func TestSweepTimeLockManual(t *testing.T) {
)
require.NoError(t, err)

baseKey, err := hdkeychain.NewKeyFromString(tc.baseKey)
require.NoError(t, err)
var baseKey *hdkeychain.ExtendedKey
if tc.baseKey != "" {
baseKey, err = hdkeychain.NewKeyFromString(tc.baseKey)
require.NoError(t, err)
} else {
rootKey, err := hdkeychain.NewKeyFromString(tc.rootKey)
require.NoError(t, err)

baseKey, err = lnd.DeriveChildren(rootKey, tc.basePath)
require.NoError(t, err)
}

revPubKeyBytes, _ := hex.DecodeString(tc.remoteRevPubKey)
revPubKey, _ := btcec.ParsePubKey(revPubKeyBytes)
Expand Down

0 comments on commit 2d40071

Please sign in to comment.