@@ -48,7 +48,6 @@ import (
48
48
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
49
49
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
50
50
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
51
- "github.com/lightningnetwork/lnd/lntest/wait"
52
51
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
53
52
"github.com/lightningnetwork/lnd/macaroons"
54
53
"github.com/lightningnetwork/lnd/rpcperms"
@@ -634,7 +633,7 @@ func (g *LightningTerminal) start() error {
634
633
}
635
634
636
635
// Set up all the LND clients required by LiT.
637
- err = g .setUpLNDClients ()
636
+ err = g .setUpLNDClients (lndQuit )
638
637
if err != nil {
639
638
g .statusMgr .SetErrored (
640
639
subservers .LND , "could not set up LND clients: %v" , err ,
@@ -699,8 +698,9 @@ func (g *LightningTerminal) start() error {
699
698
}
700
699
701
700
// setUpLNDClients sets up the various LND clients required by LiT.
702
- func (g * LightningTerminal ) setUpLNDClients () error {
701
+ func (g * LightningTerminal ) setUpLNDClients (lndQuit chan struct {} ) error {
703
702
var (
703
+ err error
704
704
insecure bool
705
705
clientOptions []lndclient.BasicClientOption
706
706
)
@@ -722,25 +722,57 @@ func (g *LightningTerminal) setUpLNDClients() error {
722
722
clientOptions = append (clientOptions , lndclient .Insecure ())
723
723
}
724
724
725
+ // checkRunning checks if we should continue running for the duration of
726
+ // the defaultStartupTimeout, or else returns an error indicating why
727
+ // a shut-down is needed.
728
+ checkRunning := func () error {
729
+ select {
730
+ case err := <- g .errQueue .ChanOut ():
731
+ return fmt .Errorf ("error from subsystem: %v" , err )
732
+
733
+ case <- lndQuit :
734
+ return fmt .Errorf ("LND has stopped" )
735
+
736
+ case <- interceptor .ShutdownChannel ():
737
+ return fmt .Errorf ("received the shutdown signal" )
738
+
739
+ case <- time .After (defaultStartupTimeout ):
740
+ return nil
741
+ }
742
+ }
743
+
725
744
// The main RPC listener of lnd might need some time to start, it could
726
745
// be that we run into a connection refused a few times. We use the
727
746
// basic client connection to find out if the RPC server is started yet
728
747
// because that doesn't do anything else than just connect. We'll check
729
748
// if lnd is also ready to be used in the next step.
730
749
log .Infof ("Connecting basic lnd client" )
731
- err := wait .NoError (func () error {
750
+
751
+ for {
732
752
// Create an lnd client now that we have the full configuration.
733
753
// We'll need a basic client and a full client because not all
734
754
// subservers have the same requirements.
735
- var err error
736
755
g .basicClient , err = lndclient .NewBasicClient (
737
- host , tlsPath , filepath .Dir (macPath ), string ( network ),
738
- clientOptions ... ,
756
+ host , tlsPath , filepath .Dir (macPath ),
757
+ string ( network ), clientOptions ... ,
739
758
)
740
- return err
741
- }, defaultStartupTimeout )
742
- if err != nil {
743
- return fmt .Errorf ("could not create basic LND Client: %v" , err )
759
+ if err == nil {
760
+ log .Infof ("Basic lnd client connected" )
761
+
762
+ break
763
+ }
764
+
765
+ g .statusMgr .SetErrored (
766
+ subservers .LIT ,
767
+ "Error when setting up basic LND Client: %v" , err ,
768
+ )
769
+
770
+ err = checkRunning ()
771
+ if err != nil {
772
+ return err
773
+ }
774
+
775
+ log .Infof ("Retrying to connect basic lnd client" )
744
776
}
745
777
746
778
// Now we know that the connection itself is ready. But we also need to
@@ -768,23 +800,39 @@ func (g *LightningTerminal) setUpLNDClients() error {
768
800
}()
769
801
770
802
log .Infof ("Connecting full lnd client" )
771
- g .lndClient , err = lndclient .NewLndServices (
772
- & lndclient.LndServicesConfig {
773
- LndAddress : host ,
774
- Network : network ,
775
- TLSPath : tlsPath ,
776
- Insecure : insecure ,
777
- CustomMacaroonPath : macPath ,
778
- CustomMacaroonHex : hex .EncodeToString (macData ),
779
- BlockUntilChainSynced : true ,
780
- BlockUntilUnlocked : true ,
781
- CallerCtx : ctxc ,
782
- CheckVersion : minimalCompatibleVersion ,
783
- },
784
- )
785
- if err != nil {
786
- return fmt .Errorf ("could not create LND Services client: %v" ,
787
- err )
803
+ for {
804
+ g .lndClient , err = lndclient .NewLndServices (
805
+ & lndclient.LndServicesConfig {
806
+ LndAddress : host ,
807
+ Network : network ,
808
+ TLSPath : tlsPath ,
809
+ Insecure : insecure ,
810
+ CustomMacaroonPath : macPath ,
811
+ CustomMacaroonHex : hex .EncodeToString (macData ),
812
+ BlockUntilChainSynced : true ,
813
+ BlockUntilUnlocked : true ,
814
+ CallerCtx : ctxc ,
815
+ CheckVersion : minimalCompatibleVersion ,
816
+ },
817
+ )
818
+ if err == nil {
819
+ log .Infof ("Full lnd client connected" )
820
+
821
+ break
822
+ }
823
+
824
+ g .statusMgr .SetErrored (
825
+ subservers .LIT ,
826
+ "Error when creating LND Services client: %v" ,
827
+ err ,
828
+ )
829
+
830
+ err = checkRunning ()
831
+ if err != nil {
832
+ return err
833
+ }
834
+
835
+ log .Infof ("Retrying to create LND Services client" )
788
836
}
789
837
790
838
// Pass LND's build tags to the permission manager so that it can
0 commit comments