@@ -49,7 +49,7 @@ pub struct DummyTrustedWalletExtraConfig {
4949impl 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+
268307impl TrustedWalletInterface for DummyTrustedWallet {
269308 fn get_balance (
270309 & self ,
0 commit comments