Ejemplo n.º 1
0
def explain_default_size():
    attestation_record = AttestationRecord()
    block = Block()
    crosslink_record = CrosslinkRecord()
    shard_and_committee = ShardAndCommittee()
    crystallized_state = CrystallizedState()

    attestation_record_bytes = msgpack.packb(attestation_record, default=messages.encode_attestation)
    block_bytes = msgpack.packb(block, default=messages.encode_block)
    crosslink_record_bytes = msgpack.packb(crosslink_record, default=messages.encode_crosslink)
    validator_record_bytes = 0
    shard_and_committee_bytes = msgpack.packb(shard_and_committee, default=messages.encode_shard_and_committee)
    crystallized_state_bytes = msgpack.packb(crystallized_state, default=messages.encode_crystallized_state)

    if (verbose):
        print('{} | {}'.format(len(attestation_record_bytes), attestation_record_bytes))
        print('{} | {}'.format(len(block_bytes), block_bytes))
        print('{} | {}'.format(len(shard_and_committee_bytes), shard_and_committee_bytes))
        print('{} | {}'.format(len(crosslink_record_bytes), crosslink_record_bytes))
        print('{} | {}'.format(len(validator_record_bytes), validator_record_bytes))
        print('{} | {}'.format(len(crystallized_state_bytes), crystallized_state_bytes))

    return {
        'attestationRecord': len(attestation_record_bytes),
        'block': len(block_bytes),
        'shardAndCommittee': len(shard_and_committee_bytes),
        'crosslinkRecord': len(crosslink_record_bytes),
        'validatorRecord': "N/A",
        'crystallizedState': len(crystallized_state_bytes),
    }
Ejemplo n.º 2
0
def genesis_crystallized_state(init_validator_keys,
                               init_shuffling_seed,
                               config):
    return CrystallizedState(
        active_validators=[ValidatorRecord(
            pubkey=pub,
            withdrawal_shard=0,
            withdrawal_address=blake(pub.to_bytes(32, 'big'))[-20:],
            randao_commitment=b'\x55'*32,
            balance=DEFAULT_BALANCE,
            switch_dynasty=DEFAULT_SWITCH_DYNASTY
        ) for pub in init_validator_keys],
        queued_validators=[],
        exited_validators=[],
        current_shuffling=get_shuffling(init_shuffling_seed, len(init_validator_keys), config=config),
        current_epoch=1,
        last_justified_epoch=0,
        last_finalized_epoch=0,
        dynasty=1,
        next_shard=0,
        current_checkpoint=blake(b'insert EOS constitution here'),
        crosslink_records=[
            CrosslinkRecord(hash=b'\x00'*32, epoch=0) for i in range(SHARD_COUNT)
        ],
        total_deposits=DEFAULT_BALANCE*len(init_validator_keys)
    )
Ejemplo n.º 3
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)
def test_num_properties(config):
    active_validators = [
        mock_validator_record(pubkey, config)
        for pubkey in range(2)
    ]
    queued_validators = [
        mock_validator_record(pubkey, config)
        for pubkey in range(3)
    ]
    exited_validators = [
        mock_validator_record(pubkey, config)
        for pubkey in range(4)
    ]
    crosslink_records = [
        CrosslinkRecord(hash=b'\x00'*32, epoch=0) for i in range(5)
    ]

    crystallized_state = CrystallizedState(
        active_validators=active_validators,
        queued_validators=queued_validators,
        exited_validators=exited_validators,
        current_shuffling=active_validators,
        crosslink_records=crosslink_records,
    )

    assert crystallized_state.num_active_validators == 2
    assert crystallized_state.num_queued_validators == 3
    assert crystallized_state.num_exited_validators == 4
    assert crystallized_state.num_crosslink_records == 5
