mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-25 14:50:43 +02:00
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:
committed by
Oliver Gugger
parent
0b9b7def15
commit
5aa0d26251
@@ -72,16 +72,6 @@ var (
|
||||
"still in the process of starting")
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Server is a sub-server of the main RPC server: the chain notifier RPC. This
|
||||
// RPC sub-server allows external callers to access the full chain notifier
|
||||
// capabilities of lnd. This allows callers to create custom protocols, external
|
||||
@@ -111,9 +101,12 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
}
|
||||
|
||||
// Now that we know the full path of the chain notifier macaroon, we can
|
||||
// check to see if we need to create it or not.
|
||||
// check to see if we need to create it or not. If stateless_init is set
|
||||
// then we don't write the macaroons.
|
||||
macFilePath := cfg.ChainNotifierMacPath
|
||||
if cfg.MacService != nil && !fileExists(macFilePath) {
|
||||
if cfg.MacService != nil && !cfg.MacService.StatelessInit &&
|
||||
!lnrpc.FileExists(macFilePath) {
|
||||
|
||||
log.Infof("Baking macaroons for ChainNotifier RPC Server at: %v",
|
||||
macFilePath)
|
||||
|
||||
@@ -121,8 +114,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// doesn't yet, exist, so we need to create it with the help of
|
||||
// the main macaroon service.
|
||||
chainNotifierMac, err := cfg.MacService.NewMacaroon(
|
||||
context.Background(),
|
||||
macaroons.DefaultRootKeyID,
|
||||
context.Background(), macaroons.DefaultRootKeyID,
|
||||
macaroonOps...,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -134,7 +126,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
}
|
||||
err = ioutil.WriteFile(macFilePath, chainNotifierMacBytes, 0644)
|
||||
if err != nil {
|
||||
os.Remove(macFilePath)
|
||||
_ = os.Remove(macFilePath)
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user