Skip to content

Commit c765545

Browse files
committed
Move inner code to sync_lightning_wallet_inner for Electrum
Previously, we might have overlooked some cases that would exit the method and bubble up an error via `?` instead of propagating to all subscribers. Here, we split out the code to an inner method to ensure we always propagate.
1 parent c1157a3 commit c765545

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

src/chain/electrum.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,6 @@ impl ElectrumChainSource {
188188
&self, channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
189189
output_sweeper: Arc<Sweeper>,
190190
) -> Result<(), Error> {
191-
let electrum_client: Arc<ElectrumRuntimeClient> =
192-
if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() {
193-
Arc::clone(client)
194-
} else {
195-
debug_assert!(
196-
false,
197-
"We should have started the chain source before syncing the lightning wallet"
198-
);
199-
return Err(Error::TxSyncFailed);
200-
};
201-
202-
let sync_cman = Arc::clone(&channel_manager);
203-
let sync_cmon = Arc::clone(&chain_monitor);
204-
let sync_sweeper = Arc::clone(&output_sweeper);
205-
let confirmables = vec![
206-
sync_cman as Arc<dyn Confirm + Sync + Send>,
207-
sync_cmon as Arc<dyn Confirm + Sync + Send>,
208-
sync_sweeper as Arc<dyn Confirm + Sync + Send>,
209-
];
210-
211191
let receiver_res = {
212192
let mut status_lock = self.lightning_wallet_sync_status.lock().unwrap();
213193
status_lock.register_or_subscribe_pending_sync()
@@ -221,6 +201,38 @@ impl ElectrumChainSource {
221201
})?;
222202
}
223203

204+
let res =
205+
self.sync_lightning_wallet_inner(channel_manager, chain_monitor, output_sweeper).await;
206+
207+
self.lightning_wallet_sync_status.lock().unwrap().propagate_result_to_subscribers(res);
208+
209+
res
210+
}
211+
212+
async fn sync_lightning_wallet_inner(
213+
&self, channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
214+
output_sweeper: Arc<Sweeper>,
215+
) -> Result<(), Error> {
216+
let sync_cman = Arc::clone(&channel_manager);
217+
let sync_cmon = Arc::clone(&chain_monitor);
218+
let sync_sweeper = Arc::clone(&output_sweeper);
219+
let confirmables = vec![
220+
sync_cman as Arc<dyn Confirm + Sync + Send>,
221+
sync_cmon as Arc<dyn Confirm + Sync + Send>,
222+
sync_sweeper as Arc<dyn Confirm + Sync + Send>,
223+
];
224+
225+
let electrum_client: Arc<ElectrumRuntimeClient> =
226+
if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() {
227+
Arc::clone(client)
228+
} else {
229+
debug_assert!(
230+
false,
231+
"We should have started the chain source before syncing the lightning wallet"
232+
);
233+
return Err(Error::TxSyncFailed);
234+
};
235+
224236
let res = electrum_client.sync_confirmables(confirmables).await;
225237

226238
if let Ok(_) = res {
@@ -245,8 +257,6 @@ impl ElectrumChainSource {
245257
)?;
246258
}
247259

248-
self.lightning_wallet_sync_status.lock().unwrap().propagate_result_to_subscribers(res);
249-
250260
res
251261
}
252262

0 commit comments

Comments
 (0)