Restructure crates (#24)

* Rename to netrunner

* Refactor sims structure

* Add missing workspace cargo

* Rebase changes

* Rebase changes

* Rebase changes

* Fix tests
This commit is contained in:
Daniel Sanchez 2024-11-07 06:05:56 +01:00 committed by GitHub
parent 810ec02ee9
commit ff2c1b4271
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 62 additions and 73 deletions

2
.gitignore vendored
View File

@ -3,5 +3,5 @@ __pycache__/
*$py.class
*.so
simulation
network-runner/target
simlib/netrunner/target
.idea/

7
simlib/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
members = [
"netrunner",
"mixnet-sims"
]
resolver = "2"

View File

@ -0,0 +1,25 @@
[package]
name = "mixnet-sims"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.93"
clap = { version = "4.5.20", features = ["derive"] }
crossbeam = "0.8.4"
ctrlc = "3.4"
parking_lot = "0.12.3"
rand = "0.8"
serde = { version = "1.0.214", features = ["derive"] }
log = "0.4.22"
serde_json = "1.0.132"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3", features = ["json", "env-filter", "tracing-log"] }
netrunner = { path = "../netrunner" }
nomos-tracing = { git = "https://github.com/logos-co/nomos-node.git", rev = "cc5fef6" }
nomos-mix = { git = "https://github.com/logos-co/nomos-node", rev = "e095964", package = "nomos-mix" }
nomos-mix-message = { git = "https://github.com/logos-co/nomos-node", rev = "e095964", package = "nomos-mix-message" }
futures = "0.3.31"
rand_chacha = "0.3"
multiaddr = "0.18"

View File

@ -4,26 +4,22 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
// crates
use crate::node::mix::state::{MixnodeRecord, MixnodeState};
use crate::node::mix::{MixMessage, MixnodeSettings};
use anyhow::Ok;
use clap::Parser;
use crossbeam::channel;
use netrunner::network::behaviour::create_behaviours;
use netrunner::network::regions::{create_regions, RegionsData};
use netrunner::network::{InMemoryNetworkInterface, Network};
use netrunner::node::{NodeId, NodeIdExt};
use netrunner::output_processors::Record;
use netrunner::runner::{BoxedNode, SimulationRunnerHandle};
use netrunner::streaming::{io::IOSubscriber, naive::NaiveSubscriber, StreamType};
use nomos_mix::message_blend::{
CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings,
};
use nomos_mix::persistent_transmission::PersistentTransmissionSettings;
use nomos_simulations_network_runner::network::behaviour::create_behaviours;
use nomos_simulations_network_runner::network::regions::{create_regions, RegionsData};
use nomos_simulations_network_runner::network::{InMemoryNetworkInterface, Network};
use nomos_simulations_network_runner::node::mix::state::{MixnodeRecord, MixnodeState};
use nomos_simulations_network_runner::node::mix::{MixMessage, MixNode, MixnodeSettings};
use nomos_simulations_network_runner::node::{NodeId, NodeIdExt};
use nomos_simulations_network_runner::output_processors::Record;
use nomos_simulations_network_runner::runner::{BoxedNode, SimulationRunnerHandle};
#[cfg(feature = "polars")]
use nomos_simulations_network_runner::streaming::polars::PolarsSubscriber;
use nomos_simulations_network_runner::streaming::{
io::IOSubscriber, naive::NaiveSubscriber, StreamType,
};
use parking_lot::Mutex;
use rand::prelude::IteratorRandom;
use rand::rngs::SmallRng;
@ -32,9 +28,11 @@ use rand::SeedableRng;
use serde::de::DeserializeOwned;
use serde::Serialize;
// internal
use nomos_simulations_network_runner::{runner::SimulationRunner, settings::SimulationSettings};
mod log;
use crate::node::mix::MixNode;
use netrunner::{runner::SimulationRunner, settings::SimulationSettings};
mod log;
mod node;
/// Main simulation wrapper
/// Pipes together the cli arguments with the execution
#[derive(Parser)]
@ -195,11 +193,6 @@ where
let settings = stream_settings.unwrap_io();
runner.simulate_and_subscribe::<IOSubscriber<MixnodeRecord>>(settings)?
}
#[cfg(feature = "polars")]
Some(StreamType::Polars) => {
let settings = stream_settings.unwrap_polars();
runner.simulate_and_subscribe::<PolarsSubscriber<MixnodeRecord>>(settings)?
}
None => runner.simulate()?,
};

View File

