Skip to content

Commit 128fdfd

Browse files
committed
Move inner code to sync_onchain_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 c765545 commit 128fdfd

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/chain/electrum.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ impl ElectrumChainSource {
103103
}
104104

105105
pub(crate) async fn sync_onchain_wallet(&self) -> Result<(), Error> {
106-
let electrum_client: Arc<ElectrumRuntimeClient> =
107-
if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() {
108-
Arc::clone(client)
109-
} else {
110-
debug_assert!(
111-
false,
112-
"We should have started the chain source before syncing the onchain wallet"
113-
);
114-
return Err(Error::FeerateEstimationUpdateFailed);
115-
};
116106
let receiver_res = {
117107
let mut status_lock = self.onchain_wallet_sync_status.lock().unwrap();
118108
status_lock.register_or_subscribe_pending_sync()
@@ -126,6 +116,24 @@ impl ElectrumChainSource {
126116
})?;
127117
}
128118

119+
let res = self.sync_onchain_wallet_inner().await;
120+
121+
self.onchain_wallet_sync_status.lock().unwrap().propagate_result_to_subscribers(res);
122+
123+
res
124+
}
125+
126+
async fn sync_onchain_wallet_inner(&self) -> Result<(), Error> {
127+
let electrum_client: Arc<ElectrumRuntimeClient> =
128+
if let Some(client) = self.electrum_runtime_status.read().unwrap().client().as_ref() {
129+
Arc::clone(client)
130+
} else {
131+
debug_assert!(
132+
false,
133+
"We should have started the chain source before syncing the onchain wallet"
134+
);
135+
return Err(Error::FeerateEstimationUpdateFailed);
136+
};
129137
// If this is our first sync, do a full scan with the configured gap limit.
130138
// Otherwise just do an incremental sync.
131139
let incremental_sync =
@@ -179,8 +187,6 @@ impl ElectrumChainSource {
179187
apply_wallet_update(update_res, now)
180188
};
181189

182-
self.onchain_wallet_sync_status.lock().unwrap().propagate_result_to_subscribers(res);
183-
184190
res
185191
}
186192

0 commit comments

Comments
 (0)