@@ -148,8 +148,10 @@ use lightning::ln::funding::SpliceContribution;
148148use lightning:: ln:: msgs:: SocketAddress ;
149149use lightning:: ln:: types:: ChannelId ;
150150use lightning:: routing:: gossip:: NodeAlias ;
151+ use lightning:: routing:: router:: { Path , RouteHop } ;
151152use lightning:: util:: persist:: KVStoreSync ;
152153use lightning_background_processor:: process_events_async;
154+ use lightning_types:: features:: { ChannelFeatures , NodeFeatures } ;
153155use liquidity:: { LSPS1Liquidity , LiquiditySource } ;
154156use logger:: { log_debug, log_error, log_info, log_trace, LdkLogger , Logger } ;
155157use payment:: asynchronous:: om_mailbox:: OnionMessageMailbox ;
@@ -649,6 +651,11 @@ impl Node {
649651 }
650652
651653 if defer_chain_sync {
654+ // Mark node as running and release the lock BEFORE the healing block,
655+ // so stop() can be called to abort startup if needed.
656+ * is_running_lock = true ;
657+ drop ( is_running_lock) ;
658+
652659 // Stale monitor recovery: the background processor and peer connections are now
653660 // running. We need to trigger a commitment round-trip on each channel to heal
654661 // the stale monitors before processing any on-chain events.
@@ -664,6 +671,7 @@ impl Node {
664671 let channel_manager = Arc :: clone ( & self . channel_manager ) ;
665672 let chain_monitor = Arc :: clone ( & self . chain_monitor ) ;
666673 let heal_logger = Arc :: clone ( & self . logger ) ;
674+ let mut stop_healing = self . stop_sender . subscribe ( ) ;
667675 self . runtime . block_on ( async move {
668676 // Record initial monitor update_ids to detect when they advance.
669677 let initial_update_ids: Vec < _ > = channel_manager
@@ -690,7 +698,13 @@ impl Node {
690698 ) ;
691699
692700 // Give peers time to connect and complete channel_reestablish.
693- tokio:: time:: sleep ( Duration :: from_secs ( 5 ) ) . await ;
701+ tokio:: select! {
702+ _ = stop_healing. changed( ) => {
703+ log_info!( heal_logger, "Stale monitor recovery: cancelled by shutdown." ) ;
704+ return ;
705+ }
706+ _ = tokio:: time:: sleep( Duration :: from_secs( 5 ) ) => { }
707+ }
694708
695709 // Send probes to force commitment round-trips on all channels.
696710 // Probes work regardless of who the channel funder is.
@@ -704,12 +718,12 @@ impl Node {
704718 None => continue ,
705719 } ;
706720
707- let path = lightning :: routing :: router :: Path {
708- hops : vec ! [ lightning :: routing :: router :: RouteHop {
721+ let path = Path {
722+ hops : vec ! [ RouteHop {
709723 pubkey: channel. counterparty. node_id,
710- node_features: lightning_types :: features :: NodeFeatures :: empty( ) ,
724+ node_features: NodeFeatures :: empty( ) ,
711725 short_channel_id: scid,
712- channel_features: lightning_types :: features :: ChannelFeatures :: empty( ) ,
726+ channel_features: ChannelFeatures :: empty( ) ,
713727 fee_msat: 1000 ,
714728 cltv_expiry_delta: 144 ,
715729 maybe_announced_channel: true ,
@@ -809,14 +823,12 @@ impl Node {
809823 . cloned ( )
810824 {
811825 if let Some ( scid) = channel. short_channel_id {
812- let path = lightning :: routing :: router :: Path {
813- hops : vec ! [ lightning :: routing :: router :: RouteHop {
826+ let path = Path {
827+ hops : vec ! [ RouteHop {
814828 pubkey: channel. counterparty. node_id,
815- node_features:
816- lightning_types:: features:: NodeFeatures :: empty( ) ,
829+ node_features: NodeFeatures :: empty( ) ,
817830 short_channel_id: scid,
818- channel_features:
819- lightning_types:: features:: ChannelFeatures :: empty( ) ,
831+ channel_features: ChannelFeatures :: empty( ) ,
820832 fee_msat: 1000 ,
821833 cltv_expiry_delta: 144 ,
822834 maybe_announced_channel: true ,
@@ -835,11 +847,19 @@ impl Node {
835847 }
836848 }
837849
838- tokio:: time:: sleep ( poll_interval) . await ;
850+ tokio:: select! {
851+ _ = stop_healing. changed( ) => {
852+ log_info!( heal_logger, "Stale monitor recovery: cancelled by shutdown." ) ;
853+ break ;
854+ }
855+ _ = tokio:: time:: sleep( poll_interval) => { }
856+ }
839857 }
840858 } ) ;
841859
842860 self . spawn_chain_sync_task ( ) ;
861+ log_info ! ( self . logger, "Startup complete." ) ;
862+ return Ok ( ( ) ) ;
843863 }
844864
845865 log_info ! ( self . logger, "Startup complete." ) ;
0 commit comments