diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 4c32eae4d..dfed19426 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -4,8 +4,8 @@ # Misc # --------------------------------------------------------------- -# [customized] Just 8 shards for testing purposes -SHARD_COUNT: 8 +# [customized] Just 2 committees for slot for testing purposes +COMMITTEES_PER_SLOT: 2 # [customized] unsecure, but fast TARGET_COMMITTEE_SIZE: 4 # 2**12 (= 4,096) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b57aa7ff4..a371df628 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -880,15 +880,16 @@ def get_committee_count(state: BeaconState, epoch: Epoch) -> uint64: #### `get_crosslink_committee` ```python -def get_crosslink_committee(state: BeaconState, epoch: Epoch, index: uint64) -> Sequence[ValidatorIndex]: +def get_crosslink_committee(state: BeaconState, slot: Slot, index: uint64) -> Sequence[ValidatorIndex]: """ Return the crosslink committee at ``epoch`` for ``index``. """ + epoch = compute_epoch_of_slot(slot) return compute_committee( indices=get_active_validator_indices(state, epoch), seed=get_seed(state, epoch, DOMAIN_BEACON_ATTESTER), - index=index, - count=get_committee_count(state, epoch), + index=(slot % SLOTS_PER_EPOCH) * COMMITTEES_PER_SLOT + index, + count=COMMITTEES_PER_SLOT * SLOTS_PER_EPOCH, ) ``` @@ -966,7 +967,7 @@ def get_attesting_indices(state: BeaconState, """ Return the set of attesting indices corresponding to ``data`` and ``bits``. """ - committee = get_crosslink_committee(state, data.target.epoch, data.index) + committee = get_crosslink_committee(state, data.slot, data.index) return set(index for i, index in enumerate(committee) if bits[i]) ``` @@ -1506,7 +1507,7 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None: assert data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot <= data.slot + SLOTS_PER_EPOCH - committee = get_crosslink_committee(state, data.target.epoch, data.index) + committee = get_crosslink_committee(state, data.slot, data.index) assert len(attestation.aggregation_bits) == len(attestation.custody_bits) == len(committee) pending_attestation = PendingAttestation( diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index d43200463..1efdadb35 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -150,7 +150,7 @@ def get_committee_assignment(state: BeaconState, start_slot = compute_start_slot_of_epoch(epoch) for slot in range(start_slot, start_slot + SLOTS_PER_EPOCH): for index in range(COMMITTEES_PER_SLOT): - committee = get_crosslink_committee(state, epoch, index) + committee = get_crosslink_committee(state, Slot(slot), index) if validator_index in committee: return committee, index, Slot(slot) return None diff --git a/test_libs/pyspec/eth2spec/test/helpers/attestations.py b/test_libs/pyspec/eth2spec/test/helpers/attestations.py index 00c25b340..afd51b0bd 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/attestations.py +++ b/test_libs/pyspec/eth2spec/test/helpers/attestations.py @@ -48,7 +48,7 @@ def get_valid_attestation(spec, state, slot=None, index=None, signed=False): crosslink_committee = spec.get_crosslink_committee( state, - attestation_data.target.epoch, + attestation_data.slot, attestation_data.index, ) @@ -117,7 +117,7 @@ def get_attestation_signature(spec, state, attestation_data, privkey, custody_bi def fill_aggregate_attestation(spec, state, attestation): crosslink_committee = spec.get_crosslink_committee( state, - attestation.data.target.epoch, + attestation.data.slot, attestation.data.index, ) for i in range(len(crosslink_committee)): diff --git a/test_libs/pyspec/eth2spec/test/helpers/custody.py b/test_libs/pyspec/eth2spec/test/helpers/custody.py index 4b7c8c97b..98659ee8e 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/custody.py +++ b/test_libs/pyspec/eth2spec/test/helpers/custody.py @@ -82,7 +82,7 @@ def bitlist_from_int(max_len, num_bits, n): def get_valid_bit_challenge(spec, state, attestation, invalid_custody_bit=False): crosslink_committee = spec.get_crosslink_committee( state, - attestation.data.target.epoch, + attestation.data.slot, attestation.data.crosslink.shard, ) responder_index = crosslink_committee[0] diff --git a/test_libs/pyspec/eth2spec/test/helpers/state.py b/test_libs/pyspec/eth2spec/test/helpers/state.py index e88fc6ade..5a2f72ff3 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/state.py +++ b/test_libs/pyspec/eth2spec/test/helpers/state.py @@ -53,13 +53,15 @@ def next_epoch_with_attestations(spec, if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY: slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1 if slot_to_attest >= spec.compute_start_slot_of_epoch(spec.get_current_epoch(post_state)): - cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest) - block.body.attestations.append(cur_attestation) + for index in range(spec.COMMITTEES_PER_SLOT): + cur_attestation = get_valid_attestation(spec, post_state, slot_to_attest, index=index) + block.body.attestations.append(cur_attestation) if fill_prev_epoch: slot_to_attest = post_state.slot - spec.SLOTS_PER_EPOCH + 1 - prev_attestation = get_valid_attestation(spec, post_state, slot_to_attest) - block.body.attestations.append(prev_attestation) + for index in range(spec.COMMITTEES_PER_SLOT): + prev_attestation = get_valid_attestation(spec, post_state, slot_to_attest, index=index) + block.body.attestations.append(prev_attestation) state_transition_and_sign_block(spec, post_state, block) blocks.append(block) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py index 7dcdb42a4..6d1762ecb 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_justification_and_finalization.py @@ -41,7 +41,7 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support if remaining_balance < 0: return - committee = spec.get_crosslink_committee(state, spec.compute_epoch_of_slot(slot), shard) + committee = spec.get_crosslink_committee(state, slot, shard) # Create a bitfield filled with the given count per attestation, # exactly on the right-most part of the committee field.