Beispiel #1
0
def get_crosslink_committees_at_slot(
    state: 'BeaconState', slot: SlotNumber, genesis_epoch: EpochNumber,
    epoch_length: int, target_committee_size: int, shard_count: int
) -> Iterable[Tuple[Iterable[ValidatorIndex], ShardNumber]]:
    """
    Return the list of ``(committee, shard)`` tuples for the ``slot``.
    """

    epoch = slot_to_epoch(slot, epoch_length)
    current_epoch = state.current_epoch(epoch_length)

    validate_epoch_for_current_epoch(
        current_epoch=current_epoch,
        given_epoch=epoch,
        genesis_epoch=genesis_epoch,
        epoch_length=epoch_length,
    )

    # TODO: need to update according to https://github.com/ethereum/eth2.0-specs/pull/520
    if epoch < current_epoch:
        committees_per_epoch = get_previous_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        seed = state.previous_epoch_seed
        shuffling_epoch = state.previous_calculation_epoch
        shuffling_start_shard = state.previous_epoch_start_shard
    else:
        committees_per_epoch = get_current_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        seed = state.current_epoch_seed
        shuffling_epoch = state.current_calculation_epoch
        shuffling_start_shard = state.current_epoch_start_shard

    shuffling = get_shuffling(
        seed=seed,
        validators=state.validator_registry,
        epoch=shuffling_epoch,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count,
    )
    offset = slot % epoch_length
    committees_per_slot = committees_per_epoch // epoch_length
    slot_start_shard = (shuffling_start_shard +
                        committees_per_slot * offset) % shard_count

    for index in range(committees_per_slot):
        committee = shuffling[committees_per_slot * offset + index]
        yield (
            committee,
            ShardNumber((slot_start_shard + index) % shard_count),
        )
Beispiel #2
0
def get_crosslink_committees_at_slot(
    state: 'BeaconState', slot: SlotNumber, epoch_length: int,
    target_committee_size: int, shard_count: int
) -> Iterable[Tuple[Iterable[ValidatorIndex], ShardNumber]]:
    """
    Return the list of ``(committee, shard)`` tuples for the ``slot``.
    """
    validate_slot_for_state_slot(
        state_slot=state.slot,
        slot=slot,
        epoch_length=epoch_length,
    )

    state_epoch_slot = state.slot - (state.slot % epoch_length)
    offset = slot % epoch_length

    if slot < state_epoch_slot:
        committees_per_slot = get_previous_epoch_committee_count_per_slot(
            state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )

        seed = state.previous_epoch_randao_mix
        shuffling_slot = state.previous_epoch_calculation_slot
        shuffling_start_shard = state.previous_epoch_start_shard
    else:
        committees_per_slot = get_current_epoch_committee_count_per_slot(
            state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        seed = state.current_epoch_randao_mix
        shuffling_slot = state.current_epoch_calculation_slot
        shuffling_start_shard = state.current_epoch_start_shard

    offset = slot % epoch_length
    shuffling = get_shuffling(
        seed=seed,
        validators=state.validator_registry,
        slot=shuffling_slot,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count,
    )
    slot_start_shard = (shuffling_start_shard +
                        committees_per_slot * offset) % shard_count

    for index in range(committees_per_slot):
        committee = shuffling[committees_per_slot * offset + index]
        yield (
            committee,
            ShardNumber((slot_start_shard + index) % shard_count),
        )
Beispiel #3
0
def _get_shards_committees_for_shard_indices(
        shard_indices: Sequence[Sequence[ValidatorIndex]],
        start_shard: ShardNumber, total_validator_count: int,
        shard_count: int) -> Iterable[ShardCommittee]:
    """
    Return filled [ShardCommittee] tuple.
    """
    for index, indices in enumerate(shard_indices):
        yield ShardCommittee(
            shard=ShardNumber((start_shard + index) % shard_count),
            committee=indices,
            total_validator_count=total_validator_count,
        )
Beispiel #4
0
def get_crosslink_committees_at_slot(
    state: 'BeaconState',
    slot: SlotNumber,
    committee_config: CommitteeConfig,
    registry_change: bool = False
) -> Iterable[Tuple[Iterable[ValidatorIndex], ShardNumber]]:
    """
    Return the list of ``(committee, shard)`` tuples for the ``slot``.
    """
    genesis_epoch = committee_config.GENESIS_EPOCH
    shard_count = committee_config.SHARD_COUNT
    epoch_length = committee_config.EPOCH_LENGTH
    target_committee_size = committee_config.TARGET_COMMITTEE_SIZE

    seed_lookahead = committee_config.SEED_LOOKAHEAD
    entry_exit_delay = committee_config.ENTRY_EXIT_DELAY
    latest_index_roots_length = committee_config.LATEST_INDEX_ROOTS_LENGTH
    latest_randao_mixes_length = committee_config.LATEST_RANDAO_MIXES_LENGTH

    epoch = slot_to_epoch(slot, epoch_length)
    current_epoch = state.current_epoch(epoch_length)
    previous_epoch = state.previous_epoch(epoch_length, genesis_epoch)
    next_epoch = state.next_epoch(epoch_length)

    validate_epoch_for_current_epoch(
        current_epoch=current_epoch,
        given_epoch=epoch,
        genesis_epoch=genesis_epoch,
    )

    if epoch == previous_epoch:
        committees_per_epoch = get_previous_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        seed = state.previous_epoch_seed
        shuffling_epoch = state.previous_calculation_epoch
        shuffling_start_shard = state.previous_epoch_start_shard
    elif epoch == current_epoch:
        committees_per_epoch = get_current_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        seed = state.current_epoch_seed
        shuffling_epoch = state.current_calculation_epoch
        shuffling_start_shard = state.current_epoch_start_shard
    elif epoch == next_epoch:
        current_committees_per_epoch = get_current_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        committees_per_epoch = get_next_epoch_committee_count(
            state=state,
            shard_count=shard_count,
            epoch_length=epoch_length,
            target_committee_size=target_committee_size,
        )
        shuffling_epoch = next_epoch
        epochs_since_last_registry_update = current_epoch - state.validator_registry_update_epoch
        should_reseed = (epochs_since_last_registry_update > 1 and
                         is_power_of_two(epochs_since_last_registry_update))

        if registry_change:
            # for mocking this out in tests.
            seed = helpers.generate_seed(
                state=state,
                epoch=next_epoch,
                epoch_length=epoch_length,
                seed_lookahead=seed_lookahead,
                entry_exit_delay=entry_exit_delay,
                latest_index_roots_length=latest_index_roots_length,
                latest_randao_mixes_length=latest_randao_mixes_length,
            )
            shuffling_start_shard = (
                state.current_epoch_start_shard +
                current_committees_per_epoch) % shard_count
        elif should_reseed:
            # for mocking this out in tests.
            seed = helpers.generate_seed(
                state=state,
                epoch=next_epoch,
                epoch_length=epoch_length,
                seed_lookahead=seed_lookahead,
                entry_exit_delay=entry_exit_delay,
                latest_index_roots_length=latest_index_roots_length,
                latest_randao_mixes_length=latest_randao_mixes_length,
            )
            shuffling_start_shard = state.current_epoch_start_shard
        else:
            seed = state.current_epoch_seed
            shuffling_start_shard = state.current_epoch_start_shard

    shuffling = get_shuffling(
        seed=seed,
        validators=state.validator_registry,
        epoch=shuffling_epoch,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count,
    )
    offset = slot % epoch_length
    committees_per_slot = committees_per_epoch // epoch_length
    slot_start_shard = (shuffling_start_shard +
                        committees_per_slot * offset) % shard_count

    for index in range(committees_per_slot):
        committee = shuffling[committees_per_slot * offset + index]
        yield (
            committee,
            ShardNumber((slot_start_shard + index) % shard_count),
        )
Beispiel #5
0
    ZERO_ADDRESS, )
from eth2.beacon.state_machines.configs import BeaconConfig
from eth2.beacon.typing import (
    SlotNumber,
    ShardNumber,
    Ether,
    Second,
)

SERENITY_CONFIG = BeaconConfig(
    # Misc
    SHARD_COUNT=2**10,  # (= 1,024) shards
    TARGET_COMMITTEE_SIZE=2**7,  # (= 128) validators
    EJECTION_BALANCE=Ether(2**4),  # (= 16) ETH
    MAX_BALANCE_CHURN_QUOTIENT=2**5,  # (= 32)
    BEACON_CHAIN_SHARD_NUMBER=ShardNumber(2**64 - 1),
    MAX_CASPER_VOTES=2**10,  # (= 1,024) votes
    LATEST_BLOCK_ROOTS_LENGTH=2**13,  # (= 8,192) block roots
    LATEST_RANDAO_MIXES_LENGTH=2**13,  # (= 8,192) randao mixes
    LATEST_PENALIZED_EXIT_LENGTH=2**13,  # (= 8,192) randao mixes
    # Deposit contract
    DEPOSIT_CONTRACT_ADDRESS=ZERO_ADDRESS,  # TBD
    DEPOSIT_CONTRACT_TREE_DEPTH=2**5,  # (= 32)
    MIN_DEPOSIT=Ether(2**0),  # (= 1) ETH
    MAX_DEPOSIT=Ether(2**5),  # (= 32) ETH
    # Initial values
    GENESIS_FORK_VERSION=0,
    GENESIS_SLOT=SlotNumber(0),
    GENESIS_START_SHARD=ShardNumber(0),
    BLS_WITHDRAWAL_PREFIX_BYTE=b'\x00',
    # Time parameters
Beispiel #6
0
    ZERO_ADDRESS, )
from eth2.beacon.state_machines.configs import BeaconConfig
from eth2.beacon.typing import (
    SlotNumber,
    ShardNumber,
    Ether,
    Second,
)

SERENITY_CONFIG = BeaconConfig(
    # Misc
    SHARD_COUNT=2**10,  # (= 1,024) shards
    TARGET_COMMITTEE_SIZE=2**7,  # (= 128) validators
    EJECTION_BALANCE=Ether(2**4),  # (= 16) ETH
    MAX_BALANCE_CHURN_QUOTIENT=2**5,  # (= 32)
    BEACON_CHAIN_SHARD_NUMBER=ShardNumber(2**64 - 1),
    MAX_CASPER_VOTES=2**10,  # (= 1,024) votes
    LATEST_BLOCK_ROOTS_LENGTH=2**13,  # (= 8,192) block roots
    LATEST_RANDAO_MIXES_LENGTH=2**13,  # (= 8,192) randao mixes
    LATEST_PENALIZED_EXIT_LENGTH=2**13,  # (= 8,192) randao mixes
    # Deposit contract
    DEPOSIT_CONTRACT_ADDRESS=ZERO_ADDRESS,  # TBD
    DEPOSIT_CONTRACT_TREE_DEPTH=2**5,  # (= 32)
    MIN_DEPOSIT=Ether(2**0),  # (= 1) ETH
    MAX_DEPOSIT=Ether(2**5),  # (= 32) ETH
    # Initial values
    GENESIS_FORK_VERSION=0,
    GENESIS_SLOT=SlotNumber(0),
    BLS_WITHDRAWAL_PREFIX_BYTE=b'\x00',
    # Time parameters
    SLOT_DURATION=Second(6),  # seconds