Skip to content

Commit 89e5a52

Browse files
authored
Merge pull request #909 from carver/default-utp-args
fix: improve the utp connection success rate, by using a default config
2 parents 4370f7e + 398598a commit 89e5a52

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

portalnet/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ethereum-types = "0.12.1"
2525
ethportal-api = { path="../ethportal-api" }
2626
fnv = "1.0.7"
2727
futures = "0.3.21"
28+
lazy_static = "1.4.0"
2829
leb128 = "0.2.1"
2930
lru = "0.7.8"
3031
parking_lot = "0.11.2"

portalnet/src/overlay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ where
496496
};
497497
let mut stream = self
498498
.utp_socket
499-
.connect_with_cid(cid, UTP_CONN_CFG)
499+
.connect_with_cid(cid, *UTP_CONN_CFG)
500500
.await
501501
.map_err(|err| OverlayRequestError::UtpError(format!("{err:?}")))?;
502502
let mut data = vec![];

portalnet/src/overlay_service.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use discv5::{
2020
rpc::RequestId,
2121
};
2222
use futures::{channel::oneshot, future::join_all, prelude::*};
23+
use lazy_static::lazy_static;
2324
use parking_lot::RwLock;
2425
use rand::seq::{IteratorRandom, SliceRandom};
2526
use smallvec::SmallVec;
@@ -82,16 +83,10 @@ const EXPECTED_NON_EMPTY_BUCKETS: usize = 17;
8283
/// Bucket refresh lookup interval in seconds
8384
const BUCKET_REFRESH_INTERVAL_SECS: u64 = 60;
8485

85-
/// The default configuration to use for uTP connections.
86-
pub const UTP_CONN_CFG: ConnectionConfig = ConnectionConfig {
87-
max_packet_size: 1024,
88-
max_conn_attempts: 3,
89-
max_idle_timeout: Duration::from_secs(32),
90-
max_timeout: Duration::from_secs(60),
91-
initial_timeout: Duration::from_millis(1500),
92-
min_timeout: Duration::from_millis(500),
93-
target_delay: Duration::from_millis(250),
94-
};
86+
lazy_static! {
87+
/// The default configuration to use for uTP connections.
88+
pub static ref UTP_CONN_CFG: ConnectionConfig = ConnectionConfig { max_packet_size: 1024, ..Default::default()};
89+
}
9590

9691
/// A network-based action that the overlay may perform.
9792
///
@@ -836,7 +831,7 @@ where
836831
tokio::spawn(async move {
837832
metrics.report_utp_active_inc(UtpDirectionLabel::Inbound);
838833
let mut stream = match utp
839-
.connect_with_cid(cid.clone(), UTP_CONN_CFG)
834+
.connect_with_cid(cid.clone(), *UTP_CONN_CFG)
840835
.await
841836
{
842837
Ok(stream) => stream,
@@ -1109,7 +1104,7 @@ where
11091104
let metrics = Arc::clone(&self.metrics);
11101105
tokio::spawn(async move {
11111106
metrics.report_utp_active_inc(UtpDirectionLabel::Outbound);
1112-
let stream = match utp.accept_with_cid(cid.clone(), UTP_CONN_CFG).await {
1107+
let stream = match utp.accept_with_cid(cid.clone(), *UTP_CONN_CFG).await {
11131108
Ok(stream) => stream,
11141109
Err(err) => {
11151110
metrics.report_utp_outcome(
@@ -1237,7 +1232,7 @@ where
12371232
// Wait for an incoming connection with the given CID. Then, read the data from the uTP
12381233
// stream.
12391234
metrics.report_utp_active_inc(UtpDirectionLabel::Inbound);
1240-
let mut stream = match utp.accept_with_cid(cid.clone(), UTP_CONN_CFG).await {
1235+
let mut stream = match utp.accept_with_cid(cid.clone(), *UTP_CONN_CFG).await {
12411236
Ok(stream) => stream,
12421237
Err(err) => {
12431238
metrics.report_utp_outcome(
@@ -1500,7 +1495,7 @@ where
15001495

15011496
tokio::spawn(async move {
15021497
metrics.report_utp_active_inc(UtpDirectionLabel::Outbound);
1503-
let stream = match utp.connect_with_cid(cid.clone(), UTP_CONN_CFG).await {
1498+
let stream = match utp.connect_with_cid(cid.clone(), *UTP_CONN_CFG).await {
15041499
Ok(stream) => stream,
15051500
Err(err) => {
15061501
metrics.report_utp_outcome(

0 commit comments

Comments
 (0)