Skip to content

Commit

Permalink
chore: move query timeout default to a shared constant (#1566)
Browse files Browse the repository at this point in the history
  • Loading branch information
carver committed Oct 30, 2024
1 parent 4a9591a commit e9be8b2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions portalnet/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::time::Duration;

/// The default timeout for a query.
///
/// A "query" here refers to the whole process for finding a single piece of Portal content, across
/// all peer interactions. A single RPC request may spawn many queries. Each query will typically
/// spawn many requests to peers.
pub const DEFAULT_QUERY_TIMEOUT: Duration = Duration::from_secs(60);
6 changes: 3 additions & 3 deletions portalnet/src/find/iterators/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
// This basis of this file has been taken from the rust-libp2p codebase:
// https://github.com/libp2p/rust-libp2p

use super::super::query_pool::QueryState;

use std::time::{Duration, Instant};

use discv5::kbucket::Key;

use crate::{constants::DEFAULT_QUERY_TIMEOUT, find::query_pool::QueryState};

// Configuration for a `Query`.
#[derive(Debug, Clone)]
pub struct QueryConfig {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Default for QueryConfig {
parallelism: 3,
num_results: 20,
peer_timeout: Duration::from_secs(2),
overall_timeout: Duration::from_secs(60),
overall_timeout: DEFAULT_QUERY_TIMEOUT,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions portalnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

pub mod accept_queue;
pub mod config;
pub mod constants;
pub mod discovery;
pub mod events;
pub mod find;
Expand Down
4 changes: 2 additions & 2 deletions portalnet/src/overlay/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Duration;

use discv5::kbucket::{Filter, MAX_NODES_PER_BUCKET};

use crate::types::node::Node;
use crate::{constants::DEFAULT_QUERY_TIMEOUT, types::node::Node};
use ethportal_api::types::{cli::DEFAULT_UTP_TRANSFER_LIMIT, enr::Enr};

/// Configuration parameters for the overlay network.
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Default for OverlayConfig {
ping_queue_interval: None,
query_parallelism: 3, // (recommended α from kademlia paper)
query_peer_timeout: Duration::from_secs(2),
query_timeout: Duration::from_secs(60),
query_timeout: DEFAULT_QUERY_TIMEOUT,
query_num_results: MAX_NODES_PER_BUCKET,
findnodes_query_distances_per_peer: 3,
disable_poke: false,
Expand Down

0 comments on commit e9be8b2

Please sign in to comment.