More proposer shuffling cleanup (#8130)

Addressing more review comments from:

- https://github.com/sigp/lighthouse/pull/8101

I've also tweaked a few more things that I think are minor bugs.


  - Instrument `ensure_state_can_determine_proposers_for_epoch`
- Fix `block_root` usage in `compute_proposer_duties_from_head`. This was a regression introduced in 8101 😬 .
- Update the `state_advance_timer` to prime the next-epoch proposer cache post-Fulu.


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Michael Sproul
2025-10-20 14:14:14 +11:00
committed by GitHub
parent 79716f6ec1
commit 2f8587301d
8 changed files with 359 additions and 59 deletions

View File

@@ -476,15 +476,23 @@ impl ChainSpec {
/// Returns a full `Fork` struct for a given epoch.
pub fn fork_at_epoch(&self, epoch: Epoch) -> Fork {
let current_fork_name = self.fork_name_at_epoch(epoch);
let previous_fork_name = current_fork_name.previous_fork().unwrap_or(ForkName::Base);
let epoch = self
let fork_epoch = self
.fork_epoch(current_fork_name)
.unwrap_or_else(|| Epoch::new(0));
// At genesis the Fork is initialised with two copies of the same value for both
// `previous_version` and `current_version` (see `initialize_beacon_state_from_eth1`).
let previous_fork_name = if fork_epoch == 0 {
current_fork_name
} else {
current_fork_name.previous_fork().unwrap_or(ForkName::Base)
};
Fork {
previous_version: self.fork_version_for_name(previous_fork_name),
current_version: self.fork_version_for_name(current_fork_name),
epoch,
epoch: fork_epoch,
}
}
@@ -3010,9 +3018,11 @@ mod yaml_tests {
fn proposer_shuffling_decision_root_around_epoch_boundary() {
type E = MainnetEthSpec;
let fulu_fork_epoch = 5;
let gloas_fork_epoch = 10;
let spec = {
let mut spec = ForkName::Electra.make_genesis_spec(E::default_spec());
spec.fulu_fork_epoch = Some(Epoch::new(fulu_fork_epoch));
spec.gloas_fork_epoch = Some(Epoch::new(gloas_fork_epoch));
Arc::new(spec)
};
@@ -3026,7 +3036,7 @@ mod yaml_tests {
}
// For epochs after Fulu, the decision slot is the end of the epoch two epochs prior.
for epoch in ((fulu_fork_epoch + 1)..(fulu_fork_epoch + 10)).map(Epoch::new) {
for epoch in ((fulu_fork_epoch + 1)..=(gloas_fork_epoch + 1)).map(Epoch::new) {
assert_eq!(
spec.proposer_shuffling_decision_slot::<E>(epoch),
(epoch - 1).start_slot(E::slots_per_epoch()) - 1