Skip to content

Commit 1503001

Browse files
orbitalturtleguggero
authored andcommitted
loopd: conditionally create default macaroon file
In some cases we don't want the default macaroon file to be created on disk, so we allow passing in a boolean that toggles the macaroon creation.
1 parent 139eac6 commit 1503001

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

loopd/daemon.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (d *Daemon) Start() error {
131131
// server client, the swap client RPC server instance and our main swap
132132
// and error handlers. If this fails, then nothing has been started yet
133133
// and we can just return the error.
134-
err = d.initialize()
134+
err = d.initialize(true)
135135
if errors.Is(err, bbolt.ErrTimeout) {
136136
// We're trying to be started as a standalone Loop daemon, most
137137
// likely LiT is already running and blocking the DB
@@ -163,7 +163,9 @@ func (d *Daemon) Start() error {
163163
// create its own gRPC server but registers to an existing one. The same goes
164164
// for REST (if enabled), instead of creating an own mux and HTTP server, we
165165
// register to an existing one.
166-
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
166+
func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices,
167+
createDefaultMacaroonFile bool) error {
168+
167169
// There should be no reason to start the daemon twice. Therefore return
168170
// an error if that's tried. This is mostly to guard against Start and
169171
// StartAsSubserver both being called.
@@ -179,7 +181,7 @@ func (d *Daemon) StartAsSubserver(lndGrpc *lndclient.GrpcLndServices) error {
179181
// the swap server client, the RPC server instance and our main swap
180182
// handlers. If this fails, then nothing has been started yet and we can
181183
// just return the error.
182-
err := d.initialize()
184+
err := d.initialize(createDefaultMacaroonFile)
183185
if errors.Is(err, bbolt.ErrTimeout) {
184186
// We're trying to be started inside LiT so there most likely is
185187
// another standalone Loop process blocking the DB.
@@ -339,7 +341,7 @@ func (d *Daemon) startWebServers() error {
339341
// the swap client RPC server instance and our main swap and error handlers. If
340342
// this method fails with an error then no goroutine was started yet and no
341343
// cleanup is necessary. If it succeeds, then goroutines have been spawned.
342-
func (d *Daemon) initialize() error {
344+
func (d *Daemon) initialize(createDefaultMacaroonFile bool) error {
343345
// If no swap server is specified, use the default addresses for mainnet
344346
// and testnet.
345347
if d.cfg.Server.Host == "" {
@@ -370,7 +372,7 @@ func (d *Daemon) initialize() error {
370372

371373
// Start the macaroon service and let it create its default macaroon in
372374
// case it doesn't exist yet.
373-
err = d.startMacaroonService()
375+
err = d.startMacaroonService(createDefaultMacaroonFile)
374376
if err != nil {
375377
// The client is the only thing we started yet, so if we clean
376378
// up its connection now, nothing else needs to be shut down at

loopd/macaroons.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ var (
151151
// unlocks the macaroon database and creates the default macaroon if it doesn't
152152
// exist yet. If macaroons are disabled in general in the configuration, none of
153153
// these actions are taken.
154-
func (d *Daemon) startMacaroonService() error {
154+
func (d *Daemon) startMacaroonService(createDefaultMacaroonFile bool) error {
155155
var err error
156156
d.macaroonDB, err = kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{
157157
DBPath: d.cfg.DataDir,
@@ -184,8 +184,11 @@ func (d *Daemon) startMacaroonService() error {
184184
return fmt.Errorf("unable to unlock macaroon DB: %v", err)
185185
}
186186

187-
// Create macaroon files for loop CLI to use if they don't exist.
188-
if !lnrpc.FileExists(d.cfg.MacaroonPath) {
187+
// There are situations in which we don't want a macaroon to be created
188+
// on disk (for example when running inside LiT stateless integrated
189+
// mode). For any other cases, we create macaroon files for the loop CLI
190+
// in the default directory.
191+
if createDefaultMacaroonFile && !lnrpc.FileExists(d.cfg.MacaroonPath) {
189192
// We don't offer the ability to rotate macaroon root keys yet,
190193
// so just use the default one since the service expects some
191194
// value to be set.

0 commit comments

Comments
 (0)