88
99 "github.com/coreos/bbolt"
1010 "github.com/lightninglabs/loop/loopdb"
11+ "github.com/lightningnetwork/lnd/kvdb"
1112 "github.com/lightningnetwork/lnd/lnrpc"
1213 "github.com/lightningnetwork/lnd/macaroons"
1314 "github.com/lightningnetwork/lnd/rpcperms"
@@ -151,18 +152,27 @@ var (
151152// exist yet. If macaroons are disabled in general in the configuration, none of
152153// these actions are taken.
153154func (d * Daemon ) startMacaroonService () error {
154- // Create the macaroon authentication/authorization service.
155155 var err error
156- d .macaroonService , err = macaroons .NewService (
157- d .cfg .DataDir , loopMacaroonLocation , false ,
158- loopdb .DefaultLoopDBTimeout , macaroons .IPLockChecker ,
159- )
156+ d .macaroonDB , err = kvdb .GetBoltBackend (& kvdb.BoltBackendConfig {
157+ DBPath : d .cfg .DataDir ,
158+ DBFileName : "macaroons.db" ,
159+ DBTimeout : loopdb .DefaultLoopDBTimeout ,
160+ })
161+ if err != nil {
162+ return fmt .Errorf ("unable to load macaroon db: %v" , err )
163+ }
160164 if err == bbolt .ErrTimeout {
161165 return fmt .Errorf ("%w: couldn't obtain exclusive lock on " +
162166 "%s/%s, timed out after %v" , bbolt .ErrTimeout ,
163167 d .cfg .DataDir , "macaroons.db" ,
164168 loopdb .DefaultLoopDBTimeout )
165169 }
170+
171+ // Create the macaroon authentication/authorization service.
172+ d .macaroonService , err = macaroons .NewService (
173+ d .macaroonDB , loopMacaroonLocation , false ,
174+ macaroons .IPLockChecker ,
175+ )
166176 if err != nil {
167177 return fmt .Errorf ("unable to set up macaroon authentication: " +
168178 "%v" , err )
@@ -213,7 +223,18 @@ func (d *Daemon) startMacaroonService() error {
213223
214224// stopMacaroonService closes the macaroon database.
215225func (d * Daemon ) stopMacaroonService () error {
216- return d .macaroonService .Close ()
226+ var shutdownErr error
227+ if err := d .macaroonService .Close (); err != nil {
228+ log .Errorf ("Error closing macaroon service: %v" , err )
229+ shutdownErr = err
230+ }
231+
232+ if err := d .macaroonDB .Close (); err != nil {
233+ log .Errorf ("Error closing macaroon DB: %v" , err )
234+ shutdownErr = err
235+ }
236+
237+ return shutdownErr
217238}
218239
219240// macaroonInterceptor creates gRPC server options with the macaroon security
@@ -225,7 +246,7 @@ func (d *Daemon) macaroonInterceptor() ([]grpc.ServerOption, error) {
225246 RequiredPermissions [endpoint ] = perm
226247 }
227248
228- interceptor := rpcperms .NewInterceptorChain (log , false )
249+ interceptor := rpcperms .NewInterceptorChain (log , false , nil )
229250 err := interceptor .Start ()
230251 if err != nil {
231252 return nil , err
0 commit comments