def run_validate_block_proposer_signature( state: BeaconState, state_machine: BaseBeaconStateMachine, block: BaseBeaconBlock) -> None: # Fast forward to state in future slot in order to pass # block.slot validity check try: future_state = state_machine.state_transition.apply_state_transition( state, future_slot=block.slot, ) except ValidationError as error: raise InvalidGossipMessage( "Failed to fast forward to state at slot=%d, error=%s", block.slot, str(error), ) try: validate_proposer_signature(future_state, block, CommitteeConfig(state_machine.config)) except ValidationError as error: logger.debug( "Failed to validate block=%s, error=%s", encode_hex(block.signing_root), str(error), )
def validate_is_unaggregated(attestation: Attestation) -> None: # Check if the attestation is unaggregated if len([bit for bit in attestation.aggregation_bits if bit is True]) != 1: raise InvalidGossipMessage( "The attestation is aggregated. Attestation: %s", attestation, ) return False
def validate_subnet_id(attestation: Attestation, subnet_id: SubnetId) -> None: if attestation.data.index % ATTESTATION_SUBNET_COUNT != subnet_id: raise InvalidGossipMessage( "Wrong attestation subnet_id=%d, topic subnet_id=%d. Attestation: %s", attestation.data.index % ATTESTATION_SUBNET_COUNT, subnet_id, attestation, )
def validate_voting_beacon_block(chain: BaseBeaconChain, attestation: Attestation) -> None: # Check that beacon blocks attested to by the attestation are validated try: chain.get_block_by_root(attestation.data.beacon_block_root) except BlockNotFound: raise InvalidGossipMessage( f"Failed to validate attestation={attestation}," f" attested block={encode_hex(attestation.data.beacon_block_root)}" " has not been not validated yet")
def run_validate_block_proposer_signature( state: BeaconState, state_machine: BaseBeaconStateMachine, block: BaseSignedBeaconBlock) -> None: # Fast forward to state in future slot in order to pass # block.slot validity check try: future_state, _ = state_machine.apply_state_transition( state, future_slot=block.slot, ) except ValidationError as error: raise InvalidGossipMessage( f"Failed to fast forward to state at slot={block.slot}", error, ) try: validate_proposer_signature(future_state, block, state_machine.config) except ValidationError as error: raise InvalidGossipMessage( f"Failed to validate block={encode_hex(block.message.hash_tree_root)}", error, )
def run_validate_aggregate_and_proof(state: BeaconState, aggregate_and_proof: AggregateAndProof, config: CommitteeConfig) -> None: try: validate_aggregate_and_proof( state, aggregate_and_proof, ATTESTATION_PROPAGATION_SLOT_RANGE, config, ) except ValidationError as error: raise InvalidGossipMessage( f"Failed to validate aggregate_and_proof={aggregate_and_proof}", error, )
def validate_subnet_id(attestation: Attestation, subnet_id: SubnetId) -> None: if attestation.data.index % ATTESTATION_SUBNET_COUNT != subnet_id: raise InvalidGossipMessage( f"Wrong attestation subnet_id={attestation.data.index % ATTESTATION_SUBNET_COUNT}," f" topic subnet_id={subnet_id}. Attestation: {attestation}")