Ejemplo n.º 5
0
def explain_default_size():
    """
    Show the size of the serialized object with defaults
    Note: ValidatorRecord omitted (has no defaults)
    """
    attestation_record = AttestationRecord()
    block = Block()
    crosslink_record = CrosslinkRecord()
    shard_and_committee = ShardAndCommittee()
    crystallized_state = CrystallizedState()

    attestation_record_bytes = serialize(attestation_record, type(attestation_record))
    block_bytes = serialize(block, type(block))
    crosslink_record_bytes = serialize(crosslink_record, type(crosslink_record))
    shard_and_committee_bytes = serialize(shard_and_committee, type(shard_and_committee))
    crystallized_state_bytes = serialize(crystallized_state, type(crystallized_state))

    if (verbose):
        print('{} | {}'.format(len(attestation_record_bytes), attestation_record_bytes))
        print('{} | {}'.format(len(block_bytes), block_bytes))
        print('{} | {}'.format(len(shard_and_committee_bytes), shard_and_committee_bytes))
        print('{} | {}'.format(len(crosslink_record_bytes), crosslink_record_bytes))
        print('{} | {}'.format(len(crystallized_state_bytes), crystallized_state_bytes))

    return {
        'attestationRecord': len(attestation_record_bytes),
        'block': len(block_bytes),
        'shardAndCommittee': len(shard_and_committee_bytes),
        'crosslinkRecord': len(crosslink_record_bytes),
        'validatorRecord': "N/A",
        'crystallizedState': len(crystallized_state_bytes),
    }
Ejemplo n.º 6
0
def explain_default_size():
    attestation_record = AttestationRecord()
    block = Block()
    crosslink_record = CrosslinkRecord()
    shard_and_committee = ShardAndCommittee()
    crystallized_state = CrystallizedState()

    attestation_record_bytes = pickle.dumps(attestation_record)
    block_bytes = pickle.dumps(block)
    crosslink_record_bytes = pickle.dumps(crosslink_record)
    shard_and_committee_bytes = pickle.dumps(shard_and_committee)
    crystallized_state_bytes = pickle.dumps(crystallized_state)

    if (verbose):
        print('{} | {}'.format(len(attestation_record_bytes), attestation_record_bytes))
        print('{} | {}'.format(len(block_bytes), block_bytes))
        print('{} | {}'.format(len(shard_and_committee_bytes), shard_and_committee_bytes))
        print('{} | {}'.format(len(crosslink_record_bytes), crosslink_record_bytes))
        print('{} | {}'.format(len(crystallized_state_bytes), crystallized_state_bytes))

    return {
        'attestationRecord': len(attestation_record_bytes),
        'block': len(block_bytes),
        'shardAndCommittee': len(shard_and_committee_bytes),
        'crosslinkRecord': len(crosslink_record_bytes),
        'validatorRecord': "N/A",
        'crystallizedState': len(crystallized_state_bytes),
    }
def test_num_crosslink_records(expected):
    crosslink_records = [
        CrosslinkRecord() for i in range(expected)
    ]
    crystallized_state = CrystallizedState(
        crosslink_records=crosslink_records,
    )

    assert crystallized_state.num_crosslink_records == expected
Ejemplo n.º 8
0
def test_defaults(param, default_value, sample_crosslink_record_params):
    del sample_crosslink_record_params[param]
    crosslink = CrosslinkRecord(**sample_crosslink_record_params)

    assert getattr(crosslink, param) == default_value
