Use logging instead of storing payload IDs in state (#42)
This commit is contained in:
parent
8c3c723710
commit
8147b7d718
|
@ -59,7 +59,7 @@ impl SimulationApp {
|
||||||
pub fn run(self) -> anyhow::Result<()> {
|
pub fn run(self) -> anyhow::Result<()> {
|
||||||
let Self {
|
let Self {
|
||||||
input_settings,
|
input_settings,
|
||||||
stream_type,
|
stream_type: _,
|
||||||
log_format: _,
|
log_format: _,
|
||||||
log_to: _,
|
log_to: _,
|
||||||
no_netcap,
|
no_netcap,
|
||||||
|
@ -135,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, settings.simulation_settings, stream_type)?;
|
run::<_, _, _>(network, nodes, settings.simulation_settings, None)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use cached::{Cached, TimedCache};
|
||||||
use crossbeam::channel;
|
use crossbeam::channel;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use lottery::StakeLottery;
|
use lottery::StakeLottery;
|
||||||
use message::Payload;
|
use message::{Payload, PayloadId};
|
||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
use netrunner::network::NetworkMessage;
|
use netrunner::network::NetworkMessage;
|
||||||
use netrunner::node::{Node, NodeId};
|
use netrunner::node::{Node, NodeId};
|
||||||
|
@ -33,10 +33,9 @@ use nomos_mix_message::mock::MockMixMessage;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use rand_chacha::ChaCha12Rng;
|
use rand_chacha::ChaCha12Rng;
|
||||||
use scheduler::{Interval, TemporalRelease};
|
use scheduler::{Interval, TemporalRelease};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use state::MixnodeState;
|
use state::MixnodeState;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::{pin::pin, task::Poll, time::Duration};
|
use std::{pin::pin, task::Poll, time::Duration};
|
||||||
use stream_wrapper::CrossbeamReceiverStream;
|
use stream_wrapper::CrossbeamReceiverStream;
|
||||||
|
|
||||||
|
@ -193,8 +192,7 @@ impl MixNode {
|
||||||
state: MixnodeState {
|
state: MixnodeState {
|
||||||
node_id: id,
|
node_id: id,
|
||||||
step_id: 0,
|
step_id: 0,
|
||||||
messages_generated: HashMap::new(),
|
num_messages_fully_unwrapped: 0,
|
||||||
messages_fully_unwrapped: HashMap::new(),
|
|
||||||
},
|
},
|
||||||
data_msg_lottery_update_time_sender,
|
data_msg_lottery_update_time_sender,
|
||||||
data_msg_lottery_interval,
|
data_msg_lottery_interval,
|
||||||
|
@ -259,6 +257,22 @@ impl MixNode {
|
||||||
self.epoch_update_sender.send(elapsed).unwrap();
|
self.epoch_update_sender.send(elapsed).unwrap();
|
||||||
self.slot_update_sender.send(elapsed).unwrap();
|
self.slot_update_sender.send(elapsed).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn log_message_generated(&self, payload: &Payload) {
|
||||||
|
self.log_message("MessageGenerated", payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_message_fully_unwrapped(&self, payload: &Payload) {
|
||||||
|
self.log_message("MessageFullyUnwrapped", payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_message(&self, tag: &str, payload: &Payload) {
|
||||||
|
let log = MessageLog {
|
||||||
|
payload_id: payload.id(),
|
||||||
|
step_id: self.state.step_id,
|
||||||
|
};
|
||||||
|
tracing::info!("{}: {}", tag, serde_json::to_string(&log).unwrap());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node for MixNode {
|
impl Node for MixNode {
|
||||||
|
@ -283,9 +297,7 @@ impl Node for MixNode {
|
||||||
if let Poll::Ready(Some(_)) = pin!(&mut self.data_msg_lottery_interval).poll_next(&mut cx) {
|
if let Poll::Ready(Some(_)) = pin!(&mut self.data_msg_lottery_interval).poll_next(&mut cx) {
|
||||||
if self.data_msg_lottery.run() {
|
if self.data_msg_lottery.run() {
|
||||||
let payload = Payload::new();
|
let payload = Payload::new();
|
||||||
self.state
|
self.log_message_generated(&payload);
|
||||||
.messages_generated
|
|
||||||
.insert(payload.id(), self.state.step_id);
|
|
||||||
let message = self
|
let message = self
|
||||||
.crypto_processor
|
.crypto_processor
|
||||||
.wrap_message(payload.as_bytes())
|
.wrap_message(payload.as_bytes())
|
||||||
|
@ -313,9 +325,8 @@ impl Node for MixNode {
|
||||||
}
|
}
|
||||||
MixOutgoingMessage::FullyUnwrapped(payload) => {
|
MixOutgoingMessage::FullyUnwrapped(payload) => {
|
||||||
let payload = Payload::load(payload);
|
let payload = Payload::load(payload);
|
||||||
self.state
|
self.log_message_fully_unwrapped(&payload);
|
||||||
.messages_fully_unwrapped
|
self.state.num_messages_fully_unwrapped += 1;
|
||||||
.insert(payload.id(), self.state.step_id);
|
|
||||||
//TODO: create a tracing event
|
//TODO: create a tracing event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,9 +335,7 @@ impl Node for MixNode {
|
||||||
// Generate a cover message probabilistically
|
// Generate a cover message probabilistically
|
||||||
if let Poll::Ready(Some(_)) = pin!(&mut self.cover_traffic).poll_next(&mut cx) {
|
if let Poll::Ready(Some(_)) = pin!(&mut self.cover_traffic).poll_next(&mut cx) {
|
||||||
let payload = Payload::new();
|
let payload = Payload::new();
|
||||||
self.state
|
self.log_message_generated(&payload);
|
||||||
.messages_generated
|
|
||||||
.insert(payload.id(), self.state.step_id);
|
|
||||||
let message = self
|
let message = self
|
||||||
.crypto_processor
|
.crypto_processor
|
||||||
.wrap_message(payload.as_bytes())
|
.wrap_message(payload.as_bytes())
|
||||||
|
@ -348,9 +357,15 @@ impl Node for MixNode {
|
||||||
match ward {
|
match ward {
|
||||||
WardCondition::Max(_) => false,
|
WardCondition::Max(_) => false,
|
||||||
WardCondition::Sum(condition) => {
|
WardCondition::Sum(condition) => {
|
||||||
*condition.step_result.borrow_mut() += self.state.messages_fully_unwrapped.len();
|
*condition.step_result.borrow_mut() += self.state.num_messages_fully_unwrapped;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct MessageLog {
|
||||||
|
payload_id: PayloadId,
|
||||||
|
step_id: usize,
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{any::Any, collections::HashMap};
|
use std::any::Any;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -9,15 +9,12 @@ use netrunner::{
|
||||||
warding::SimulationState,
|
warding::SimulationState,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::message::PayloadId;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct MixnodeState {
|
pub struct MixnodeState {
|
||||||
#[serde(serialize_with = "serialize_node_id_as_index")]
|
#[serde(serialize_with = "serialize_node_id_as_index")]
|
||||||
pub node_id: NodeId,
|
pub node_id: NodeId,
|
||||||
pub step_id: usize,
|
pub step_id: usize,
|
||||||
pub messages_generated: HashMap<PayloadId, usize>,
|
pub num_messages_fully_unwrapped: usize,
|
||||||
pub messages_fully_unwrapped: HashMap<PayloadId, usize>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
Loading…
Reference in New Issue