From e3c2c14bd1b8189bc0c39e7abfcdc6f53d886135 Mon Sep 17 00:00:00 2001 From: Turtle Date: Sun, 26 Sep 2021 01:30:41 -0500 Subject: [PATCH 1/2] frdrpc: 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. --- frdrpc/macaroons.go | 9 ++++++--- frdrpc/rpcserver.go | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/frdrpc/macaroons.go b/frdrpc/macaroons.go index e68228c..fa631a0 100644 --- a/frdrpc/macaroons.go +++ b/frdrpc/macaroons.go @@ -96,7 +96,7 @@ var ( // startMacaroonService starts the macaroon validation service, creates or // unlocks the macaroon database and creates the default macaroon if it doesn't // exist yet. -func (s *RPCServer) startMacaroonService() error { +func (s *RPCServer) startMacaroonService(createDefaultMacaroonFile bool) error { var err error s.macaroonDB, err = kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{ DBPath: s.cfg.FaradayDir, @@ -131,8 +131,11 @@ func (s *RPCServer) startMacaroonService() error { return fmt.Errorf("unable to unlock macaroon DB: %v", err) } - // Create macaroon files for faraday CLI to use if they don't exist. - if !lnrpc.FileExists(s.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 faraday + // CLI in the default directory. + if createDefaultMacaroonFile && !lnrpc.FileExists(s.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. diff --git a/frdrpc/rpcserver.go b/frdrpc/rpcserver.go index 28056de..c6ac732 100644 --- a/frdrpc/rpcserver.go +++ b/frdrpc/rpcserver.go @@ -182,7 +182,7 @@ func (s *RPCServer) Start() error { // Start the macaroon service and let it create its default macaroon in // case it doesn't exist yet. - if err := s.startMacaroonService(); err != nil { + if err := s.startMacaroonService(true); err != nil { return fmt.Errorf("error starting macaroon service: %v", err) } shutdownFuncs["macaroon"] = s.stopMacaroonService @@ -301,14 +301,16 @@ func (s *RPCServer) 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 (s *RPCServer) StartAsSubserver(lndClient lndclient.LndServices) error { +func (s *RPCServer) StartAsSubserver(lndClient lndclient.LndServices, + createDefaultMacaroonFile bool) error { + if atomic.AddInt32(&s.started, 1) != 1 { return errServerAlreadyStarted } // Start the macaroon service and let it create its default macaroon in // case it doesn't exist yet. - if err := s.startMacaroonService(); err != nil { + if err := s.startMacaroonService(createDefaultMacaroonFile); err != nil { return fmt.Errorf("error starting macaroon service: %v", err) } From 8c1f25dae3d281bcc55b77a8c78ac968f626e970 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 4 Nov 2021 13:55:27 +0100 Subject: [PATCH 2/2] rpcserver: stop macaroon service correctly --- frdrpc/rpcserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frdrpc/rpcserver.go b/frdrpc/rpcserver.go index c6ac732..00d91c8 100644 --- a/frdrpc/rpcserver.go +++ b/frdrpc/rpcserver.go @@ -347,7 +347,7 @@ func (s *RPCServer) Stop() error { } } - if err := s.macaroonService.Close(); err != nil { + if err := s.stopMacaroonService(); err != nil { log.Errorf("Error stopping macaroon service: %v", err) }