@@ -482,12 +482,39 @@ func (g *LightningTerminal) Run() error {
482
482
g .cfg .lndAdminMacaroon = <- macChan
483
483
}
484
484
485
- err = g .startSubservers ()
485
+ // Set up all the LND clients required by LiT.
486
+ err = g .setUpLNDClients ()
486
487
if err != nil {
487
- log .Errorf ("Could not start subservers : %v " , err )
488
+ log .Errorf ("Could not set up LND clients : %w " , err )
488
489
return err
489
490
}
490
491
492
+ // If we're in integrated and stateless init mode, we won't create
493
+ // macaroon files in any of the subserver daemons.
494
+ createDefaultMacaroons := true
495
+ if g .cfg .LndMode == ModeIntegrated && g .lndInterceptorChain != nil &&
496
+ g .lndInterceptorChain .MacaroonService () != nil {
497
+
498
+ // If the wallet was initialized in stateless mode, we don't
499
+ // want any macaroons lying around on the filesystem. In that
500
+ // case only the UI will be able to access any of the integrated
501
+ // daemons. In all other cases we want default macaroons so we
502
+ // can use the CLI tools to interact with loop/pool/faraday.
503
+ macService := g .lndInterceptorChain .MacaroonService ()
504
+ createDefaultMacaroons = ! macService .StatelessInit
505
+ }
506
+
507
+ err = g .startIntegratedDaemons (createDefaultMacaroons )
508
+ if err != nil {
509
+ log .Errorf ("Could not start integrated daemons: %v" , err )
510
+ return err
511
+ }
512
+
513
+ err = g .startInternalSubServers (createDefaultMacaroons )
514
+ if err != nil {
515
+ return fmt .Errorf ("could not start litd sub-servers: %v" , err )
516
+ }
517
+
491
518
// Now block until we receive an error or the main shutdown signal.
492
519
select {
493
520
case err := <- g .loopServer .ErrChan :
@@ -513,10 +540,8 @@ func (g *LightningTerminal) Run() error {
513
540
return nil
514
541
}
515
542
516
- // startSubservers creates an internal connection to lnd and then starts all
517
- // embedded daemons as external subservers that hook into the same gRPC and REST
518
- // servers that lnd started.
519
- func (g * LightningTerminal ) startSubservers () error {
543
+ // setUpLNDClients sets up the various LND clients required by LiT.
544
+ func (g * LightningTerminal ) setUpLNDClients () error {
520
545
var (
521
546
insecure bool
522
547
clientOptions []lndclient.BasicClientOption
@@ -557,7 +582,7 @@ func (g *LightningTerminal) startSubservers() error {
557
582
return err
558
583
}, defaultStartupTimeout )
559
584
if err != nil {
560
- return err
585
+ return fmt . Errorf ( "could not create basic LND Client: %v" , err )
561
586
}
562
587
563
588
// Now we know that the connection itself is ready. But we also need to
@@ -600,7 +625,8 @@ func (g *LightningTerminal) startSubservers() error {
600
625
},
601
626
)
602
627
if err != nil {
603
- return err
628
+ return fmt .Errorf ("could not create LND Services client: %v" ,
629
+ err )
604
630
}
605
631
606
632
// Pass LND's build tags to the permission manager so that it can
@@ -628,26 +654,19 @@ func (g *LightningTerminal) startSubservers() error {
628
654
g .rpcProxy .superMacaroon = superMacaroon
629
655
}
630
656
631
- // If we're in integrated and stateless init mode, we won't create
632
- // macaroon files in any of the subserver daemons.
633
- createDefaultMacaroons := true
634
- if g .cfg .LndMode == ModeIntegrated && g .lndInterceptorChain != nil &&
635
- g .lndInterceptorChain .MacaroonService () != nil {
657
+ return nil
658
+ }
636
659
637
- // If the wallet was initialized in stateless mode, we don't
638
- // want any macaroons lying around on the filesystem. In that
639
- // case only the UI will be able to access any of the integrated
640
- // daemons. In all other cases we want default macaroons so we
641
- // can use the CLI tools to interact with loop/pool/faraday.
642
- macService := g .lndInterceptorChain .MacaroonService ()
643
- createDefaultMacaroons = ! macService .StatelessInit
644
- }
660
+ // startIntegratedDaemons starts all embedded daemons as external sub-servers
661
+ // that hook into the same gRPC and REST servers that lnd started.
662
+ func (g * LightningTerminal ) startIntegratedDaemons (
663
+ createDefaultMacaroons bool ) error {
645
664
646
- // Both connection types are ready now, let's start our subservers if
665
+ // Both connection types are ready now, let's start our sub-servers if
647
666
// they should be started locally as an integrated service.
648
667
if ! g .cfg .faradayRemote {
649
668
log .Infof ("Starting integrated faraday daemon" )
650
- err = g .faradayServer .StartAsSubserver (
669
+ err : = g .faradayServer .StartAsSubserver (
651
670
g .lndClient .LndServices , createDefaultMacaroons ,
652
671
)
653
672
if err != nil {
@@ -658,7 +677,7 @@ func (g *LightningTerminal) startSubservers() error {
658
677
659
678
if ! g .cfg .loopRemote {
660
679
log .Infof ("Starting integrated loop daemon" )
661
- err = g .loopServer .StartAsSubserver (
680
+ err : = g .loopServer .StartAsSubserver (
662
681
g .lndClient , createDefaultMacaroons ,
663
682
)
664
683
if err != nil {
@@ -669,7 +688,7 @@ func (g *LightningTerminal) startSubservers() error {
669
688
670
689
if ! g .cfg .poolRemote {
671
690
log .Infof ("Starting integrated pool daemon" )
672
- err = g .poolServer .StartAsSubserver (
691
+ err : = g .poolServer .StartAsSubserver (
673
692
g .basicClient , g .lndClient , createDefaultMacaroons ,
674
693
)
675
694
if err != nil {
@@ -678,6 +697,13 @@ func (g *LightningTerminal) startSubservers() error {
678
697
g .poolStarted = true
679
698
}
680
699
700
+ return nil
701
+ }
702
+
703
+ // startInternalSubServers starts all Litd specific sub-servers.
704
+ func (g * LightningTerminal ) startInternalSubServers (
705
+ createDefaultMacaroons bool ) error {
706
+
681
707
log .Infof ("Starting LiT macaroon service" )
682
708
683
709
// Set up the macaroon service.
@@ -770,15 +796,10 @@ func (g *LightningTerminal) startSubservers() error {
770
796
}
771
797
772
798
if ! g .cfg .Autopilot .Disable {
773
- info , err := g .lndClient .Client .GetInfo (ctxc )
774
- if err != nil {
775
- return fmt .Errorf ("GetInfo call failed: %v" , err )
776
- }
777
-
778
799
ruleEnforcer := firewall .NewRuleEnforcer (
779
800
g .firewallDB , g .firewallDB ,
780
801
g .autopilotClient .ListFeaturePerms ,
781
- g .permsMgr , info . IdentityPubkey ,
802
+ g .permsMgr , g . lndClient . NodePubkey ,
782
803
g .lndClient .Router ,
783
804
g .lndClient .Client , g .ruleMgrs ,
784
805
func (reqID uint64 , reason string ) error {
0 commit comments