Skip to content

Commit 7513141

Browse files
authored
Merge pull request #1213 from lightninglabs/lnd-wallet-restore
[wallet]: fix signing interaction with lnd, allowing restore from seed
2 parents f35de11 + 14d6f5d commit 7513141

File tree

8 files changed

+130
-25
lines changed

8 files changed

+130
-25
lines changed

docs/examples/basic-price-oracle/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ require (
9292
github.com/kkdai/bstream v1.0.0 // indirect
9393
github.com/lib/pq v1.10.9 // indirect
9494
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
95-
github.com/lightninglabs/lndclient v0.18.4-5 // indirect
95+
github.com/lightninglabs/lndclient v0.18.4-7 // indirect
9696
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd // indirect
9797
github.com/lightninglabs/neutrino/cache v1.1.2 // indirect
9898
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb // indirect
99-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2 // indirect
99+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1 // indirect
100100
github.com/lightningnetwork/lnd/clock v1.1.1 // indirect
101101
github.com/lightningnetwork/lnd/fn v1.2.3 // indirect
102102
github.com/lightningnetwork/lnd/healthcheck v1.2.5 // indirect

docs/examples/basic-price-oracle/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQ
418418
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbxOCWwUA6TIZvrkE0APd1T3WjFAwg=
419419
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
420420
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
421-
github.com/lightninglabs/lndclient v0.18.4-5 h1:KokX5ZlFuZEmtD7sHWg1cXzee0ZsnBWuSKV9/RcTEv4=
422-
github.com/lightninglabs/lndclient v0.18.4-5/go.mod h1:tafbfrisn1Iwt3em3nYWdE06C8jpoZtpNyiSB485OCg=
421+
github.com/lightninglabs/lndclient v0.18.4-7 h1:3lV3jeaL66wtxFeR+7YTo+1ZJ8YzD3gYHG8U9yas3YM=
422+
github.com/lightninglabs/lndclient v0.18.4-7/go.mod h1:qaIx+eqEV+Bdf1j7GVeJiDqJbtZXsr9XTfHu/8HmgQU=
423423
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
424424
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
425425
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
@@ -428,8 +428,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
428428
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
429429
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
430430
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
431-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2 h1:zGnSH1gTpPA637465d5tp7VkdWw5sVyWZxxmfZ0rKo4=
432-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
431+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1 h1:z6hFKvtbfo8udPrIb81GbSoKlUWd06d4LRxTkD19IMQ=
432+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
433433
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
434434
github.com/lightningnetwork/lnd/clock v1.1.1/go.mod h1:mGnAhPyjYZQJmebS7aevElXKTFDuO+uNFFfMXK1W8xQ=
435435
github.com/lightningnetwork/lnd/fn v1.2.3 h1:Q1OrgNSgQynVheBNa16CsKVov1JI5N2AR6G07x9Mles=

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ require (
2626
github.com/lib/pq v1.10.9
2727
github.com/lightninglabs/aperture v0.3.2-beta.0.20241015115230-d59b5514c19a
2828
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2
29-
github.com/lightninglabs/lndclient v0.18.4-5
29+
github.com/lightninglabs/lndclient v0.18.4-7
3030
github.com/lightninglabs/neutrino/cache v1.1.2
31-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2
31+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1
3232
github.com/lightningnetwork/lnd/cert v1.2.2
3333
github.com/lightningnetwork/lnd/clock v1.1.1
3434
github.com/lightningnetwork/lnd/fn v1.2.3

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ github.com/lightninglabs/lightning-node-connect v0.2.5-alpha h1:ZRVChwczFXK0CEbx
486486
github.com/lightninglabs/lightning-node-connect v0.2.5-alpha/go.mod h1:A9Pof9fETkH+F67BnOmrBDThPKstqp73wlImWOZvTXQ=
487487
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 h1:Er1miPZD2XZwcfE4xoS5AILqP1mj7kqnhbBSxW9BDxY=
488488
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2/go.mod h1:antQGRDRJiuyQF6l+k6NECCSImgCpwaZapATth2Chv4=
489-
github.com/lightninglabs/lndclient v0.18.4-5 h1:KokX5ZlFuZEmtD7sHWg1cXzee0ZsnBWuSKV9/RcTEv4=
490-
github.com/lightninglabs/lndclient v0.18.4-5/go.mod h1:tafbfrisn1Iwt3em3nYWdE06C8jpoZtpNyiSB485OCg=
489+
github.com/lightninglabs/lndclient v0.18.4-7 h1:3lV3jeaL66wtxFeR+7YTo+1ZJ8YzD3gYHG8U9yas3YM=
490+
github.com/lightninglabs/lndclient v0.18.4-7/go.mod h1:qaIx+eqEV+Bdf1j7GVeJiDqJbtZXsr9XTfHu/8HmgQU=
491491
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd h1:D8aRocHpoCv43hL8egXEMYyPmyOiefFHZ66338KQB2s=
492492
github.com/lightninglabs/neutrino v0.16.1-0.20240425105051-602843d34ffd/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk=
493493
github.com/lightninglabs/neutrino/cache v1.1.2 h1:C9DY/DAPaPxbFC+xNNEI/z1SJY9GS3shmlu5hIQ798g=
@@ -496,8 +496,8 @@ github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display h1:Y2WiPkBS
496496
github.com/lightninglabs/protobuf-go-hex-display v1.33.0-hex-display/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
497497
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb h1:yfM05S8DXKhuCBp5qSMZdtSwvJ+GFzl94KbXMNB1JDY=
498498
github.com/lightningnetwork/lightning-onion v1.2.1-0.20240712235311-98bd56499dfb/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
499-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2 h1:zGnSH1gTpPA637465d5tp7VkdWw5sVyWZxxmfZ0rKo4=
500-
github.com/lightningnetwork/lnd v0.18.3-beta.rc3.0.20241120143113-9246d5c51cd2/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
499+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1 h1:z6hFKvtbfo8udPrIb81GbSoKlUWd06d4LRxTkD19IMQ=
500+
github.com/lightningnetwork/lnd v0.18.4-beta.rc1/go.mod h1:nPRQzLla5uHPQFyyZn8r9Vgddkd23PBUDa9rggEPOfY=
501501
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
502502
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
503503
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=

itest/send_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,96 @@ func testSendNoCourierUniverseImport(t *harnessTest) {
19541954
AssertSendEventsComplete(t.t, receiveAddr.ScriptKey, sendEvents)
19551955
}
19561956

1957+
// testRestoreLndFromSeed tests that we can restore an LND node from a seed and
1958+
// then continue to interact with assets previously minted on the node.
1959+
func testRestoreLndFromSeed(t *harnessTest) {
1960+
// We create a new lnd node from a seed, so we can restore it with the
1961+
// same seed later.
1962+
password := []byte("somepassword")
1963+
seedLnd, mnemonic, _ := t.lndHarness.NewNodeWithSeed(
1964+
"seed-lnd", lndDefaultArgs, password, false,
1965+
)
1966+
t.lndHarness.FundCoins(btcutil.SatoshiPerBitcoin, seedLnd)
1967+
1968+
// We're going to restart Bob at some point, so we don't do a deferred
1969+
// shutdown here.
1970+
bob := setupTapdHarness(t.t, t, seedLnd, t.universeServer)
1971+
1972+
// We mint a batch of normal assets with enough units to allow us to
1973+
// send it around a few times.
1974+
rpcAssets := MintAssetsConfirmBatch(
1975+
t.t, t.lndHarness.Miner().Client, bob,
1976+
[]*mintrpc.MintAssetRequest{issuableAssets[0]},
1977+
)
1978+
1979+
var (
1980+
alice = t.tapd
1981+
ctxb = context.Background()
1982+
rpcAsset = rpcAssets[0]
1983+
genInfo = rpcAsset.AssetGenesis
1984+
)
1985+
1986+
// We send some of the minted assets to our default tapd node.
1987+
const sendAmount = 123
1988+
aliceAddr, err := alice.NewAddr(ctxb, &taprpc.NewAddrRequest{
1989+
AssetId: genInfo.AssetId,
1990+
Amt: sendAmount,
1991+
})
1992+
require.NoError(t.t, err)
1993+
1994+
AssertAddrCreated(t.t, alice, rpcAsset, aliceAddr)
1995+
1996+
sendResp, sendEvents := sendAssetsToAddr(t, bob, aliceAddr)
1997+
1998+
ConfirmAndAssertOutboundTransfer(
1999+
t.t, t.lndHarness.Miner().Client, bob, sendResp,
2000+
genInfo.AssetId,
2001+
[]uint64{rpcAsset.Amount - sendAmount, sendAmount}, 0, 1,
2002+
)
2003+
AssertNonInteractiveRecvComplete(t.t, alice, 1)
2004+
AssertSendEventsComplete(t.t, aliceAddr.ScriptKey, sendEvents)
2005+
2006+
// We now restore Bob's lnd node from the seed.
2007+
require.NoError(t.t, bob.stop(false))
2008+
require.NoError(t.t, seedLnd.Shutdown())
2009+
2010+
// Starting the node again should restore it to the same state as
2011+
// before. This takes a couple of seconds, so let's log that we're
2012+
// waiting for the node to start.
2013+
t.Logf("Restoring node from seed, this may take a few seconds...")
2014+
seedLnd = t.lndHarness.RestoreNodeWithSeed(
2015+
"lnd-seed-restored", lndDefaultArgs, password, mnemonic, "",
2016+
2500, nil,
2017+
)
2018+
require.NoError(t.t, updateConfigWithNode(bob.clientCfg, seedLnd))
2019+
2020+
require.NoError(t.t, bob.start(false))
2021+
2022+
// Let's make sure we properly clean up the node at the end of the test.
2023+
defer func() {
2024+
require.NoError(t.t, bob.stop(!*noDelete))
2025+
}()
2026+
2027+
// Send more assets after restoring the node.
2028+
aliceAddr, err = alice.NewAddr(ctxb, &taprpc.NewAddrRequest{
2029+
AssetId: genInfo.AssetId,
2030+
Amt: sendAmount,
2031+
})
2032+
require.NoError(t.t, err)
2033+
2034+
AssertAddrCreated(t.t, alice, rpcAsset, aliceAddr)
2035+
2036+
sendResp, sendEvents = sendAssetsToAddr(t, bob, aliceAddr)
2037+
2038+
ConfirmAndAssertOutboundTransfer(
2039+
t.t, t.lndHarness.Miner().Client, bob, sendResp,
2040+
genInfo.AssetId,
2041+
[]uint64{rpcAsset.Amount - sendAmount*2, sendAmount}, 1, 2,
2042+
)
2043+
AssertNonInteractiveRecvComplete(t.t, alice, 2)
2044+
AssertSendEventsComplete(t.t, aliceAddr.ScriptKey, sendEvents)
2045+
}
2046+
19572047
// addProofTestVectorFromFile adds a proof test vector by extracting it from the
19582048
// proof file found at the given asset ID and script key.
19592049
func addProofTestVectorFromFile(t *testing.T, testName string,

itest/tapd_harness.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
150150
}
151151
}
152152

153-
if cfg.LndNode == nil || cfg.LndNode.Cfg == nil {
154-
return nil, fmt.Errorf("lnd node configuration cannot be nil")
155-
}
156-
lndMacPath := filepath.Join(
157-
cfg.LndNode.Cfg.DataDir, "chain", "bitcoin", cfg.NetParams.Name,
158-
"admin.macaroon",
159-
)
160-
161153
tapCfg := tapcfg.DefaultConfig()
162154
tapCfg.LogDir = "."
163155
tapCfg.MaxLogFiles = 99
@@ -196,10 +188,9 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
196188
fmt.Sprintf("127.0.0.1:%d", nextAvailablePort()),
197189
}
198190

