@@ -396,6 +396,28 @@ func (n *NetworkHarness) RegisterNode(node *HarnessNode) {
396
396
n .mtx .Unlock ()
397
397
}
398
398
399
+ func (n * NetworkHarness ) connect (ctx context.Context ,
400
+ req * lnrpc.ConnectPeerRequest , a * HarnessNode ) error {
401
+
402
+ syncTimeout := time .After (15 * time .Second )
403
+ tryconnect:
404
+ if _ , err := a .ConnectPeer (ctx , req ); err != nil {
405
+ // If the chain backend is still syncing, retry.
406
+ if strings .Contains (err .Error (), "still syncing" ) {
407
+ select {
408
+ case <- time .After (100 * time .Millisecond ):
409
+ goto tryconnect
410
+ case <- syncTimeout :
411
+ return fmt .Errorf ("chain backend did not " +
412
+ "finish syncing" )
413
+ }
414
+ }
415
+ return err
416
+ }
417
+
418
+ return nil
419
+ }
420
+
399
421
// EnsureConnected will try to connect to two nodes, returning no error if they
400
422
// are already connected. If the nodes were not connected previously, this will
401
423
// behave the same as ConnectNodes. If a pending connection request has already
@@ -422,7 +444,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
422
444
}
423
445
424
446
ctxt , _ = context .WithTimeout (ctx , 15 * time .Second )
425
- _ , err = a . ConnectPeer (ctxt , req )
447
+ err = n . connect (ctxt , req , a )
426
448
switch {
427
449
428
450
// Request was successful, wait for both to display the
@@ -508,7 +530,8 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, a, b *HarnessNode) er
508
530
Host : b .cfg .P2PAddr (),
509
531
},
510
532
}
511
- if _ , err := a .ConnectPeer (ctx , req ); err != nil {
533
+
534
+ if err := n .connect (ctx , req , a ); err != nil {
512
535
return err
513
536
}
514
537
0 commit comments