Skip to content

Commit f4e68d9

Browse files
committed
sim-rs: fix bug with voting logic
1 parent 120d8c5 commit f4e68d9

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl Node {
642642
let Some(EndorserBlockState::Received(eb)) = self.leios.ebs.get(eb_id) else {
643643
panic!("Tried voting for EB which we haven't received");
644644
};
645-
match self.should_vote_for(slot, eb) {
645+
match self.should_vote_for(eb) {
646646
Ok(()) => true,
647647
Err(reason) => {
648648
self.tracker.track_no_vote(
@@ -670,12 +670,8 @@ impl Node {
670670
bytes: self.sim_config.sizes.vote_bundle(ebs.len()),
671671
ebs: ebs.into_iter().map(|eb| (eb, votes_allowed)).collect(),
672672
};
673-
if !votes.ebs.is_empty() {
674-
self.schedule_cpu_task(CpuTaskType::VTBundleGenerated(votes));
675-
true
676-
} else {
677-
false
678-
}
673+
self.schedule_cpu_task(CpuTaskType::VTBundleGenerated(votes));
674+
true
679675
}
680676

681677
fn generate_input_blocks(&mut self, slot: u64) {
@@ -1389,17 +1385,20 @@ impl Node {
13891385
Ok(())
13901386
}
13911387

1392-
fn should_vote_for(&self, slot: u64, eb: &EndorserBlock) -> Result<(), NoVoteReason> {
1388+
fn should_vote_for(&self, eb: &EndorserBlock) -> Result<(), NoVoteReason> {
13931389
let stage_length = self.sim_config.stage_length;
13941390

1395-
let Some(ib_slot_start) = slot.checked_sub(stage_length * 4) else {
1396-
// The IBs for this EB were "generated" before the sim began.
1397-
// It's valid iff there are no IBs.
1398-
return if eb.ibs.is_empty() {
1399-
Ok(())
1400-
} else {
1401-
Err(NoVoteReason::ExtraIB)
1402-
};
1391+
let ib_slot_start = match eb.pipeline.checked_sub(4) {
1392+
Some(x) => x * stage_length,
1393+
None => {
1394+
// The IBs for this EB were "generated" before the sim began.
1395+
// It's valid iff there are no IBs.
1396+
return if eb.ibs.is_empty() {
1397+
Ok(())
1398+
} else {
1399+
Err(NoVoteReason::ExtraIB)
1400+
};
1401+
}
14031402
};
14041403
let ib_slot_end = ib_slot_start + stage_length;
14051404
let ib_slot_range = ib_slot_start..ib_slot_end;

0 commit comments

Comments
 (0)