Skip to content

Commit 6eb6a67

Browse files
SupernaviXwill-break-it
authored andcommitted
sim-rs: use node names in traces
1 parent 08b1ae7 commit 6eb6a67

File tree

6 files changed

+287
-153
lines changed

6 files changed

+287
-153
lines changed

sim-rs/sim-cli/src/events.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use serde::Serialize;
1111
use sim_core::{
1212
clock::Timestamp,
1313
config::{NodeId, SimConfiguration},
14-
events::Event,
15-
model::{EndorserBlockId, InputBlockId, TransactionId, VoteBundleId},
14+
events::{Event, Node},
15+
model::TransactionId,
1616
};
1717
use tokio::{
1818
fs::{self, File},
@@ -21,6 +21,10 @@ use tokio::{
2121
};
2222
use tracing::{info, info_span};
2323

24+
type InputBlockId = sim_core::model::InputBlockId<Node>;
25+
type EndorserBlockId = sim_core::model::EndorserBlockId<Node>;
26+
type VoteBundleId = sim_core::model::VoteBundleId<Node>;
27+
2428
#[derive(Clone, Serialize)]
2529
struct OutputEvent {
2630
time: Timestamp,
@@ -206,16 +210,16 @@ impl EventMonitor {
206210
}
207211
if let Some((old_producer, old_vrf)) = blocks.get(&slot) {
208212
if *old_vrf > vrf {
209-
*blocks_published.entry(producer).or_default() += 1;
213+
*blocks_published.entry(producer.id).or_default() += 1;
210214
*blocks_published.entry(*old_producer).or_default() -= 1;
211215
*blocks_rejected.entry(*old_producer).or_default() += 1;
212-
blocks.insert(slot, (producer, vrf));
216+
blocks.insert(slot, (producer.id, vrf));
213217
} else {
214-
*blocks_rejected.entry(producer).or_default() += 1;
218+
*blocks_rejected.entry(producer.id).or_default() += 1;
215219
}
216220
} else {
217-
*blocks_published.entry(producer).or_default() += 1;
218-
blocks.insert(slot, (producer, vrf));
221+
*blocks_published.entry(producer.id).or_default() += 1;
222+
blocks.insert(slot, (producer.id, vrf));
219223
}
220224
for published_tx in all_txs {
221225
let tx = txs.get_mut(&published_tx).unwrap();
@@ -229,33 +233,30 @@ impl EventMonitor {
229233
Event::PraosBlockSent { .. } => {}
230234
Event::PraosBlockReceived { .. } => {}
231235
Event::InputBlockLotteryWon { .. } => {}
232-
Event::InputBlockGenerated {
233-
header,
234-
transactions,
235-
} => {
236+
Event::InputBlockGenerated { id, transactions } => {
236237
generated_ibs += 1;
237238
if transactions.is_empty() {
238239
empty_ibs += 1;
239240
}
240-
pending_ibs.insert(header.id);
241-
ib_txs.insert(header.id, transactions.clone());
241+
pending_ibs.insert(id.clone());
242+
ib_txs.insert(id.clone(), transactions.clone());
242243
let mut ib_bytes = 0;
243244
for tx_id in &transactions {
244-
*txs_in_ib.entry(header.id).or_default() += 1.;
245+
*txs_in_ib.entry(id.clone()).or_default() += 1.;
245246
*ibs_containing_tx.entry(*tx_id).or_default() += 1.;
246247
let tx = txs.get_mut(tx_id).unwrap();
247248
ib_bytes += tx.bytes;
248-
*bytes_in_ib.entry(header.id).or_default() += tx.bytes as f64;
249+
*bytes_in_ib.entry(id.clone()).or_default() += tx.bytes as f64;
249250
if tx.included_in_ib.is_none() {
250251
tx.included_in_ib = Some(time);
251252
}
252253
}
253-
*seen_ibs.entry(header.id.producer).or_default() += 1.;
254+
*seen_ibs.entry(id.producer.id).or_default() += 1.;
254255
info!(
255256
"Pool {} generated an IB with {} transaction(s) in slot {} ({}).",
256-
header.id.producer,
257+
id.producer,
257258
transactions.len(),
258-
header.id.slot,
259+
id.slot,
259260
pretty_bytes(ib_bytes, pbo.clone()),
260261
)
261262
}
@@ -264,15 +265,15 @@ impl EventMonitor {
264265
}
265266
Event::InputBlockReceived { recipient, .. } => {
266267
ib_messages.received += 1;
267-
*seen_ibs.entry(recipient).or_default() += 1.;
268+
*seen_ibs.entry(recipient.id).or_default() += 1.;
268269
}
269270
Event::EndorserBlockLotteryWon { .. } => {}
270271
Event::EndorserBlockGenerated { id, input_blocks } => {
271272
generated_ebs += 1;
272-
eb_ibs.insert(id, input_blocks.clone());
273+
eb_ibs.insert(id.clone(), input_blocks.clone());
273274
for ib_id in &input_blocks {
274-
*ibs_in_eb.entry(id).or_default() += 1.0;
275-
*ebs_containing_ib.entry(*ib_id).or_default() += 1.0;
275+
*ibs_in_eb.entry(id.clone()).or_default() += 1.0;
276+
*ebs_containing_ib.entry(ib_id.clone()).or_default() += 1.0;
276277
pending_ibs.remove(ib_id);
277278
for tx_id in ib_txs.get(ib_id).unwrap() {
278279
let tx = txs.get_mut(tx_id).unwrap();
@@ -298,9 +299,9 @@ impl EventMonitor {
298299
Event::VotesGenerated { id, votes } => {
299300
for (eb, count) in votes.0 {
300301
total_votes += count as u64;
301-
*votes_per_bundle.entry(id).or_default() += count as f64;
302+
*votes_per_bundle.entry(id.clone()).or_default() += count as f64;
302303
*eb_votes.entry(eb).or_default() += count as f64;
303-
*votes_per_pool.entry(id.producer).or_default() += count as f64;
304+
*votes_per_pool.entry(id.producer.id).or_default() += count as f64;
304305
}
305306
}
306307
Event::NoVote { .. } => {}

sim-rs/sim-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async fn main() -> Result<()> {
107107

108108
let clock_coordinator = ClockCoordinator::new();
109109
let clock = clock_coordinator.clock();
110-
let tracker = EventTracker::new(events_sink, clock.clone());
110+
let tracker = EventTracker::new(events_sink, clock.clone(), &config.nodes);
111111
let mut simulation = Simulation::new(config, tracker, clock_coordinator).await?;
112112

113113
select! {

sim-rs/sim-core/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
1111

1212
use crate::probability::FloatDistribution;
1313

14-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
14+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1515
pub struct NodeId(usize);
1616
impl Display for NodeId {
1717
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -194,6 +194,7 @@ impl From<RawLegacyTopology> for Topology {
194194
.enumerate()
195195
.map(|(index, raw)| NodeConfiguration {
196196
id: NodeId::new(index),
197+
name: format!("node-{index}"),
197198
location: Some(to_netsim_location(raw.location)),
198199
stake: raw.stake.unwrap_or_default(),
199200
cpu_multiplier: raw.cpu_multiplier,
@@ -232,6 +233,7 @@ impl From<RawTopology> for Topology {
232233
};
233234
let mut node = NodeConfiguration {
234235
id,
236+
name,
235237
location,
236238
stake: raw_node.stake.unwrap_or_default(),
237239
cpu_multiplier: 1.0,
@@ -412,6 +414,7 @@ fn compute_latency(
412414
#[derive(Debug, Clone)]
413415
pub struct NodeConfiguration {
414416
pub id: NodeId,
417+
pub name: String,
415418
pub location: Option<Location>,
416419
pub stake: u64,
417420
pub cpu_multiplier: f64,

0 commit comments

Comments
 (0)