def create_mock_signed_attestations_at_slot( state: BeaconState, config: Eth2Config, state_machine: BaseBeaconStateMachine, attestation_slot: Slot, beacon_block_root: Root, keymap: Dict[BLSPubkey, int], voted_attesters_ratio: float = 1.0, ) -> Iterable[Attestation]: """ Create the mocking attestations of the given ``attestation_slot`` slot with ``keymap``. """ if voted_attesters_ratio == 0: return () committees_per_slot = get_committee_count_at_slot( state, attestation_slot, config.MAX_COMMITTEES_PER_SLOT, config.SLOTS_PER_EPOCH, config.TARGET_COMMITTEE_SIZE, ) # Get `target_root` target_root = _get_target_root(state, config, beacon_block_root) target_epoch = compute_epoch_at_slot(state.slot, config.SLOTS_PER_EPOCH) for committee, committee_index, _ in iterate_committees_at_slot( state, attestation_slot, committees_per_slot, config): attestation_data = AttestationData.create( slot=attestation_slot, index=CommitteeIndex(committee_index), beacon_block_root=beacon_block_root, source=Checkpoint.create( epoch=state.current_justified_checkpoint.epoch, root=state.current_justified_checkpoint.root, ), target=Checkpoint.create(root=target_root, epoch=target_epoch), ) num_voted_attesters = max(int(len(committee) * voted_attesters_ratio), 1) yield _create_mock_signed_attestation( state, attestation_data, attestation_slot, committee, num_voted_attesters, keymap, config.SLOTS_PER_EPOCH, )
def _get_committees(state, target_slot, config, sampling_fraction): committees_per_slot = get_committee_count_at_slot( state, target_slot, config.MAX_COMMITTEES_PER_SLOT, config.SLOTS_PER_EPOCH, config.TARGET_COMMITTEE_SIZE, ) committees_at_slot = () for committee, _, _ in iterate_committees_at_slot(state, target_slot, committees_per_slot, config): committees_at_slot += (committee, ) return tuple( random.sample(committees_at_slot, int((sampling_fraction * committees_per_slot))))