Example #1
0
def create_signed_attestation_at_slot(state: BeaconState, config: Eth2Config,
                                      state_machine: BaseBeaconStateMachine,
                                      attestation_slot: Slot,
                                      beacon_block_root: Hash32,
                                      validator_privkeys: Dict[ValidatorIndex,
                                                               int],
                                      committee: Tuple[ValidatorIndex, ...],
                                      shard: Shard) -> Attestation:
    """
    Create the attestations of the given ``attestation_slot`` slot with ``validator_privkeys``.
    """
    state_transition = state_machine.state_transition
    state = state_transition.apply_state_transition(
        state,
        future_slot=attestation_slot,
    )

    target_epoch = compute_epoch_of_slot(
        attestation_slot,
        config.SLOTS_PER_EPOCH,
    )

    target_root = _get_target_root(state, config, beacon_block_root)

    parent_crosslink = state.current_crosslinks[shard]

    attestation_data = AttestationData(
        beacon_block_root=beacon_block_root,
        source=Checkpoint(
            epoch=state.current_justified_checkpoint.epoch,
            root=state.current_justified_checkpoint.root,
        ),
        target=Checkpoint(
            root=target_root,
            epoch=target_epoch,
        ),
        crosslink=Crosslink(
            shard=shard,
            parent_root=parent_crosslink.hash_tree_root,
            start_epoch=parent_crosslink.end_epoch,
            end_epoch=target_epoch,
        ))

    return _create_mock_signed_attestation(
        state,
        attestation_data,
        attestation_slot,
        committee,
        len(committee),
        keymapper(lambda index: state.validators[index].pubkey,
                  validator_privkeys),
        config.SLOTS_PER_EPOCH,
    )
Example #2
0
def create_signed_attestation_at_slot(
    state: BeaconState,
    config: Eth2Config,
    state_machine: BaseBeaconStateMachine,
    attestation_slot: Slot,
    beacon_block_root: SigningRoot,
    validator_privkeys: Dict[ValidatorIndex, int],
    committee: Tuple[ValidatorIndex, ...],
    committee_index: CommitteeIndex,
    attesting_indices: Sequence[CommitteeValidatorIndex],
) -> Attestation:
    """
    Create the attestations of the given ``attestation_slot`` slot with ``validator_privkeys``.
    """
    state_transition = state_machine.state_transition
    state = state_transition.apply_state_transition(
        state, future_slot=attestation_slot)

    target_epoch = compute_epoch_at_slot(attestation_slot,
                                         config.SLOTS_PER_EPOCH)

    target_root = _get_target_root(state, config, beacon_block_root)

    attestation_data = AttestationData(
        slot=attestation_slot,
        index=committee_index,
        beacon_block_root=beacon_block_root,
        source=Checkpoint(
            epoch=state.current_justified_checkpoint.epoch,
            root=state.current_justified_checkpoint.root,
        ),
        target=Checkpoint(root=target_root, epoch=target_epoch),
    )

    return _create_mock_signed_attestation(
        state,
        attestation_data,
        attestation_slot,
        committee,
        len(committee),
        keymapper(lambda index: state.validators[index].pubkey,
                  validator_privkeys),
        config.SLOTS_PER_EPOCH,
        is_for_simulation=False,
        attesting_indices=attesting_indices,
    )
Example #3
0
def create_signed_attestation_at_slot(
    state: BeaconState,
    config: Eth2Config,
    state_machine: BaseBeaconStateMachine,
    attestation_slot: Slot,
    beacon_block_root: Root,
    validator_privkeys: Dict[ValidatorIndex, int],
    committee: Tuple[ValidatorIndex, ...],
    committee_index: CommitteeIndex,
    attesting_indices: Sequence[CommitteeValidatorIndex],
) -> Attestation:
    """
    Create the aggregated attestation of the given ``attestation_slot`` slot
    of the given committee.
    """
    state_transition = state_machine.state_transition
    state = state_transition.apply_state_transition(
        state, future_slot=attestation_slot)

    attestation_data = create_atteatsion_data(
        state,
        config,
        state_machine,
        attestation_slot,
        beacon_block_root,
        committee_index,
    )

    return _create_mock_signed_attestation(
        state,
        attestation_data,
        attestation_slot,
        committee,
        len(committee),
        keymapper(lambda index: state.validators[index].pubkey,
                  validator_privkeys),
        config.SLOTS_PER_EPOCH,
        is_for_simulation=False,
        attesting_indices=attesting_indices,
    )