From f854afa3528a7aae4b8062926b53dbf0c060e072 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 12 Nov 2025 12:46:05 +1100 Subject: [PATCH] Prevent unnecessary state advances pre-Fulu (#8388) State advances were observed as especially slow on pre-Fulu networks (mainnet). The reason being: we were doing an extra epoch of state advance because of code that should only have been running after Fulu, when proposer shufflings are determined with lookahead. Only attempt to cache the _next epoch_ shuffling if the state's slot determines it (this will only be true post-Fulu). Reusing the logic for `proposer_shuffling_decision_slot` avoids having to repeat the fiddly logic about the Fulu fork epoch itself. Co-Authored-By: Michael Sproul --- .../beacon_chain/src/state_advance_timer.rs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/beacon_node/beacon_chain/src/state_advance_timer.rs b/beacon_node/beacon_chain/src/state_advance_timer.rs index b10edf2336..a070dc350b 100644 --- a/beacon_node/beacon_chain/src/state_advance_timer.rs +++ b/beacon_node/beacon_chain/src/state_advance_timer.rs @@ -363,24 +363,30 @@ fn advance_head(beacon_chain: &Arc>) -> Resu // For epochs *greater than* the Fulu fork epoch, we have also determined the proposer // shuffling for the next epoch. let next_epoch = state.next_epoch()?; - let next_epoch_decision_root = state.proposer_shuffling_decision_root_at_epoch( - next_epoch, - head_block_root, - &beacon_chain.spec, - )?; - beacon_chain.with_proposer_cache( - next_epoch_decision_root, - next_epoch, - |_| Ok(()), - || { - debug!( - shuffling_decision_root = ?next_epoch_decision_root, - epoch = %next_epoch, - "Computing next epoch proposer shuffling in state advance" - ); - Ok::<_, Error>((advanced_state_root, state.clone())) - }, - )?; + let next_epoch_decision_slot = beacon_chain + .spec + .proposer_shuffling_decision_slot::(next_epoch); + + if state.slot() > next_epoch_decision_slot { + let next_epoch_decision_root = state.proposer_shuffling_decision_root_at_epoch( + next_epoch, + head_block_root, + &beacon_chain.spec, + )?; + beacon_chain.with_proposer_cache( + next_epoch_decision_root, + next_epoch, + |_| Ok(()), + || { + debug!( + shuffling_decision_root = ?next_epoch_decision_root, + epoch = %next_epoch, + "Computing next epoch proposer shuffling in state advance" + ); + Ok::<_, Error>((advanced_state_root, state.clone())) + }, + )?; + } // Update the attester cache. let shuffling_id =