Extract node configuration to simulation settings
This commit is contained in:
parent
8faafcfb6f
commit
04b1250e75
|
@ -20,7 +20,6 @@ use nomos_mix::cover_traffic::CoverTrafficSettings;
|
||||||
use nomos_mix::message_blend::{
|
use nomos_mix::message_blend::{
|
||||||
CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings,
|
CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings,
|
||||||
};
|
};
|
||||||
use nomos_mix::persistent_transmission::PersistentTransmissionSettings;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use rand::prelude::IteratorRandom;
|
use rand::prelude::IteratorRandom;
|
||||||
use rand::rngs::SmallRng;
|
use rand::rngs::SmallRng;
|
||||||
|
@ -30,10 +29,13 @@ use serde::de::DeserializeOwned;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
// internal
|
// internal
|
||||||
use crate::node::mix::MixNode;
|
use crate::node::mix::MixNode;
|
||||||
|
use crate::settings::SimSettings;
|
||||||
use netrunner::{runner::SimulationRunner, settings::SimulationSettings};
|
use netrunner::{runner::SimulationRunner, settings::SimulationSettings};
|
||||||
|
|
||||||
mod log;
|
mod log;
|
||||||
mod node;
|
mod node;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
/// Main simulation wrapper
|
/// Main simulation wrapper
|
||||||
/// Pipes together the cli arguments with the execution
|
/// Pipes together the cli arguments with the execution
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -63,22 +65,26 @@ impl SimulationApp {
|
||||||
no_netcap,
|
no_netcap,
|
||||||
with_metrics: _,
|
with_metrics: _,
|
||||||
} = self;
|
} = self;
|
||||||
let simulation_settings: SimulationSettings = load_json_from_file(&input_settings)?;
|
let settings: SimSettings = load_json_from_file(&input_settings)?;
|
||||||
|
|
||||||
let seed = simulation_settings.seed.unwrap_or_else(|| {
|
let seed = settings.simulation_settings.seed.unwrap_or_else(|| {
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.expect("Time went backwards")
|
.expect("Time went backwards")
|
||||||
.as_secs()
|
.as_secs()
|
||||||
});
|
});
|
||||||
let mut rng = SmallRng::seed_from_u64(seed);
|
let mut rng = SmallRng::seed_from_u64(seed);
|
||||||
let mut node_ids: Vec<NodeId> = (0..simulation_settings.node_count)
|
let mut node_ids: Vec<NodeId> = (0..settings.simulation_settings.node_count)
|
||||||
.map(NodeId::from_index)
|
.map(NodeId::from_index)
|
||||||
.collect();
|
.collect();
|
||||||
node_ids.shuffle(&mut rng);
|
node_ids.shuffle(&mut rng);
|
||||||
|
|
||||||
let regions = create_regions(&node_ids, &mut rng, &simulation_settings.network_settings);
|
let regions = create_regions(
|
||||||
let behaviours = create_behaviours(&simulation_settings.network_settings);
|
&node_ids,
|
||||||
|
&mut rng,
|
||||||
|
&settings.simulation_settings.network_settings,
|
||||||
|
);
|
||||||
|
let behaviours = create_behaviours(&settings.simulation_settings.network_settings);
|
||||||
let regions_data = RegionsData::new(regions, behaviours);
|
let regions_data = RegionsData::new(regions, behaviours);
|
||||||
|
|
||||||
let ids = node_ids.clone();
|
let ids = node_ids.clone();
|
||||||
|
@ -92,36 +98,33 @@ impl SimulationApp {
|
||||||
create_boxed_mixnode(
|
create_boxed_mixnode(
|
||||||
node_id,
|
node_id,
|
||||||
&mut network,
|
&mut network,
|
||||||
simulation_settings.clone(),
|
settings.simulation_settings.clone(),
|
||||||
no_netcap,
|
no_netcap,
|
||||||
MixnodeSettings {
|
MixnodeSettings {
|
||||||
connected_peers: ids
|
connected_peers: ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&id| id != &node_id)
|
.filter(|&id| id != &node_id)
|
||||||
.copied()
|
.copied()
|
||||||
.choose_multiple(&mut rng, 3),
|
.choose_multiple(&mut rng, settings.connected_peers_count),
|
||||||
data_message_lottery_interval: Duration::from_secs(20),
|
data_message_lottery_interval: settings.data_message_lottery_interval,
|
||||||
stake_proportion: 1.0 / node_ids.len() as f64,
|
stake_proportion: settings.stake_proportion / node_ids.len() as f64,
|
||||||
seed: 0,
|
seed: settings.seed,
|
||||||
epoch_duration: Duration::from_secs(86400 * 5), // 5 days seconds
|
epoch_duration: settings.epoch_duration, // 5 days seconds
|
||||||
slot_duration: Duration::from_secs(20),
|
slot_duration: settings.slot_duration,
|
||||||
persistent_transmission: PersistentTransmissionSettings {
|
persistent_transmission: settings.persistent_transmission,
|
||||||
max_emission_frequency: 1.0,
|
|
||||||
drop_message_probability: 0.0,
|
|
||||||
},
|
|
||||||
message_blend: MessageBlendSettings {
|
message_blend: MessageBlendSettings {
|
||||||
cryptographic_processor: CryptographicProcessorSettings {
|
cryptographic_processor: CryptographicProcessorSettings {
|
||||||
private_key: node_id.into(),
|
private_key: node_id.into(),
|
||||||
num_mix_layers: 4,
|
num_mix_layers: settings.number_of_mix_layers,
|
||||||
},
|
},
|
||||||
temporal_processor: TemporalSchedulerSettings {
|
temporal_processor: TemporalSchedulerSettings {
|
||||||
max_delay_seconds: 10,
|
max_delay_seconds: settings.max_delay_secconds,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
cover_traffic_settings: CoverTrafficSettings {
|
cover_traffic_settings: CoverTrafficSettings {
|
||||||
node_id: node_id.0,
|
node_id: node_id.0,
|
||||||
number_of_hops: 4,
|
number_of_hops: settings.number_of_mix_layers,
|
||||||
slots_per_epoch: 21600,
|
slots_per_epoch: settings.slots_per_epoch,
|
||||||
network_size: node_ids.len(),
|
network_size: node_ids.len(),
|
||||||
},
|
},
|
||||||
membership: node_ids.iter().map(|&id| id.into()).collect(),
|
membership: node_ids.iter().map(|&id| id.into()).collect(),
|
||||||
|
@ -132,7 +135,7 @@ impl SimulationApp {
|
||||||
let network = Arc::try_unwrap(network)
|
let network = Arc::try_unwrap(network)
|
||||||
.expect("network is not used anywhere else")
|
.expect("network is not used anywhere else")
|
||||||
.into_inner();
|
.into_inner();
|
||||||
run::<_, _, _>(network, nodes, simulation_settings, stream_type)?;
|
run::<_, _, _>(network, nodes, settings.simulation_settings, stream_type)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
use netrunner::settings::SimulationSettings;
|
||||||
|
use nomos_mix::persistent_transmission::PersistentTransmissionSettings;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct SimSettings {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub simulation_settings: SimulationSettings,
|
||||||
|
pub connected_peers_count: usize,
|
||||||
|
pub data_message_lottery_interval: Duration,
|
||||||
|
pub stake_proportion: f64,
|
||||||
|
pub seed: u64,
|
||||||
|
pub epoch_duration: Duration,
|
||||||
|
pub slot_duration: Duration,
|
||||||
|
pub persistent_transmission: PersistentTransmissionSettings,
|
||||||
|
pub number_of_mix_layers: usize,
|
||||||
|
pub max_delay_secconds: u64,
|
||||||
|
pub slots_per_epoch: usize,
|
||||||
|
}
|
Loading…
Reference in New Issue