Skip to content

Commit ec25073

Browse files
committed
sim-rs: respect sharding configuration in full-without-ibs variant
1 parent 128d736 commit ec25073

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
leios-variant: full-without-ibs
2+
ib-shard-group-count: 1

sim-rs/parameters/no-ibs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ leios-variant: full-without-ibs
22
leios-mempool-strategy: random
33
leios-late-ib-inclusion: true
44
praos-chain-quality: 100
5+
ib-shard-group-count: 1

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ impl SimConfiguration {
514514
params.ib_shard_group_count
515515
);
516516
}
517+
if matches!(params.leios_variant, LeiosVariant::FullWithoutIbs)
518+
&& params.ib_shard_group_count != 1
519+
&& params.ib_shard_period_length_slots % params.leios_stage_length_slots != 0
520+
{
521+
bail!(
522+
"Invalid sharding configuration. EBs are generated every {} slot(s). This sim is configured to choose EB shards from 1 of {} groups, using a different group every {} slot(s). Some groups would never be chosen.",
523+
params.leios_stage_length_slots,
524+
params.ib_shard_group_count,
525+
params.ib_shard_period_length_slots
526+
);
527+
}
517528
Ok(Self {
518529
seed: 0,
519530
timestamp_resolution: duration_ms(params.timestamp_resolution_ms),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ pub enum Event {
206206
slot: u64,
207207
pipeline: u64,
208208
producer: Node,
209+
shard: u64,
209210
size_bytes: u64,
210211
transactions: Vec<BlockRef<TransactionId>>,
211212
input_blocks: Vec<BlockRef<InputBlockId<Node>>>,
@@ -538,6 +539,7 @@ impl EventTracker {
538539
slot: block.slot,
539540
pipeline: block.pipeline,
540541
producer: self.to_node(block.producer),
542+
shard: block.shard,
541543
size_bytes: block.bytes,
542544
transactions: block.txs.iter().map(|id| BlockRef { id: *id }).collect(),
543545
input_blocks: block

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct EndorserBlock {
170170
pub slot: u64,
171171
pub pipeline: u64,
172172
pub producer: NodeId,
173+
pub shard: u64,
173174
pub bytes: u64,
174175
pub txs: Vec<TransactionId>,
175176
pub ibs: Vec<InputBlockId>,

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

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ impl Node {
596596
}
597597
}
598598

599+
fn find_available_eb_shards(&self, slot: u64) -> Vec<u64> {
600+
if !matches!(self.sim_config.variant, LeiosVariant::FullWithoutIbs) {
601+
// EBs only need shards if we don't have IBs.
602+
return vec![0];
603+
}
604+
self.find_available_ib_shards(slot)
605+
}
606+
599607
fn find_available_ib_shards(&self, slot: u64) -> Vec<u64> {
600608
let period = slot / self.sim_config.ib_shard_period_slots;
601609
let group = period % self.sim_config.ib_shard_groups;
@@ -610,21 +618,24 @@ impl Node {
610618
// Don't generate EBs before that pipeline, because they would just be empty.
611619
return;
612620
}
621+
let shards = self.find_available_eb_shards(slot);
613622
for next_p in vrf_probabilities(self.sim_config.eb_generation_probability) {
614-
if self.run_vrf(next_p).is_some() {
623+
if let Some(vrf) = self.run_vrf(next_p) {
615624
self.tracker.track_eb_lottery_won(EndorserBlockId {
616625
slot,
617626
pipeline,
618627
producer: self.id,
619628
});
620-
let txs = self.select_txs_for_eb(pipeline);
629+
let shard = shards[vrf as usize % shards.len()];
630+
let txs = self.select_txs_for_eb(shard, pipeline);
621631
let ibs = self.select_ibs_for_eb(pipeline);
622632
let ebs = self.select_ebs_for_eb(pipeline);
623633
let bytes = self.sim_config.sizes.eb(txs.len(), ibs.len(), ebs.len());
624634
let eb = EndorserBlock {
625635
slot,
626636
pipeline,
627637
producer: self.id,
638+
shard,
628639
bytes,
629640
txs,
630641
ibs,
@@ -1407,27 +1418,15 @@ impl Node {
14071418
vec![Arc::new(tx)]
14081419
} else {
14091420
let ledger_state = self.resolve_ledger_state(rb_ref);
1410-
let ib_shards = self.sim_config.ib_shards;
1411-
let tx_may_use_shard = |tx: &Transaction, ib_shard: u64| {
1412-
for shard in tx.shard..=tx.shard + tx.overcollateralization_factor {
1413-
let shard = shard % ib_shards;
1414-
if shard == ib_shard {
1415-
return true;
1416-
}
1417-
}
1418-
false
1419-
};
14201421
self.select_txs(
1421-
|seen| {
1422-
tx_may_use_shard(&seen.tx, shard)
1423-
&& !ledger_state.spent_inputs.contains(&seen.tx.input_id)
1424-
},
1422+
shard,
1423+
|seen| !ledger_state.spent_inputs.contains(&seen.tx.input_id),
14251424
self.sim_config.max_ib_size,
14261425
)
14271426
}
14281427
}
14291428

1430-
fn select_txs_for_eb(&mut self, pipeline: u64) -> Vec<TransactionId> {
1429+
fn select_txs_for_eb(&mut self, shard: u64, pipeline: u64) -> Vec<TransactionId> {
14311430
if self.sim_config.variant != LeiosVariant::FullWithoutIbs {
14321431
return vec![];
14331432
}
@@ -1440,6 +1439,7 @@ impl Node {
14401439
let max_seen_at = Timestamp::from_secs(last_legal_slot);
14411440

14421441
self.select_txs(
1442+
shard,
14431443
|seen| seen.seen_at <= max_seen_at,
14441444
self.sim_config.max_eb_size,
14451445
)
@@ -1448,16 +1448,31 @@ impl Node {
14481448
.collect()
14491449
}
14501450

1451-
fn select_txs<C>(&mut self, condition: C, max_size: u64) -> Vec<Arc<Transaction>>
1451+
fn select_txs<C>(
1452+
&mut self,
1453+
container_shard: u64,
1454+
condition: C,
1455+
max_size: u64,
1456+
) -> Vec<Arc<Transaction>>
14521457
where
14531458
C: Fn(&SeenTransaction) -> bool,
14541459
{
1460+
let ib_shards = self.sim_config.ib_shards;
1461+
let tx_may_use_shard = |tx: &Transaction| {
1462+
for shard in tx.shard..=tx.shard + tx.overcollateralization_factor {
1463+
let shard = shard % ib_shards;
1464+
if shard == container_shard {
1465+
return true;
1466+
}
1467+
}
1468+
false
1469+
};
14551470
let mut candidate_txs: Vec<_> = self
14561471
.leios
14571472
.mempool
14581473
.values()
14591474
.filter_map(|seen| {
1460-
if condition(seen) {
1475+
if tx_may_use_shard(&seen.tx) && condition(seen) {
14611476
Some((seen.tx.id, seen.tx.bytes, seen.tx.input_id))
14621477
} else {
14631478
None

0 commit comments

Comments
 (0)