diff --git a/loopd/daemon.go b/loopd/daemon.go index 2081f19..0cd487b 100644 --- a/loopd/daemon.go +++ b/loopd/daemon.go @@ -131,7 +131,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(true) 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 @@ -163,7 +163,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, + createDefaultMacaroonFile 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. @@ -179,7 +181,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(createDefaultMacaroonFile) 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. @@ -339,7 +341,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(createDefaultMacaroonFile bool) error { // If no swap server is specified, use the default addresses for mainnet // and testnet. if d.cfg.Server.Host == "" { @@ -370,7 +372,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(createDefaultMacaroonFile) 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 diff --git a/loopd/macaroons.go b/loopd/macaroons.go index 706aafe..9d3689a 100644 --- a/loopd/macaroons.go +++ b/loopd/macaroons.go @@ -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(createDefaultMacaroonFile bool) error { var err error d.macaroonDB, err = kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{ DBPath: d.cfg.DataDir, @@ -184,8 +184,11 @@ 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) { + // There are situations in which we don't want a macaroon to be created + // on disk (for example when running inside LiT stateless integrated + // mode). For any other cases, we create macaroon files for the loop CLI + // in the default directory. + if createDefaultMacaroonFile && !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.