@@ -24,6 +24,7 @@ import (
24
24
"github.com/btcsuite/btcd/chaincfg/chainhash"
25
25
"github.com/btcsuite/btcd/wire"
26
26
"github.com/lightninglabs/faraday/frdrpc"
27
+ "github.com/lightninglabs/lightning-terminal/litrpc"
27
28
"github.com/lightninglabs/loop/looprpc"
28
29
"github.com/lightninglabs/pool/poolrpc"
29
30
"github.com/lightningnetwork/lnd/lnrpc"
@@ -228,9 +229,13 @@ type HarnessNode struct {
228
229
// methods SignMessage and VerifyMessage.
229
230
SignerClient signrpc.SignerClient
230
231
231
- // conn is the underlying connection to the grpc endpoint of the node.
232
+ // conn is the underlying connection to the lnd grpc endpoint of the
233
+ // node.
232
234
conn * grpc.ClientConn
233
235
236
+ // litConn is the underlying connection to Lit's grpc endpoint.
237
+ litConn * grpc.ClientConn
238
+
234
239
// RouterClient, WalletKitClient, WatchtowerClient cannot be embedded,
235
240
// because a name collision would occur with LightningClient.
236
241
RouterClient routerrpc.RouterClient
@@ -596,13 +601,24 @@ func (hn *HarnessNode) start(litdBinary string, litdError chan<- error,
596
601
return nil
597
602
}
598
603
604
+ // Also connect to Lit's RPC port for any Litd specific calls.
605
+ litConn , err := connectLitRPC (
606
+ context .Background (), hn .Cfg .LitAddr (), hn .Cfg .LitTLSCertPath ,
607
+ hn .Cfg .LitMacPath ,
608
+ )
609
+ if err != nil {
610
+ return err
611
+ }
612
+ hn .litConn = litConn
613
+
599
614
return hn .initLightningClient (conn )
600
615
}
601
616
602
617
// WaitUntilStarted waits until the wallet state flips from "WAITING_TO_START".
603
618
func (hn * HarnessNode ) WaitUntilStarted (conn grpc.ClientConnInterface ,
604
619
timeout time.Duration ) error {
605
620
621
+ // First wait for Litd state server to show that LND has started.
606
622
err := hn .waitForState (conn , timeout , func (s lnrpc.WalletState ) bool {
607
623
return s >= lnrpc .WalletState_SERVER_ACTIVE
608
624
})
@@ -1106,6 +1122,21 @@ func (hn *HarnessNode) stop() error {
1106
1122
}
1107
1123
}
1108
1124
1125
+ // If lit is running in remote mode, then calling LNDs StopDaemon
1126
+ // method will not shut down Lit, and so we need to explicitly request
1127
+ // lit to shut down.
1128
+ if hn .Cfg .RemoteMode {
1129
+ ctx , cancel := context .WithTimeout (
1130
+ context .Background (), lntest .DefaultTimeout ,
1131
+ )
1132
+ litConn := litrpc .NewLitServiceClient (hn .litConn )
1133
+ _ , err := litConn .StopDaemon (ctx , & litrpc.StopDaemonRequest {})
1134
+ cancel ()
1135
+ if err != nil {
1136
+ return err
1137
+ }
1138
+ }
1139
+
1109
1140
// Wait for lnd process and other goroutines to exit.
1110
1141
select {
1111
1142
case <- hn .processExit :
@@ -1800,3 +1831,40 @@ func (hn *HarnessNode) getChannelPolicies(include bool) policyUpdateMap {
1800
1831
1801
1832
return policyUpdates
1802
1833
}
1834
+
1835
+ // connectLigRPC can be used to connect to the lit rpc server.
1836
+ func connectLitRPC (ctx context.Context , hostPort , tlsCertPath ,
1837
+ macPath string ) (* grpc.ClientConn , error ) {
1838
+
1839
+ tlsCreds , err := credentials .NewClientTLSFromFile (tlsCertPath , "" )
1840
+ if err != nil {
1841
+ return nil , err
1842
+ }
1843
+
1844
+ opts := []grpc.DialOption {
1845
+ grpc .WithBlock (),
1846
+ grpc .WithTransportCredentials (tlsCreds ),
1847
+ }
1848
+
1849
+ if macPath != "" {
1850
+ macBytes , err := ioutil .ReadFile (macPath )
1851
+ if err != nil {
1852
+ return nil , err
1853
+ }
1854
+
1855
+ mac := & macaroon.Macaroon {}
1856
+ if err = mac .UnmarshalBinary (macBytes ); err != nil {
1857
+ return nil , fmt .Errorf ("error unmarshalling macaroon " +
1858
+ "file: %v" , err )
1859
+ }
1860
+
1861
+ macCred , err := macaroons .NewMacaroonCredential (mac )
1862
+ if err != nil {
1863
+ return nil , fmt .Errorf ("error cloning mac: %v" , err )
1864
+ }
1865
+
1866
+ opts = append (opts , grpc .WithPerRPCCredentials (macCred ))
1867
+ }
1868
+
1869
+ return grpc .DialContext (ctx , hostPort , opts ... )
1870
+ }
0 commit comments