コード例 #1
0
def genesis_crystallized_state(genesis_validators, init_shuffling_seed,
                               config):
    current_dynasty = 1
    crosslinking_start_shard = 0
    validators = genesis_validators

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

    return CrystallizedState(validators=validators,
                             epoch_number=0,
                             indices_for_heights=indices_for_heights,
                             last_justified_slot=0,
                             justified_streak=0,
                             last_finalized_slot=0,
                             current_dynasty=current_dynasty,
                             crosslinking_start_shard=crosslinking_start_shard,
                             crosslink_records=[
                                 CrosslinkRecord(hash=b'\x00' * 32, dynasty=0)
                                 for i in range(config['shard_count'])
                             ],
                             total_deposits=config['deposit_size'] *
                             len(validators),
                             dynasty_seed=init_shuffling_seed,
                             dynasty_seed_last_reset=1)
コード例 #2
0
def test_get_new_shuffling_handles_shard_wrap(genesis_validators, config):
    dynasty = 1

    shuffling = get_new_shuffling(b'\x35' * 32, genesis_validators, dynasty,
                                  config['shard_count'] - 1, 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 < config['shard_count']
コード例 #3
0
def test_get_new_shuffling_is_complete(genesis_validators, config):
    dynasty = 1

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

    assert len(shuffling) == 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 vi in shard_and_committee.committee:
                validators.add(vi)

    # assert len(shards) == config['shard_count']
    assert len(validators) == len(genesis_validators)
コード例 #4
0
ファイル: experiment_1.py プロジェクト: sigp/eth2.0-resources
    'cycle_length': CYCLE_LENGTH,
    'min_committee_size': MIN_COMMITTEE_SIZE,
    'shard_count': SHARD_COUNT
}
for validator_count in range(VALIDATOR_COUNT, VALIDATOR_COUNT + 1):
    # Setup for the cycle
    seed = b"\x00" * 32
    validators = [
        ValidatorRecord(start_dynasty=0, end_dynasty=10)
        for _ in range(validator_count)
    ]
    dynasty = 1
    crosslinking_start_shard = 0

    # Generate the cycle
    cycle = get_new_shuffling(seed, validators, dynasty,
                              crosslinking_start_shard, config)

    # Recurse into the cycle and add each shard id to the
    # accumlative set.
    for slot in cycle:
        for sac in slot:
            assigned_shards.add(sac.shard_id)
            committee_sizes.append(len(sac.committee))

    # Calculate how many shards we think should be possible.
    expected_shard_count = min(SHARD_COUNT,
                               VALIDATOR_COUNT // MIN_COMMITTEE_SIZE)
    # Find how many shards were attested to in total
    assigned_shard_count = len(assigned_shards)
    # Find the average committee size
    average_committee_size = sum(committee_sizes) / len(committee_sizes)