From 1669e3d5ec92d6fd6a01b59d91c96319cd8953f7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 17 Feb 2018 15:40:10 -0800 Subject: [PATCH] lnd: use first key in keychain.KeyFamilyNodeKey as our nodeID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we update lnd to now access the deterministic keychain.KeyRing struct in order to obtain our identity public key. With this change, if the user recovers their wallet with the same seed, then they’ll have access to the same prior node identity. This change also makes it easy for us to support node key rotation in the future by bumping up our requested index. --- lnd.go | 14 +++++++++++--- mock.go | 3 +-- pilot.go | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lnd.go b/lnd.go index d88affda..0c269f65 100644 --- a/lnd.go +++ b/lnd.go @@ -37,6 +37,7 @@ import ( flags "github.com/jessevdk/go-flags" "github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/btcwallet" @@ -237,7 +238,13 @@ func lndMain() error { primaryChain := registeredChains.PrimaryChain() registeredChains.RegisterChain(primaryChain, activeChainControl) - idPrivKey, err := activeChainControl.wallet.GetIdentitykey() + // TODO(roasbeef): add rotation + idPrivKey, err := activeChainControl.wallet.DerivePrivKey(keychain.KeyDescriptor{ + KeyLocator: keychain.KeyLocator{ + Family: keychain.KeyFamilyNodeKey, + Index: 0, + }, + }) if err != nil { return err } @@ -252,8 +259,9 @@ func lndMain() error { // Set up the core server which will listen for incoming peer // connections. - server, err := newServer(cfg.Listeners, chanDB, activeChainControl, - idPrivKey) + server, err := newServer( + cfg.Listeners, chanDB, activeChainControl, idPrivKey, + ) if err != nil { srvrLog.Errorf("unable to create server: %v\n", err) return err diff --git a/mock.go b/mock.go index 2e47532c..5d2868d0 100644 --- a/mock.go +++ b/mock.go @@ -203,8 +203,7 @@ func (*mockWalletController) FetchInputInfo( } return txOut, nil } -func (*mockWalletController) ConfirmedBalance(confs int32, - witness bool) (btcutil.Amount, error) { +func (*mockWalletController) ConfirmedBalance(confs int32) (btcutil.Amount, error) { return 0, nil } diff --git a/pilot.go b/pilot.go index c82b0f17..b6eb3a78 100644 --- a/pilot.go +++ b/pilot.go @@ -146,7 +146,7 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error) Heuristic: prefAttachment, ChanController: &chanController{svr}, WalletBalance: func() (btcutil.Amount, error) { - return svr.cc.wallet.ConfirmedBalance(1, true) + return svr.cc.wallet.ConfirmedBalance(1) }, Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()), }