Просмотр исходного кода

Revert "[bin/darkfid2] async retry receive with timeout"

This reverts commit 00d00ae6bde09c13446ea238e0165232b2667c8e.
aggstam 2 лет назад
Родитель
Сommit
6cb51623fe
3 измененных файлов с 7 добавлено и 23 удалено
  1. 0 1
      bin/darkfid2/Cargo.toml
  2. 1 1
      bin/darkfid2/src/task/mod.rs
  3. 6 21
      bin/darkfid2/src/task/sync.rs

+ 0 - 1
bin/darkfid2/Cargo.toml

@@ -24,7 +24,6 @@ log = "0.4.20"
 num-bigint = "0.4.4"
 sled = "0.34.7"
 rand = "0.8.5"
-async-std = "1.12.0"
 
 # JSON-RPC
 async-trait = "0.1.74"

+ 1 - 1
bin/darkfid2/src/task/mod.rs

@@ -19,7 +19,7 @@
 // TODO: Handle ? with matches in these files. They should be robust.
 
 pub mod sync;
-pub use sync::sync_task;
+pub use sync::{sync_task};
 
 pub mod miner;
 pub use miner::miner_task;

+ 6 - 21
bin/darkfid2/src/task/sync.rs

@@ -20,8 +20,6 @@ use darkfi::{system::sleep, util::encoding::base64};
 use darkfi_serial::serialize;
 use log::{debug, info, warn, error};
 use tinyjson::JsonValue;
-use std::time::Duration;
-use async_std::future;
 
 use crate::{
     proto::{SyncRequest, SyncResponse},
@@ -76,34 +74,21 @@ pub async fn sync_task(node: &Darkfid) {
         if let Err(why) = channel.send(&request).await {
             error!(target: "darkfid::task::sync_task", "request send failure: {:}", why);
             sleep(10).await;
-            // try to resend
             continue;
         }
 
-
-        let mut counter = 0;
-        let mut response_result;
+        // TODO: add a timeout here to retry
         // Node waits for response
-        loop {
-            let timeout_response_result = future::timeout(Duration::from_millis(10), block_response_sub.receive()).await;
-            response_result = timeout_response_result.unwrap();
-            if response_result.is_ok() {
-                break
-            } else {
-                sleep(10).await;
-                counter +=1;
-            }
-            if counter == 10 {
-                panic!("darkfid::task::sync_task block_response_sub receive error at recv_queue recv")
-            }
+        let response = match block_response_sub.receive().await {
+            Err(why) => {
+                panic!("darkfid::task::sync_task block_response_sub receive error at recv_queue recv: {:?}", why)
+            },
+            Ok(value) => value
         };
-        // safe to unwrap at this point, if returned error after retries it should had  paniced.
-        let response = response_result.unwrap();
 
         // Verify and store retrieved blocks
         debug!(target: "darkfid::task::sync_task", "Processing received blocks");
         if let Err(why) = node.validator.write().await.add_blocks(&response.blocks).await {
-            // nothing to do if the requested block verification fails.
             panic!("darkfid::task::sync_task block validation failed: {:?}", why)
         };