From 27fe8d9d2fc3ea6468605ef5edea56efdcc8248f Mon Sep 17 00:00:00 2001 From: Brian Pearce Date: Tue, 6 Jun 2023 10:54:48 +0200 Subject: [PATCH] fix(wallet-ffi): don't block on start (#5437) Description --- Currently the ffi call to create and start the wallet will block until connections have been made. Instead return the Wallet asap, and throw the previously blocking call into an async non blocking call and let it complete on its own time. Motivation and Context --- The wallet freezes up for a duration while connecting to tor and the base node if the user has low connectivity. This prevents all other local actions from functioning. Instead we can return an initialized wallet that doesn't have connectivity allowing for local manipulation and gain connectivity in the background. How Has This Been Tested? --- CI only What process can a PR reviewer use to test or verify this change? --- Watch for green checks Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify --- base_layer/wallet_ffi/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index de7e0f1c7f..c1b16eff3f 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -5434,7 +5434,7 @@ pub unsafe extern "C" fn wallet_create( )); match w { - Ok(mut w) => { + Ok(w) => { // lets ensure the wallet tor_id is saved, this could have been changed during wallet startup if let Some(hs) = w.comms.hidden_service() { if let Err(e) = w.db.set_tor_identity(hs.tor_identity().clone()) { @@ -5476,12 +5476,15 @@ pub unsafe extern "C" fn wallet_create( runtime.spawn(callback_handler.start()); - if let Err(e) = runtime.block_on(w.transaction_service.restart_transaction_protocols()) { - warn!( - target: LOG_TARGET, - "Could not restart transaction negotiation protocols: {:?}", e - ); - } + let mut ts = w.transaction_service.clone(); + runtime.spawn(async move { + if let Err(e) = ts.restart_transaction_protocols().await { + warn!( + target: LOG_TARGET, + "Could not restart transaction negotiation protocols: {:?}", e + ); + } + }); let tari_wallet = TariWallet { wallet: w,