示例#1
0
def add_pending_validator(
        state: BeaconState, validator: ValidatorRecord, deposit: Gwei,
        zero_balance_validator_ttl: int) -> Tuple[BeaconState, ValidatorIndex]:
    """
    Add a validator to the existing minimum empty validator index or
    append to ``validator_registry``.
    """
    # Check if there's empty validator index in `validator_registry`
    try:
        index = get_min_empty_validator_index(
            state.validator_registry,
            state.validator_balances,
            state.slot,
            zero_balance_validator_ttl,
        )
    except MinEmptyValidatorIndexNotFound:
        index = None
        # Append to the validator_registry
        validator_registry = state.validator_registry + (validator, )
        state = state.copy(validator_registry=validator_registry,
                           validator_balances=state.validator_balances +
                           (deposit, ))
        index = ValidatorIndex(len(state.validator_registry) - 1)
    else:
        # Use the empty validator index
        state = state.update_validator(index, validator, deposit)

    return state, index
示例#2
0
def process_attestations(state: BeaconState,
                         block: BaseBeaconBlock,
                         config: BeaconConfig) -> BeaconState:
    """
    Implements 'per-block-processing.operations.attestations' portion of Phase 0 spec:
    https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#attestations-1

    Validate the ``attestations`` contained within the ``block`` in the context of ``state``.
    If any invalid, throw ``ValidationError``.
    Otherwise, append an ``PendingAttestationRecords`` for each to ``latest_attestations``.
    Return resulting ``state``.
    """
    for attestation in block.body.attestations:
        validate_serenity_attestation(
            state,
            attestation,
            config.EPOCH_LENGTH,
            config.MIN_ATTESTATION_INCLUSION_DELAY,
            config.LATEST_BLOCK_ROOTS_LENGTH,
        )

    # update_latest_attestations
    additional_pending_attestations = tuple(
        PendingAttestationRecord(
            data=attestation.data,
            participation_bitfield=attestation.participation_bitfield,
            custody_bitfield=attestation.custody_bitfield,
            slot_included=state.slot,
        )
        for attestation in block.body.attestations
    )
    state = state.copy(
        latest_attestations=state.latest_attestations + additional_pending_attestations,
    )
    return state
示例#3
0
 def per_slot_transition(self,
                         state: BeaconState,
                         previous_block_root: Hash32) -> BeaconState:
     # TODO
     state = state.copy(
         slot=state.slot + 1
     )
     return state
示例#4
0
def add_pending_validator(state: BeaconState, validator: ValidatorRecord,
                          amount: Gwei) -> BeaconState:
    """
    Add a validator to ``state``.
    """
    state = state.copy(
        validator_registry=state.validator_registry + (validator, ),
        validator_balances=state.validator_balances + (amount, ),
    )

    return state
示例#5
0
def process_attestations(state: BeaconState, block: BaseBeaconBlock,
                         config: BeaconConfig) -> BeaconState:
    # TODO
    # It's just for demo!!!
    state = state.copy(slot=config.ZERO_BALANCE_VALIDATOR_TTL, )
    return state