コード例 #1
0
    def duty_fetcher(current_tick, _public_keys, target_epoch,
                     _slots_per_epoch, _seconds_per_slot):
        duties = ()
        if target_epoch < 0:
            return duties

        some_slot = current_tick.slot
        if current_tick.epoch >= 0:
            block_proposal_duty = BlockProposalDuty(
                public_key, Tick(0, some_slot, target_epoch, 0), current_tick)
            duties += (block_proposal_duty, )
        attestation_duty = AttestationDuty(
            public_key,
            Tick(0, some_slot + slots_per_epoch, target_epoch, 1),
            current_tick,
            CommitteeIndex(22),
        )
        duties += (attestation_duty, )
        return duties
コード例 #2
0
def _parse_block_proposal_duty(
    duty_data: Dict[str, Any],
    validator_public_key: BLSPubkey,
    current_tick: Tick,
    target_epoch: Epoch,
    genesis_time: int,
    seconds_per_slot: int,
    ticks_per_slot: int,
) -> BlockProposalDuty:
    target_tick = Tick.computing_t_from(
        Slot(duty_data["block_proposal_slot"]),
        target_epoch,
        BlockProposalDuty.tick_count,
        genesis_time,
        seconds_per_slot,
        ticks_per_slot,
    )
    return BlockProposalDuty(
        validator_public_key=validator_public_key,
        tick_for_execution=target_tick,
        discovered_at_tick=current_tick,
    )
コード例 #3
0
def _fetch_some_random_duties(
    current_tick: Tick,
    public_keys: Collection[BLSPubkey],
    target_epoch: Epoch,
    slots_per_epoch: Slot,
    seconds_per_slot: int,
) -> Tuple[Duty, ...]:
    if not public_keys:
        return ()
    if target_epoch < 0:
        return ()
    some_slot = Slot(
        random.randint(0, slots_per_epoch) + target_epoch * slots_per_epoch)
    execution_time = seconds_per_slot * (some_slot -
                                         current_tick.slot) + current_tick.t
    is_attestation = bool(random.getrandbits(1))
    # NOTE: use of ``tuple`` here is satisfy ``mypy``.
    some_validator = random.choice(tuple(public_keys))
    if is_attestation:
        committee_index = random.randint(0, 64)
        some_tick_count = 1
        attestation_duty = AttestationDuty(
            some_validator,
            Tick(execution_time, some_slot, target_epoch, some_tick_count),
            current_tick,
            CommitteeIndex(committee_index),
        )
        return (attestation_duty, )
    else:
        some_tick_count = 0
        block_proposal_duty = BlockProposalDuty(
            some_validator,
            Tick(execution_time, some_slot, target_epoch, some_tick_count),
            current_tick,
        )
        return (block_proposal_duty, )
コード例 #4
0
ファイル: test_signatory_db.py プロジェクト: onyb/trinity
def _mk_resolved_block_proposal_duty(slot, public_key):
    return (
        BlockProposalDuty(public_key, Tick(0, slot, 0, 0), Tick(0, 0, 0, 0)),
        BeaconBlock.create(slot=slot),
    )