Ejemplo n.º 9
0
def explain_maxval_size():
    # Attestation Record
    # TODO replace oblique hash loop with correct size
    obl_hashes = []
    for i in range(0, 64):
        obl_hashes.append(helpers.MAX_BYTES)

    attestation_record = AttestationRecord(
        slot=helpers.MAX_I64,
        shard_id=helpers.MAX_I16,
        oblique_parent_hashes=obl_hashes,
        shard_block_hash=helpers.MAX_BYTES,
        attester_bitfield=helpers.MAX_BYTES,
        aggregate_sig=[helpers.MAX_256, helpers.MAX_256]
    )

    # Blocks
    # TODO: provide realistic number for attestations
    attestations = []
    for i in range(0, helpers.MAX_ATTESTATIONS):
        attestations.append(attestation_record)

    block = Block(
        parent_hash=helpers.MAX_BYTES,
        slot_number=helpers.MAX_I64,
        randao_reveal=helpers.MAX_BYTES,
        attestations=attestations,
        pow_chain_ref=helpers.MAX_BYTES,
        active_state_root=helpers.MAX_BYTES,
        crystallized_state_root=helpers.MAX_BYTES,
    )

    # Crosslink Record
    crosslink_record = CrosslinkRecord(
        hash=helpers.MAX_BYTES,
        dynasty=helpers.MAX_I64,
    )

    # Validator Record
    validator_record = ValidatorRecord(
        pubkey=helpers.MAX_256,
        withdrawal_shard=helpers.MAX_I16,
        withdrawal_address=helpers.ADDRESS_BYTES,
        randao_commitment=helpers.MAX_BYTES,
        balance=helpers.MAX_I64,
        start_dynasty=helpers.MAX_I64,
        end_dynasty=helpers.MAX_I64,
    )

    # Shard and Committee
    # TODO: replace placeholder
    committees = []
    for i in range(0, helpers.PLACEHOLDER):
        committees.append(helpers.MAX_I16)

    shard_and_committee = ShardAndCommittee(
        shard_id=helpers.MAX_I16,
        committee=committees,
    )

    # Crystallized State
    validatorlist = []
    for i in range(0, helpers.MAX_VALIDATORS):
        validatorlist.append(validator_record)

    # TODO: replace placeholder
    crosslinklist = []
    for i in range(0, helpers.PLACEHOLDER):
        crosslinklist.append(crosslink_record)

    # TODO: replace placeholder
    indices_heights = []
    for i in range(0, helpers.PLACEHOLDER):
        tmp = []
        for j in range(0, 10):
            tmp.append(shard_and_committee)
        indices_heights.append(tmp)

    crystallized_state = CrystallizedState(
        validators=validatorlist,
        indices_for_heights=indices_heights,
        last_justified_slot=helpers.MAX_I64,
        justified_streak=helpers.MAX_I64,
        last_finalized_slot=helpers.MAX_I64,
        current_dynasty=helpers.MAX_I64,
        crosslinking_start_shard=helpers.MAX_I16,
        crosslink_records=crosslinklist,
        total_deposits=helpers.MAX_256,
        dynasty_seed=helpers.MAX_BYTES,
        dynasty_seed_last_reset=helpers.MAX_I64,
        last_state_recalc=helpers.MAX_I64,
    )

    attestation_record_bytes = msgpack.packb(attestation_record, default=messages.encode_attestation)
    block_bytes = msgpack.packb(block, default=messages.encode_block)
    crosslink_record_bytes = msgpack.packb(crosslink_record, default=messages.encode_crosslink)
    validator_record_bytes = msgpack.packb(validator_record, default=messages.encode_validator_record)
    shard_and_committee_bytes = msgpack.packb(shard_and_committee, default=messages.encode_shard_and_committee)
    crystallized_state_bytes = msgpack.packb(crystallized_state, default=messages.encode_crystallized_state)

    if (verbose):
        print('{} | {}'.format(len(attestation_record_bytes), attestation_record_bytes))
        print('{} | {}'.format(len(block_bytes), block_bytes))
        print('{} | {}'.format(len(shard_and_committee_bytes), shard_and_committee_bytes))
        print('{} | {}'.format(len(crosslink_record_bytes), crosslink_record_bytes))
        print('{} | {}'.format(len(validator_record_bytes), validator_record_bytes))
        print('{} | {}'.format(len(crystallized_state_bytes), crystallized_state_bytes))

    return {
        'attestationRecord': len(attestation_record_bytes),
        'block': len(block_bytes),
        'shardAndCommittee': len(shard_and_committee_bytes),
        'crosslinkRecord': len(crosslink_record_bytes),
        'validatorRecord': len(validator_record_bytes),
        'crystallizedState': len(crystallized_state_bytes),
    }