ソースを参照

darkfid: respect P2P configuration outbound connections timeout

skoupidi 2 年 前
コミット
0892e3f58a

+ 0 - 3
bin/darkfid/src/proto/mod.rs

@@ -32,6 +32,3 @@ pub use protocol_sync::{
 /// Transaction broadcast protocol
 mod protocol_tx;
 pub use protocol_tx::ProtocolTx;
-
-/// Communications timeout
-pub const COMMS_TIMEOUT: u64 = 15;

+ 2 - 2
bin/darkfid/src/proto/protocol_proposal.rs

@@ -36,7 +36,7 @@ use darkfi::{
 };
 use darkfi_serial::{serialize_async, SerialDecodable, SerialEncodable};
 
-use crate::proto::{ForkSyncRequest, ForkSyncResponse, COMMS_TIMEOUT};
+use crate::proto::{ForkSyncRequest, ForkSyncResponse};
 
 /// Auxiliary [`Proposal`] wrapper structure used for messaging.
 #[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
@@ -158,7 +158,7 @@ impl ProtocolProposal {
             // Node waits for response
             let response = match self
                 .proposals_response_sub
-                .receive_with_timeout(COMMS_TIMEOUT)
+                .receive_with_timeout(self.p2p.settings().outbound_connect_timeout)
                 .await
             {
                 Ok(r) => r,

+ 10 - 6
bin/darkfid/src/task/sync.rs

@@ -30,7 +30,7 @@ use tinyjson::JsonValue;
 use crate::{
     proto::{
         ForkSyncRequest, ForkSyncResponse, HeaderSyncRequest, HeaderSyncResponse, SyncRequest,
-        SyncResponse, TipRequest, TipResponse, BATCH, COMMS_TIMEOUT,
+        SyncResponse, TipRequest, TipResponse, BATCH,
     },
     Darkfid,
 };
@@ -142,6 +142,7 @@ async fn synced_peers(
     checkpoint: Option<(u32, HeaderHash)>,
 ) -> Result<HashMap<(u32, [u8; 32]), Vec<ChannelPtr>>> {
     info!(target: "darkfid::task::sync::synced_peers", "Receiving tip from peers...");
+    let comms_timeout = node.p2p.settings().outbound_connect_timeout;
     let mut tips = HashMap::new();
     loop {
         // Grab channels
@@ -161,7 +162,7 @@ async fn synced_peers(
                     peer.send(&request).await?;
 
                     // Node waits for response
-                    let Ok(response) = response_sub.receive_with_timeout(COMMS_TIMEOUT).await
+                    let Ok(response) = response_sub.receive_with_timeout(comms_timeout).await
                     else {
                         continue
                     };
@@ -181,7 +182,7 @@ async fn synced_peers(
                 peer.send(&request).await?;
 
                 // Node waits for response
-                let Ok(response) = response_sub.receive_with_timeout(COMMS_TIMEOUT).await else {
+                let Ok(response) = response_sub.receive_with_timeout(comms_timeout).await else {
                     continue
                 };
 
@@ -252,6 +253,7 @@ async fn retrieve_headers(
     for peer in peers {
         peer_subs.push(peer.subscribe_msg::<HeaderSyncResponse>().await?);
     }
+    let comms_timeout = node.p2p.settings().outbound_connect_timeout;
 
     // We subtract 1 since tip_height is increased by one
     let total = tip_height - last_known - 1;
@@ -263,7 +265,7 @@ async fn retrieve_headers(
             peer.send(&request).await?;
 
             // Node waits for response
-            let Ok(response) = peer_subs[index].receive_with_timeout(COMMS_TIMEOUT).await else {
+            let Ok(response) = peer_subs[index].receive_with_timeout(comms_timeout).await else {
                 continue
             };
 
@@ -356,6 +358,7 @@ async fn retrieve_blocks(
     for peer in peers {
         peer_subs.push(peer.subscribe_msg::<SyncResponse>().await?);
     }
+    let comms_timeout = node.p2p.settings().outbound_connect_timeout;
 
     let mut received_blocks = 0;
     let total = node.validator.blockchain.headers.len_sync();
@@ -378,7 +381,7 @@ async fn retrieve_blocks(
             peer.send(&request).await?;
 
             // Node waits for response
-            let Ok(response) = peer_subs[index].receive_with_timeout(COMMS_TIMEOUT).await else {
+            let Ok(response) = peer_subs[index].receive_with_timeout(comms_timeout).await else {
                 continue
             };
 
@@ -444,7 +447,8 @@ async fn sync_best_fork(node: &Darkfid, peers: &[ChannelPtr], last_tip: &HeaderH
     channel.send(&request).await?;
 
     // Node waits for response
-    let response = response_sub.receive_with_timeout(COMMS_TIMEOUT).await?;
+    let response =
+        response_sub.receive_with_timeout(node.p2p.settings().outbound_connect_timeout).await?;
 
     // Verify and store retrieved proposals
     debug!(target: "darkfid::task::sync_task", "Processing received proposals");