Skip to content

Commit c917e91

Browse files
committed
config: remove deprecated macaroondir
To make the macaroon handling a bit more intuitive and the code easier to understand we now remove the deprecated macaroondir config option in favor of the more explicit macaroonpath one.
1 parent 1b00381 commit c917e91

File tree

1 file changed

+16
-44
lines changed

1 file changed

+16
-44
lines changed

config.go

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const (
5959
defaultRemoteLndRpcServer = "localhost:10009"
6060
defaultLndChainSubDir = "chain"
6161
defaultLndChain = "bitcoin"
62-
defaultLndMacaroon = "admin.macaroon"
6362
)
6463

6564
var (
@@ -99,13 +98,6 @@ var (
9998
defaultLetsEncryptDir = filepath.Join(
10099
defaultLitDir, defaultLetsEncryptSubDir,
101100
)
102-
103-
// defaultRemoteLndMacDir is the default directory we assume for a local
104-
// lnd node to store all its macaroon files.
105-
defaultRemoteLndMacDir = filepath.Join(
106-
lndDefaultConfig.DataDir, defaultLndChainSubDir,
107-
defaultLndChain, defaultNetwork,
108-
)
109101
)
110102

111103
// Config is the main configuration struct of lightning-terminal. It contains
@@ -170,16 +162,12 @@ type RemoteDaemonConfig struct {
170162
// listening on.
171163
RPCServer string `long:"rpcserver" description:"The host:port that the remote daemon is listening for RPC connections on."`
172164

173-
// MacaroonDir is the directory that contains all the macaroon files
174-
// required for the remote connection.
175-
MacaroonDir string `long:"macaroondir" description:"DEPRECATED: Use macaroonpath. The directory containing all lnd macaroons to use for the remote connection."`
176-
177165
// MacaroonPath is the path to the single macaroon that should be used
178166
// instead of needing to specify the macaroon directory that contains
179-
// all of lnd's macaroons. The specified macaroon MUST have all
167+
// all of the daemon's macaroons. The specified macaroon MUST have all
180168
// permissions that all the subservers use, otherwise permission errors
181169
// will occur.
182-
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the admin.macaroon or a custom baked one. Cannot be specified at the same time as macaroondir. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`
170+
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the main (admin.macaroon in lnd's case) or a custom baked one. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`
183171

184172
// TLSCertPath is the path to the tls cert of the remote daemon that
185173
// should be used to verify the TLS identity of the remote RPC server.
@@ -194,24 +182,10 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string,
194182
// In remote lnd mode, we just pass along what was configured in the
195183
// remote section of the lnd config.
196184
if c.LndMode == ModeRemote {
197-
// Because we now have the option to specify a single, custom
198-
// macaroon to the lndclient, we either use the single macaroon
199-
// indicated by the user or the admin macaroon from the mac dir
200-
// that was specified.
201-
macPath := path.Join(
202-
lncfg.CleanAndExpandPath(c.Remote.Lnd.MacaroonDir),
203-
defaultLndMacaroon,
204-
)
205-
if c.Remote.Lnd.MacaroonPath != "" {
206-
macPath = lncfg.CleanAndExpandPath(
207-
c.Remote.Lnd.MacaroonPath,
208-
)
209-
}
210-
211185
return c.Remote.Lnd.RPCServer,
212186
lndclient.Network(c.network),
213187
lncfg.CleanAndExpandPath(c.Remote.Lnd.TLSCertPath),
214-
macPath
188+
lncfg.CleanAndExpandPath(c.Remote.Lnd.MacaroonPath)
215189
}
216190

217191
// When we start lnd internally, we take the listen address as
@@ -248,10 +222,10 @@ func defaultConfig() *Config {
248222
LitMaxLogFiles: defaultMaxLogFiles,
249223
LitMaxLogFileSize: defaultMaxLogFileSize,
250224
Lnd: &RemoteDaemonConfig{
251-
Network: defaultNetwork,
252-
RPCServer: defaultRemoteLndRpcServer,
253-
MacaroonDir: defaultRemoteLndMacDir,
254-
TLSCertPath: lndDefaultConfig.TLSCertPath,
225+
Network: defaultNetwork,
226+
RPCServer: defaultRemoteLndRpcServer,
227+
MacaroonPath: lndDefaultConfig.AdminMacPath,
228+
TLSCertPath: lndDefaultConfig.TLSCertPath,
255229
},
256230
},
257231
LndMode: defaultLndMode,
@@ -464,25 +438,23 @@ func validateRemoteModeConfig(cfg *Config) error {
464438
}
465439
cfg.network = r.Lnd.Network
466440

467-
// Users can either specify the macaroon directory or the custom
468-
// macaroon to use, but not both.
469-
if r.Lnd.MacaroonDir != defaultRemoteLndMacDir &&
470-
r.Lnd.MacaroonPath != "" {
471-
472-
return fmt.Errorf("cannot set both macaroon dir and macaroon " +
473-
"path")
474-
}
441+
// When referring to the default lnd configuration later on, let's make
442+
// sure we use the actual default values and not the lndDefaultConfig
443+
// variable which could've been overwritten by the user. Otherwise this
444+
// could lead to weird behavior and hard to catch bugs.
445+
defaultLndCfg := lnd.DefaultConfig()
475446

476447
// If the remote lnd's network isn't the default, we also check if we
477448
// need to adjust the default macaroon directory so the user can only
478449
// specify --network=testnet for example if everything else is using
479450
// the defaults.
480451
if r.Lnd.Network != defaultNetwork &&
481-
r.Lnd.MacaroonDir == defaultRemoteLndMacDir {
452+
r.Lnd.MacaroonPath == defaultLndCfg.AdminMacPath {
482453

483-
r.Lnd.MacaroonDir = filepath.Join(
484-
lndDefaultConfig.DataDir, defaultLndChainSubDir,
454+
r.Lnd.MacaroonPath = filepath.Join(
455+
defaultLndCfg.DataDir, defaultLndChainSubDir,
485456
defaultLndChain, r.Lnd.Network,
457+
path.Base(defaultLndCfg.AdminMacPath),
486458
)
487459
}
488460

0 commit comments

Comments
 (0)