lnd: use first key in keychain.KeyFamilyNodeKey as our nodeID

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.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-17 15:40:10 -08:00
parent b41222b316
commit 1669e3d5ec
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 13 additions and 6 deletions

14
lnd.go
View File

@ -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

View File

@ -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
}

View File

@ -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()),
}