Skip to content

Commit a3c4a1d

Browse files
committed
sim-rs: first pass at Full Leios
1 parent ca5785f commit a3c4a1d

File tree

9 files changed

+240
-38
lines changed

9 files changed

+240
-38
lines changed

data/simulation/config.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface Config {
2424
"cleanup-policies": CleanupPolicies;
2525

2626
// Leios Protocol Configuration
27+
/** Only supported by Rust simulation. */
28+
"leios-variant": LeiosVariant;
2729
"leios-stage-length-slots": bigint;
2830
"leios-stage-active-voting-slots": bigint;
2931
/**
@@ -33,6 +35,12 @@ export interface Config {
3335
*
3436
* Only supported by Haskell simulation. */
3537
"leios-vote-send-recv-stages": boolean;
38+
/**
39+
* The expected time it takes a header to fully diffuse across the network.
40+
* This is Δhdr from the Leios paper.
41+
*
42+
* Only supported by Rust simulation. */
43+
"leios-header-diffusion-time-ms": number;
3644

3745
// Transaction Configuration
3846
/** Only supported by Rust simulation. */
@@ -185,3 +193,8 @@ export enum RelayStrategy {
185193
RequestFromAll = "request-from-all",
186194
RequestFromFirst = "request-from-first",
187195
}
196+
197+
export enum LeiosVariant {
198+
Short = "short",
199+
Full = "full",
200+
}

data/simulation/config.default.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ cleanup-policies: ["cleanup-expired-vote"]
2222
# Leios Protocol Configuration
2323
################################################################################
2424

25+
leios-variant: short
2526
leios-stage-length-slots: 20
2627
leios-stage-active-voting-slots: 1
2728
leios-vote-send-recv-stages: false
29+
leios-header-diffusion-time-ms: 1000.0
2830

2931
################################################################################
3032
# Transaction Configuration

data/simulation/config.schema.json

+12
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
},
7373
"type": "object"
7474
},
75+
"LeiosVariant": {
76+
"enum": ["short", "full"],
77+
"type": "string"
78+
},
7579
"LogNormalDistribution": {
7680
"properties": {
7781
"distribution": {
@@ -244,6 +248,10 @@
244248
"description": "Only supported by Rust simulation.",
245249
"type": "number"
246250
},
251+
"leios-header-diffusion-time-ms": {
252+
"description": "The expected time it takes a header to fully diffuse across the network.\nThis is Δhdr from the Leios paper.\n\nOnly supported by Rust simulation.",
253+
"type": "number"
254+
},
247255
"leios-stage-active-voting-slots": {
248256
"additionalProperties": false,
249257
"properties": {},
@@ -254,6 +262,10 @@
254262
"properties": {},
255263
"type": "number"
256264
},
265+
"leios-variant": {
266+
"$ref": "#/definitions/LeiosVariant",
267+
"description": "Only supported by Rust simulation."
268+
},
257269
"leios-vote-send-recv-stages": {
258270
"description": "Determines whether a Leios pipeline has separate Vote (Send) and Vote (Recv) stages.\nIf this is set to `true`, it is recommended to set `leios-stage-active-voting-slots`\nto be equal to `leios-stage-length-slots`.\n\nOnly supported by Haskell simulation.",
259271
"type": "boolean"

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl EventMonitor {
9292
let mut eb_votes: BTreeMap<EndorserBlockId, f64> = BTreeMap::new();
9393
let mut ib_txs: BTreeMap<InputBlockId, Vec<TransactionId>> = BTreeMap::new();
9494
let mut eb_ibs: BTreeMap<EndorserBlockId, Vec<InputBlockId>> = BTreeMap::new();
95+
let mut eb_ebs: BTreeMap<EndorserBlockId, Vec<EndorserBlockId>> = BTreeMap::new();
9596

9697
let mut last_timestamp = Timestamp::zero();
9798
let mut total_slots = 0u64;
@@ -205,10 +206,13 @@ impl EventMonitor {
205206
leios_blocks_with_endorsements += 1;
206207
pending_ebs.retain(|eb| eb.slot != endorsement.eb.slot);
207208

208-
let block_leios_txs: Vec<_> = eb_ibs
209+
let all_eb_ids = eb_ebs
209210
.get(&endorsement.eb)
210211
.unwrap()
211212
.iter()
213+
.chain(std::iter::once(&endorsement.eb));
214+
let block_leios_txs: Vec<_> = all_eb_ids
215+
.flat_map(|eb| eb_ibs.get(eb).unwrap())
212216
.flat_map(|ib| ib_txs.get(ib).unwrap())
213217
.copied()
214218
.collect();
@@ -290,11 +294,15 @@ impl EventMonitor {
290294
}
291295
Event::EBLotteryWon { .. } => {}
292296
Event::EBGenerated {
293-
id, input_blocks, ..
297+
id,
298+
input_blocks,
299+
endorser_blocks,
300+
..
294301
} => {
295302
generated_ebs += 1;
296303
pending_ebs.insert(id.clone());
297304
eb_ibs.insert(id.clone(), input_blocks.clone());
305+
eb_ebs.insert(id.clone(), endorser_blocks);
298306
for ib_id in &input_blocks {
299307
*ibs_in_eb.entry(id.clone()).or_default() += 1.0;
300308
*ebs_containing_ib.entry(ib_id.clone()).or_default() += 1.0;

sim-rs/sim-core/src/clock/timestamp.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ use std::{
77
use serde::Serialize;
88

99
/// A timestamp tracks the time from the start of the simulation.
10-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
10+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
1111
pub struct Timestamp(Duration);
1212

1313
impl Timestamp {
1414
pub fn zero() -> Self {
1515
Self(Duration::from_secs(0))
1616
}
17+
18+
pub fn from_secs(secs: u64) -> Self {
19+
Self(Duration::from_secs(secs))
20+
}
21+
22+
pub fn checked_sub_duration(self, rhs: Duration) -> Option<Self> {
23+
Some(Self(self.0.checked_sub(rhs)?))
24+
}
1725
}
1826

1927
impl From<Duration> for Timestamp {

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

+13
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ impl From<DistributionConfig> for FloatDistribution {
5353
#[serde(rename_all = "kebab-case")]
5454
pub struct RawParameters {
5555
// Simulation Configuration
56+
pub leios_variant: LeiosVariant,
5657
pub relay_strategy: RelayStrategy,
5758
pub simulate_transactions: bool,
5859

5960
// Leios protocol configuration
6061
pub leios_stage_length_slots: u64,
6162
pub leios_stage_active_voting_slots: u64,
63+
pub leios_header_diffusion_time_ms: f64,
6264

6365
// Transaction configuration
6466
pub tx_generation_distribution: DistributionConfig,
@@ -123,6 +125,13 @@ pub enum DiffusionStrategy {
123125
OldestFirst,
124126
}
125127

128+
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
129+
#[serde(rename_all = "kebab-case")]
130+
pub enum LeiosVariant {
131+
Short,
132+
Full,
133+
}
134+
126135
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
127136
#[serde(rename_all = "kebab-case")]
128137
pub enum RelayStrategy {
@@ -404,6 +413,8 @@ pub struct SimConfiguration {
404413
pub links: Vec<LinkConfiguration>,
405414
pub stage_length: u64,
406415
pub max_eb_age: u64,
416+
pub(crate) variant: LeiosVariant,
417+
pub(crate) header_diffusion_time: Duration,
407418
pub(crate) relay_strategy: RelayStrategy,
408419
pub(crate) block_generation_probability: f64,
409420
pub(crate) ib_generation_probability: f64,
@@ -429,6 +440,8 @@ impl SimConfiguration {
429440
nodes: topology.nodes,
430441
trace_nodes: HashSet::new(),
431442
links: topology.links,
443+
variant: params.leios_variant,
444+
header_diffusion_time: duration_ms(params.leios_header_diffusion_time_ms),
432445
relay_strategy: params.relay_strategy,
433446
block_generation_probability: params.rb_generation_probability,
434447
ib_generation_probability: params.ib_generation_probability,

sim-rs/sim-core/src/events.rs

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub enum Event {
149149
id: EndorserBlockId<Node>,
150150
bytes: u64,
151151
input_blocks: Vec<InputBlockId<Node>>,
152+
endorser_blocks: Vec<EndorserBlockId<Node>>,
152153
},
153154
EBSent {
154155
#[serde(flatten)]
@@ -380,6 +381,11 @@ impl EventTracker {
380381
.iter()
381382
.map(|id| self.to_input_block(*id))
382383
.collect(),
384+
endorser_blocks: block
385+
.ebs
386+
.iter()
387+
.map(|id| self.to_endorser_block(*id))
388+
.collect(),
383389
});
384390
}
385391

sim-rs/sim-core/src/model.rs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ pub struct EndorserBlock {
178178
pub bytes: u64,
179179
// The real impl will store hashes
180180
pub ibs: Vec<InputBlockId>,
181+
pub ebs: Vec<EndorserBlockId>,
181182
}
182183
impl EndorserBlock {
183184
pub fn id(&self) -> EndorserBlockId {
@@ -223,6 +224,7 @@ pub enum NoVoteReason {
223224
InvalidSlot,
224225
ExtraIB,
225226
MissingIB,
227+
MissingEB,
226228
}
227229

228230
#[derive(Clone, Debug, Serialize)]

0 commit comments

Comments
 (0)