Example #1
0
 def _get_canonical_crystallized_state_root(db: BaseDB,
                                            slot: int) -> Hash32:
     validate_slot(slot)
     slot_to_hash_key = SchemaV1.make_slot_to_crystallized_state_lookup_key(
         slot)
     try:
         encoded_key = db[slot_to_hash_key]
     except KeyError:
         raise StateRootNotFound(
             "No canonical crystallized state for slot #{0}".format(slot))
     else:
         return rlp.decode(encoded_key, sedes=rlp.sedes.binary)
Example #2
0
    def _add_slot_to_crystallized_state_lookup(
            cls, db: BaseDB, crystallized_state: CrystallizedState) -> None:
        """
        Set a record in the database to allow looking up this block by its
        last state recalculation slot.

        If it's a fork, store the old state root in `deletable_state_roots`.
        """
        slot_to_hash_key = SchemaV1.make_slot_to_crystallized_state_lookup_key(
            crystallized_state.last_state_recalc)
        if db.exists(slot_to_hash_key):
            deletable_state_roots = cls._get_deletable_state_roots(db)
            replaced_state_root = rlp.decode(db[slot_to_hash_key],
                                             sedes=rlp.sedes.binary)
            cls._set_deletatable_state(
                db,
                deletable_state_roots + (replaced_state_root, ),
            )
        db.set(
            slot_to_hash_key,
            rlp.encode(crystallized_state.hash, sedes=rlp.sedes.binary),
        )