From 45a2152bbae44d11dd861ab5c1f3c1da9c518f6e Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:31:28 +0900 Subject: [PATCH] refactor(blendnet): rename mix to blend (#63) * rename mix to blend * update ci * add missing dir --- .github/workflows/ci.yaml | 2 +- simlib/blendnet-sims/Cargo.toml | 4 +- simlib/blendnet-sims/config/blendnet.json | 2 +- simlib/blendnet-sims/src/main.rs | 34 ++++----- .../node/{mix => blend}/consensus_streams.rs | 2 +- .../src/node/{mix => blend}/lottery.rs | 0 .../src/node/{mix => blend}/message.rs | 0 .../src/node/{mix => blend}/mod.rs | 70 +++++++++---------- .../src/node/{mix => blend}/scheduler.rs | 0 .../src/node/{mix => blend}/state.rs | 26 +++---- .../src/node/{mix => blend}/stream_wrapper.rs | 0 simlib/blendnet-sims/src/node/mod.rs | 2 +- simlib/blendnet-sims/src/settings.rs | 4 +- 13 files changed, 73 insertions(+), 73 deletions(-) rename simlib/blendnet-sims/src/node/{mix => blend}/consensus_streams.rs (98%) rename simlib/blendnet-sims/src/node/{mix => blend}/lottery.rs (100%) rename simlib/blendnet-sims/src/node/{mix => blend}/message.rs (100%) rename simlib/blendnet-sims/src/node/{mix => blend}/mod.rs (88%) rename simlib/blendnet-sims/src/node/{mix => blend}/scheduler.rs (100%) rename simlib/blendnet-sims/src/node/{mix => blend}/state.rs (71%) rename simlib/blendnet-sims/src/node/{mix => blend}/stream_wrapper.rs (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 79bd484..7e98e87 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,7 +11,7 @@ env: CARGO_TERM_COLOR: always jobs: - mixnet: + simlib: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/simlib/blendnet-sims/Cargo.toml b/simlib/blendnet-sims/Cargo.toml index 73b7f1e..9729a7a 100644 --- a/simlib/blendnet-sims/Cargo.toml +++ b/simlib/blendnet-sims/Cargo.toml @@ -18,8 +18,8 @@ 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" } -nomos-mix = { git = "https://github.com/logos-co/nomos-node", package = "nomos-mix" } -nomos-mix-message = { git = "https://github.com/logos-co/nomos-node", package = "nomos-mix-message" } +nomos-blend = { git = "https://github.com/logos-co/nomos-node", package = "nomos-blend" } +nomos-blend-message = { git = "https://github.com/logos-co/nomos-node", package = "nomos-blend-message" } futures = "0.3.31" rand_chacha = "0.3" multiaddr = "0.18" diff --git a/simlib/blendnet-sims/config/blendnet.json b/simlib/blendnet-sims/config/blendnet.json index 6636913..9179c44 100644 --- a/simlib/blendnet-sims/config/blendnet.json +++ b/simlib/blendnet-sims/config/blendnet.json @@ -44,6 +44,6 @@ "max_emission_frequency": 1.0, "drop_message_probability": 0.0 }, - "number_of_mix_layers": 2, + "number_of_blend_layers": 2, "max_delay_seconds": 10 } diff --git a/simlib/blendnet-sims/src/main.rs b/simlib/blendnet-sims/src/main.rs index 1e9eb91..378716b 100644 --- a/simlib/blendnet-sims/src/main.rs +++ b/simlib/blendnet-sims/src/main.rs @@ -4,8 +4,8 @@ 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 crate::node::blend::state::{BlendnodeRecord, BlendnodeState}; +use crate::node::blend::{BlendMessage, BlendnodeSettings}; use anyhow::Ok; use clap::Parser; use crossbeam::channel; @@ -16,8 +16,8 @@ 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::cover_traffic::CoverTrafficSettings; -use nomos_mix::message_blend::{ +use nomos_blend::cover_traffic::CoverTrafficSettings; +use nomos_blend::message_blend::{ CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings, }; use parking_lot::Mutex; @@ -28,7 +28,7 @@ use rand_chacha::ChaCha12Rng; use serde::de::DeserializeOwned; use serde::Serialize; // internal -use crate::node::mix::MixNode; +use crate::node::blend::BlendNode; use crate::settings::SimSettings; use netrunner::{runner::SimulationRunner, settings::SimulationSettings}; @@ -88,19 +88,19 @@ impl SimulationApp { let regions_data = RegionsData::new(regions, behaviours); let ids = node_ids.clone(); - let network = Arc::new(Mutex::new(Network::::new(regions_data, seed))); + let network = Arc::new(Mutex::new(Network::::new(regions_data, seed))); let nodes: Vec<_> = node_ids .iter() .copied() .map(|node_id| { let mut network = network.lock(); - create_boxed_mixnode( + create_boxed_blendnode( node_id, &mut network, settings.simulation_settings.clone(), no_netcap, - MixnodeSettings { + BlendnodeSettings { connected_peers: ids .iter() .filter(|&id| id != &node_id) @@ -115,7 +115,7 @@ impl SimulationApp { message_blend: MessageBlendSettings { cryptographic_processor: CryptographicProcessorSettings { private_key: node_id.into(), - num_mix_layers: settings.number_of_mix_layers, + num_blend_layers: settings.number_of_blend_layers, }, temporal_processor: TemporalSchedulerSettings { max_delay_seconds: settings.max_delay_seconds, @@ -140,13 +140,13 @@ impl SimulationApp { } } -fn create_boxed_mixnode( +fn create_boxed_blendnode( node_id: NodeId, - network: &mut Network, + network: &mut Network, simulation_settings: SimulationSettings, no_netcap: bool, - mixnode_settings: MixnodeSettings, -) -> BoxedNode { + blendnode_settings: BlendnodeSettings, +) -> BoxedNode { let (node_message_broadcast_sender, node_message_broadcast_receiver) = channel::unbounded(); let (node_message_sender, node_message_receiver) = channel::unbounded(); // Dividing milliseconds in second by milliseconds in the step. @@ -174,7 +174,7 @@ fn create_boxed_mixnode( node_message_sender, network_message_receiver, ); - Box::new(MixNode::new(node_id, mixnode_settings, network_interface)) + Box::new(BlendNode::new(node_id, blendnode_settings, network_interface)) } fn run( @@ -189,7 +189,7 @@ where T: Serialize + Clone + 'static, { let stream_settings = settings.stream_settings.clone(); - let runner = SimulationRunner::<_, MixnodeRecord, S, T>::new( + let runner = SimulationRunner::<_, BlendnodeRecord, S, T>::new( network, nodes, Default::default(), @@ -199,11 +199,11 @@ where let handle = match stream_type { Some(StreamType::Naive) => { let settings = stream_settings.unwrap_naive(); - runner.simulate_and_subscribe::>(settings)? + runner.simulate_and_subscribe::>(settings)? } Some(StreamType::IO) => { let settings = stream_settings.unwrap_io(); - runner.simulate_and_subscribe::>(settings)? + runner.simulate_and_subscribe::>(settings)? } None => runner.simulate()?, }; diff --git a/simlib/blendnet-sims/src/node/mix/consensus_streams.rs b/simlib/blendnet-sims/src/node/blend/consensus_streams.rs similarity index 98% rename from simlib/blendnet-sims/src/node/mix/consensus_streams.rs rename to simlib/blendnet-sims/src/node/blend/consensus_streams.rs index ea1edf1..08e7dfe 100644 --- a/simlib/blendnet-sims/src/node/mix/consensus_streams.rs +++ b/simlib/blendnet-sims/src/node/blend/consensus_streams.rs @@ -1,4 +1,4 @@ -use crate::node::mix::scheduler::Interval; +use crate::node::blend::scheduler::Interval; use crossbeam::channel; use futures::stream::iter; use futures::{Stream, StreamExt}; diff --git a/simlib/blendnet-sims/src/node/mix/lottery.rs b/simlib/blendnet-sims/src/node/blend/lottery.rs similarity index 100% rename from simlib/blendnet-sims/src/node/mix/lottery.rs rename to simlib/blendnet-sims/src/node/blend/lottery.rs diff --git a/simlib/blendnet-sims/src/node/mix/message.rs b/simlib/blendnet-sims/src/node/blend/message.rs similarity index 100% rename from simlib/blendnet-sims/src/node/mix/message.rs rename to simlib/blendnet-sims/src/node/blend/message.rs diff --git a/simlib/blendnet-sims/src/node/mix/mod.rs b/simlib/blendnet-sims/src/node/blend/mod.rs similarity index 88% rename from simlib/blendnet-sims/src/node/mix/mod.rs rename to simlib/blendnet-sims/src/node/blend/mod.rs index cf5cca4..27924cb 100644 --- a/simlib/blendnet-sims/src/node/mix/mod.rs +++ b/simlib/blendnet-sims/src/node/blend/mod.rs @@ -5,7 +5,7 @@ pub mod scheduler; pub mod state; pub mod stream_wrapper; -use crate::node::mix::consensus_streams::{Epoch, Slot}; +use crate::node::blend::consensus_streams::{Epoch, Slot}; use cached::{Cached, TimedCache}; use crossbeam::channel; use futures::Stream; @@ -18,7 +18,7 @@ use netrunner::{ network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize}, warding::WardCondition, }; -use nomos_mix::{ +use nomos_blend::{ cover_traffic::{CoverTraffic, CoverTrafficSettings}, membership::Membership, message_blend::{ @@ -27,29 +27,29 @@ use nomos_mix::{ persistent_transmission::{ PersistentTransmissionExt, PersistentTransmissionSettings, PersistentTransmissionStream, }, - MixOutgoingMessage, + BlendOutgoingMessage, }; -use nomos_mix_message::mock::MockMixMessage; +use nomos_blend_message::mock::MockBlendMessage; use rand::SeedableRng; use rand_chacha::ChaCha12Rng; use scheduler::{Interval, TemporalRelease}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -use state::MixnodeState; +use state::BlendnodeState; use std::{pin::pin, task::Poll, time::Duration}; use stream_wrapper::CrossbeamReceiverStream; #[derive(Debug, Clone)] -pub struct MixMessage(Vec); +pub struct BlendMessage(Vec); -impl PayloadSize for MixMessage { +impl PayloadSize for BlendMessage { fn size_bytes(&self) -> u32 { 2208 } } #[derive(Deserialize)] -pub struct MixnodeSettings { +pub struct BlendnodeSettings { pub connected_peers: Vec, pub data_message_lottery_interval: Duration, pub stake_proportion: f64, @@ -57,19 +57,19 @@ pub struct MixnodeSettings { pub epoch_duration: Duration, pub slot_duration: Duration, pub persistent_transmission: PersistentTransmissionSettings, - pub message_blend: MessageBlendSettings, + pub message_blend: MessageBlendSettings, pub cover_traffic_settings: CoverTrafficSettings, - pub membership: Vec<::PublicKey>, + pub membership: Vec<::PublicKey>, } type Sha256Hash = [u8; 32]; /// This node implementation only used for testing different streaming implementation purposes. -pub struct MixNode { +pub struct BlendNode { id: NodeId, - state: MixnodeState, - settings: MixnodeSettings, - network_interface: InMemoryNetworkInterface, + state: BlendnodeState, + settings: BlendnodeSettings, + network_interface: InMemoryNetworkInterface, message_cache: TimedCache, data_msg_lottery_update_time_sender: channel::Sender, @@ -81,28 +81,28 @@ pub struct MixNode { persistent_transmission_messages: PersistentTransmissionStream< CrossbeamReceiverStream>, ChaCha12Rng, - MockMixMessage, + MockBlendMessage, Interval, >, - crypto_processor: CryptographicProcessor, + crypto_processor: CryptographicProcessor, blend_sender: channel::Sender>, blend_update_time_sender: channel::Sender, blend_messages: MessageBlendStream< CrossbeamReceiverStream>, ChaCha12Rng, - MockMixMessage, + MockBlendMessage, TemporalRelease, >, epoch_update_sender: channel::Sender, slot_update_sender: channel::Sender, - cover_traffic: CoverTraffic, + cover_traffic: CoverTraffic, } -impl MixNode { +impl BlendNode { pub fn new( id: NodeId, - settings: MixnodeSettings, - network_interface: InMemoryNetworkInterface, + settings: BlendnodeSettings, + network_interface: InMemoryNetworkInterface, ) -> Self { let mut rng_generator = ChaCha12Rng::seed_from_u64(settings.seed); @@ -137,18 +137,18 @@ impl MixNode { let (blend_sender, blend_receiver) = channel::unbounded(); let (blend_update_time_sender, blend_update_time_receiver) = channel::unbounded(); let nodes: Vec< - nomos_mix::membership::Node< - ::PublicKey, + nomos_blend::membership::Node< + ::PublicKey, >, > = settings .membership .iter() - .map(|&public_key| nomos_mix::membership::Node { + .map(|&public_key| nomos_blend::membership::Node { address: Multiaddr::empty(), public_key, }) .collect(); - let membership = Membership::::new(nodes, id.into()); + let membership = Membership::::new(nodes, id.into()); let crypto_processor = CryptographicProcessor::new( settings.message_blend.cryptographic_processor.clone(), membership.clone(), @@ -172,7 +172,7 @@ impl MixNode { // tier 3 cover traffic let (epoch_update_sender, epoch_updater_update_receiver) = channel::unbounded(); let (slot_update_sender, slot_updater_update_receiver) = channel::unbounded(); - let cover_traffic: CoverTraffic = CoverTraffic::new( + let cover_traffic: CoverTraffic = CoverTraffic::new( settings.cover_traffic_settings, Epoch::new(settings.epoch_duration, epoch_updater_update_receiver), Slot::new( @@ -189,7 +189,7 @@ impl MixNode { // We expected that a message will be delivered to most of nodes within 60s. message_cache: TimedCache::with_lifespan(60), settings, - state: MixnodeState { + state: BlendnodeState { node_id: id, step_id: 0, num_messages_fully_unwrapped: 0, @@ -212,7 +212,7 @@ impl MixNode { fn forward( &mut self, - message: MixMessage, + message: BlendMessage, exclude_node: Option, log: Option, ) { @@ -234,7 +234,7 @@ impl MixNode { self.message_cache.cache_set(Self::sha256(&message.0), ()); } - fn receive(&mut self) -> Vec> { + fn receive(&mut self) -> Vec> { self.network_interface .receive_messages() .into_iter() @@ -293,10 +293,10 @@ impl MixNode { } } -impl Node for MixNode { - type Settings = MixnodeSettings; +impl Node for BlendNode { + type Settings = BlendnodeSettings; - type State = MixnodeState; + type State = BlendnodeState; fn id(&self) -> NodeId { self.id @@ -339,10 +339,10 @@ impl Node for MixNode { // Proceed message blend if let Poll::Ready(Some(msg)) = pin!(&mut self.blend_messages).poll_next(&mut cx) { match msg { - MixOutgoingMessage::Outbound(msg) => { + BlendOutgoingMessage::Outbound(msg) => { self.persistent_sender.send(msg).unwrap(); } - MixOutgoingMessage::FullyUnwrapped(payload) => { + BlendOutgoingMessage::FullyUnwrapped(payload) => { let payload = Payload::load(payload); self.log_message_fully_unwrapped(&payload); self.state.num_messages_fully_unwrapped += 1; @@ -367,7 +367,7 @@ impl Node for MixNode { pin!(&mut self.persistent_transmission_messages).poll_next(&mut cx) { self.forward( - MixMessage(msg), + BlendMessage(msg), None, Some(self.new_emission_log("FromPersistent")), ); diff --git a/simlib/blendnet-sims/src/node/mix/scheduler.rs b/simlib/blendnet-sims/src/node/blend/scheduler.rs similarity index 100% rename from simlib/blendnet-sims/src/node/mix/scheduler.rs rename to simlib/blendnet-sims/src/node/blend/scheduler.rs diff --git a/simlib/blendnet-sims/src/node/mix/state.rs b/simlib/blendnet-sims/src/node/blend/state.rs similarity index 71% rename from simlib/blendnet-sims/src/node/mix/state.rs rename to simlib/blendnet-sims/src/node/blend/state.rs index ff0d9c1..7fb4417 100644 --- a/simlib/blendnet-sims/src/node/mix/state.rs +++ b/simlib/blendnet-sims/src/node/blend/state.rs @@ -10,7 +10,7 @@ use netrunner::{ }; #[derive(Debug, Clone, Serialize)] -pub struct MixnodeState { +pub struct BlendnodeState { #[serde(serialize_with = "serialize_node_id_as_index")] pub node_id: NodeId, pub step_id: usize, @@ -19,45 +19,45 @@ pub struct MixnodeState { #[derive(Serialize)] #[serde(untagged)] -pub enum MixnodeRecord { +pub enum BlendnodeRecord { Runtime(Runtime), Settings(Box), #[allow(clippy::vec_box)] // we downcast stuff and we need the extra boxing - Data(Vec>), + Data(Vec>), } -impl From for MixnodeRecord { +impl From for BlendnodeRecord { fn from(value: Runtime) -> Self { Self::Runtime(value) } } -impl From for MixnodeRecord { +impl From for BlendnodeRecord { fn from(value: SimulationSettings) -> Self { Self::Settings(Box::new(value)) } } -impl Record for MixnodeRecord { - type Data = MixnodeState; +impl Record for BlendnodeRecord { + type Data = BlendnodeState; fn record_type(&self) -> RecordType { match self { - MixnodeRecord::Runtime(_) => RecordType::Meta, - MixnodeRecord::Settings(_) => RecordType::Settings, - MixnodeRecord::Data(_) => RecordType::Data, + BlendnodeRecord::Runtime(_) => RecordType::Meta, + BlendnodeRecord::Settings(_) => RecordType::Settings, + BlendnodeRecord::Data(_) => RecordType::Data, } } - fn data(&self) -> Vec<&MixnodeState> { + fn data(&self) -> Vec<&BlendnodeState> { match self { - MixnodeRecord::Data(d) => d.iter().map(AsRef::as_ref).collect(), + BlendnodeRecord::Data(d) => d.iter().map(AsRef::as_ref).collect(), _ => vec![], } } } -impl TryFrom<&SimulationState> for MixnodeRecord { +impl TryFrom<&SimulationState> for BlendnodeRecord { type Error = anyhow::Error; fn try_from(state: &SimulationState) -> Result { diff --git a/simlib/blendnet-sims/src/node/mix/stream_wrapper.rs b/simlib/blendnet-sims/src/node/blend/stream_wrapper.rs similarity index 100% rename from simlib/blendnet-sims/src/node/mix/stream_wrapper.rs rename to simlib/blendnet-sims/src/node/blend/stream_wrapper.rs diff --git a/simlib/blendnet-sims/src/node/mod.rs b/simlib/blendnet-sims/src/node/mod.rs index bd1b04a..e54dd7c 100644 --- a/simlib/blendnet-sims/src/node/mod.rs +++ b/simlib/blendnet-sims/src/node/mod.rs @@ -1 +1 @@ -pub mod mix; +pub mod blend; diff --git a/simlib/blendnet-sims/src/settings.rs b/simlib/blendnet-sims/src/settings.rs index ba53b46..ef63637 100644 --- a/simlib/blendnet-sims/src/settings.rs +++ b/simlib/blendnet-sims/src/settings.rs @@ -1,5 +1,5 @@ use netrunner::settings::SimulationSettings; -use nomos_mix::persistent_transmission::PersistentTransmissionSettings; +use nomos_blend::persistent_transmission::PersistentTransmissionSettings; use serde::{Deserialize, Deserializer}; use std::time::Duration; @@ -21,7 +21,7 @@ pub struct SimSettings { // For tier 1 pub persistent_transmission: PersistentTransmissionSettings, // For tier 2 - pub number_of_mix_layers: usize, + pub number_of_blend_layers: usize, pub max_delay_seconds: u64, }