@ -1,18 +1,18 @@
mod lottery;
mod consensus_streams;
mod scheduler;
pub mod consensus_streams;
pub mod lottery;
pub mod scheduler;
pub mod state;
mod stream_wrapper;
pub mod stream_wrapper;
use super::{Node, NodeId};
use crate::{
network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize},
warding::WardCondition,
};
use crossbeam::channel;
use futures::Stream;
use lottery::StakeLottery;
use multiaddr::Multiaddr;
use netrunner::node::{Node, NodeId};
use netrunner::{
network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize},
warding::WardCondition,
};
use nomos_mix::{
membership::Membership,
message_blend::{

View File

@ -2,7 +2,7 @@ use std::any::Any;
use serde::Serialize;
use crate::{
use netrunner::{
node::NodeId,
output_processors::{Record, RecordType, Runtime},
settings::SimulationSettings,

View File

@ -0,0 +1 @@
pub mod mix;

View File

@ -1,22 +1,16 @@
[package]
name = "nomos-simulations-network-runner"
name = "netrunner"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "simulation"
path = "src/bin/app/main.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
blake2 = "0.10"
bls-signatures = "0.14"
digest = "0.10"
csv = "1"
clap = { version = "4", features = ["derive"] }
ctrlc = "3.4"
chrono = { version = "0.4", features = ["serde"] }
crc32fast = "1.3"
crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] }
@ -24,10 +18,8 @@ fixed-slice-deque = "0.1.0-beta2"
futures = "0.3"
humantime = "2.1"
humantime-serde = "1"
nomos-tracing = { git = "https://github.com/logos-co/nomos-node.git", rev = "cc5fef6" }
once_cell = "1.17"
parking_lot = "0.12"
polars = { version = "0.27", features = ["serde", "object", "json", "csv-file", "parquet", "dtype-struct"], optional = true }
rand = { version = "0.8", features = ["small_rng"] }
rayon = "1.7"
scopeguard = "1"
@ -36,14 +28,6 @@ serde_with = "2.3"
serde_json = "1.0"
thiserror = "1"
tracing = { version = "0.1", default-features = false, features = ["log", "attributes"] }
tracing-subscriber = { version = "0.3", features = ["json", "env-filter", "tracing-log"]}
nomos-mix = { git = "https://github.com/logos-co/nomos-node", rev = "e095964", package = "nomos-mix" }
nomos-mix-message = { git = "https://github.com/logos-co/nomos-node", rev = "e095964", package = "nomos-mix-message" }
rand_chacha = "0.3"
multiaddr = "0.18"
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
[features]
polars = ["dep:polars"]

View File

@ -1,6 +1,5 @@
#[cfg(test)]
pub mod dummy_streaming;
pub mod mix;
// std
use std::{

View File

@ -11,8 +11,6 @@ use crate::output_processors::{Record, RecordType, Runtime};
pub mod io;
pub mod naive;
#[cfg(feature = "polars")]
pub mod polars;
pub mod runtime_subscriber;
pub mod settings_subscriber;
@ -84,8 +82,6 @@ pub enum StreamType {
#[default]
IO,
Naive,
#[cfg(feature = "polars")]
Polars,
}
impl FromStr for StreamType {
@ -95,8 +91,6 @@ impl FromStr for StreamType {
match s.trim().to_ascii_lowercase().as_str() {
"io" => Ok(Self::IO),
"naive" => Ok(Self::Naive),
#[cfg(feature = "polars")]
"polars" => Ok(Self::Polars),
tag => Err(format!(
"Invalid {tag} streaming type, only [naive, polars] are supported",
)),
@ -119,8 +113,6 @@ impl<'de> serde::Deserialize<'de> for StreamType {
pub enum StreamSettings {
Naive(naive::NaiveSettings),
IO(io::IOStreamSettings),
#[cfg(feature = "polars")]
Polars(polars::PolarsSettings),
}
impl Default for StreamSettings {
@ -143,14 +135,6 @@ impl StreamSettings {
_ => panic!("unwrap io failed"),
}
}
#[cfg(feature = "polars")]
pub fn unwrap_polars(self) -> polars::PolarsSettings {
match self {
StreamSettings::Polars(settings) => settings,
_ => panic!("unwrap polars failed"),
}
}
}
pub struct SubscriberHandle<S> {

View File

@ -101,9 +101,10 @@ where
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use std::{collections::HashMap, time::Duration};
use consensus_engine::View;
type View = usize;
use crate::{
network::{
@ -123,7 +124,7 @@ mod tests {
use super::*;
#[derive(Debug, Clone, Serialize)]
struct SettingsRecord {
states: HashMap<NodeId, View>,
states: HashSet<NodeId>,
}
impl<S, T: Serialize> TryFrom<&SimulationState<S, T>> for SettingsRecord {
@ -131,12 +132,7 @@ mod tests {
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
Ok(Self {
states: value
.nodes
.read()
.iter()
.map(|node| (node.id(), node.current_view()))
.collect(),
states: value.nodes.read().iter().map(|node| node.id()).collect(),
})
}
}