Skip to content

Commit 5d16aff

Browse files
committed
Bound dummy wallet setup calls
Run blocking LDK and bitcoind setup calls through timed blocking tasks so dummy wallet initialization fails at the stuck operation instead of waiting for the outer test lifecycle timeout.
1 parent 57fca0c commit 5d16aff

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

orange-sdk/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ impl Wallet {
637637
ExtraConfig::Dummy(cfg) => Arc::new(Box::new(
638638
DummyTrustedWallet::new(
639639
cfg.uuid,
640-
&cfg.lsp,
641-
&cfg.bitcoind,
640+
Arc::clone(&cfg.lsp),
641+
Arc::clone(&cfg.bitcoind),
642642
tx_metadata.clone(),
643643
Arc::clone(&event_queue),
644644
Arc::clone(&runtime),

orange-sdk/src/trusted_wallet/dummy.rs

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct DummyTrustedWalletExtraConfig {
4949
impl DummyTrustedWallet {
5050
/// Creates a new `DummyTrustedWallet` instance.
5151
pub(crate) async fn new(
52-
uuid: Uuid, lsp: &Node, bitcoind: &Bitcoind, tx_metadata: TxMetadataStore,
52+
uuid: Uuid, lsp: Arc<Node>, bitcoind: Arc<Bitcoind>, tx_metadata: TxMetadataStore,
5353
event_queue: Arc<EventQueue>, rt: Arc<Runtime>,
5454
) -> Self {
5555
let mut builder = ldk_node::Builder::new();
@@ -230,30 +230,57 @@ impl DummyTrustedWallet {
230230
}
231231

232232
// have LSP open channel to node
233-
lsp.open_channel(ldk_node.node_id(), socket_addr, 1_000_000, Some(500_000_000), None)
234-
.unwrap();
233+
let lsp_clone = Arc::clone(&lsp);
234+
let ldk_node_id = ldk_node.node_id();
235+
blocking_with_timeout("dummy LSP channel open", Duration::from_secs(30), move || {
236+
lsp_clone.open_channel(ldk_node_id, socket_addr, 1_000_000, Some(500_000_000), None)
237+
})
238+
.await
239+
.unwrap();
240+
235241
// wait for channel to be broadcast
236242
for _ in 0..iterations {
237-
let num_txs = bitcoind.client.get_mempool_info().unwrap().size;
243+
let bitcoind_clone = Arc::clone(&bitcoind);
244+
let num_txs =
245+
blocking_with_timeout("dummy mempool check", Duration::from_secs(5), move || {
246+
bitcoind_clone.client.get_mempool_info().unwrap().size
247+
})
248+
.await;
238249
if num_txs > 0 {
239250
break;
240251
}
241252
tokio::time::sleep(Duration::from_millis(250)).await;
242253
}
254+
243255
// confirm channel
244-
let addr = bitcoind.client.new_address().unwrap();
245-
bitcoind.client.generate_to_address(6, &addr).unwrap();
256+
let bitcoind_clone = Arc::clone(&bitcoind);
257+
blocking_with_timeout("dummy channel confirmation", Duration::from_secs(30), move || {
258+
let addr = bitcoind_clone.client.new_address().unwrap();
259+
bitcoind_clone.client.generate_to_address(6, &addr).unwrap();
260+
})
261+
.await;
246262

247263
// wait for sync/channel ready
248264
for _ in 0..iterations {
249-
if ldk_node.list_channels().first().is_some_and(|c| c.is_usable) {
265+
let ldk_node_clone = Arc::clone(&ldk_node);
266+
let is_usable =
267+
blocking_with_timeout("dummy channel list", Duration::from_secs(5), move || {
268+
ldk_node_clone.list_channels().first().is_some_and(|c| c.is_usable)
269+
})
270+
.await;
271+
if is_usable {
250272
break;
251273
}
252274
tokio::time::sleep(Duration::from_secs(1)).await;
253275
}
254276

255-
let channels = ldk_node.list_channels();
256-
if !ldk_node.list_channels().first().is_some_and(|c| c.is_usable) {
277+
let ldk_node_clone = Arc::clone(&ldk_node);
278+
let channels =
279+
blocking_with_timeout("dummy final channel list", Duration::from_secs(5), move || {
280+
ldk_node_clone.list_channels()
281+
})
282+
.await;
283+
if !channels.first().is_some_and(|c| c.is_usable) {
257284
panic!("No usable channels found {channels:?}");
258285
}
259286

@@ -265,6 +292,18 @@ impl DummyTrustedWallet {
265292
}
266293
}
267294

295+
async fn blocking_with_timeout<F, T>(operation: &'static str, timeout: Duration, f: F) -> T
296+
where
297+
F: FnOnce() -> T + Send + 'static,
298+
T: Send + 'static,
299+
{
300+
match tokio::time::timeout(timeout, tokio::task::spawn_blocking(f)).await {
301+
Ok(Ok(result)) => result,
302+
Ok(Err(e)) => panic!("{operation} blocking task failed: {e}"),
303+
Err(_) => panic!("{operation} timed out after {timeout:?}"),
304+
}
305+
}
306+
268307
impl TrustedWalletInterface for DummyTrustedWallet {
269308
fn get_balance(
270309
&self,

0 commit comments

Comments
 (0)