Remove dummy node from simapp settings and app itself (#196)
This commit is contained in:
parent
40048fa47b
commit
faacd10172
|
@ -19,9 +19,9 @@
|
||||||
},
|
},
|
||||||
"overlay_settings": "Flat",
|
"overlay_settings": "Flat",
|
||||||
"node_settings": {
|
"node_settings": {
|
||||||
"seed": 0,
|
|
||||||
"timeout": "1000ms"
|
"timeout": "1000ms"
|
||||||
},
|
},
|
||||||
|
"step_time": "100ms",
|
||||||
"runner_settings": "Sync",
|
"runner_settings": "Sync",
|
||||||
"stream_settings": {
|
"stream_settings": {
|
||||||
"format": "json"
|
"format": "json"
|
||||||
|
|
|
@ -2,28 +2,23 @@
|
||||||
use anyhow::Ok;
|
use anyhow::Ok;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use simulations::node::carnot::CarnotSettings;
|
use simulations::node::carnot::CarnotSettings;
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
// crates
|
// crates
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use consensus_engine::overlay::{FlatOverlay, RandomBeaconState, RoundRobin};
|
use consensus_engine::overlay::{FlatOverlay, RandomBeaconState, RoundRobin};
|
||||||
use consensus_engine::Block;
|
use consensus_engine::Block;
|
||||||
use crossbeam::channel;
|
use crossbeam::channel;
|
||||||
use parking_lot::RwLock;
|
|
||||||
use rand::rngs::SmallRng;
|
use rand::rngs::SmallRng;
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use rand::{Rng, SeedableRng};
|
use rand::SeedableRng;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use simulations::network::behaviour::create_behaviours;
|
use simulations::network::behaviour::create_behaviours;
|
||||||
use simulations::network::regions::{create_regions, RegionsData};
|
use simulations::network::regions::{create_regions, RegionsData};
|
||||||
use simulations::network::{InMemoryNetworkInterface, Network};
|
use simulations::network::{InMemoryNetworkInterface, Network};
|
||||||
use simulations::node::dummy::DummyNode;
|
use simulations::node::{Node, NodeId};
|
||||||
use simulations::node::{Node, NodeId, OverlayState, ViewOverlay};
|
|
||||||
use simulations::output_processors::Record;
|
use simulations::output_processors::Record;
|
||||||
use simulations::overlay::{create_overlay, SimulationOverlay};
|
|
||||||
use simulations::runner::SimulationRunnerHandle;
|
use simulations::runner::SimulationRunnerHandle;
|
||||||
use simulations::streaming::{
|
use simulations::streaming::{
|
||||||
io::IOSubscriber, naive::NaiveSubscriber, polars::PolarsSubscriber, StreamType,
|
io::IOSubscriber, naive::NaiveSubscriber, polars::PolarsSubscriber, StreamType,
|
||||||
|
@ -70,23 +65,7 @@ impl SimulationApp {
|
||||||
let regions = create_regions(&node_ids, &mut rng, &simulation_settings.network_settings);
|
let regions = create_regions(&node_ids, &mut rng, &simulation_settings.network_settings);
|
||||||
let behaviours = create_behaviours(&simulation_settings.network_settings);
|
let behaviours = create_behaviours(&simulation_settings.network_settings);
|
||||||
let regions_data = RegionsData::new(regions, behaviours);
|
let regions_data = RegionsData::new(regions, behaviours);
|
||||||
let overlay = create_overlay(&simulation_settings.overlay_settings);
|
|
||||||
let overlays = generate_overlays(
|
|
||||||
&node_ids,
|
|
||||||
&overlay,
|
|
||||||
simulation_settings.views_count,
|
|
||||||
simulation_settings.leaders_count,
|
|
||||||
&mut rng,
|
|
||||||
);
|
|
||||||
|
|
||||||
let overlay_state = Arc::new(RwLock::new(OverlayState {
|
|
||||||
all_nodes: node_ids.clone(),
|
|
||||||
overlay,
|
|
||||||
overlays,
|
|
||||||
}));
|
|
||||||
|
|
||||||
match &simulation_settings.node_settings {
|
|
||||||
simulations::settings::NodeSettings::Carnot { timeout } => {
|
|
||||||
let ids = node_ids.clone();
|
let ids = node_ids.clone();
|
||||||
let mut network = Network::new(regions_data);
|
let mut network = Network::new(regions_data);
|
||||||
let nodes = node_ids
|
let nodes = node_ids
|
||||||
|
@ -94,8 +73,7 @@ impl SimulationApp {
|
||||||
.copied()
|
.copied()
|
||||||
.map(|node_id| {
|
.map(|node_id| {
|
||||||
let (node_message_sender, node_message_receiver) = channel::unbounded();
|
let (node_message_sender, node_message_receiver) = channel::unbounded();
|
||||||
let network_message_receiver =
|
let network_message_receiver = network.connect(node_id, node_message_receiver);
|
||||||
network.connect(node_id, node_message_receiver);
|
|
||||||
let network_interface = InMemoryNetworkInterface::new(
|
let network_interface = InMemoryNetworkInterface::new(
|
||||||
node_id,
|
node_id,
|
||||||
node_message_sender,
|
node_message_sender,
|
||||||
|
@ -119,7 +97,7 @@ impl SimulationApp {
|
||||||
);
|
);
|
||||||
CarnotNode::<FlatOverlay<RoundRobin>>::new(
|
CarnotNode::<FlatOverlay<RoundRobin>>::new(
|
||||||
node_id,
|
node_id,
|
||||||
CarnotSettings::new(nodes, *timeout),
|
CarnotSettings::new(nodes, simulation_settings.node_settings.timeout),
|
||||||
overlay_settings,
|
overlay_settings,
|
||||||
genesis,
|
genesis,
|
||||||
network_interface,
|
network_interface,
|
||||||
|
@ -128,26 +106,6 @@ impl SimulationApp {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
run(network, nodes, simulation_settings, stream_type)?;
|
run(network, nodes, simulation_settings, stream_type)?;
|
||||||
}
|
|
||||||
simulations::settings::NodeSettings::Dummy => {
|
|
||||||
let mut network = Network::new(regions_data);
|
|
||||||
let nodes = node_ids
|
|
||||||
.iter()
|
|
||||||
.map(|node_id| {
|
|
||||||
let (node_message_sender, node_message_receiver) = channel::unbounded();
|
|
||||||
let network_message_receiver =
|
|
||||||
network.connect(*node_id, node_message_receiver);
|
|
||||||
let network_interface = InMemoryNetworkInterface::new(
|
|
||||||
*node_id,
|
|
||||||
node_message_sender,
|
|
||||||
network_message_receiver,
|
|
||||||
);
|
|
||||||
DummyNode::new(*node_id, 0, overlay_state.clone(), network_interface)
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
run(network, nodes, simulation_settings, stream_type)?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,19 +169,6 @@ fn load_json_from_file<T: DeserializeOwned>(path: &Path) -> anyhow::Result<T> {
|
||||||
Ok(serde_json::from_reader(f)?)
|
Ok(serde_json::from_reader(f)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to pregenerate views.
|
|
||||||
// TODO: Remove once shared overlay can generate new views on demand.
|
|
||||||
fn generate_overlays<R: Rng>(
|
|
||||||
_node_ids: &[NodeId],
|
|
||||||
_overlay: &SimulationOverlay,
|
|
||||||
_overlay_count: usize,
|
|
||||||
_leader_count: usize,
|
|
||||||
_rng: &mut R,
|
|
||||||
) -> BTreeMap<usize, ViewOverlay> {
|
|
||||||
// TODO: This call needs to be removed
|
|
||||||
Default::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let app: SimulationApp = SimulationApp::parse();
|
let app: SimulationApp = SimulationApp::parse();
|
||||||
log::config_tracing(app.log_format);
|
log::config_tracing(app.log_format);
|
||||||
|
|
|
@ -22,14 +22,9 @@ pub enum RunnerSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||||
#[serde(untagged)]
|
pub struct NodeSettings {
|
||||||
pub enum NodeSettings {
|
|
||||||
Carnot {
|
|
||||||
#[serde(with = "humantime_serde")]
|
#[serde(with = "humantime_serde")]
|
||||||
timeout: std::time::Duration,
|
pub timeout: std::time::Duration,
|
||||||
},
|
|
||||||
#[default]
|
|
||||||
Dummy,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||||
|
|
Loading…
Reference in New Issue