diff --git a/consensus/fork_choice/src/fork_choice.rs b/consensus/fork_choice/src/fork_choice.rs index 213ed11f26c..cf86341fed7 100644 --- a/consensus/fork_choice/src/fork_choice.rs +++ b/consensus/fork_choice/src/fork_choice.rs @@ -592,6 +592,7 @@ where self.fc_store.set_proposer_boost_root(block_root); } + // Update store with checkpoints if necessary self.update_checkpoints( state.current_justified_checkpoint(), state.finalized_checkpoint(), @@ -602,7 +603,7 @@ where // Update unrealized justified/finalized checkpoints. let (unrealized_justified_checkpoint, unrealized_finalized_checkpoint) = { - if !matches!(block, BeaconBlock::Base(_)) { + if !matches!(block, BeaconBlock::Merge(_)) { let (justifiable_beacon_state, _) = state_processing::per_epoch_processing::altair::process_justifiable( state, spec, @@ -717,7 +718,7 @@ where execution_status, unrealized_justified_checkpoint, unrealized_finalized_checkpoint, - })?; + }, current_slot)?; Ok(()) } diff --git a/consensus/proto_array/src/fork_choice_test_definition.rs b/consensus/proto_array/src/fork_choice_test_definition.rs index 38fb30e867e..a638eecac3a 100644 --- a/consensus/proto_array/src/fork_choice_test_definition.rs +++ b/consensus/proto_array/src/fork_choice_test_definition.rs @@ -103,6 +103,7 @@ impl ForkChoiceTestDefinition { finalized_checkpoint, &justified_state_balances, Hash256::zero(), + Slot::new(0), &spec, ) .map_err(|e| e) @@ -130,6 +131,7 @@ impl ForkChoiceTestDefinition { finalized_checkpoint, &justified_state_balances, proposer_boost_root, + Slot::new(0), &spec, ) .map_err(|e| e) @@ -154,6 +156,7 @@ impl ForkChoiceTestDefinition { finalized_checkpoint, &justified_state_balances, Hash256::zero(), + Slot::new(0), &spec, ); @@ -195,7 +198,7 @@ impl ForkChoiceTestDefinition { unrealized_justified_checkpoint: None, unrealized_finalized_checkpoint: None, }; - fork_choice.process_block(block).unwrap_or_else(|e| { + fork_choice.process_block(block, slot).unwrap_or_else(|e| { panic!( "process_block op at index {} returned error: {:?}", op_index, e diff --git a/consensus/proto_array/src/proto_array.rs b/consensus/proto_array/src/proto_array.rs index d8b5f828e97..8e6ca78d8cc 100644 --- a/consensus/proto_array/src/proto_array.rs +++ b/consensus/proto_array/src/proto_array.rs @@ -291,7 +291,7 @@ impl ProtoArray { /// Register a block with the fork choice. /// /// It is only sane to supply a `None` parent for the genesis block. - pub fn on_block(&mut self, block: Block) -> Result<(), Error> { + pub fn on_block(&mut self, block: Block, current_slot:Slot) -> Result<(), Error> { // If the block is already known, simply ignore it. if self.indices.contains_key(&block.root) { return Ok(()); @@ -338,7 +338,7 @@ impl ProtoArray { self.nodes.push(node.clone()); if let Some(parent_index) = node.parent { - self.maybe_update_best_child_and_descendant(parent_index, node_index)?; + self.maybe_update_best_child_and_descendant(parent_index, node_index, current_slot)?; if matches!(block.execution_status, ExecutionStatus::Valid(_)) { self.propagate_execution_payload_validation_by_index(parent_index)?; @@ -857,8 +857,6 @@ impl ProtoArray { return false; } - let node_epoch = node.slot.epoch(MainnetEthSpec::slots_per_epoch()); - let checkpoint_match_predicate = |node_justified_checkpoint: Checkpoint, node_finalized_checkpoint: Checkpoint| { let correct_justified = node_justified_checkpoint == self.justified_checkpoint @@ -879,17 +877,12 @@ impl ProtoArray { node.justified_checkpoint, node.finalized_checkpoint, ) { - if justified_checkpoint.epoch < self.justified_checkpoint.epoch - && finalized_checkpoint.epoch < self.finalized_checkpoint.epoch + if node.slot.epoch(MainnetEthSpec::slots_per_epoch()) < current_slot.epoch(MainnetEthSpec::slots_per_epoch()) { checkpoint_match_predicate( unrealized_justified_checkpoint, unrealized_finalized_checkpoint, ) - } else if justified_checkpoint.epoch < self.justified_checkpoint.epoch { - checkpoint_match_predicate(unrealized_justified_checkpoint, finalized_checkpoint) - } else if finalized_checkpoint.epoch < self.finalized_checkpoint.epoch { - checkpoint_match_predicate(justified_checkpoint, unrealized_finalized_checkpoint) } else { checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint) } diff --git a/consensus/proto_array/src/proto_array_fork_choice.rs b/consensus/proto_array/src/proto_array_fork_choice.rs index c1c2672acb0..1122d427720 100644 --- a/consensus/proto_array/src/proto_array_fork_choice.rs +++ b/consensus/proto_array/src/proto_array_fork_choice.rs @@ -200,7 +200,7 @@ impl ProtoArrayForkChoice { }; proto_array - .on_block(block) + .on_block(block, finalized_block_slot) .map_err(|e| format!("Failed to add finalized block to proto_array: {:?}", e))?; Ok(Self { @@ -246,13 +246,13 @@ impl ProtoArrayForkChoice { Ok(()) } - pub fn process_block(&mut self, block: Block) -> Result<(), String> { + pub fn process_block(&mut self, block: Block, current_slot:Slot) -> Result<(), String> { if block.parent_root.is_none() { return Err("Missing parent root".to_string()); } self.proto_array - .on_block(block) + .on_block(block, current_slot) .map_err(|e| format!("process_block_error: {:?}", e)) } @@ -292,7 +292,7 @@ impl ProtoArrayForkChoice { *old_balances = new_balances.to_vec(); self.proto_array - .find_head(&justified_checkpoint.root) + .find_head(&justified_checkpoint.root, current_slot) .map_err(|e| format!("find_head failed: {:?}", e)) } diff --git a/testing/ef_tests/src/cases/fork_choice.rs b/testing/ef_tests/src/cases/fork_choice.rs index 5a92961ba74..097fcbbda24 100644 --- a/testing/ef_tests/src/cases/fork_choice.rs +++ b/testing/ef_tests/src/cases/fork_choice.rs @@ -303,21 +303,27 @@ impl Tester { } pub fn set_tick(&self, tick: u64) { - self.harness - .chain - .slot_clock - .set_current_time(Duration::from_secs(tick)); - // Compute the slot time manually to ensure the slot clock is correct. - let slot = self.tick_to_slot(tick).unwrap(); - assert_eq!(slot, self.harness.chain.slot().unwrap()); + // get current slot, get difference, call update_time on every slot - self.harness - .chain - .fork_choice - .write() - .update_time(slot) - .unwrap(); + let slot = self.harness.chain.slot().unwrap(); + let new_slots = tick.checked_div(self.spec.seconds_per_slot).unwrap(); + + for i in slot.as_u64()..new_slots { + let new_slot = i + 1; + + self.harness + .chain + .slot_clock + .set_slot(new_slot); + + self.harness + .chain + .fork_choice + .write() + .update_time(Slot::new(new_slot)) + .unwrap(); + } } pub fn process_block(&self, block: SignedBeaconBlock, valid: bool) -> Result<(), Error> { diff --git a/testing/ef_tests/src/handler.rs b/testing/ef_tests/src/handler.rs index be6c495aaed..7d6e4618b30 100644 --- a/testing/ef_tests/src/handler.rs +++ b/testing/ef_tests/src/handler.rs @@ -54,6 +54,7 @@ pub trait Handler { .filter_map(as_directory) .map(|test_case_dir| { let path = test_case_dir.path(); + dbg!(&path); let case = Self::Case::load_from_dir(&path, fork_name).expect("test should load"); (path, case) })