lnd+walletunlocker: remove macaroon dependency from UnlockerService

This commit is contained in:
Wilmer Paulino 2018-04-20 03:06:06 -04:00
parent e73b457e1f
commit b32e0ced45
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
3 changed files with 26 additions and 54 deletions

44
lnd.go

@ -195,18 +195,6 @@ func lndMain() error {
}
proxyOpts := []grpc.DialOption{grpc.WithTransportCredentials(cCreds)}
var macaroonService *macaroons.Service
if !cfg.NoMacaroons {
// Create the macaroon authentication/authorization service.
macaroonService, err = macaroons.NewService(macaroonDatabaseDir,
macaroons.IPLockChecker)
if err != nil {
srvrLog.Errorf("unable to create macaroon service: %v", err)
return err
}
defer macaroonService.Close()
}
var (
privateWalletPw = []byte("hello")
publicWalletPw = []byte("public")
@ -216,11 +204,11 @@ func lndMain() error {
// We wait until the user provides a password over RPC. In case lnd is
// started with the --noencryptwallet flag, we use the default password
// "hello" for wallet encryption.
// for wallet encryption.
if !cfg.NoEncryptWallet {
walletInitParams, err := waitForWalletPassword(
cfg.RPCListeners, cfg.RESTListeners, serverOpts,
proxyOpts, tlsConf, macaroonService,
proxyOpts, tlsConf,
)
if err != nil {
return err
@ -238,12 +226,20 @@ func lndMain() error {
}
}
var macaroonService *macaroons.Service
if !cfg.NoMacaroons {
// Create the macaroon authentication/authorization service.
macaroonService, err = macaroons.NewService(macaroonDatabaseDir,
macaroons.IPLockChecker)
if err != nil {
srvrLog.Errorf("unable to create macaroon service: %v", err)
return err
}
defer macaroonService.Close()
// Try to unlock the macaroon store with the private password.
// Ignore ErrAlreadyUnlocked since it could be unlocked by the
// wallet unlocker.
err = macaroonService.CreateUnlock(&privateWalletPw)
if err != nil && err != macaroons.ErrAlreadyUnlocked {
if err != nil {
srvrLog.Error(err)
return err
}
@ -879,12 +875,9 @@ type WalletUnlockParams struct {
// waitForWalletPassword will spin up gRPC and REST endpoints for the
// WalletUnlocker server, and block until a password is provided by
// the user to this RPC server.
func waitForWalletPassword(
grpcEndpoints, restEndpoints []string,
serverOpts []grpc.ServerOption,
proxyOpts []grpc.DialOption,
tlsConf *tls.Config,
macaroonService *macaroons.Service) (*WalletUnlockParams, error) {
func waitForWalletPassword(grpcEndpoints, restEndpoints []string,
serverOpts []grpc.ServerOption, proxyOpts []grpc.DialOption,
tlsConf *tls.Config) (*WalletUnlockParams, error) {
// Set up a new PasswordService, which will listen
// for passwords provided over RPC.
@ -894,8 +887,9 @@ func waitForWalletPassword(
if registeredChains.PrimaryChain() == litecoinChain {
chainConfig = cfg.Litecoin
}
pwService := walletunlocker.New(macaroonService,
chainConfig.ChainDir, activeNetParams.Params)
pwService := walletunlocker.New(
chainConfig.ChainDir, activeNetParams.Params,
)
lnrpc.RegisterWalletUnlockerServer(grpcServer, pwService)
// Use a WaitGroup so we can be sure the instructions on how to input the

@ -8,7 +8,6 @@ import (
"github.com/lightningnetwork/lnd/aezeed"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/roasbeef/btcd/chaincfg"
"github.com/roasbeef/btcwallet/wallet"
"golang.org/x/net/context"
@ -67,13 +66,10 @@ type UnlockerService struct {
chainDir string
netParams *chaincfg.Params
authSvc *macaroons.Service
}
// New creates and returns a new UnlockerService.
func New(authSvc *macaroons.Service, chainDir string,
params *chaincfg.Params) *UnlockerService {
func New(chainDir string, params *chaincfg.Params) *UnlockerService {
return &UnlockerService{
InitMsgs: make(chan *WalletInitMsg, 1),
UnlockMsgs: make(chan *WalletUnlockMsg, 1),
@ -216,15 +212,6 @@ func (u *UnlockerService) InitWallet(ctx context.Context,
return nil, err
}
// Attempt to create a password for the macaroon service.
if u.authSvc != nil {
err = u.authSvc.CreateUnlock(&password)
if err != nil {
return nil, fmt.Errorf("unable to create/unlock "+
"macaroon store: %v", err)
}
}
// With the cipher seed deciphered, and the auth service created, we'll
// now send over the wallet password and the seed. This will allow the
// daemon to initialize itself and startup.
@ -277,15 +264,6 @@ func (u *UnlockerService) UnlockWallet(ctx context.Context,
return nil, err
}
// Attempt to create a password for the macaroon service.
if u.authSvc != nil {
err = u.authSvc.CreateUnlock(&password)
if err != nil {
return nil, fmt.Errorf("unable to create/unlock "+
"macaroon store: %v", err)
}
}
walletUnlockMsg := &WalletUnlockMsg{
Passphrase: password,
RecoveryWindow: recoveryWindow,

@ -67,7 +67,7 @@ func TestGenSeed(t *testing.T) {
defer func() {
os.RemoveAll(testDir)
}()
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase.
@ -108,7 +108,7 @@ func TestGenSeedGenerateEntropy(t *testing.T) {
defer func() {
os.RemoveAll(testDir)
}()
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase. Note that we don't actually
@ -148,7 +148,7 @@ func TestGenSeedInvalidEntropy(t *testing.T) {
defer func() {
os.RemoveAll(testDir)
}()
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
// Now that the service has been created, we'll ask it to generate a
// new seed for us given a test passphrase. However, we'll be using an
@ -186,7 +186,7 @@ func TestInitWallet(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
// Once we have the unlocker service created, we'll now instantiate a
// new cipher seed instance.
@ -287,7 +287,7 @@ func TestCreateWalletInvalidEntropy(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
// We'll attempt to init the wallet with an invalid cipher seed and
// passphrase.
@ -320,7 +320,7 @@ func TestUnlockWallet(t *testing.T) {
}()
// Create new UnlockerService.
service := walletunlocker.New(nil, testDir, testNetParams)
service := walletunlocker.New(testDir, testNetParams)
ctx := context.Background()
req := &lnrpc.UnlockWalletRequest{