def _get_deletable_state_roots(db: BaseDB) -> Tuple[Hash32]: """ Return deletable_state_roots. """ lookup_key = SchemaV1.make_deletable_state_roots_lookup_key() if not db.exists(lookup_key): db.set( lookup_key, rlp.encode((), sedes=CountableList(hash32)), ) deletable_state_roots = rlp.decode(db[lookup_key], sedes=CountableList(hash32)) return deletable_state_roots
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), )