Skip to content

Commit

Permalink
Merge pull request #909 from carver/default-utp-args
Browse files Browse the repository at this point in the history
fix: improve the utp connection success rate, by using a default config
  • Loading branch information
carver authored Sep 13, 2023
2 parents 4370f7e + 398598a commit 89e5a52
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions portalnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ethereum-types = "0.12.1"
ethportal-api = { path="../ethportal-api" }
fnv = "1.0.7"
futures = "0.3.21"
lazy_static = "1.4.0"
leb128 = "0.2.1"
lru = "0.7.8"
parking_lot = "0.11.2"
Expand Down
2 changes: 1 addition & 1 deletion portalnet/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ where
};
let mut stream = self
.utp_socket
.connect_with_cid(cid, UTP_CONN_CFG)
.connect_with_cid(cid, *UTP_CONN_CFG)
.await
.map_err(|err| OverlayRequestError::UtpError(format!("{err:?}")))?;
let mut data = vec![];
Expand Down
23 changes: 9 additions & 14 deletions portalnet/src/overlay_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use discv5::{
rpc::RequestId,
};
use futures::{channel::oneshot, future::join_all, prelude::*};
use lazy_static::lazy_static;
use parking_lot::RwLock;
use rand::seq::{IteratorRandom, SliceRandom};
use smallvec::SmallVec;
Expand Down Expand Up @@ -82,16 +83,10 @@ const EXPECTED_NON_EMPTY_BUCKETS: usize = 17;
/// Bucket refresh lookup interval in seconds
const BUCKET_REFRESH_INTERVAL_SECS: u64 = 60;

/// The default configuration to use for uTP connections.
pub const UTP_CONN_CFG: ConnectionConfig = ConnectionConfig {
max_packet_size: 1024,
max_conn_attempts: 3,
max_idle_timeout: Duration::from_secs(32),
max_timeout: Duration::from_secs(60),
initial_timeout: Duration::from_millis(1500),
min_timeout: Duration::from_millis(500),
target_delay: Duration::from_millis(250),
};
lazy_static! {
/// The default configuration to use for uTP connections.
pub static ref UTP_CONN_CFG: ConnectionConfig = ConnectionConfig { max_packet_size: 1024, ..Default::default()};
}

/// A network-based action that the overlay may perform.
///
Expand Down Expand Up @@ -836,7 +831,7 @@ where
tokio::spawn(async move {
metrics.report_utp_active_inc(UtpDirectionLabel::Inbound);
let mut stream = match utp
.connect_with_cid(cid.clone(), UTP_CONN_CFG)
.connect_with_cid(cid.clone(), *UTP_CONN_CFG)
.await
{
Ok(stream) => stream,
Expand Down Expand Up @@ -1109,7 +1104,7 @@ where
let metrics = Arc::clone(&self.metrics);
tokio::spawn(async move {
metrics.report_utp_active_inc(UtpDirectionLabel::Outbound);
let stream = match utp.accept_with_cid(cid.clone(), UTP_CONN_CFG).await {
let stream = match utp.accept_with_cid(cid.clone(), *UTP_CONN_CFG).await {
Ok(stream) => stream,
Err(err) => {
metrics.report_utp_outcome(
Expand Down Expand Up @@ -1237,7 +1232,7 @@ where
// Wait for an incoming connection with the given CID. Then, read the data from the uTP
// stream.
metrics.report_utp_active_inc(UtpDirectionLabel::Inbound);
let mut stream = match utp.accept_with_cid(cid.clone(), UTP_CONN_CFG).await {
let mut stream = match utp.accept_with_cid(cid.clone(), *UTP_CONN_CFG).await {
Ok(stream) => stream,
Err(err) => {
metrics.report_utp_outcome(
Expand Down Expand Up @@ -1500,7 +1495,7 @@ where

tokio::spawn(async move {
metrics.report_utp_active_inc(UtpDirectionLabel::Outbound);
let stream = match utp.connect_with_cid(cid.clone(), UTP_CONN_CFG).await {
let stream = match utp.connect_with_cid(cid.clone(), *UTP_CONN_CFG).await {
Ok(stream) => stream,
Err(err) => {
metrics.report_utp_outcome(
Expand Down

0 comments on commit 89e5a52

Please sign in to comment.