lnrpc+macaroon: skip subserver macaroons on stateless_init
This will prevent the subservers from writing macaroons to disk when the stateless_init flag is set to true. It accomplishes this by storing the StatelessInit value in the Macaroon Service.
This commit is contained in:
1 parent
0b9b7def15
commit
5aa0d26251
5 files changed
+32
-39
No files matched your search
@@ -131,16 +131,6 @@ type Server struct {
|
||||
// gRPC service.
|
||||
var _ RouterServer = (*Server)(nil)
|
||||
|
||||
// fileExists reports whether the named file or directory exists.
|
||||
func fileExists(name string) bool {
|
||||
if _, err := os.Stat(name); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// New creates a new instance of the RouterServer given a configuration struct
|
||||
// that contains all external dependencies. If the target macaroon exists, and
|
||||
// we're unable to create it, then an error will be returned. We also return
|
||||
@@ -156,9 +146,12 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
}
|
||||
|
||||
// Now that we know the full path of the router macaroon, we can check
|
||||
// to see if we need to create it or not.
|
||||
// to see if we need to create it or not. If stateless_init is set
|
||||
// then we don't write the macaroons.
|
||||
macFilePath := cfg.RouterMacPath
|
||||
if !fileExists(macFilePath) && cfg.MacService != nil {
|
||||
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||
!lnrpc.FileExists(macFilePath) {
|
||||
|
||||
log.Infof("Making macaroons for Router RPC Server at: %v",
|
||||
macFilePath)
|
||||
|
||||
@@ -178,7 +171,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
}
|
||||
err = ioutil.WriteFile(macFilePath, routerMacBytes, 0644)
|
||||
if err != nil {
|
||||
os.Remove(macFilePath)
|
||||
_ = os.Remove(macFilePath)
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user