mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-26 10:29:07 +00:00
fix seed calc issue
This commit is contained in:
parent
2747882776
commit
200c049778
@ -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
|
Note: This function is not stable during a sync committee period as
|
||||||
a validator's effective balance may change enough to affect the sampling.
|
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
|
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, epoch)
|
||||||
active_validator_indices = get_active_validator_indices(state, base_epoch)
|
|
||||||
active_validator_count = uint64(len(active_validator_indices))
|
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
|
i = 0
|
||||||
sync_committee_indices: List[ValidatorIndex] = []
|
sync_committee_indices: List[ValidatorIndex] = []
|
||||||
while len(sync_committee_indices) < SYNC_COMMITTEE_SIZE:
|
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:
|
def process_sync_committee_updates(state: BeaconState) -> None:
|
||||||
next_epoch = get_current_epoch(state) + Epoch(1)
|
next_epoch = get_current_epoch(state) + Epoch(1)
|
||||||
if next_epoch % EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
if next_epoch % EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
||||||
|
print("HEEEREEE")
|
||||||
state.current_sync_committee = state.next_sync_committee
|
state.current_sync_committee = state.next_sync_committee
|
||||||
state.next_sync_committee = get_sync_committee(state, next_epoch)
|
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)
|
state.genesis_validators_root = hash_tree_root(state.validators)
|
||||||
|
|
||||||
# [New in Altair] Fill in sync committees
|
# [New in Altair] Fill in sync committees
|
||||||
state.current_sync_committee = get_sync_committee(state, get_current_epoch(state))
|
current_period = get_current_epoch(state) // EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||||
state.next_sync_committee = get_sync_committee(state, 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
|
return state
|
||||||
```
|
```
|
||||||
|
@ -345,10 +345,10 @@ def test_valid_signature_future_committee(spec, state):
|
|||||||
transition_to(spec, state, slot_in_future_sync_committee_period)
|
transition_to(spec, state, slot_in_future_sync_committee_period)
|
||||||
|
|
||||||
sync_committee = state.current_sync_committee
|
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 next_sync_committee == expected_next_sync_committee
|
||||||
|
|
||||||
assert sync_committee == expected_sync_committee
|
|
||||||
assert sync_committee != old_current_sync_committee
|
assert sync_committee != old_current_sync_committee
|
||||||
assert sync_committee != old_next_sync_committee
|
assert sync_committee != old_next_sync_committee
|
||||||
|
|
||||||
|
@ -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
|
# Can compute the third committee having computed final balances in the last epoch
|
||||||
# of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`
|
# of this `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`
|
||||||
current_epoch = spec.get_current_epoch(state)
|
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.current_sync_committee == second_sync_committee
|
||||||
assert state.next_sync_committee == third_sync_committee
|
assert state.next_sync_committee == third_sync_committee
|
||||||
|
@ -69,9 +69,12 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
|
|||||||
|
|
||||||
if spec.fork not in FORKS_BEFORE_ALTAIR:
|
if spec.fork not in FORKS_BEFORE_ALTAIR:
|
||||||
# Fill in sync committees
|
# Fill in sync committees
|
||||||
state.current_sync_committee = spec.get_sync_committee(state, spec.get_current_epoch(state))
|
current_period = spec.get_current_epoch(state) // spec.EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||||
state.next_sync_committee = (
|
previous_period = current_period - min(1, current_period)
|
||||||
spec.get_sync_committee(state, spec.get_current_epoch(state) + spec.EPOCHS_PER_SYNC_COMMITTEE_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
|
return state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user