Skip to content

Commit

Permalink
Merge pull request #2461 from maqi/scramble_native_bootstrap
Browse files Browse the repository at this point in the history
Scramble native bootstrap
  • Loading branch information
jacderida authored Nov 26, 2024
2 parents 5bc153e + cd6088a commit a1dc7ae
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

*When editing this file, please respect a line length of 100.*

## 2024-11-25

### Network

#### Fixed

- Make native kad bootstrap interval more random. So that when running multiple nodes
on one machine, there is no resource usage spike appears with fixed interval.

## 2024-11-13

### Network
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rand = "0.8.5"
rmp-serde = "1.1.1"
self_encryption = "~0.30.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
sn_networking = { path = "../sn_networking", version = "0.19.4" }
sn_networking = { path = "../sn_networking", version = "0.19.5" }
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.7" }
sn_protocol = { version = "0.17.15", path = "../sn_protocol" }
sn_registers = { path = "../sn_registers", version = "0.4.3" }
Expand Down
2 changes: 1 addition & 1 deletion nat-detection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ libp2p = { version = "0.54.1", features = [
"upnp",
] }
sn_build_info = { path = "../sn_build_info", version = "0.1.19" }
sn_networking = { path = "../sn_networking", version = "0.19.4" }
sn_networking = { path = "../sn_networking", version = "0.19.5" }
sn_protocol = { path = "../sn_protocol", version = "0.17.15" }
tokio = { version = "1.32.0", features = ["full"] }
tracing = { version = "~0.1.26" }
Expand Down
2 changes: 1 addition & 1 deletion release-cycle-info
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
release-year: 2024
release-month: 11
release-cycle: 1
release-cycle-counter: 5
release-cycle-counter: 6
2 changes: 1 addition & 1 deletion sn_build_info/src/release_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const RELEASE_YEAR: &str = "2024";
pub const RELEASE_MONTH: &str = "11";
pub const RELEASE_CYCLE: &str = "1";
pub const RELEASE_CYCLE_COUNTER: &str = "5";
pub const RELEASE_CYCLE_COUNTER: &str = "6";
2 changes: 1 addition & 1 deletion sn_networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-3.0"
name = "sn_networking"
readme = "README.md"
repository = "https://github.com/maidsafe/safe_network"
version = "0.19.4"
version = "0.19.5"

[features]
default = []
Expand Down
12 changes: 9 additions & 3 deletions sn_networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use libp2p::{
use libp2p::{swarm::SwarmEvent, Transport as _};
#[cfg(feature = "open-metrics")]
use prometheus_client::metrics::info::Info;
use rand::Rng;
use sn_evm::PaymentQuote;
use sn_protocol::{
messages::{ChunkProof, Nonce, Request, Response},
Expand Down Expand Up @@ -126,8 +127,9 @@ const NETWORKING_CHANNEL_SIZE: usize = 10_000;
/// Time before a Kad query times out if no response is received
const KAD_QUERY_TIMEOUT_S: Duration = Duration::from_secs(10);

/// Periodic bootstrap interval
const KAD_PERIODIC_BOOTSTRAP_INTERVAL_S: Duration = Duration::from_secs(180 * 60);
/// Interval to trigger native libp2p::kad bootstrap.
/// This is the max time it should take. Minimum interval at any node will be half this
const PERIODIC_KAD_BOOTSTRAP_INTERVAL_MAX_S: u64 = 21600;

// Init during compilation, instead of runtime error that should never happen
// Option<T>::expect will be stabilised as const in the future (https://github.com/rust-lang/rust/issues/67441)
Expand Down Expand Up @@ -345,6 +347,10 @@ impl NetworkBuilder {
self,
root_dir: PathBuf,
) -> Result<(Network, mpsc::Receiver<NetworkEvent>, SwarmDriver)> {
let bootstrap_interval = rand::thread_rng().gen_range(
PERIODIC_KAD_BOOTSTRAP_INTERVAL_MAX_S / 2..PERIODIC_KAD_BOOTSTRAP_INTERVAL_MAX_S,
);

let mut kad_cfg = kad::Config::new(KAD_STREAM_PROTOCOL_ID);
let _ = kad_cfg
.set_kbucket_inserts(libp2p::kad::BucketInserts::Manual)
Expand All @@ -365,7 +371,7 @@ impl NetworkBuilder {
// Records never expire
.set_record_ttl(None)
.set_replication_factor(REPLICATION_FACTOR)
.set_periodic_bootstrap_interval(Some(KAD_PERIODIC_BOOTSTRAP_INTERVAL_S))
.set_periodic_bootstrap_interval(Some(Duration::from_secs(bootstrap_interval)))
// Emit PUT events for validation prior to insertion into the RecordStore.
// This is no longer needed as the record_storage::put now can carry out validation.
// .set_record_filtering(KademliaStoreInserts::FilterBoth)
Expand Down
2 changes: 1 addition & 1 deletion sn_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ serde = { version = "1.0.133", features = ["derive", "rc"] }
sn_build_info = { path = "../sn_build_info", version = "0.1.19" }
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.7" }
sn_logging = { path = "../sn_logging", version = "0.2.40" }
sn_networking = { path = "../sn_networking", version = "0.19.4" }
sn_networking = { path = "../sn_networking", version = "0.19.5" }
sn_protocol = { path = "../sn_protocol", version = "0.17.15" }
sn_registers = { path = "../sn_registers", version = "0.4.3" }
sn_transfers = { path = "../sn_transfers", version = "0.20.3" }
Expand Down

0 comments on commit a1dc7ae

Please sign in to comment.