199-
tapCfg.Lnd = &tapcfg.LndConfig{
200-
Host: cfg.LndNode.Cfg.RPCAddr(),
201-
MacaroonPath: lndMacPath,
202-
TLSPath: cfg.LndNode.Cfg.TLSCertPath,
191+
// Update the config with the lnd node's connection info.
192+
if err := updateConfigWithNode(&tapCfg, cfg.LndNode); err != nil {
193+
return nil, err
203194
}
204195

205196
// Configure the universe server to ensure that valid proofs from tapd
@@ -297,6 +288,26 @@ func newTapdHarness(t *testing.T, ht *harnessTest, cfg tapdConfig,
297288
}, nil
298289
}
299290

291+
// updateConfigWithNode updates the tapd configuration with the connection
292+
// information of the given lnd node.
293+
func updateConfigWithNode(cfg *tapcfg.Config, lnd *node.HarnessNode) error {
294+
if lnd == nil || lnd.Cfg == nil {
295+
return fmt.Errorf("lnd node configuration cannot be nil")
296+
}
297+
lndMacPath := filepath.Join(
298+
lnd.Cfg.DataDir, "chain", "bitcoin", cfg.ChainConf.Network,
299+
"admin.macaroon",
300+
)
301+
302+
cfg.Lnd = &tapcfg.LndConfig{
303+
Host: lnd.Cfg.RPCAddr(),
304+
MacaroonPath: lndMacPath,
305+
TLSPath: lnd.Cfg.TLSCertPath,
306+
}
307+
308+
return nil
309+
}
310+
300311
// rpcHost returns the RPC host for the tapd server.
301312
func (hs *tapdHarness) rpcHost() string {
302313
return hs.clientCfg.RpcConf.RawRPCListeners[0]

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ var testCases = []*testCase{
324324
name: "ownership verification",
325325
test: testOwnershipVerification,
326326
},
327+
{
328+
name: "asset signing after lnd restore from seed",
329+
test: testRestoreLndFromSeed,
330+
},
327331
}
328332

329333
var optionalTestCases = []*testCase{

virtual_tx_signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewLndRpcVirtualTxSigner(lnd *lndclient.LndServices) *LndRpcVirtualTxSigner
2929
func (l *LndRpcVirtualTxSigner) SignVirtualTx(signDesc *lndclient.SignDescriptor,
3030
tx *wire.MsgTx, prevOut *wire.TxOut) (*schnorr.Signature, error) {
3131

32-
sigs, err := l.lnd.Signer.SignOutputRaw(
32+
sigs, err := l.lnd.Signer.SignOutputRawKeyLocator(
3333
context.Background(), tx, []*lndclient.SignDescriptor{signDesc},
3434
[]*wire.TxOut{prevOut},
3535
)

0 commit comments

Comments
 (0)