event_graph: replace the rest of timeout() with receive_with_timeout()

This commit is contained in:
dasman
2024-10-04 02:13:18 +03:00
parent 86351d88fa
commit 2b47026bdd
2 changed files with 29 additions and 50 deletions

View File

@@ -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(),
)
// Node waits for response
let Ok(parent) = ev_rep_sub
.receive_with_timeout(self.p2p.settings().read().await.outbound_connect_timeout)
.await
{
Ok(parent) => parent,
Err(_) => {
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();

View File

@@ -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,16 +255,14 @@ 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(_) => {
else {
error!(
target: "event_graph::protocol::handle_event_put()",
"[EVENTGRAPH] Timeout while waiting for parents {:?} from {}",
@@ -273,8 +270,8 @@ impl ProtocolEventGraph {
);
self.channel.stop().await;
return Err(Error::ChannelStopped)
}
};
let parents = parents.0.clone();
for parent in parents {