Skip to content

Commit 3a2cdbc

Browse files
committed
itest: update WaitUntilStarted to only use status server
This is so that we can use this Wait function to check the state of sub-servers even when LiT is running in stateless init mode. As currently, a macaroon is used to make a call to each sub-server which we wont have access to in stateless init mode. This commit also adds a new WaitForLNDWalletReady call which only waits for LND's wallet to be ready. We'll use this during the set-up of a stateless init node in an itest so that we can know when we are able to Create the wallet.
1 parent e4e68d0 commit 3a2cdbc

File tree

1 file changed

+61
-42
lines changed

1 file changed

+61
-42
lines changed

itest/litd_node.go

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,47 @@ func (hn *HarnessNode) Start(litdBinary string, litdError chan<- error,
724724
}, lntest.DefaultTimeout)
725725
}
726726

727-
// WaitUntilStarted waits until the wallet state flips from "WAITING_TO_START".
727+
// WaitForLNDWalletReady waits until the wallet state flips from
728+
// "WAITING_TO_START".
729+
func (hn *HarnessNode) WaitForLNDWalletReady() error {
730+
// First wait for Litd status server to show that LND has started.
731+
ctx := context.Background()
732+
rawConn, err := connectLitRPC(
733+
ctx, hn.Cfg.LitAddr(), hn.Cfg.LitTLSCertPath, "",
734+
)
735+
if err != nil {
736+
return err
737+
}
738+
739+
litConn := litrpc.NewStatusClient(rawConn)
740+
741+
return wait.NoError(func() error {
742+
states, err := litConn.SubServerStatus(
743+
ctx, &litrpc.SubServerStatusReq{},
744+
)
745+
if err != nil {
746+
return err
747+
}
748+
749+
lndStatus, ok := states.SubServers[subservers.LND]
750+
if !ok {
751+
return fmt.Errorf("LND has not yet started")
752+
}
753+
754+
if lndStatus.Running {
755+
return nil
756+
}
757+
758+
if lndStatus.CustomStatus != "Wallet Ready" {
759+
return fmt.Errorf("LND has not yet started")
760+
}
761+
762+
return nil
763+
}, defaultTimeout)
764+
}
765+
766+
// WaitUntilStarted waits until the wallet state flips from "WAITING_TO_START"
767+
// and waits for all LiT's active sub-servers to be ready.
728768
func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
729769
timeout time.Duration) error {
730770

@@ -753,7 +793,7 @@ func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
753793
}
754794

755795
return nil
756-
}, lntest.DefaultTimeout)
796+
}, timeout)
757797
if err != nil {
758798
return err
759799
}
@@ -773,59 +813,38 @@ func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
773813
ctxt, cancel := context.WithTimeout(context.Background(), timeout)
774814
defer cancel()
775815
return wait.NoError(func() error {
776-
if faradayMode != terminal.ModeDisable {
777-
faradayClient, err := hn.faradayClient()
778-
if err != nil {
779-
return err
780-
}
816+
states, err := litConn.SubServerStatus(
817+
ctxt, &litrpc.SubServerStatusReq{},
818+
)
819+
if err != nil {
820+
return err
821+
}
781822

782-
_, err = faradayClient.RevenueReport(
783-
ctxt, &frdrpc.RevenueReportRequest{},
784-
)
785-
if err != nil {
786-
return err
823+
if faradayMode != terminal.ModeDisable {
824+
faraday, ok := states.SubServers[subservers.FARADAY]
825+
if !ok || !faraday.Running {
826+
return fmt.Errorf("faraday has not yet started")
787827
}
788828
}
789829

790830
if loopMode != terminal.ModeDisable {
791-
loopClient, err := hn.loopClient()
792-
if err != nil {
793-
return err
794-
}
795-
796-
_, err = loopClient.ListSwaps(
797-
ctxt, &looprpc.ListSwapsRequest{},
798-
)
799-
if err != nil {
800-
return err
831+
loop, ok := states.SubServers[subservers.LOOP]
832+
if !ok || !loop.Running {
833+
return fmt.Errorf("loop has not yet started")
801834
}
802835
}
803836

804837
if poolMode != terminal.ModeDisable {
805-
poolClient, err := hn.poolClient()
806-
if err != nil {
807-
return err
808-
}
809-
810-
_, err = poolClient.GetInfo(
811-
ctxt, &poolrpc.GetInfoRequest{},
812-
)
813-
if err != nil {
814-
return err
838+
pool, ok := states.SubServers[subservers.POOL]
839+
if !ok || !pool.Running {
840+
return fmt.Errorf("pool has not yet started")
815841
}
816842
}
817843

818844
if tapMode != terminal.ModeDisable {
819-
tapClient, err := hn.tapClient()
820-
if err != nil {
821-
return err
822-
}
823-
824-
_, err = tapClient.ListAssets(
825-
ctxt, &taprpc.ListAssetRequest{},
826-
)
827-
if err != nil {
828-
return err
845+
tap, ok := states.SubServers[subservers.TAP]
846+
if !ok || !tap.Running {
847+
return fmt.Errorf("tap has not yet started")
829848
}
830849
}
831850

0 commit comments

Comments
 (0)