Skip to content

Commit

Permalink
fix(wallet-ffi): don't block on start (#5437)
Browse files Browse the repository at this point in the history
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

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
brianp authored Jun 6, 2023
1 parent 0dfdb3a commit 27fe8d9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 27fe8d9

Please sign in to comment.