Skip to content

Commit a15e946

Browse files
authored
Move stracciatella to a separate implementation (#461)
* sim-rs: move stracciatella to a separate implementation * sim-rs: fix issues with stracciatella * sim-rs: support referencing txs from last stage in stracciatella * sim-rs: remove stracciatella code from normal leios sim
1 parent a9da220 commit a15e946

File tree

9 files changed

+1343
-131
lines changed

9 files changed

+1343
-131
lines changed

data/simulation/config.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ export interface Config {
174174
"eb-size-bytes-constant": bigint;
175175
"eb-size-bytes-per-ib": bigint;
176176
"eb-body-avg-size-bytes": bigint;
177+
/** For stracciatella: when creating a new EB, have it reference transactions from a previous EB */
178+
"eb-include-txs-from-previous-stage": boolean
179+
177180
/** Only supported by Haskell simulation. */
178181
"eb-diffusion-strategy": DiffusionStrategy;
179182
/** Only supported by Haskell simulation. */

data/simulation/config.default.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ eb-header-validation-cpu-time-ms: 50.0
150150
# For linear leios: complete validation of the EB
151151
eb-body-validation-cpu-time-ms-constant: 50.0
152152
eb-body-validation-cpu-time-ms-per-byte: 0.0005
153+
# For stracciatella: when creating a new EB, have it reference transactions from a previous EB
154+
eb-include-txs-from-previous-stage: false
153155

154156
eb-diffusion-strategy: "peer-order"
155157

data/simulation/config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@
192192
"eb-header-validation-cpu-time-ms": {
193193
"type": "number"
194194
},
195+
"eb-include-txs-from-previous-stage": {
196+
"description": "For stracciatella: when creating a new EB, have it reference transactions from a previous EB",
197+
"type": "boolean"
198+
},
195199
"eb-max-age-for-relay-slots": {
196200
"additionalProperties": false,
197201
"description": "The maximum age of EBs to be relayed.\n\nAn EB from slot `s` will only be relayed\nup to slot `s+eb-max-age-for-relay-slots`.\n\nOnly supported by Haskell simulation.",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub struct RawParameters {
123123
pub eb_max_age_slots: u64,
124124
pub eb_referenced_txs_max_size_bytes: u64,
125125
pub eb_body_avg_size_bytes: u64,
126+
pub eb_include_txs_from_previous_stage: bool,
126127

127128
// Vote configuration
128129
pub vote_generation_probability: f64,
@@ -539,6 +540,7 @@ pub struct SimConfiguration {
539540
pub(crate) eb_generation_probability: f64,
540541
pub(crate) vote_probability: f64,
541542
pub(crate) vote_slot_length: u64,
543+
pub(crate) eb_include_txs_from_previous_stage: bool,
542544
pub(crate) linear_vote_stage_length: u64,
543545
pub(crate) linear_diffuse_stage_length: u64,
544546
pub(crate) max_block_size: u64,
@@ -602,6 +604,7 @@ impl SimConfiguration {
602604
vote_probability: params.vote_generation_probability,
603605
vote_threshold: params.vote_threshold,
604606
vote_slot_length: params.leios_stage_active_voting_slots,
607+
eb_include_txs_from_previous_stage: params.eb_include_txs_from_previous_stage,
605608
linear_vote_stage_length: params.linear_vote_stage_length_slots,
606609
linear_diffuse_stage_length: params.linear_diffuse_stage_length_slots,
607610
max_block_size: params.rb_body_max_size_bytes,

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl EventTracker {
608608
producer: self.to_node(block.producer),
609609
shard: block.shard,
610610
size_bytes: block.bytes,
611-
transactions: block.txs.iter().map(|tx| BlockRef { id: tx.id }).collect(),
611+
transactions: vec![],
612612
input_blocks: block
613613
.ibs
614614
.iter()
@@ -626,6 +626,29 @@ impl EventTracker {
626626
});
627627
}
628628

629+
pub fn track_stracciatella_eb_generated(
630+
&self,
631+
block: &crate::model::StracciatellaEndorserBlock,
632+
) {
633+
self.send(Event::EBGenerated {
634+
id: self.to_endorser_block(block.id()),
635+
slot: block.slot,
636+
pipeline: block.pipeline,
637+
producer: self.to_node(block.producer),
638+
shard: block.shard,
639+
size_bytes: block.bytes,
640+
transactions: block.txs.iter().map(|tx| BlockRef { id: tx.id }).collect(),
641+
input_blocks: vec![],
642+
endorser_blocks: block
643+
.ebs
644+
.iter()
645+
.map(|id| BlockRef {
646+
id: self.to_endorser_block(*id),
647+
})
648+
.collect(),
649+
});
650+
}
651+
629652
pub fn track_no_eb_generated(&self, node: NodeId, slot: u64) {
630653
self.send(Event::NoEBGenerated {
631654
node: self.to_node(node),
@@ -667,6 +690,23 @@ impl EventTracker {
667690
});
668691
}
669692

693+
pub fn track_stracciatella_eb_sent(
694+
&self,
695+
block: &crate::model::StracciatellaEndorserBlock,
696+
sender: NodeId,
697+
recipient: NodeId,
698+
) {
699+
self.send(Event::EBSent {
700+
id: self.to_endorser_block(block.id()),
701+
slot: block.slot,
702+
pipeline: block.pipeline,
703+
producer: self.to_node(block.producer),
704+
sender: self.to_node(sender),
705+
recipient: self.to_node(recipient),
706+
msg_size_bytes: block.bytes,
707+
});
708+
}
709+
670710
pub fn track_eb_received(&self, id: EndorserBlockId, sender: NodeId, recipient: NodeId) {
671711
self.send(Event::EBReceived {
672712
id: self.to_endorser_block(id),

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ pub struct EndorserBlock {
194194
pub producer: NodeId,
195195
pub shard: u64,
196196
pub bytes: u64,
197-
pub txs: Vec<Arc<Transaction>>,
198197
pub ibs: Vec<InputBlockId>,
199198
pub ebs: Vec<EndorserBlockId>,
200199
}
@@ -208,6 +207,26 @@ impl EndorserBlock {
208207
}
209208
}
210209

210+
#[derive(Debug)]
211+
pub struct StracciatellaEndorserBlock {
212+
pub slot: u64,
213+
pub pipeline: u64,
214+
pub producer: NodeId,
215+
pub shard: u64,
216+
pub bytes: u64,
217+
pub txs: Vec<Arc<Transaction>>,
218+
pub ebs: Vec<EndorserBlockId>,
219+
}
220+
impl StracciatellaEndorserBlock {
221+
pub fn id(&self) -> EndorserBlockId {
222+
EndorserBlockId {
223+
slot: self.slot,
224+
pipeline: self.pipeline,
225+
producer: self.producer,
226+
}
227+
}
228+
}
229+
211230
#[derive(Debug)]
212231
pub struct LinearEndorserBlock {
213232
pub slot: u64,

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use crate::{
1414
events::EventTracker,
1515
model::Transaction,
1616
network::Network,
17-
sim::{driver::NodeDriver, leios::LeiosNode, linear_leios::LinearLeiosNode},
17+
sim::{
18+
driver::NodeDriver, leios::LeiosNode, linear_leios::LinearLeiosNode,
19+
stracciatella::StracciatellaLeiosNode,
20+
},
1821
};
1922

2023
mod cpu;
@@ -23,30 +26,35 @@ mod leios;
2326
mod linear_leios;
2427
mod lottery;
2528
mod slot;
29+
mod stracciatella;
2630
mod tx;
2731

2832
enum NetworkWrapper {
2933
Leios(Network<MiniProtocol, <LeiosNode as NodeImpl>::Message>),
34+
Stracciatella(Network<MiniProtocol, <StracciatellaLeiosNode as NodeImpl>::Message>),
3035
LinearLeios(Network<MiniProtocol, <LinearLeiosNode as NodeImpl>::Message>),
3136
}
3237
impl NetworkWrapper {
3338
async fn run(&mut self) -> Result<()> {
3439
match self {
3540
Self::Leios(network) => network.run().await,
41+
Self::Stracciatella(network) => network.run().await,
3642
Self::LinearLeios(network) => network.run().await,
3743
}
3844
}
3945

4046
fn shutdown(self) -> Result<()> {
4147
match self {
4248
Self::Leios(network) => network.shutdown(),
49+
Self::Stracciatella(network) => network.shutdown(),
4350
Self::LinearLeios(network) => network.shutdown(),
4451
}
4552
}
4653
}
4754

4855
enum NodeListWrapper {
4956
Leios(Vec<NodeDriver<LeiosNode>>),
57+
Stracciatella(Vec<NodeDriver<StracciatellaLeiosNode>>),
5058
LinearLeios(Vec<NodeDriver<LinearLeiosNode>>),
5159
}
5260
impl NodeListWrapper {
@@ -57,6 +65,11 @@ impl NodeListWrapper {
5765
set.spawn(node.run());
5866
}
5967
}
68+
Self::Stracciatella(nodes) => {
69+
for node in nodes.drain(..) {
70+
set.spawn(node.run());
71+
}
72+
}
6073
Self::LinearLeios(nodes) => {
6174
for node in nodes.drain(..) {
6275
set.spawn(node.run());
@@ -91,6 +104,13 @@ impl Simulation {
91104
NetworkWrapper::LinearLeios,
92105
NodeListWrapper::LinearLeios,
93106
)?,
107+
LeiosVariant::FullWithoutIbs => Self::init(
108+
&config,
109+
&tracker,
110+
&clock,
111+
NetworkWrapper::Stracciatella,
112+
NodeListWrapper::Stracciatella,
113+
)?,
94114
_ => Self::init(
95115
&config,
96116
&tracker,

0 commit comments

Comments
 (0)