Exemplo n.º 1
0
    def get_canonical_block_by_slot(self, slot: SlotNumber) -> BaseBeaconBlock:
        """
        Return the block with the given number in the canonical chain.

        Raise ``BlockNotFound`` if there's no block with the given number in the
        canonical chain.
        """
        validate_slot(slot)
        return self.get_block_by_root(self.chaindb.get_canonical_block_root(slot))
Exemplo n.º 2
0
 def _get_canonical_block_root(db: BaseDB, slot: int) -> Hash32:
     validate_slot(slot)
     slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key(slot)
     try:
         encoded_key = db[slot_to_root_key]
     except KeyError:
         raise BlockNotFound(
             "No canonical block for block slot #{0}".format(slot))
     else:
         return ssz.decode(encoded_key, sedes=ssz.sedes.bytes_sedes)
Exemplo n.º 3
0
    def get_state_by_slot(self, slot: Slot) -> BeaconState:
        """
        Return the requested state as specified by slot number.

        Raise ``StateSlotNotFound`` if there's no state with the given slot in the db.
        """
        validate_slot(slot)
        sm_class = self.get_state_machine_class_for_block_slot(slot)
        state_class = sm_class.get_state_class()
        return self.chaindb.get_state_by_slot(slot, state_class)
Exemplo n.º 4
0
    def get_state_machine_class_for_block_slot(
            cls,
            slot: SlotNumber) -> Type['BaseBeaconStateMachine']:
        """
        Return the ``StateMachine`` class for the given block slot number.
        """
        if cls.sm_configuration is None:
            raise AttributeError("Chain classes must define the StateMachines in sm_configuration")

        validate_slot(slot)
        for start_slot, sm_class in reversed(cls.sm_configuration):
            if slot >= start_slot:
                return sm_class
        raise StateMachineNotFound("No StateMachine available for block slot: #{0}".format(slot))
Exemplo n.º 5
0
def test_validate_slot(slot, is_valid):
    if is_valid:
        validate_slot(slot)
    else:
        with pytest.raises(ValidationError):
            validate_slot(slot)
Exemplo n.º 6
0
 def _get_canonical_block_root_by_slot(cls, db: BaseDB,
                                       slot: int) -> Hash32:
     validate_slot(slot)
     return cls._get_canonical_block_root(db, slot)