parazyd 4 лет назад
Родитель
Сommit
9e72280ea8
1 измененных файлов с 15 добавлено и 6 удалено
  1. 15 6
      src/client.rs

+ 15 - 6
src/client.rs

@@ -16,7 +16,7 @@ use crate::{
     },
     },
     serial::{serialize, Decodable, Encodable},
     serial::{serialize, Decodable, Encodable},
     service::GatewayClient,
     service::GatewayClient,
-    state::{state_transition, State},
+    state::{state_transition, State, StateUpdate},
     tx,
     tx,
     types::DrkTokenId,
     types::DrkTokenId,
     wallet::{
     wallet::{
@@ -257,13 +257,22 @@ impl Client {
         debug!("Decoding payload");
         debug!("Decoding payload");
         let tx = tx::Transaction::decode(&payload[..])?;
         let tx = tx::Transaction::decode(&payload[..])?;
 
 
-        let st = &*state.lock().await;
-        let update = state_transition(st, tx)?;
-        debug!("Successfully passed state_transition");
-        let mut st = state.lock().await;
+        let update: StateUpdate;
+
+        // This is separate because otherwise the mutex is never unlocked.
+        {
+            debug!("Acquiring state lock");
+            let state = &*state.lock().await;
+            update = state_transition(state, tx)?;
+            debug!("Successfully passed state_transition");
+        }
+
+        debug!("Acquiring state lock");
+        let mut state = state.lock().await;
         debug!("Trying to apply the new state");
         debug!("Trying to apply the new state");
-        st.apply(update, secret_keys, notify, wallet).await?;
+        state.apply(update, secret_keys, notify, wallet).await?;
         debug!("Successfully passed state.apply");
         debug!("Successfully passed state.apply");
+
         Ok(())
         Ok(())
     }
     }