Skip to content

Commit 9444bc4

Browse files
committed
Move inner code to poll_and_update_listeners_inner
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 128fdfd commit 9444bc4

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/chain/bitcoind.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,19 @@ impl BitcoindChainSource {
306306
})?;
307307
}
308308

309+
let res = self
310+
.poll_and_update_listeners_inner(channel_manager, chain_monitor, output_sweeper)
311+
.await;
312+
313+
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
314+
315+
res
316+
}
317+
318+
async fn poll_and_update_listeners_inner(
319+
&self, channel_manager: Arc<ChannelManager>, chain_monitor: Arc<ChainMonitor>,
320+
output_sweeper: Arc<Sweeper>,
321+
) -> Result<(), Error> {
309322
let latest_chain_tip_opt = self.latest_chain_tip.read().unwrap().clone();
310323
let chain_tip = if let Some(tip) = latest_chain_tip_opt {
311324
tip
@@ -317,9 +330,7 @@ impl BitcoindChainSource {
317330
},
318331
Err(e) => {
319332
log_error!(self.logger, "Failed to poll for chain data: {:?}", e);
320-
let res = Err(Error::TxSyncFailed);
321-
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
322-
return res;
333+
return Err(Error::TxSyncFailed);
323334
},
324335
}
325336
};
@@ -348,9 +359,7 @@ impl BitcoindChainSource {
348359
Ok(_) => {},
349360
Err(e) => {
350361
log_error!(self.logger, "Failed to poll for chain data: {:?}", e);
351-
let res = Err(Error::TxSyncFailed);
352-
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
353-
return res;
362+
return Err(Error::TxSyncFailed);
354363
},
355364
}
356365

@@ -376,9 +385,7 @@ impl BitcoindChainSource {
376385
},
377386
Err(e) => {
378387
log_error!(self.logger, "Failed to poll for mempool transactions: {:?}", e);
379-
let res = Err(Error::TxSyncFailed);
380-
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
381-
return res;
388+
return Err(Error::TxSyncFailed);
382389
},
383390
}
384391

@@ -388,24 +395,13 @@ impl BitcoindChainSource {
388395
locked_node_metrics.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
389396
locked_node_metrics.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
390397

391-
let write_res = write_node_metrics(
398+
write_node_metrics(
392399
&*locked_node_metrics,
393400
Arc::clone(&self.kv_store),
394401
Arc::clone(&self.logger),
395-
);
396-
match write_res {
397-
Ok(()) => (),
398-
Err(e) => {
399-
log_error!(self.logger, "Failed to persist node metrics: {}", e);
400-
let res = Err(Error::PersistenceFailed);
401-
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
402-
return res;
403-
},
404-
}
402+
)?;
405403

406-
let res = Ok(());
407-
self.wallet_polling_status.lock().unwrap().propagate_result_to_subscribers(res);
408-
res
404+
Ok(())
409405
}
410406

411407
pub(super) async fn update_fee_rate_estimates(&self) -> Result<(), Error> {

0 commit comments

Comments
 (0)