log topology

This commit is contained in:
Youngjoon Lee 2024-12-18 12:35:42 +09:00
parent fcc0b8d907
commit 0ef5c3cfdb
No known key found for this signature in database
GPG Key ID: 303963A54A81DD4D
2 changed files with 34 additions and 4 deletions

View File

@ -16,7 +16,7 @@ use netrunner::node::{NodeId, NodeIdExt};
use netrunner::output_processors::Record;
use netrunner::runner::{BoxedNode, SimulationRunnerHandle};
use netrunner::streaming::{io::IOSubscriber, naive::NaiveSubscriber, StreamType};
use node::blend::topology::build_topology;
use node::blend::topology::{build_topology, longest_path_len, Topology};
use nomos_blend::cover_traffic::CoverTrafficSettings;
use nomos_blend::message_blend::{
CryptographicProcessorSettings, MessageBlendSettings, TemporalSchedulerSettings,
@ -26,7 +26,7 @@ use rand::seq::SliceRandom;
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng;
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde::{Deserialize, Serialize};
// internal
use crate::node::blend::BlendNode;
use crate::settings::SimSettings;
@ -90,6 +90,7 @@ impl SimulationApp {
let network = Arc::new(Mutex::new(Network::<BlendMessage>::new(regions_data, seed)));
let topology = build_topology(&node_ids, settings.connected_peers_count, &mut rng);
log_topology(&topology);
let nodes: Vec<_> = node_ids
.iter()
@ -243,6 +244,33 @@ fn load_json_from_file<T: DeserializeOwned>(path: &Path) -> anyhow::Result<T> {
Ok(serde_json::from_reader(f)?)
}
fn log_topology(topology: &Topology) {
topology.iter().for_each(|(node, peers)| {
let log = TopologyEntryLog {
node_id: node.index(),
num_peers: peers.len(),
peers: peers.iter().map(|peer| peer.index()).collect(),
};
tracing::info!("TopologyEntry: {}", serde_json::to_string(&log).unwrap());
});
let log = TopologyInfoLog {
longest_path_len: longest_path_len(topology),
};
tracing::info!("TopologyInfo: {}", serde_json::to_string(&log).unwrap());
}
#[derive(Debug, Serialize, Deserialize)]
struct TopologyEntryLog {
node_id: usize,
num_peers: usize,
peers: Vec<usize>,
}
#[derive(Debug, Serialize, Deserialize)]
struct TopologyInfoLog {
longest_path_len: usize,
}
fn main() -> anyhow::Result<()> {
let app: SimulationApp = SimulationApp::parse();
let maybe_guard = log::config_tracing(app.log_format, &app.log_to, app.with_metrics);

View File

@ -84,7 +84,7 @@ fn check_equal_conns(topology: &Topology, peering_degree: usize) -> bool {
}
/// Returns the longest path length in the topology.
fn longest_path_len(topology: &Topology) -> usize {
pub fn longest_path_len(topology: &Topology) -> usize {
let mut max_len = 0;
topology.keys().for_each(|&node| {
let len = longest_path_len_from(topology, node);
@ -166,6 +166,8 @@ mod tests {
let peering_degree = 4;
let mut rng = ChaCha8Rng::seed_from_u64(0);
let topology = build_topology(&nodes, peering_degree, &mut rng);
assert!(longest_path_len(&topology) > 0);
let len = longest_path_len(&topology);
assert!(len > 0);
assert!(len <= nodes.len());
}
}