Example #1
0
    def mark_finalized_head(self, block: BaseBeaconBlock) -> None:
        """
        Marks the given ``block`` as finalized and stores each newly finalized state and block at
        their corresponding slot.
        """
        if block.slot > 0:
            newly_finalized_states = self.get_state_parents(
                block.state_root,
                block.slot - self.get_finalized_head(BeaconBlock).slot) + (
                    block.state_root, )
        else:
            newly_finalized_states = (block.state_root, )

        for state_root in newly_finalized_states:
            slot = ssz.decode(self.db[SchemaV1.state_root_to_slot(state_root)],
                              ssz.uint64)
            self.db[SchemaV1.slot_to_state_root(slot)] = state_root

            latest_block_header = self._read_state_block_header(state_root)
            slot_to_block_root = SchemaV1.slot_to_block_root(
                latest_block_header.slot)
            self.db[slot_to_block_root] = latest_block_header.hash_tree_root

        self.db[SchemaV1.slot_to_block_root(block.slot)] = block.hash_tree_root
        self.db[SchemaV1.finalized_head_root()] = block.hash_tree_root
Example #2
0
 def get_block_by_slot(
         self, slot: Slot,
         block_class: Type[BaseBeaconBlock]) -> Optional[BaseBeaconBlock]:
     key = SchemaV1.slot_to_block_root(slot)
     try:
         root = Root(Hash32(self.db[key]))
     except KeyError:
         return None
     return self.get_block_by_root(root, block_class)
Example #3
0
    def mark_canonical_block(self, block: BaseBeaconBlock) -> None:
        slot_to_block_root = SchemaV1.slot_to_block_root(block.slot)
        self.db[slot_to_block_root] = block.hash_tree_root

        slot_to_state_root = SchemaV1.slot_to_state_root(block.slot)
        self.db[slot_to_state_root] = block.state_root