From 6cc4ec6952cdb6bde699d91fa7e272c749cc2dd5 Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Wed, 14 Jun 2023 13:57:14 +0300 Subject: [PATCH] Complete TODO items in fork logic --- specs/_features/whisk/beacon-chain.md | 13 +++++++--- specs/_features/whisk/fork.md | 37 ++++++++++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/specs/_features/whisk/beacon-chain.md b/specs/_features/whisk/beacon-chain.md index bad8188378..412d3a8c2c 100644 --- a/specs/_features/whisk/beacon-chain.md +++ b/specs/_features/whisk/beacon-chain.md @@ -191,17 +191,21 @@ class BeaconState(Container): ``` ```python -def select_whisk_trackers(state: BeaconState, epoch: Epoch) -> None: +def select_whisk_proposer_trackers(state: BeaconState, epoch: Epoch) -> None: # Select proposer trackers from candidate trackers - proposer_seed = get_seed(state, epoch - WHISK_PROPOSER_SELECTION_GAP, DOMAIN_WHISK_PROPOSER_SELECTION) + proposer_seed_epoch = max(epoch, WHISK_PROPOSER_SELECTION_GAP) - WHISK_PROPOSER_SELECTION_GAP # prevent underflow + proposer_seed = get_seed(state, proposer_seed_epoch, DOMAIN_WHISK_PROPOSER_SELECTION) for i in range(WHISK_PROPOSER_TRACKERS_COUNT): index = compute_shuffled_index(uint64(i), uint64(len(state.whisk_candidate_trackers)), proposer_seed) state.whisk_proposer_trackers[i] = state.whisk_candidate_trackers[index] +``` +```python +def select_whisk_candidate_trackers(state: BeaconState, epoch: Epoch) -> None: # Select candidate trackers from active validator trackers active_validator_indices = get_active_validator_indices(state, epoch) for i in range(WHISK_CANDIDATE_TRACKERS_COUNT): - seed = hash(get_seed(state, epoch, DOMAIN_WHISK_CANDIDATE_SELECTION) + uint_to_bytes(i)) + seed = hash(get_seed(state, epoch, DOMAIN_WHISK_CANDIDATE_SELECTION) + uint_to_bytes(uint64(i))) candidate_index = compute_proposer_index(state, active_validator_indices, seed) # sample by effective balance state.whisk_candidate_trackers[i] = state.validators[candidate_index].whisk_tracker ``` @@ -210,7 +214,8 @@ def select_whisk_trackers(state: BeaconState, epoch: Epoch) -> None: def process_whisk_updates(state: BeaconState) -> None: next_epoch = Epoch(get_current_epoch(state) + 1) if next_epoch % WHISK_EPOCHS_PER_SHUFFLING_PHASE == 0: # select trackers at the start of shuffling phases - select_whisk_trackers(state, next_epoch) + select_whisk_proposer_trackers(state, next_epoch) + select_whisk_candidate_trackers(state, next_epoch) ``` ```python diff --git a/specs/_features/whisk/fork.md b/specs/_features/whisk/fork.md index 189d8c5b32..42e2f646ef 100644 --- a/specs/_features/whisk/fork.md +++ b/specs/_features/whisk/fork.md @@ -53,22 +53,8 @@ The upgrade occurs after the completion of the inner loop of `process_slots` tha This ensures that we drop right into the beginning of the shuffling phase but without `process_whisk_epoch()` triggering for this Whisk run. Hence we handle all the setup ourselves in `upgrade_to_whisk()` below. ```python -def whisk_candidate_selection(state: BeaconState, epoch: Epoch) -> None: - # TODO - # pylint: disable=unused-argument - pass -``` - -```python -def whisk_proposer_selection(state: BeaconState, epoch: Epoch) -> None: - # TODO - # pylint: disable=unused-argument - pass -``` - -```python -def upgrade_to_whisk(pre: bellatrix.BeaconState) -> BeaconState: - epoch = bellatrix.get_current_epoch(pre) +def upgrade_to_whisk(pre: capella.BeaconState) -> BeaconState: + epoch = get_current_epoch(pre) post = BeaconState( # Versioning genesis_time=pre.genesis_time, @@ -104,7 +90,17 @@ def upgrade_to_whisk(pre: bellatrix.BeaconState) -> BeaconState: current_justified_checkpoint=pre.current_justified_checkpoint, finalized_checkpoint=pre.finalized_checkpoint, # Inactivity - inactivity_scores=pre.inactivity_Scores, + inactivity_scores=pre.inactivity_scores, + # Sync + current_sync_committee=pre.current_sync_committee, + next_sync_committee=pre.next_sync_committee, + # Execution-layer + latest_execution_payload_header=pre.latest_execution_payload_header, + # Withdrawals + next_withdrawal_index=pre.next_withdrawal_index, + next_withdrawal_validator_index=pre.next_withdrawal_validator_index, + # Deep history valid from Capella onwards + historical_summaries=pre.historical_summaries, ) # Initialize all validators with predictable commitments @@ -127,12 +123,13 @@ def upgrade_to_whisk(pre: bellatrix.BeaconState) -> BeaconState: # Do a candidate selection followed by a proposer selection so that we have proposers for the upcoming day # Use an old epoch when selecting candidates so that we don't get the same seed as in the next candidate selection - whisk_candidate_selection(post, epoch - WHISK_PROPOSER_SELECTION_GAP - 1) - whisk_proposer_selection(post, epoch) + initial_candidate_gap = WHISK_PROPOSER_SELECTION_GAP + Epoch(1) + select_whisk_candidate_trackers(post, max(epoch, initial_candidate_gap) - initial_candidate_gap) + select_whisk_proposer_trackers(post, epoch) # Do a final round of candidate selection. # We need it so that we have something to shuffle over the upcoming shuffling phase. - whisk_candidate_selection(post, epoch) + select_whisk_candidate_trackers(post, epoch) return post ```