Skip to content

Commit 9f22cf1

Browse files
committed
sim-rs: support "full without ibs" variant
1 parent 94925a8 commit 9f22cf1

File tree

9 files changed

+132
-27
lines changed

9 files changed

+132
-27
lines changed

data/simulation/config.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ export interface Config {
158158
*/
159159
"eb-max-age-for-relay-slots": bigint;
160160

161+
/**
162+
* The maximum size of transactions (in bytes) which an EB can reference.
163+
* Only relevant when running with the "full-without-ibs" variant.
164+
*
165+
* Only supported by Rust simulation.
166+
*/
167+
"eb-referenced-txs-max-size-bytes": bigint;
168+
161169
// Vote Configuration
162170
"vote-generation-probability": number;
163171
"vote-generation-cpu-time-ms-constant": number;
@@ -234,6 +242,10 @@ export enum RelayStrategy {
234242
}
235243

236244
export enum LeiosVariant {
245+
/** Short Leios: EBs only reference IBs */
237246
Short = "short",
247+
/** Full Leios: EBs reference IBs and other EBs */
238248
Full = "full",
249+
/** Full Leios Without IBs: EBs reference TXs directly, as well as other EBs */
250+
FullWithoutIbs = "full-without-ibs",
239251
}

data/simulation/config.default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ eb-max-age-slots: 100
153153
# up to slot `s+eb-max-age-for-relay-slots`.
154154
eb-max-age-for-relay-slots: 40
155155

156+
# The maximum size of transactions (in bytes) which an EB can reference.
157+
# Only relevant when running with the "full-without-ibs" variant.
158+
eb-referenced-txs-max-size-bytes: 16384000
159+
156160
################################################################################
157161
# Vote Configuration
158162
################################################################################

data/simulation/config.schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": "object"
7474
},
7575
"LeiosVariant": {
76-
"enum": ["short", "full"],
76+
"enum": ["short", "full", "full-without-ibs"],
7777
"type": "string"
7878
},
7979
"LogNormalDistribution": {
@@ -179,6 +179,12 @@
179179
"properties": {},
180180
"type": "number"
181181
},
182+
"eb-referenced-txs-max-size-bytes": {
183+
"additionalProperties": false,
184+
"description": "The maximum size of transactions (in bytes) which an EB can reference.\nOnly relevant when running with the \"full-without-ibs\" variant.\n\nOnly supported by Rust simulation.",
185+
"properties": {},
186+
"type": "number"
187+
},
182188
"eb-size-bytes-constant": {
183189
"additionalProperties": false,
184190
"properties": {},

sim-rs/parameters/no-ibs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
leios-variant: full-without-ibs
2+
leios-late-ib-inclusion: true
3+
praos-chain-quality: 40

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use pretty_bytes_rust::{pretty_bytes, PrettyBytesOptions};
1313
use serde::Serialize;
1414
use sim_core::{
1515
clock::Timestamp,
16-
config::{NodeId, SimConfiguration},
16+
config::{LeiosVariant, NodeId, SimConfiguration},
1717
events::{BlockRef, Event, Node},
1818
model::{BlockId, TransactionId},
1919
};
@@ -45,6 +45,7 @@ enum OutputFormat {
4545
}
4646

4747
pub struct EventMonitor {
48+
variant: LeiosVariant,
4849
node_ids: Vec<NodeId>,
4950
pool_ids: Vec<NodeId>,
5051
maximum_ib_age: u64,
@@ -69,6 +70,7 @@ impl EventMonitor {
6970
let stage_length = config.stage_length;
7071
let maximum_ib_age = stage_length * 3;
7172
Self {
73+
variant: config.variant,
7274
node_ids,
7375
pool_ids,
7476
maximum_ib_age,
@@ -100,6 +102,7 @@ impl EventMonitor {
100102
self.pool_ids.into_iter().map(|id| (id, 0.0)).collect();
101103
let mut eb_votes: BTreeMap<EndorserBlockId, f64> = BTreeMap::new();
102104
let mut ib_txs: BTreeMap<InputBlockId, Vec<TransactionId>> = BTreeMap::new();
105+
let mut eb_txs: BTreeMap<EndorserBlockId, Vec<TransactionId>> = BTreeMap::new();
103106
let mut eb_ibs: BTreeMap<EndorserBlockId, Vec<InputBlockId>> = BTreeMap::new();
104107
let mut eb_ebs: BTreeMap<EndorserBlockId, Vec<EndorserBlockId>> = BTreeMap::new();
105108
let mut leios_tx_bytes: BTreeMap<TransactionId, u64> = BTreeMap::new();
@@ -241,16 +244,23 @@ impl EventMonitor {
241244
leios_blocks_with_endorsements += 1;
242245
pending_ebs.retain(|eb| eb.slot != endorsement.eb.id.slot);
243246

244-
let all_eb_ids = eb_ebs
247+
let all_eb_ids: Vec<_> = eb_ebs
245248
.get(&endorsement.eb.id)
246249
.unwrap()
247250
.iter()
248-
.chain(std::iter::once(&endorsement.eb.id));
249-
let block_leios_txs: Vec<_> = all_eb_ids
251+
.chain(std::iter::once(&endorsement.eb.id))
252+
.collect();
253+
let block_ib_leios_txs = all_eb_ids
254+
.iter()
250255
.flat_map(|eb| eb_ibs.get(eb).unwrap())
251256
.flat_map(|ib| ib_txs.get(ib).unwrap())
252-
.copied()
253-
.collect();
257+
.copied();
258+
let block_eb_leios_txs = all_eb_ids
259+
.iter()
260+
.flat_map(|eb| eb_txs.get(eb).unwrap())
261+
.copied();
262+
let block_leios_txs: Vec<_> =
263+
block_ib_leios_txs.chain(block_eb_leios_txs).collect();
254264

255265
let mut unique_block_leios_txs: Vec<_> =
256266
block_leios_txs.iter().copied().sorted().dedup().collect();
@@ -336,6 +346,7 @@ impl EventMonitor {
336346
Event::EBLotteryWon { .. } => {}
337347
Event::EBGenerated {
338348
id,
349+
transactions,
339350
input_blocks,
340351
endorser_blocks,
341352
size_bytes,
@@ -344,6 +355,7 @@ impl EventMonitor {
344355
total_leios_bytes += size_bytes;
345356
generated_ebs += 1;
346357
pending_ebs.insert(id.clone());
358+
eb_txs.insert(id.clone(), transactions.iter().map(|r| r.id).collect());
347359
eb_ibs.insert(
348360
id.clone(),
349361
input_blocks.iter().map(|r| r.id.clone()).collect(),
@@ -352,6 +364,12 @@ impl EventMonitor {
352364
id.clone(),
353365
endorser_blocks.into_iter().map(|r| r.id.clone()).collect(),
354366
);
367+
for BlockRef { id: tx_id } in &transactions {
368+
let tx = txs.get_mut(tx_id).unwrap();
369+
if tx.included_in_eb.is_none() {
370+
tx.included_in_eb = Some(time);
371+
}
372+
}
355373
for BlockRef { id: ib_id } in &input_blocks {
356374
*ibs_in_eb.entry(id.clone()).or_default() += 1.0;
357375
*ebs_containing_ib.entry(ib_id.clone()).or_default() += 1.0;
@@ -364,9 +382,10 @@ impl EventMonitor {
364382
}
365383
}
366384
info!(
367-
"Pool {} generated an EB with {} IBs(s) in slot {}.",
385+
"Pool {} generated an EB with {} IB(s) and {} TX(s) in slot {}.",
368386
id.producer,
369387
input_blocks.len(),
388+
transactions.len(),
370389
id.slot,
371390
)
372391
}
@@ -546,7 +565,9 @@ impl EventMonitor {
546565
info!("{} L1 block(s) had a Leios endorsement.", leios_blocks_with_endorsements);
547566
info!("{} tx(s) were referenced by a Leios endorsement.", unique_leios_txs);
548567
info!("{} tx(s) were included directly in a Praos block.", praos_txs);
549-
info!("Spatial efficiency: {}/{} ({:.3}%) of Leios bytes were transactions.", pretty_bytes(total_leios_tx_bytes, pbo.clone()), pretty_bytes(total_leios_bytes, pbo.clone()), space_efficiency * 100.);
568+
if self.variant != LeiosVariant::FullWithoutIbs {
569+
info!("Spatial efficiency: {}/{} ({:.3}%) of Leios bytes were transactions.", pretty_bytes(total_leios_tx_bytes, pbo.clone()), pretty_bytes(total_leios_bytes, pbo.clone()), space_efficiency * 100.);
570+
}
550571
info!("{} tx(s) ({:.3}%) referenced by a Leios endorsement were redundant.", leios_txs - unique_leios_txs, (leios_txs - unique_leios_txs) as f64 / leios_txs as f64 * 100.);
551572
info!(
552573
"Each transaction took an average of {:.3}s (stddev {:.3}) to be included in an IB.",

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct RawParameters {
106106
pub eb_size_bytes_constant: u64,
107107
pub eb_size_bytes_per_ib: u64,
108108
pub eb_max_age_slots: u64,
109+
pub eb_referenced_txs_max_size_bytes: u64,
109110

110111
// Vote configuration
111112
pub vote_generation_probability: f64,
@@ -138,6 +139,7 @@ pub enum DiffusionStrategy {
138139
pub enum LeiosVariant {
139140
Short,
140141
Full,
142+
FullWithoutIbs,
141143
}
142144

143145
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
@@ -434,7 +436,7 @@ pub struct SimConfiguration {
434436
pub stage_length: u64,
435437
pub max_eb_age: u64,
436438
pub late_ib_inclusion: bool,
437-
pub(crate) variant: LeiosVariant,
439+
pub variant: LeiosVariant,
438440
pub(crate) header_diffusion_time: Duration,
439441
pub(crate) relay_strategy: RelayStrategy,
440442
pub(crate) praos_chain_quality: u64,
@@ -446,6 +448,7 @@ pub struct SimConfiguration {
446448
pub(crate) vote_slot_length: u64,
447449
pub(crate) max_block_size: u64,
448450
pub(crate) max_ib_size: u64,
451+
pub(crate) max_eb_size: u64,
449452
pub(crate) ib_diffusion_strategy: DiffusionStrategy,
450453
pub(crate) max_ib_requests_per_peer: usize,
451454
pub(crate) ib_shards: u64,
@@ -488,6 +491,7 @@ impl SimConfiguration {
488491
vote_slot_length: params.leios_stage_active_voting_slots,
489492
max_block_size: params.rb_body_max_size_bytes,
490493
max_ib_size: params.ib_body_max_size_bytes,
494+
max_eb_size: params.eb_referenced_txs_max_size_bytes,
491495
ib_diffusion_strategy: params.ib_diffusion_strategy,
492496
max_ib_requests_per_peer: params.ib_diffusion_max_bodies_to_request as usize,
493497
ib_shards: params.ib_shards,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ pub enum Event {
200200
pipeline: u64,
201201
producer: Node,
202202
size_bytes: u64,
203+
#[serde(skip_serializing_if = "Vec::is_empty")]
204+
transactions: Vec<BlockRef<TransactionId>>,
205+
#[serde(skip_serializing_if = "Vec::is_empty")]
203206
input_blocks: Vec<BlockRef<InputBlockId<Node>>>,
204207
endorser_blocks: Vec<BlockRef<EndorserBlockId<Node>>>,
205208
},
@@ -526,6 +529,7 @@ impl EventTracker {
526529
pipeline: block.pipeline,
527530
producer: self.to_node(block.producer),
528531
size_bytes: block.bytes,
532+
transactions: block.txs.iter().map(|id| BlockRef { id: *id }).collect(),
529533
input_blocks: block
530534
.ibs
531535
.iter()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub struct EndorserBlock {
167167
pub pipeline: u64,
168168
pub producer: NodeId,
169169
pub bytes: u64,
170-
// The real impl will store hashes
170+
pub txs: Vec<TransactionId>,
171171
pub ibs: Vec<InputBlockId>,
172172
pub ebs: Vec<EndorserBlockId>,
173173
}

0 commit comments

Comments
 (0)