@@ -7,9 +7,11 @@ import (
77 "os"
88 "time"
99
10+ "github.com/lightningnetwork/lnd/kvdb"
1011 "github.com/lightningnetwork/lnd/lnrpc"
1112 "github.com/lightningnetwork/lnd/macaroons"
1213 "github.com/lightningnetwork/lnd/rpcperms"
14+ "go.etcd.io/bbolt"
1315 "google.golang.org/grpc"
1416 "gopkg.in/macaroon-bakery.v2/bakery"
1517)
@@ -95,11 +97,27 @@ var (
9597// unlocks the macaroon database and creates the default macaroon if it doesn't
9698// exist yet.
9799func (s * RPCServer ) startMacaroonService () error {
100+ backend , err := kvdb .GetBoltBackend (& kvdb.BoltBackendConfig {
101+ DBPath : s .cfg .FaradayDir ,
102+ DBFileName : "macaroons.db" ,
103+ DBTimeout : macDatabaseOpenTimeout ,
104+ })
105+ if err == bbolt .ErrTimeout {
106+ return fmt .Errorf ("error while trying to open %s/%s: " +
107+ "timed out after %v when trying to obtain exclusive " +
108+ "lock - make sure no other faraday daemon process " +
109+ "(standalone or embedded in lightning-terminal) is " +
110+ "running" , s .cfg .FaradayDir , "macaroons.db" ,
111+ macDatabaseOpenTimeout )
112+ }
113+ if err != nil {
114+ return fmt .Errorf ("unable to load macaroon db: %v" , err )
115+ }
116+
98117 // Create the macaroon authentication/authorization service.
99- var err error
100118 s .macaroonService , err = macaroons .NewService (
101- s . cfg . FaradayDir , faradayMacaroonLocation , false ,
102- macDatabaseOpenTimeout , macaroons .IPLockChecker ,
119+ backend , faradayMacaroonLocation , false ,
120+ macaroons .IPLockChecker ,
103121 )
104122 if err != nil {
105123 return fmt .Errorf ("unable to set up macaroon authentication: " +
@@ -156,7 +174,7 @@ func (s *RPCServer) stopMacaroonService() error {
156174// macaroonInterceptor creates gRPC server options with the macaroon security
157175// interceptors.
158176func (s * RPCServer ) macaroonInterceptor () ([]grpc.ServerOption , error ) {
159- interceptor := rpcperms .NewInterceptorChain (log , false )
177+ interceptor := rpcperms .NewInterceptorChain (log , false , nil )
160178
161179 err := interceptor .Start ()
162180 if err != nil {
0 commit comments