def test_process_eth1_data(
    original_votes,
    block_data,
    expected_votes,
    sample_beacon_state_params,
    sample_beacon_block_params,
    sample_beacon_block_body_params,
    config,
):
    eth1_data_votes = tuple(mapcat(_expand_eth1_votes, original_votes))
    state = BeaconState.create(**sample_beacon_state_params).set(
        "eth1_data_votes", eth1_data_votes)

    block_body = BeaconBlockBody.create(
        **sample_beacon_block_body_params).mset(
            "eth1_data", Eth1Data.create(block_hash=block_data))

    block = BeaconBlock.create(**sample_beacon_block_params).set(
        "body", block_body)

    updated_state = process_eth1_data(state, block, config)
    updated_votes = updated_state.eth1_data_votes
    expanded_expected_votes = tuple(mapcat(_expand_eth1_votes, expected_votes))

    assert tuple(updated_votes) == expanded_expected_votes
Beispiel #2
0
def test_process_eth1_data(original_votes,
                           block_data,
                           expected_votes,
                           sample_beacon_state_params,
                           sample_beacon_block_params,
                           sample_beacon_block_body_params,
                           config):
    eth1_data_votes = tuple(mapcat(
        _expand_eth1_votes,
        original_votes,
    ))
    state = BeaconState(**sample_beacon_state_params).copy(
        eth1_data_votes=eth1_data_votes,
    )

    block_body = BeaconBlockBody(**sample_beacon_block_body_params).copy(
        eth1_data=Eth1Data(
            block_hash=block_data,
        ),
    )

    block = BeaconBlock(**sample_beacon_block_params).copy(
        body=block_body,
    )

    updated_state = process_eth1_data(state, block, config)
    updated_votes = updated_state.eth1_data_votes
    expanded_expected_votes = tuple(mapcat(
        _expand_eth1_votes,
        expected_votes,
    ))

    assert updated_votes == expanded_expected_votes
Beispiel #3
0
    async def fetch_duties(
        self,
        current_tick: Tick,
        public_keys: Collection[BLSPubkey],
        target_epoch: Epoch,
    ) -> Collection[Duty]:
        if target_epoch < 0:  # GENESIS_EPOCH == 0
            # avoid fetching duties before genesis
            # NOTE: we do want to fetch duties from the genesis epoch
            # with at least 1 epoch of lookahead.
            return ()

        url = self._url_for(BeaconNodePath.validator_duties)
        duties_data = await _get_duties_from_beacon_node(
            self._session, url, public_keys, target_epoch)
        return tuple(
            filter(
                _is_current_duty,
                mapcat(
                    lambda data: _parse_duties(
                        data,
                        current_tick,
                        target_epoch,
                        self._genesis_time,
                        self._seconds_per_slot,
                        self._ticks_per_slot,
                    ),
                    duties_data,
                ),
            ))
Beispiel #4
0
 def _mark_complete(self, task_id: TTaskID) -> None:
     qualified_tasks = tuple([task_id])
     while qualified_tasks:
         qualified_tasks = tuple(mapcat(
             self._mark_one_task_complete,
             qualified_tasks,
         ))
Beispiel #5
0
 def _mk_pre_index_from_attestations(
         self, state: BeaconState,
         attestations: Sequence[AttestationLike]) -> PreIndex:
     """
     A 'pre-index' is a Dict[ValidatorIndex, Tuple[Slot, AttestationData]].
     """
     return merge(
         *mapcat(self._mk_pre_index_from_attestation(state), attestations))
Beispiel #6
0
 async def fetch_duties(
     self,
     current_tick: Tick,
     public_keys: Collection[BLSPubkey],
     target_epoch: Epoch,
 ) -> Collection[Duty]:
     url = self._url_for(BeaconNodePath.validator_duties)
     duties_data = await _get_duties_from_beacon_node(
         self._session, url, public_keys, target_epoch)
     return tuple(
         mapcat(
             lambda data: _parse_duties(
                 data,
                 current_tick,
                 target_epoch,
                 self._genesis_time,
                 self._seconds_per_slot,
                 self._ticks_per_slot,
             ),
             duties_data,
         ))