@@ -556,6 +556,7 @@ def __init__(self, lightning_dir, bitcoindproxy, port=9735, random_hsm=False, no
556556 self .cmd_prefix = []
557557 self .disconnect_file = None
558558 self .lightning_dir = lightning_dir
559+ self .use_rsignerd = False ;
559560 self .rsignerd_dir = os .path .join (lightning_dir , "remotesigner" )
560561
561562 self .rpcproxy = bitcoindproxy
@@ -577,15 +578,18 @@ def __init__(self, lightning_dir, bitcoindproxy, port=9735, random_hsm=False, no
577578
578579 if SUBDAEMON :
579580 opts ['subdaemon' ] = SUBDAEMON
580-
581+ if SUBDAEMON == 'hsmd:remote_hsmd' :
582+ self .use_rsignerd = True
583+
581584 for k , v in opts .items ():
582585 self .opts [k ] = v
583586
584587 if not os .path .exists (os .path .join (lightning_dir , TEST_NETWORK )):
585588 os .makedirs (os .path .join (lightning_dir , TEST_NETWORK ))
586589
587- if not os .path .exists (self .rsignerd_dir ):
588- os .makedirs (self .rsignerd_dir )
590+ if self .use_rsignerd :
591+ if not os .path .exists (self .rsignerd_dir ):
592+ os .makedirs (self .rsignerd_dir )
589593
590594 # Last 32-bytes of final part of dir -> seed.
591595 seed = (bytes (re .search ('([^/]+)/*$' , lightning_dir ).group (1 ), encoding = 'utf-8' ) + bytes (32 ))[:32 ]
@@ -598,8 +602,11 @@ def __init__(self, lightning_dir, bitcoindproxy, port=9735, random_hsm=False, no
598602 self .prefix = 'lightningd-%d' % (node_id )
599603
600604 def cleanup (self ):
601- # Make sure the remotesigner is shutdown
602- self .rsignerd .stop ()
605+ if self .use_rsignerd :
606+ if self .use_rsignerd :
607+ # Make sure the remotesigner is shutdown
608+ self .rsignerd .stop ()
609+
603610 # To force blackhole to exit, disconnect file must be truncated!
604611 if self .disconnect_file :
605612 with open (self .disconnect_file , "w" ) as f :
@@ -623,32 +630,36 @@ def cmd_line(self):
623630 def start (self , stdin = None , stdout = None , stderr = None ,
624631 wait_for_initialized = True ):
625632 try :
626- # Start the remote signer first
627- rsignerd_port = reserve ()
628- self .rsignerd = RemoteSignerD (self .rsignerd_dir , rsignerd_port )
629- self .rsignerd .start (stdin , stdout , stderr , wait_for_initialized )
633+ if self .use_rsignerd :
634+ # Start the remote signer first
635+ rsignerd_port = reserve ()
636+ self .rsignerd = RemoteSignerD (self .rsignerd_dir , rsignerd_port )
637+ self .rsignerd .start (stdin , stdout , stderr , wait_for_initialized )
630638
631- # We can't do this in the constructor because we need a new port on each restart.
632- self .env ['REMOTE_HSMD_ENDPOINT' ] = 'localhost:{}' .format (rsignerd_port )
639+ # We can't do this in the constructor because we need a new port on each restart.
640+ self .env ['REMOTE_HSMD_ENDPOINT' ] = 'localhost:{}' .format (rsignerd_port )
633641
634642 self .opts ['bitcoin-rpcport' ] = self .rpcproxy .rpcport
635643 TailableProc .start (self , stdin , stdout , stderr )
636644 if wait_for_initialized :
637645 self .wait_for_log ("Server started with public key" )
638646 logging .info ("LightningD started" )
639647 except Exception :
640- # LightningD didn't start, stop the remotesigner
641- self .rsignerd .stop ()
648+ if self .use_rsignerd :
649+ # LightningD didn't start, stop the remotesigner
650+ self .rsignerd .stop ()
642651 raise
643652
644653 def stop (self , timeout = 10 ):
645- # Stop the remote signer first
646- self .rsignerd .stop (timeout )
654+ if self .use_rsignerd :
655+ # Stop the remote signer first
656+ self .rsignerd .stop (timeout )
647657 return TailableProc .stop (self , timeout )
648658
649659 def kill (self ):
650- # Kill the remote signer first
651- self .rsignerd .kill ()
660+ if self .use_rsignerd :
661+ # Kill the remote signer first
662+ self .rsignerd .kill ()
652663 TailableProc .kill (self )
653664
654665 def wait (self , timeout = 10 ):
0 commit comments