mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
event_graph: replace the rest of timeout() with receive_with_timeout()
This commit is contained in:
@@ -20,7 +20,6 @@ use std::{
|
||||
collections::{BTreeMap, HashMap, HashSet, VecDeque},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use darkfi_serial::{deserialize_async, serialize_async};
|
||||
@@ -40,10 +39,7 @@ use crate::{
|
||||
jsonrpc::{JsonResponse, JsonResult},
|
||||
util::json_map,
|
||||
},
|
||||
system::{
|
||||
msleep, timeout::timeout, Publisher, PublisherPtr, StoppableTask, StoppableTaskPtr,
|
||||
Subscription,
|
||||
},
|
||||
system::{msleep, Publisher, PublisherPtr, StoppableTask, StoppableTaskPtr, Subscription},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -358,34 +354,20 @@ impl EventGraph {
|
||||
continue
|
||||
}
|
||||
|
||||
let parent = match timeout(
|
||||
Duration::from_secs(self.p2p.settings().read().await.outbound_connect_timeout),
|
||||
ev_rep_sub.receive(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(parent) => parent,
|
||||
Err(_) => {
|
||||
error!(
|
||||
target: "event_graph::dag_sync()",
|
||||
"[EVENTGRAPH] Sync: Timeout waiting for parents {:?} from {}",
|
||||
missing_parents, url,
|
||||
);
|
||||
continue
|
||||
}
|
||||
// Node waits for response
|
||||
let Ok(parent) = ev_rep_sub
|
||||
.receive_with_timeout(self.p2p.settings().read().await.outbound_connect_timeout)
|
||||
.await
|
||||
else {
|
||||
error!(
|
||||
target: "event_graph::dag_sync()",
|
||||
"[EVENTGRAPH] Sync: Timeout waiting for parents {:?} from {}",
|
||||
missing_parents, url,
|
||||
);
|
||||
continue
|
||||
};
|
||||
|
||||
let parents = match parent {
|
||||
Ok(v) => v.0.clone(),
|
||||
Err(e) => {
|
||||
error!(
|
||||
target: "event_graph::dag_sync()",
|
||||
"[EVENTGRAPH] Sync: Failed receiving parents {:?}: {}",
|
||||
missing_parents, e,
|
||||
);
|
||||
continue
|
||||
}
|
||||
};
|
||||
let parents = parent.0.clone();
|
||||
|
||||
for parent in parents {
|
||||
let parent_id = parent.id();
|
||||
|
||||
@@ -22,7 +22,6 @@ use std::{
|
||||
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
Arc,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use darkfi_serial::{async_trait, SerialDecodable, SerialEncodable};
|
||||
@@ -30,7 +29,7 @@ use log::{debug, error, trace, warn};
|
||||
use smol::Executor;
|
||||
|
||||
use super::{Event, EventGraphPtr, NULL_ID};
|
||||
use crate::{impl_p2p_message, net::*, system::timeout::timeout, Error, Result};
|
||||
use crate::{impl_p2p_message, net::*, Error, Result};
|
||||
|
||||
/// Malicious behaviour threshold. If the threshold is reached, we will
|
||||
/// drop the peer from our P2P connection.
|
||||
@@ -256,25 +255,23 @@ impl ProtocolEventGraph {
|
||||
.send(&EventReq(missing_parents.clone().into_iter().collect()))
|
||||
.await?;
|
||||
|
||||
let parents = match timeout(
|
||||
Duration::from_secs(
|
||||
// Node waits for response
|
||||
let Ok(parents) = self
|
||||
.ev_rep_sub
|
||||
.receive_with_timeout(
|
||||
self.event_graph.p2p.settings().read().await.outbound_connect_timeout,
|
||||
),
|
||||
self.ev_rep_sub.receive(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(parent) => parent?,
|
||||
Err(_) => {
|
||||
error!(
|
||||
target: "event_graph::protocol::handle_event_put()",
|
||||
"[EVENTGRAPH] Timeout while waiting for parents {:?} from {}",
|
||||
missing_parents, self.channel.address(),
|
||||
);
|
||||
self.channel.stop().await;
|
||||
return Err(Error::ChannelStopped)
|
||||
}
|
||||
)
|
||||
.await
|
||||
else {
|
||||
error!(
|
||||
target: "event_graph::protocol::handle_event_put()",
|
||||
"[EVENTGRAPH] Timeout while waiting for parents {:?} from {}",
|
||||
missing_parents, self.channel.address(),
|
||||
);
|
||||
self.channel.stop().await;
|
||||
return Err(Error::ChannelStopped)
|
||||
};
|
||||
|
||||
let parents = parents.0.clone();
|
||||
|
||||
for parent in parents {
|
||||
|
||||
Reference in New Issue
Block a user