From b22f51098a93f4d9bb293949dac30f36ce78f963 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 23 Sep 2021 16:54:33 +0200 Subject: [PATCH] rpcperms+lnd: use macaroon service from interceptor chain We'll refactor the wallet creation and unlock process in a following commit and want to make it possible to not need a direct reference to the macaroon service in our main function. Since we store it in the interceptor chain anyway (if we're using macaroons in the first place), we might as well use the instance there directly. --- lnd.go | 4 ++-- rpcperms/interceptor.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lnd.go b/lnd.go index 61f6d2b98..12c4e1139 100644 --- a/lnd.go +++ b/lnd.go @@ -917,8 +917,8 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error // Now we have created all dependencies necessary to populate and // start the RPC server. err = rpcServer.addDeps( - server, macaroonService, cfg.SubRPCServers, atplManager, - server.invoices, tower, chainedAcceptor, + server, interceptorChain.MacaroonService(), cfg.SubRPCServers, + atplManager, server.invoices, tower, chainedAcceptor, ) if err != nil { err := fmt.Errorf("unable to add deps to RPC server: %v", err) diff --git a/rpcperms/interceptor.go b/rpcperms/interceptor.go index 4b8f47db9..71481592a 100644 --- a/rpcperms/interceptor.go +++ b/rpcperms/interceptor.go @@ -386,6 +386,15 @@ func (r *InterceptorChain) AddMacaroonService(svc *macaroons.Service) { r.svc = svc } +// MacaroonService returns the currently registered macaroon service. This might +// be nil if none was registered (yet). +func (r *InterceptorChain) MacaroonService() *macaroons.Service { + r.RLock() + defer r.RUnlock() + + return r.svc +} + // AddPermission adds a new macaroon rule for the given method. func (r *InterceptorChain) AddPermission(method string, ops []bakery.Op) error { r.Lock()