|
7 | 7 | "encoding/hex"
|
8 | 8 | "errors"
|
9 | 9 | "fmt"
|
| 10 | + "github.com/lightningnetwork/lnd/chainreg" |
| 11 | + "github.com/lightningnetwork/lnd/lnwallet/btcwallet" |
| 12 | + "github.com/lightningnetwork/lnd/rpcperms" |
10 | 13 | "io/fs"
|
11 | 14 | "net"
|
12 | 15 | "net/http"
|
@@ -127,6 +130,10 @@ type LightningTerminal struct {
|
127 | 130 |
|
128 | 131 | defaultImplCfg *lnd.ImplementationCfg
|
129 | 132 |
|
| 133 | + // lndInterceptorChain is a reference to lnd's interceptor chain that |
| 134 | + // guards all incoming calls. This is only set in integrated mode! |
| 135 | + lndInterceptorChain *rpcperms.InterceptorChain |
| 136 | + |
130 | 137 | wg sync.WaitGroup
|
131 | 138 | lndErrChan chan error
|
132 | 139 |
|
@@ -212,7 +219,7 @@ func (g *LightningTerminal) Run() error {
|
212 | 219 | RestRegistrar: g,
|
213 | 220 | ExternalValidator: g,
|
214 | 221 | DatabaseBuilder: g.defaultImplCfg.DatabaseBuilder,
|
215 |
| - WalletConfigBuilder: g.defaultImplCfg.WalletConfigBuilder, |
| 222 | + WalletConfigBuilder: g, |
216 | 223 | ChainControlBuilder: g.defaultImplCfg.ChainControlBuilder,
|
217 | 224 | }
|
218 | 225 |
|
@@ -458,9 +465,20 @@ func (g *LightningTerminal) startSubservers() error {
|
458 | 465 | g.rpcProxy.superMacaroon = res.Macaroon
|
459 | 466 | }
|
460 | 467 |
|
461 |
| - // If we're in integrated mode, we won't create macaroon files in any |
462 |
| - // of the subserver daemons. |
463 |
| - createDefaultMacaroons := g.cfg.LndMode != ModeIntegrated |
| 468 | + // If we're in integrated and stateless init mode, we won't create |
| 469 | + // macaroon files in any of the subserver daemons. |
| 470 | + createDefaultMacaroons := true |
| 471 | + if g.cfg.LndMode == ModeIntegrated && g.lndInterceptorChain != nil && |
| 472 | + g.lndInterceptorChain.MacaroonService() != nil { |
| 473 | + |
| 474 | + // If the wallet was initialized in stateless mode, we don't |
| 475 | + // want any macaroons lying around on the filesystem. In that |
| 476 | + // case only the UI will be able to access any of the integrated |
| 477 | + // daemons. In all other cases we want default macaroons so we |
| 478 | + // can use the CLI tools to interact with loop/pool/faraday. |
| 479 | + macService := g.lndInterceptorChain.MacaroonService() |
| 480 | + createDefaultMacaroons = !macService.StatelessInit |
| 481 | + } |
464 | 482 |
|
465 | 483 | // Both connection types are ready now, let's start our subservers if
|
466 | 484 | // they should be started locally as an integrated service.
|
@@ -689,6 +707,25 @@ func (g *LightningTerminal) Permissions() map[string][]bakery.Op {
|
689 | 707 | return getSubserverPermissions()
|
690 | 708 | }
|
691 | 709 |
|
| 710 | +// BuildWalletConfig is responsible for creating or unlocking and then |
| 711 | +// fully initializing a wallet. |
| 712 | +// |
| 713 | +// NOTE: This is only implemented in order for us to intercept the setup call |
| 714 | +// and store a reference to the interceptor chain. |
| 715 | +// |
| 716 | +// NOTE: This is part of the lnd.WalletConfigBuilder interface. |
| 717 | +func (g *LightningTerminal) BuildWalletConfig(ctx context.Context, |
| 718 | + dbs *lnd.DatabaseInstances, interceptorChain *rpcperms.InterceptorChain, |
| 719 | + grpcListeners []*lnd.ListenerWithSignal) (*chainreg.PartialChainControl, |
| 720 | + *btcwallet.Config, func(), error) { |
| 721 | + |
| 722 | + g.lndInterceptorChain = interceptorChain |
| 723 | + |
| 724 | + return g.defaultImplCfg.WalletConfigBuilder.BuildWalletConfig( |
| 725 | + ctx, dbs, interceptorChain, grpcListeners, |
| 726 | + ) |
| 727 | +} |
| 728 | + |
692 | 729 | // shutdown stops all subservers that were started and attached to lnd.
|
693 | 730 | func (g *LightningTerminal) shutdown() error {
|
694 | 731 | var returnErr error
|
|
0 commit comments