Unify StorageKey
and CacheKey
#643
Labels
enhancement
New feature or request
good first issue
Good for newcomers
Small
Use this label for quick cleanup and maintenance tasks
Description
Currently, StorageKey and CacheKey are equivalent types. They historically were different, but as the implementation evolved, they converged to have the same. However,
StorageKey
implements serialization, whereasCacheKey
doesn't.This limits our implementation as the conversion between the types may force us to take the key as owned for simple operations such as get, when a reference should suffice
sovereign-sdk/module-system/sov-state/src/scratchpad.rs
Line 187 in 0137568
Solution
Deprecate
CacheKey
and replace its usage byStorageKey
. This will allow us to pass references downstream and make the map API more powerful, as the types are just borrowed references and can be passed downstream without any conversion. This will unlock a simplification requested on #427Alternatives
We could unsafely cast one type to the other, but we have no clear gain to maintain the distinction and would create a potential undefined behavior if the layout of any of the types ever change. This would create a maintenance burden to cross-check both types whenever they are updated.
A working alternative suggested by @preston-evans98 is to use yoke to cast one type to the other. This will allow a zero-cost solution and will preserve both types, in case we want to maintain the distinction. The
CacheKey
is currently used for memory-only representation, andStorageKey
is used for serialization. It might be desirable to maintain this domain separation if we want to have a layer that don't interact with I/O.The text was updated successfully, but these errors were encountered: