Exemplo n.º 1
0
def get_genesis_crystallized_state(
        validators: List['ValidatorRecord'], init_shuffling_seed: Hash32,
        beacon_config: 'BeaconConfig') -> CrystallizedState:

    current_dynasty = 1
    crosslinking_start_shard = 0

    shard_and_committee_for_slots = get_new_shuffling(
        init_shuffling_seed,
        validators,
        current_dynasty,
        crosslinking_start_shard,
        beacon_config=beacon_config,
    )
    # concatenate with itself to span 2*CYCLE_LENGTH
    shard_and_committee_for_slots = shard_and_committee_for_slots + shard_and_committee_for_slots

    return CrystallizedState(
        validators=validators,
        last_state_recalc=0,
        shard_and_committee_for_slots=shard_and_committee_for_slots,
        last_justified_slot=0,
        justified_streak=0,
        last_finalized_slot=0,
        current_dynasty=current_dynasty,
        crosslink_records=[
            CrosslinkRecord(
                dynasty=0,
                slot=0,
                hash=ZERO_HASH32,
            ) for _ in range(beacon_config.shard_count)
        ],
        dynasty_seed=init_shuffling_seed,
        dynasty_start=0,
    )
Exemplo n.º 2
0
def test_get_new_shuffling_is_complete(genesis_validators,
                                       cycle_length,
                                       min_committee_size,
                                       shard_count):
    dynasty = 1

    shuffling = get_new_shuffling(
        seed=b'\x35' * 32,
        validators=genesis_validators,
        dynasty=dynasty,
        crosslinking_start_shard=0,
        cycle_length=cycle_length,
        min_committee_size=min_committee_size,
        shard_count=shard_count,
    )

    assert len(shuffling) == cycle_length
    validators = set()
    shards = set()
    for slot_indices in shuffling:
        for shard_and_committee in slot_indices:
            shards.add(shard_and_committee.shard_id)
            for validator_index in shard_and_committee.committee:
                validators.add(validator_index)

    assert len(validators) == len(genesis_validators)
Exemplo n.º 3
0
def test_get_new_shuffling_handles_shard_wrap(genesis_validators,
                                              beacon_config):
    dynasty = 1

    shuffling = get_new_shuffling(b'\x35' * 32, genesis_validators, dynasty,
                                  beacon_config.shard_count - 1, beacon_config)

    # shard assignments should wrap around to 0 rather than continuing to SHARD_COUNT
    for slot_indices in shuffling:
        for shard_and_committee in slot_indices:
            assert shard_and_committee.shard_id < beacon_config.shard_count
Exemplo n.º 4
0
def test_get_new_shuffling_handles_shard_wrap(genesis_validators, epoch_length,
                                              target_committee_size,
                                              shard_count):
    shuffling = get_new_shuffling(
        seed=b'\x35' * 32,
        validators=genesis_validators,
        crosslinking_start_shard=shard_count - 1,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count,
    )

    # shard assignments should wrap around to 0 rather than continuing to SHARD_COUNT
    for slot_indices in shuffling:
        for shard_committee in slot_indices:
            assert shard_committee.shard < shard_count
Exemplo n.º 5
0
def test_get_new_shuffling_is_complete(genesis_validators, beacon_config):
    dynasty = 1

    shuffling = get_new_shuffling(b'\x35' * 32, genesis_validators, dynasty, 0,
                                  beacon_config)

    assert len(shuffling) == beacon_config.cycle_length
    validators = set()
    shards = set()
    for slot_indices in shuffling:
        for shard_and_committee in slot_indices:
            shards.add(shard_and_committee.shard_id)
            for validator_index in shard_and_committee.committee:
                validators.add(validator_index)

    assert len(validators) == len(genesis_validators)
Exemplo n.º 6
0
def get_genesis_crystallized_state(
        validators: Sequence['ValidatorRecord'],
        init_shuffling_seed: Hash32,
        cycle_length: int,
        min_committee_size: int,
        shard_count: int) -> CrystallizedState:

    current_dynasty = 1
    crosslinking_start_shard = 0

    shard_and_committee_for_slots = get_new_shuffling(
        seed=init_shuffling_seed,
        validators=validators,
        dynasty=current_dynasty,
        crosslinking_start_shard=crosslinking_start_shard,
        cycle_length=cycle_length,
        min_committee_size=min_committee_size,
        shard_count=shard_count,
    )
    # concatenate with itself to span 2*CYCLE_LENGTH
    shard_and_committee_for_slots = shard_and_committee_for_slots + shard_and_committee_for_slots

    return CrystallizedState(
        validators=validators,
        last_state_recalc=0,
        shard_and_committee_for_slots=shard_and_committee_for_slots,
        last_justified_slot=0,
        justified_streak=0,
        last_finalized_slot=0,
        current_dynasty=current_dynasty,
        crosslink_records=[
            CrosslinkRecord(
                dynasty=0,
                slot=0,
                hash=ZERO_HASH32,
            )
            for _ in range(shard_count)
        ],
        dynasty_seed=init_shuffling_seed,
        dynasty_start=0,
    )
Exemplo n.º 7
0
def test_get_new_shuffling_is_complete(genesis_validators, epoch_length,
                                       target_committee_size, shard_count):
    shuffling = get_new_shuffling(
        seed=b'\x35' * 32,
        validators=genesis_validators,
        crosslinking_start_shard=0,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count,
    )

    assert len(shuffling) == epoch_length
    validators = set()
    shards = set()
    for slot_indices in shuffling:
        for shard_committee in slot_indices:
            shards.add(shard_committee.shard)
            for validator_index in shard_committee.committee:
                validators.add(validator_index)

    assert len(validators) == len(genesis_validators)
Exemplo n.º 8
0
def genesis_state(sample_beacon_state_params, genesis_validators, epoch_length,
                  target_committee_size, initial_slot_number, shard_count,
                  latest_block_roots_length):
    initial_shuffling = get_new_shuffling(
        seed=ZERO_HASH32,
        validators=genesis_validators,
        crosslinking_start_shard=0,
        epoch_length=epoch_length,
        target_committee_size=target_committee_size,
        shard_count=shard_count)

    return BeaconState(**sample_beacon_state_params).copy(
        validator_registry=genesis_validators,
        shard_committees_at_slots=initial_shuffling + initial_shuffling,
        latest_block_roots=tuple(ZERO_HASH32
                                 for _ in range(latest_block_roots_length)),
        latest_crosslinks=tuple(
            CrosslinkRecord(
                slot=initial_slot_number,
                shard_block_root=ZERO_HASH32,
            ) for _ in range(shard_count)))