When a noMacaroonCreation bool is passed in, don't create new macaroons

pull/406/head
Turtle 3 years ago
parent e46a345a0d
commit 7e694f01e2
No known key found for this signature in database
GPG Key ID: 3E325201FFD68EC0

@ -129,7 +129,7 @@ func (d *Daemon) Start() error {
// server client, the swap client RPC server instance and our main swap
// and error handlers. If this fails, then nothing has been started yet
// and we can just return the error.
err = d.initialize()
err = d.initialize(false)
if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started as a standalone Loop daemon, most
// likely LiT is already running and blocking the DB
@ -161,7 +161,9 @@ func (d *Daemon) Start() error {
// create its own gRPC server but registers to an existing one. The same goes
// for REST (if enabled), instead of creating an own mux and HTTP server, we
// register to an existing one.
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
noMacaroonCreation bool) error {
// There should be no reason to start the daemon twice. Therefore return
// an error if that's tried. This is mostly to guard against Start and
// StartAsSubserver both being called.
@ -177,7 +179,7 @@ func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
// the swap server client, the RPC server instance and our main swap
// handlers. If this fails, then nothing has been started yet and we can
// just return the error.
err := d.initialize()
err := d.initialize(noMacaroonCreation)
if errors.Is(err, bbolt.ErrTimeout) {
// We're trying to be started inside LiT so there most likely is
// another standalone Loop process blocking the DB.
@ -337,7 +339,7 @@ func (d *Daemon) startWebServers() error {
// the swap client RPC server instance and our main swap and error handlers. If
// this method fails with an error then no goroutine was started yet and no
// cleanup is necessary. If it succeeds, then goroutines have been spawned.
func (d *Daemon) initialize() error {
func (d *Daemon) initialize(noMacaroonCreation bool) error {
// If no swap server is specified, use the default addresses for mainnet
// and testnet.
if d.cfg.Server.Host == "" {
@ -368,7 +370,7 @@ func (d *Daemon) initialize() error {
// Start the macaroon service and let it create its default macaroon in
// case it doesn't exist yet.
err = d.startMacaroonService()
err = d.startMacaroonService(noMacaroonCreation)
if err != nil {
// The client is the only thing we started yet, so if we clean
// up its connection now, nothing else needs to be shut down at

@ -151,7 +151,7 @@ var (
// unlocks the macaroon database and creates the default macaroon if it doesn't
// exist yet. If macaroons are disabled in general in the configuration, none of
// these actions are taken.
func (d *Daemon) startMacaroonService() error {
func (d *Daemon) startMacaroonService(noMacaroonCreation bool) error {
backend, err := kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{
DBPath: d.cfg.DataDir,
DBFileName: "macaroons.db",
@ -182,8 +182,10 @@ func (d *Daemon) startMacaroonService() error {
return fmt.Errorf("unable to unlock macaroon DB: %v", err)
}
// Create macaroon files for loop CLI to use if they don't exist.
if !lnrpc.FileExists(d.cfg.MacaroonPath) {
// If a macaroon string was passed into pool, then we already have a
// macaroon and don't need to create macaroon files. Otherwise, we'll
// create macaroon files for loop CLI to use if they don't exist.
if !noMacaroonCreation && !lnrpc.FileExists(d.cfg.MacaroonPath) {
// We don't offer the ability to rotate macaroon root keys yet,
// so just use the default one since the service expects some
// value to be set.

Loading…
Cancel
Save