Skip to content

Commit

Permalink
Sg/leios ib generation (#44)
Browse files Browse the repository at this point in the history
* Make TransactionId wrapper

* Implement IB generation and header propagation

* Move praos and leios state to different structs

* Fix realistic test data and update README

* Don't use hash inside of InputBlockId

* Propagate input block bodies

* Do not include transactions in multiple IBs

* Fix bug preventing more than one IB lottery per round

* Log more info after each run

* Improve sim accuracy

* Fix event queue bugs/slowness
  • Loading branch information
SupernaviX authored Oct 17, 2024
1 parent fc92c79 commit c80136a
Show file tree
Hide file tree
Showing 13 changed files with 808 additions and 223 deletions.
39 changes: 37 additions & 2 deletions sim-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sim-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ edition = "2021"

[dependencies]
anyhow = "1"
async-stream = "0.3"
clap = { version = "4", features = ["derive"] }
ctrlc = "3"
futures = "0.3"
netsim-async = { git = "https://github.com/SupernaviX/ce-netsim.git", rev = "8569a6f" }
netsim-async = { git = "https://github.com/input-output-hk/ce-netsim.git", rev = "f4feba6" }
priority-queue = "2"
rand = "0.8"
rand_chacha = "0.3"
rand_distr = "0.4"
Expand Down
4 changes: 3 additions & 1 deletion sim-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ cargo run --release ./test_data/simple.toml output/simple.json

The `input_path` is a TOML file which describes protocol parameters, the network topology, and other necessary configuration. Input files for predefined scenarios are in the `test_data` directory.

While the simulation is running, it will log what's going on to the console. You can stop it at any time with ctrl+c, and when you do it will save the stream of events to `output_path`.
While the simulation is running, it will log what's going on to the console. You can stop it at any time with ctrl+c, and when you do it will save the stream of events to `output_path`.

The simulation runs in realtime (1 slot every second), but you can speed it up by passing e.g. `-t 16` to run 16 times faster.
2 changes: 1 addition & 1 deletion sim-rs/src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use serde::Serialize;
use tokio::time::{self, Sleep};

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Timestamp(Duration);
impl Add<Duration> for Timestamp {
type Output = Timestamp;
Expand Down
11 changes: 10 additions & 1 deletion sim-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::probability::FloatDistribution;

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct NodeId(usize);
impl Display for NodeId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -50,8 +50,11 @@ struct RawConfig {
nodes: Vec<RawNodeConfig>,
links: Vec<RawLinkConfig>,
block_generation_probability: f64,
ib_generation_probability: f64,
max_block_size: u64,
max_tx_size: u64,
max_ib_size: u64,
max_ib_requests_per_peer: usize,
transaction_frequency_ms: DistributionConfig,
transaction_size_bytes: DistributionConfig,
}
Expand All @@ -75,8 +78,11 @@ pub struct SimConfiguration {
pub nodes: Vec<NodeConfiguration>,
pub links: Vec<LinkConfiguration>,
pub block_generation_probability: f64,
pub ib_generation_probability: f64,
pub max_block_size: u64,
pub max_tx_size: u64,
pub max_ib_size: u64,
pub max_ib_requests_per_peer: usize,
pub transaction_frequency_ms: FloatDistribution,
pub transaction_size_bytes: FloatDistribution,
}
Expand Down Expand Up @@ -126,8 +132,11 @@ impl From<RawConfig> for SimConfiguration {
nodes,
links,
block_generation_probability: value.block_generation_probability,
ib_generation_probability: value.ib_generation_probability,
max_block_size: value.max_block_size,
max_tx_size: value.max_tx_size,
max_ib_size: value.max_ib_size,
max_ib_requests_per_peer: value.max_ib_requests_per_peer,
transaction_frequency_ms: value.transaction_frequency_ms.into(),
transaction_size_bytes: value.transaction_size_bytes.into(),
}
Expand Down
Loading

0 comments on commit c80136a

Please sign in to comment.