Skip to content

Commit

Permalink
Prune libp2p config file (#1819)
Browse files Browse the repository at this point in the history
* prune libp2p config file

* fmt
  • Loading branch information
rob-maron authored Sep 26, 2023
1 parent fdf4c13 commit 219a4e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
7 changes: 1 addition & 6 deletions crates/orchestrator/default-libp2p-run-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ padding = 10
start_delay_seconds = 60

[libp2p_config]
num_bootstrap_nodes = 5
index_ports = true
bootstrap_mesh_n_high = 4
bootstrap_mesh_n_low = 4
Expand All @@ -49,11 +48,7 @@ mesh_n_high = 4
mesh_n_low = 4
mesh_outbound_min = 2
mesh_n = 4
next_view_timeout = 10
propose_min_round_time = 0
propose_max_round_time = 10
online_time = 10
num_txn_per_round = 10
base_port = 9000

[config]
Expand All @@ -68,7 +63,7 @@ timeout_ratio = [
]
round_start_delay = 1
start_delay = 1
num_bootstrap = 4
num_bootstrap = 5

[config.propose_min_round_time]
secs = 0
Expand Down
35 changes: 21 additions & 14 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct Libp2pConfig {
pub bootstrap_nodes: Vec<(SocketAddr, Vec<u8>)>,
pub num_bootstrap_nodes: u64,
pub num_bootstrap_nodes: usize,
pub public_ip: IpAddr,
pub base_port: u16,
pub node_index: u64,
Expand All @@ -22,15 +22,14 @@ pub struct Libp2pConfig {
pub mesh_outbound_min: usize,
pub mesh_n: usize,
pub next_view_timeout: u64,
pub propose_min_round_time: u64,
pub propose_max_round_time: u64,
pub propose_min_round_time: Duration,
pub propose_max_round_time: Duration,
pub online_time: u64,
pub num_txn_per_round: u64,
pub num_txn_per_round: usize,
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct Libp2pConfigFile {
pub num_bootstrap_nodes: u64,
pub index_ports: bool,
pub bootstrap_mesh_n_high: usize,
pub bootstrap_mesh_n_low: usize,
Expand All @@ -40,11 +39,7 @@ pub struct Libp2pConfigFile {
pub mesh_n_low: usize,
pub mesh_outbound_min: usize,
pub mesh_n: usize,
pub next_view_timeout: u64,
pub propose_min_round_time: u64,
pub propose_max_round_time: u64,
pub online_time: u64,
pub num_txn_per_round: u64,
pub base_port: u16,
}

Expand All @@ -59,6 +54,10 @@ pub struct WebServerConfig {
pub struct NetworkConfig<KEY, ENTRY, ELECTIONCONFIG> {
pub rounds: usize,
pub transactions_per_round: usize,
pub num_bootrap: usize,
pub next_view_timeout: u64,
pub propose_min_round_time: Duration,
pub propose_max_round_time: Duration,
pub node_index: u64,
pub seed: [u8; 32],
pub padding: usize,
Expand Down Expand Up @@ -88,6 +87,10 @@ impl<K, ENTRY, E> Default for NetworkConfig<K, ENTRY, E> {
web_server_config: None,
da_web_server_config: None,
_key_type_phantom: PhantomData,
next_view_timeout: 10,
num_bootrap: 5,
propose_min_round_time: Duration::from_secs(0),
propose_max_round_time: Duration::from_secs(10),
}
}
}
Expand Down Expand Up @@ -126,10 +129,14 @@ impl<K, ENTRY, E> From<NetworkConfigFile> for NetworkConfig<K, ENTRY, E> {
rounds: val.rounds,
transactions_per_round: val.transactions_per_round,
node_index: 0,
num_bootrap: val.config.num_bootstrap,
next_view_timeout: val.config.next_view_timeout,
propose_max_round_time: val.config.propose_max_round_time,
propose_min_round_time: val.config.propose_min_round_time,
seed: val.seed,
padding: val.padding,
libp2p_config: val.libp2p_config.map(|libp2p_config| Libp2pConfig {
num_bootstrap_nodes: libp2p_config.num_bootstrap_nodes,
num_bootstrap_nodes: val.config.num_bootstrap,
index_ports: libp2p_config.index_ports,
bootstrap_nodes: Vec::new(),
public_ip: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
Expand All @@ -143,11 +150,11 @@ impl<K, ENTRY, E> From<NetworkConfigFile> for NetworkConfig<K, ENTRY, E> {
mesh_n_low: libp2p_config.mesh_n_low,
mesh_outbound_min: libp2p_config.mesh_outbound_min,
mesh_n: libp2p_config.mesh_n,
next_view_timeout: libp2p_config.next_view_timeout,
propose_min_round_time: libp2p_config.propose_min_round_time,
propose_max_round_time: libp2p_config.propose_max_round_time,
next_view_timeout: val.config.next_view_timeout,
propose_min_round_time: val.config.propose_min_round_time,
propose_max_round_time: val.config.propose_max_round_time,
online_time: libp2p_config.online_time,
num_txn_per_round: libp2p_config.num_txn_per_round,
num_txn_per_round: val.transactions_per_round,
}),
config: val.config.into(),
key_type_name: std::any::type_name::<K>().to_string(),
Expand Down
8 changes: 2 additions & 6 deletions crates/orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ where
if self.config.libp2p_config.clone().is_some() {
let libp2p_config_clone = self.config.libp2p_config.clone().unwrap();
// Designate node as bootstrap node and store its identity information
if libp2p_config_clone.bootstrap_nodes.len()
< libp2p_config_clone.num_bootstrap_nodes.try_into().unwrap()
{
if libp2p_config_clone.bootstrap_nodes.len() < libp2p_config_clone.num_bootstrap_nodes {
let port_index = match libp2p_config_clone.index_ports {
true => node_index,
false => 0,
Expand All @@ -145,9 +143,7 @@ where
) -> Result<NetworkConfig<KEY, KEY::StakeTableEntry, ELECTION>, ServerError> {
if self.config.libp2p_config.is_some() {
let libp2p_config = self.config.clone().libp2p_config.unwrap();
if libp2p_config.bootstrap_nodes.len()
< libp2p_config.num_bootstrap_nodes.try_into().unwrap()
{
if libp2p_config.bootstrap_nodes.len() < libp2p_config.num_bootstrap_nodes {
return Err(ServerError {
status: tide_disco::StatusCode::BadRequest,
message: "Not enough bootstrap nodes have registered".to_string(),
Expand Down

0 comments on commit 219a4e9

Please sign in to comment.