Beispiel #1
0
def test_get_committee_assignment(genesis_state, slots_per_epoch, shard_count,
                                  config, num_validators, state_epoch, epoch,
                                  registry_change):
    state_slot = get_epoch_start_slot(state_epoch, slots_per_epoch)
    state = genesis_state.copy(slot=state_slot, )
    proposer_count = 0
    shard_validator_count = [0 for _ in range(shard_count)]
    slots = []

    epoch_start_slot = get_epoch_start_slot(epoch, slots_per_epoch)

    for validator_index in range(num_validators):
        assignment = get_committee_assignment(
            state,
            config,
            epoch,
            validator_index,
            registry_change,
        )
        assert assignment.slot >= epoch_start_slot
        assert assignment.slot < epoch_start_slot + slots_per_epoch
        if assignment.is_proposer:
            proposer_count += 1

        shard_validator_count[assignment.shard] += 1
        slots.append(assignment.slot)

    assert proposer_count == slots_per_epoch
    assert sum(shard_validator_count) == num_validators
Beispiel #2
0
def test_get_committee_assignment_no_assignment(genesis_state, genesis_epoch,
                                                slots_per_epoch, config):
    state = genesis_state
    validator_index = 1
    current_epoch = state.current_epoch(slots_per_epoch)
    validator = state.validator_registry[validator_index].copy(
        exit_epoch=genesis_epoch, )
    state = state.update_validator_registry(
        validator_index,
        validator=validator,
    )
    assert not validator.is_active(current_epoch)

    with pytest.raises(NoCommitteeAssignment):
        get_committee_assignment(state, config, current_epoch, validator_index,
                                 True)
Beispiel #3
0
 def _get_this_epoch_assignment(self, validator_index: ValidatorIndex,
                                this_epoch: Epoch) -> CommitteeAssignment:
     # update `this_epoch_assignment` if it's outdated
     if this_epoch > self.this_epoch_assignment[validator_index][0]:
         state_machine = self.chain.get_state_machine()
         state = state_machine.state
         self.this_epoch_assignment[validator_index] = (
             this_epoch,
             get_committee_assignment(
                 state,
                 state_machine.config,
                 this_epoch,
                 validator_index,
                 # FIXME: in simple testnet, `registry_change` is not likely to change
                 # so hardcode it as `False`.
                 registry_change=False,
             ))
     return self.this_epoch_assignment[validator_index][1]