def _get_canonical_head_root(db: DatabaseAPI) -> Hash32: try: canonical_head_root = db[ SchemaV1.make_canonical_head_root_lookup_key()] except KeyError: raise CanonicalHeadNotFound("No canonical head set for this chain") return canonical_head_root
def _get_canonical_head(cls, db: BaseDB) -> BaseBeaconBlock: try: canonical_head_hash = db[ SchemaV1.make_canonical_head_hash_lookup_key()] except KeyError: raise CanonicalHeadNotFound("No canonical head set for this chain") return cls._get_block_by_hash(db, canonical_head_hash)
def _get_canonical_head(cls, db: DatabaseAPI) -> BlockHeaderAPI: try: canonical_head_hash = db[ SchemaV1.make_canonical_head_hash_lookup_key()] except KeyError: raise CanonicalHeadNotFound("No canonical head set for this chain") return cls._get_block_header_by_hash(db, Hash32(canonical_head_hash))
def _get_finalized_head(cls, db: BaseDB, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock: try: finalized_head_root = db[SchemaV1.make_finalized_head_root_lookup_key()] except KeyError: raise CanonicalHeadNotFound("No finalized head set for this chain") return cls._get_block_by_root(db, Hash32(finalized_head_root), block_class)
def get_canonical_head(self) -> BlockHeader: """ Returns the current block header at the head of the chain. """ try: canonical_head_hash = self.db[ SchemaV1.make_canonical_head_hash_lookup_key()] except KeyError: raise CanonicalHeadNotFound("No canonical head set for this chain") return self.get_block_header_by_hash(canonical_head_hash)
def _get_canonical_head_hash(cls, db: DatabaseAPI) -> Hash32: try: return Hash32(db[SchemaV1.make_canonical_head_hash_lookup_key()]) except KeyError: raise CanonicalHeadNotFound("No canonical head set for this chain")