Esempio n. 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
Esempio n. 2
0
 def get_finalized_head(
         self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
     finalized_head_root_key = SchemaV1.finalized_head_root()
     finalized_head_root = Root(Hash32(self.db[finalized_head_root_key]))
     return self.get_block_by_root(finalized_head_root, block_class)
Esempio n. 3
0
 def mark_finalized_head(self, block: BaseBeaconBlock) -> None:
     finalized_head_root = SchemaV1.finalized_head_root()
     self.db[finalized_head_root] = block.hash_tree_root