Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize description of crosslink and persistent committee selection #729

Closed
vbuterin opened this issue Mar 7, 2019 · 1 comment
Closed
Labels
general:presentation Presentation (as opposed to content)

Comments

@vbuterin
Copy link
Contributor

vbuterin commented Mar 7, 2019

Both phase 0 and phase 1 have code for committee selection that seems to be doing a fundamentally almost identical task, but where code is arguably needlessly duplicated.

The two use different patterns to express what is ultimately the same logic. In crosslink committee selection (phase 0), the logic is in get_shuffling which is used exactly once:

    shuffling = get_shuffling(
        seed,
        state.validator_registry,
        shuffling_epoch,
    )
    offset = slot % SLOTS_PER_EPOCH
    committees_per_slot = committees_per_epoch // SLOTS_PER_EPOCH
    slot_start_shard = (shuffling_start_shard + committees_per_slot * offset) % SHARD_COUNT

    return [
        (
            shuffling[committees_per_slot * offset + i],
            (slot_start_shard + i) % SHARD_COUNT,
        )
        for i in range(committees_per_slot)
    ]

In persistent committee selection (phase 1), the core function is instead get_shuffled_committee, which returns only a single committee instead of a split of the entire validator set.

One way to harmonize the two by having functions as follows (note that this is a non-substantive change; it is purely a change in presentation):

def get_shuffled_committee(validator_indices: [int],
                           seed: Bytes32,
                           index: int,
                           total_committees: int) -> List[ValidatorIndex]:
    """
    Return shuffled committee.
    """
    validator_indices = get_active_validator_indices(state.validator_registry, committee_start_epoch)
    start_offset = get_split_offset(len(validator_indices), total_committees, index)
    end_offset = get_split_offset(len(validator_indices), total_committees, index + 1)
    return [
        validator_indices[get_permuted_index(i, len(validator_indices), seed)]
        for i in range(start_offset, end_offset)
    ]

In phase 0, we now replace the code with:

    indices = get_active_validator_indices(state.validator_registry, shuffling_epoch)
    committee_count = get_epoch_committee_count(len(indices))
    committees_per_slot = committee_count // EPOCH_LENGTH
    return [
        (
            get_shuffled_committee(indices, seed, committees_per_slot * offset + i, committee_count)
            (slot_start_shard + i) % SHARD_COUNT,
        )
        for i in range(committees_per_slot)
    ]

In phase 1, we now replace the code with:

def get_persistent_shuffled_committee(state: BeaconState,
                                     shard: Shard,
                                     committee_start_epoch: Epoch) -> List[ValidatorIndex]:
    seed = generate_seed(state, committee_start_epoch)
    return get_shuffled_committee(state.validator_registry, seed, shard, SHARD_COUNT)

This also allows us to remove the split function, as with the removal of get_shuffling we no longer use it.

@vbuterin vbuterin changed the title Harmonize crosslink and persistent committee selection Harmonize description of crosslink and persistent committee selection Mar 7, 2019
vbuterin added a commit that referenced this issue Mar 15, 2019
See #729 and #774 

The behavior now is that the first committee will consist of `get_permuted_index(0..n-1)`, the second committee `get_permuted_index(n....2n-1)`, etc.
@JustinDrake JustinDrake added the general:presentation Presentation (as opposed to content) label Mar 27, 2019
@JustinDrake
Copy link
Collaborator

Addressed in #776 I believe :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general:presentation Presentation (as opposed to content)
Projects
None yet
Development

No branches or pull requests

2 participants