diff --git a/specs/altair/beacon-chain.md b/specs/altair/beacon-chain.md index aa1509460..a69412c31 100644 --- a/specs/altair/beacon-chain.md +++ b/specs/altair/beacon-chain.md @@ -281,11 +281,12 @@ def get_sync_committee_indices(state: BeaconState, epoch: Epoch) -> Sequence[Val Note: This function is not stable during a sync committee period as a validator's effective balance may change enough to affect the sampling. """ + assert epoch % EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0 + MAX_RANDOM_BYTE = 2**8 - 1 - base_epoch = Epoch((max(epoch // EPOCHS_PER_SYNC_COMMITTEE_PERIOD, 1) - 1) * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) - active_validator_indices = get_active_validator_indices(state, base_epoch) + active_validator_indices = get_active_validator_indices(state, epoch) active_validator_count = uint64(len(active_validator_indices)) - seed = get_seed(state, base_epoch, DOMAIN_SYNC_COMMITTEE) + seed = get_seed(state, epoch, DOMAIN_SYNC_COMMITTEE) i = 0 sync_committee_indices: List[ValidatorIndex] = [] while len(sync_committee_indices) < SYNC_COMMITTEE_SIZE: @@ -689,6 +690,7 @@ def process_participation_flag_updates(state: BeaconState) -> None: def process_sync_committee_updates(state: BeaconState) -> None: next_epoch = get_current_epoch(state) + Epoch(1) if next_epoch % EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0: + print("HEEEREEE") state.current_sync_committee = state.next_sync_committee state.next_sync_committee = get_sync_committee(state, next_epoch) ``` @@ -735,8 +737,13 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32, state.genesis_validators_root = hash_tree_root(state.validators) # [New in Altair] Fill in sync committees - state.current_sync_committee = get_sync_committee(state, get_current_epoch(state)) - state.next_sync_committee = get_sync_committee(state, get_current_epoch(state) + EPOCHS_PER_SYNC_COMMITTEE_PERIOD) + current_period = get_current_epoch(state) // EPOCHS_PER_SYNC_COMMITTEE_PERIOD + previous_period = current_period - min(1, current_period) + current_base_epoch = current_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD + previous_base_epoch = previous_period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD + + state.current_sync_committee = get_sync_committee(state, previous_base_epoch) + state.next_sync_committee = get_sync_committee(state, current_base_epoch) return state ``` diff --git a/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_committee.py b/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_committee.py index 2e5d62d11..48e556f50 100644 --- a/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_committee.py +++ b/tests/core/pyspec/eth2spec/test/altair/block_processing/test_process_sync_committee.py @@ -345,10 +345,10 @@ def test_valid_signature_future_committee(spec, state): transition_to(spec, state, slot_in_future_sync_committee_period) sync_committee = state.current_sync_committee + next_sync_committee = state.next_sync_committee + expected_next_sync_committee = spec.get_sync_committee(state, epoch_in_future_sync_committee_period) - expected_sync_committee = spec.get_sync_committee(state, epoch_in_future_sync_committee_period) - - assert sync_committee == expected_sync_committee + assert next_sync_committee == expected_next_sync_committee assert sync_committee != old_current_sync_committee assert sync_committee != old_next_sync_committee diff --git a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py index c909c791c..ca25797c4 100644 --- a/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py +++ b/tests/core/pyspec/eth2spec/test/altair/epoch_processing/test_process_sync_committee_updates.py @@ -40,7 +40,7 @@ def run_sync_committees_progress_test(spec, state): # Can compute the third committee having computed final balances in the last epoch # of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD` current_epoch = spec.get_current_epoch(state) - third_sync_committee = spec.get_sync_committee(state, current_epoch + 2 * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD) + third_sync_committee = spec.get_sync_committee(state, current_epoch + 1) assert state.current_sync_committee == second_sync_committee assert state.next_sync_committee == third_sync_committee diff --git a/tests/core/pyspec/eth2spec/test/helpers/genesis.py b/tests/core/pyspec/eth2spec/test/helpers/genesis.py index 4a34a5eb3..23cd04c93 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/genesis.py +++ b/tests/core/pyspec/eth2spec/test/helpers/genesis.py @@ -69,9 +69,12 @@ def create_genesis_state(spec, validator_balances, activation_threshold): if spec.fork not in FORKS_BEFORE_ALTAIR: # Fill in sync committees - state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state)) - state.next_sync_committee = ( - spec.get_sync_committee(state, spec.get_current_epoch(state) + spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD) - ) + current_period = spec.get_current_epoch(state) // spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD + previous_period = current_period - min(1, current_period) + current_base_epoch = current_period * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD + previous_base_epoch = previous_period * spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD + + state.current_sync_committee = spec.get_sync_committee(state, previous_base_epoch) + state.next_sync_committee = spec.get_sync_committee(state, current_base_epoch) return state