def test_validate_attestation_slot(sample_attestation_data_params, attestation_slot, state_slot, slots_per_epoch, genesis_slot, genesis_epoch, min_attestation_inclusion_delay, is_valid): attestation_data = AttestationData(**sample_attestation_data_params).copy( slot=attestation_slot, ) if is_valid: validate_attestation_slot( attestation_data, state_slot, slots_per_epoch, min_attestation_inclusion_delay, genesis_slot, ) else: with pytest.raises(ValidationError): validate_attestation_slot( attestation_data, state_slot, slots_per_epoch, min_attestation_inclusion_delay, genesis_slot, )
def test_validate_attestation_slot(sample_attestation_data_params, attestation_slot, current_slot, epoch_length, min_attestation_inclusion_delay, is_valid): attestation_data = AttestationData(**sample_attestation_data_params).copy( slot=attestation_slot, ) if is_valid: validate_attestation_slot( attestation_data, current_slot, epoch_length, min_attestation_inclusion_delay, ) else: with pytest.raises(ValidationError): validate_attestation_slot( attestation_data, current_slot, epoch_length, min_attestation_inclusion_delay, )
def is_valid_slot(attestation: Attestation, current_slot: Slot, config: Eth2Config) -> bool: try: validate_attestation_slot( attestation.data.slot, current_slot, config.SLOTS_PER_EPOCH, config.MIN_ATTESTATION_INCLUSION_DELAY, ) except ValidationError: return False else: return True
def get_ready_attestations(self, current_slot: Slot) -> Iterable[Attestation]: config = self.chain.get_state_machine().config for attestation in self.attestation_pool.get_all(): try: validate_attestation_slot( attestation.data.slot, current_slot, config.SLOTS_PER_EPOCH, config.MIN_ATTESTATION_INCLUSION_DELAY, ) except ValidationError: continue else: yield attestation
def get_ready_attestations(self) -> Iterable[Attestation]: config = self.chain.get_state_machine().config state = self.chain.get_head_state() for attestation in self.attestation_pool.get_all(): data = attestation.data attestation_slot = get_attestation_data_slot(state, data, config) try: validate_attestation_slot( attestation_slot, state.slot, config.SLOTS_PER_EPOCH, config.MIN_ATTESTATION_INCLUSION_DELAY, ) except ValidationError: continue else: yield attestation
def get_ready_attestations(self, inclusion_slot: Slot) -> Iterable[Attestation]: config = self.chain.get_state_machine().config for attestation in self.attestation_pool.get_all(): # Validate attestation slot try: validate_attestation_slot( attestation.data, inclusion_slot, config.SLOTS_PER_EPOCH, config.MIN_ATTESTATION_INCLUSION_DELAY, config.GENESIS_SLOT, ) except ValidationError: # TODO: Should clean up attestations with invalid slot because # they are no longer available for inclusion into block. continue else: yield attestation
def test_validate_attestation_slot(attestation_slot, state_slot, slots_per_epoch, min_attestation_inclusion_delay, is_valid): if is_valid: validate_attestation_slot( attestation_slot, state_slot, slots_per_epoch, min_attestation_inclusion_delay, ) else: with pytest.raises(ValidationError): validate_attestation_slot( attestation_slot, state_slot, slots_per_epoch, min_attestation_inclusion_delay, )
def get_ready_attestations(self) -> Iterable[Attestation]: state_machine = self.chain.get_state_machine() config = state_machine.config state = state_machine.state for attestation in self.attestation_pool.get_all(): data = attestation.data attestation_slot = get_attestation_data_slot(state, data, config) try: validate_attestation_slot( attestation_slot, state.slot, config.SLOTS_PER_EPOCH, config.MIN_ATTESTATION_INCLUSION_DELAY, ) except ValidationError: # TODO: Should clean up attestations with invalid slot because # they are no longer available for inclusion into block. continue else: yield attestation