fix(transfer): deadlock on client's RwLock usage with transfer and MQTT, closes
@@ -414,6 +414,8 @@ impl SyncedAccount {
let value: u64 = transfer_obj.amount;
let account_id: AccountIdentifier = self.account_id.clone().into();
let mut account = crate::storage::get_account(&self.storage_path, account_id.clone())?;
+
+ let (message, message_id) = {
let client = crate::client::get_client(account.client_options());
let client = client.read().unwrap();
@@ -527,7 +529,6 @@ impl SyncedAccount {
// keep the remainder value on the address
RemainderValueStrategy::ReuseAddress => remainder_address.address().clone(),
};
-
essence_builder = essence_builder.add_output(
SignatureLockedSingleOutput::new(
remainder_target_address,
@@ -548,7 +549,8 @@ impl SyncedAccount {
let essence = essence_builder
.finish()
.map_err(|e| anyhow::anyhow!(format!("{:?}", e)))?;
- let unlock_blocks = crate::with_stronghold_from_path(&self.storage_path, |stronghold| {
+ let unlock_blocks =
+ crate::with_stronghold_from_path(&self.storage_path, |stronghold| {
stronghold.get_transaction_unlock_blocks(
&account_id_to_stronghold_record_id(account.id())?,
&essence,
@@ -572,7 +574,6 @@ impl SyncedAccount {
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
let message_id = client.post_message(&message).await?;
-
// if this is a transfer to the account's latest address, we generate a new one to keep the latest address unused
if account.latest_address().unwrap().address() == &transfer_obj.address {
let addr = crate::address::get_new_address(&account)?;
@@ -580,12 +581,13 @@ impl SyncedAccount {
}
let message = client.get_message().data(&message_id).await?;
-
let message = Message::from_iota_message(message_id, account.addresses(), &message)?;
account.append_messages(vec![message.clone()]);
crate::storage::with_adapter(&self.storage_path, |storage| {
storage.set(account_id, serde_json::to_string(&account)?)
})?;
+ (message, message_id)
+ };
// ignore errors because we fallback to the polling system
let _ = crate::monitor::monitor_confirmation_state_change(&account, &message_id);
