@@ -6,7 +6,7 @@ use lightning::util::events::EventsProvider;
66use tokio:: sync:: broadcast;
77use tokio:: task:: JoinHandle ;
88use tokio:: time:: { interval, interval_at, Instant } ;
9- use tracing:: { debug, error, info, trace} ;
9+ use tracing:: { debug, error, info, trace, warn } ;
1010
1111use crate :: lexe:: channel_manager:: LexeChannelManager ;
1212use crate :: lexe:: peer_manager:: LexePeerManager ;
@@ -39,6 +39,7 @@ impl LexeBackgroundProcessor {
3939 event_handler : Arc < InvoicePayerType > ,
4040 gossip_sync : Arc < P2PGossipSyncType > ,
4141 scorer : Arc < Mutex < ProbabilisticScorerType > > ,
42+ shutdown_tx : broadcast:: Sender < ( ) > ,
4243 mut shutdown_rx : broadcast:: Receiver < ( ) > ,
4344 ) -> JoinHandle < ( ) > {
4445 tokio:: task:: spawn ( async move {
@@ -78,24 +79,43 @@ impl LexeBackgroundProcessor {
7879 let needs_persist = channel_manager
7980 . await_persistable_update_timeout( timeout) ;
8081 if needs_persist {
81- // TODO Log err and shut down if persist fails
82- persister. persist_manager( channel_manager. deref( ) ) . await
83- . expect( "TODO: Shut down if persist fails" ) ;
82+ let persist_res = persister
83+ . persist_manager( channel_manager. deref( ) )
84+ . await ;
85+ if let Err ( e) = persist_res {
86+ // Failing to persist the channel manager won't
87+ // lose funds so long as the chain monitors have
88+ // been persisted correctly, but it's still
89+ // serious - initiate a shutdown
90+ error!( "Couldn't persist channel manager: {:#}" , e) ;
91+ let _ = shutdown_tx. send( ( ) ) ;
92+ break ;
93+ }
8494 }
8595 }
8696 _ = ng_timer. tick( ) => {
8797 debug!( "Pruning and persisting network graph" ) ;
8898 let network_graph = gossip_sync. network_graph( ) ;
8999 network_graph. remove_stale_channels( ) ;
90- // TODO Log err and shut down if persist fails
91- persister. persist_graph( network_graph) . await
92- . expect( "TODO: Shut down if persist fails" ) ;
100+ let persist_res = persister
101+ . persist_graph( network_graph)
102+ . await ;
103+ if let Err ( e) = persist_res {
104+ // The network graph isn't super important,
105+ // but we still should log a warning.
106+ warn!( "Couldn't persist network graph: {:#}" , e) ;
107+ }
93108 }
94109 _ = ps_timer. tick( ) => {
95110 debug!( "Persisting probabilistic scorer" ) ;
96- // TODO Log err and shut down if persist fails
97- persister. persist_scorer( scorer. as_ref( ) ) . await
98- . expect( "TODO: Shut down if persist fails" ) ;
111+ let persist_res = persister
112+ . persist_scorer( scorer. as_ref( ) )
113+ . await ;
114+ if let Err ( e) = persist_res {
115+ // The scorer isn't super important,
116+ // but we still should log a warning.
117+ warn!( "Couldn't persist network graph: {:#}" , e) ;
118+ }
99119 }
100120
101121 // --- Shutdown branch --- //
0 commit comments