mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-03 21:53:09 +00:00
Refactor sims structure
This commit is contained in:
parent
40a5e8d176
commit
86fd0e578b
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,5 @@ __pycache__/
|
||||
*$py.class
|
||||
*.so
|
||||
simulation
|
||||
netrunner/target
|
||||
simlib/netrunner/target
|
||||
.idea/
|
||||
25
simlib/mixnet-sims/Cargo.toml
Normal file
25
simlib/mixnet-sims/Cargo.toml
Normal 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"
|
||||
|
||||
@ -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()?,
|
||||
};
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
mod lottery;
|
||||
mod consensus_streams;
|
||||
mod scheduler;
|
||||
pub mod scheduler;
|
||||
pub mod lottery;
|
||||
pub mod consensus_streams;
|
||||
pub mod state;
|
||||
mod stream_wrapper;
|
||||
pub mod stream_wrapper;
|
||||
|
||||
use super::{Node, NodeId};
|
||||
use crate::{
|
||||
@ -13,6 +13,8 @@ use crossbeam::channel;
|
||||
use futures::Stream;
|
||||
use lottery::StakeLottery;
|
||||
use multiaddr::Multiaddr;
|
||||
use netrunner::network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize};
|
||||
use netrunner::node::{Node, NodeId};
|
||||
use nomos_mix::{
|
||||
membership::Membership,
|
||||
message_blend::{
|
||||
@ -24,7 +26,7 @@ use nomos_mix::{
|
||||
MixOutgoingMessage,
|
||||
};
|
||||
use nomos_mix_message::mock::MockMixMessage;
|
||||
use rand::SeedableRng;
|
||||
use rand::{Rng, RngCore, SeedableRng};
|
||||
use rand_chacha::ChaCha12Rng;
|
||||
use scheduler::{Interval, TemporalRelease};
|
||||
use serde::Deserialize;
|
||||
@ -2,7 +2,7 @@ use std::any::Any;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
use netrunner::{
|
||||
node::NodeId,
|
||||
output_processors::{Record, RecordType, Runtime},
|
||||
settings::SimulationSettings,
|
||||
1
simlib/mixnet-sims/src/node/mod.rs
Normal file
1
simlib/mixnet-sims/src/node/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod mix;
|
||||
@ -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"]
|
||||
@ -1,6 +1,5 @@
|
||||
#[cfg(test)]
|
||||
pub mod dummy_streaming;
|
||||
pub mod mix;
|
||||
|
||||
// std
|
||||
use std::{
|
||||
@ -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> {
|
||||
Loading…
x
Reference in New Issue
Block a user