@@ -52,16 +52,21 @@ var (
5252 // numActiveNodes is the number of active nodes within the test network.
5353 numActiveNodes = 0
5454 numActiveNodesMtx sync.Mutex
55+
56+ defaultLndPassphrase = []byte ("default-wallet-password" )
5557)
5658
5759type LitNodeConfig struct {
5860 * lntest.BaseNodeConfig
5961
6062 LitArgs []string
6163
64+ RemoteMode bool
65+
6266 FaradayMacPath string
6367 LoopMacPath string
6468 PoolMacPath string
69+ LitTLSCertPath string
6570
6671 UIPassword string
6772 LitDir string
@@ -105,9 +110,9 @@ func (cfg *LitNodeConfig) GenArgs() []string {
105110 fmt .Sprintf ("--pool.basedir=%s" , cfg .PoolDir ),
106111 fmt .Sprintf ("--uipassword=%s" , cfg .UIPassword ),
107112 "--restcors=*" ,
108- "--lnd-mode=integrated" ,
109113 }
110114 )
115+ litArgs = append (litArgs , cfg .LitArgs ... )
111116
112117 switch cfg .NetParams {
113118 case & chaincfg .TestNet3Params :
@@ -118,9 +123,27 @@ func (cfg *LitNodeConfig) GenArgs() []string {
118123 litArgs = append (litArgs , "--network=regtest" )
119124 }
120125
126+ // In remote mode, we don't need any lnd specific arguments other than
127+ // those we need to connect.
128+ if cfg .RemoteMode {
129+ litArgs = append (litArgs , "--lnd-mode=remote" )
130+ litArgs = append (litArgs , fmt .Sprintf (
131+ "--remote.lnd.rpcserver=%s" , cfg .RPCAddr ()),
132+ )
133+ litArgs = append (litArgs , fmt .Sprintf (
134+ "--remote.lnd.tlscertpath=%s" , cfg .TLSCertPath ),
135+ )
136+ litArgs = append (litArgs , fmt .Sprintf (
137+ "--remote.lnd.macaroonpath=%s" , cfg .AdminMacPath ),
138+ )
139+
140+ return litArgs
141+ }
142+
121143 // All arguments so far were for lnd. Let's namespace them now so we can
122144 // add args for the other daemons and LiT itself afterwards.
123145 litArgs = append (litArgs , cfg .LitArgs ... )
146+ litArgs = append (litArgs , "--lnd-mode=integrated" )
124147 lndArgs := cfg .BaseNodeConfig .GenArgs ()
125148 for idx := range lndArgs {
126149 litArgs = append (
@@ -156,6 +179,9 @@ type HarnessNode struct {
156179 // NodeID is a unique identifier for the node within a NetworkHarness.
157180 NodeID int
158181
182+ RemoteLnd * lntest.HarnessNode
183+ RemoteLndHarness * lntest.NetworkHarness
184+
159185 // PubKey is the serialized compressed identity public key of the node.
160186 // This field will only be populated once the node itself has been
161187 // started via the start() method.
@@ -220,7 +246,7 @@ var _ lnrpc.WalletUnlockerClient = (*HarnessNode)(nil)
220246var _ invoicesrpc.InvoicesClient = (* HarnessNode )(nil )
221247
222248// newNode creates a new test lightning node instance from the passed config.
223- func newNode (cfg * LitNodeConfig ) (* HarnessNode , error ) {
249+ func newNode (cfg * LitNodeConfig , harness * NetworkHarness ) (* HarnessNode , error ) {
224250 if cfg .BaseDir == "" {
225251 var err error
226252 cfg .BaseDir , err = ioutil .TempDir ("" , "litdtest-node" )
@@ -252,6 +278,7 @@ func newNode(cfg *LitNodeConfig) (*HarnessNode, error) {
252278 cfg .PoolMacPath = filepath .Join (
253279 cfg .PoolDir , cfg .NetParams .Name , "pool.macaroon" ,
254280 )
281+ cfg .LitTLSCertPath = filepath .Join (cfg .LitDir , "tls.cert" )
255282 cfg .GenerateListeningPorts ()
256283
257284 // Generate a random UI password by reading 16 random bytes and base64
@@ -270,9 +297,41 @@ func newNode(cfg *LitNodeConfig) (*HarnessNode, error) {
270297 numActiveNodes ++
271298 numActiveNodesMtx .Unlock ()
272299
300+ var (
301+ remoteNode * lntest.HarnessNode
302+ remoteNodeHarness * lntest.NetworkHarness
303+ err error
304+ )
305+ if cfg .RemoteMode {
306+ lndBinary := strings .ReplaceAll (
307+ getLitdBinary (), itestLitdBinary , itestLndBinary ,
308+ )
309+ remoteNodeHarness , err = lntest .NewNetworkHarness (
310+ harness .Miner , harness .BackendCfg , lndBinary ,
311+ lntest .BackendBbolt ,
312+ )
313+ if err != nil {
314+ return nil , err
315+ }
316+
317+ remoteNode , _ , _ , err = remoteNodeHarness .NewNodeWithSeed (
318+ cfg .Name , cfg .ExtraArgs , defaultLndPassphrase , false ,
319+ )
320+ if err != nil {
321+ return nil , err
322+ }
323+
324+ cfg .RPCPort = remoteNode .Cfg .RPCPort
325+ cfg .P2PPort = remoteNode .Cfg .P2PPort
326+ cfg .TLSCertPath = remoteNode .Cfg .TLSCertPath
327+ cfg .AdminMacPath = remoteNode .Cfg .AdminMacPath
328+ }
329+
273330 return & HarnessNode {
274331 Cfg : cfg ,
275332 NodeID : nodeNum ,
333+ RemoteLnd : remoteNode ,
334+ RemoteLndHarness : remoteNodeHarness ,
276335 chanWatchRequests : make (chan * chanWatchRequest ),
277336 openChans : make (map [wire.OutPoint ]int ),
278337 openChanWatchers : make (map [wire.OutPoint ][]chan struct {}),
@@ -929,14 +988,21 @@ func (hn *HarnessNode) ReadMacaroon(macPath string, timeout time.Duration) (
929988func (hn * HarnessNode ) ConnectRPCWithMacaroon (mac * macaroon.Macaroon ) (
930989 * grpc.ClientConn , error ) {
931990
991+ var (
992+ certPath = hn .Cfg .TLSCertPath
993+ connectAddr = hn .Cfg .RPCAddr ()
994+ )
995+ if hn .Cfg .RemoteMode {
996+ certPath = hn .Cfg .LitTLSCertPath
997+ connectAddr = hn .Cfg .LitAddr ()
998+ }
999+
9321000 // Wait until TLS certificate is created and has valid content before
9331001 // using it, up to 30 sec.
9341002 var tlsCreds credentials.TransportCredentials
9351003 err := wait .NoError (func () error {
9361004 var err error
937- tlsCreds , err = credentials .NewClientTLSFromFile (
938- hn .Cfg .TLSCertPath , "" ,
939- )
1005+ tlsCreds , err = credentials .NewClientTLSFromFile (certPath , "" )
9401006 return err
9411007 }, lntest .DefaultTimeout )
9421008 if err != nil {
@@ -948,19 +1014,21 @@ func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) (
9481014 grpc .WithTransportCredentials (tlsCreds ),
9491015 }
9501016
951- ctx , cancel := context .WithTimeout (context .Background (), lntest .DefaultTimeout )
1017+ ctx , cancel := context .WithTimeout (
1018+ context .Background (), lntest .DefaultTimeout ,
1019+ )
9521020 defer cancel ()
9531021
9541022 if mac == nil {
955- return grpc .DialContext (ctx , hn . Cfg . RPCAddr () , opts ... )
1023+ return grpc .DialContext (ctx , connectAddr , opts ... )
9561024 }
9571025 macCred , err := macaroons .NewMacaroonCredential (mac )
9581026 if err != nil {
9591027 return nil , fmt .Errorf ("error cloning mac: %v" , err )
9601028 }
9611029 opts = append (opts , grpc .WithPerRPCCredentials (macCred ))
9621030
963- return grpc .DialContext (ctx , hn . Cfg . RPCAddr () , opts ... )
1031+ return grpc .DialContext (ctx , connectAddr , opts ... )
9641032}
9651033
9661034// ConnectRPC uses the TLS certificate and admin macaroon files written by the
@@ -1061,6 +1129,10 @@ func (hn *HarnessNode) stop() error {
10611129 }
10621130 }
10631131
1132+ if hn .Cfg .RemoteMode {
1133+ return hn .RemoteLndHarness .ShutdownNode (hn .RemoteLnd )
1134+ }
1135+
10641136 return nil
10651137}
10661138
0 commit comments