You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The jmt crate implements a byte-oriented Key/Value store. The Sovereign SDK transforms that byte store into a typed key/value store using the StateValue and StateMap abstractions. When a #[state] value is set, the underlying implementation uses the StorageKey::new() and StorageValue::new() constructors to serialize the key and value with borsh before inserting them into the current WorkingSet.
While this system works very well for keys and values which implement borsh, it has a few limitations:
Items which don't implement the borsh serialize/deserialize traits can't be stored, so many foreign types have to be wrapped in a newtype
It adds an additional layer of serialization when storing pre-encoded types
It prevents us from supporting IBC, since IBC requires that the chain's authenticated state tree must store the raw protobuf encodings of certain messages.
Desired Outcome
To support IBC, we need to be able to take the Rust struct representing an IBC message and store its protobuf encoding into the state tree without introducing any additional serialization. There are at least two designs which will support this pattern.
Option 1: Add a (phantom) serializer to the StateValue
In this option, we change the API of StateValue from StateValue<T> to StateValue<T, C>. A rough sketch of the APIs is as follows:
Note that this description is slightly inaccurate, since it pretends that the WorkingSet accepts a StorageValue as an argument. In reality, the WorkingSet accepts the raw type and calls the StorageValue constructor internally - so we would need to add generics to the WorkingSet::set function as well.
Option 2: Add a new RawStateValue type; add a from_bytes implementation to StorageKey and StorageValue.
Background
The
jmt
crate implements a byte-oriented Key/Value store. The Sovereign SDK transforms that byte store into a typed key/value store using theStateValue
andStateMap
abstractions. When a#[state]
value is set, the underlying implementation uses theStorageKey::new()
andStorageValue::new()
constructors to serialize the key and value withborsh
before inserting them into the currentWorkingSet
.While this system works very well for keys and values which implement
borsh
, it has a few limitations:Desired Outcome
To support IBC, we need to be able to take the Rust struct representing an IBC message and store its protobuf encoding into the state tree without introducing any additional serialization. There are at least two designs which will support this pattern.
Option 1: Add a (phantom) serializer to the StateValue
In this option, we change the API of StateValue from
StateValue<T>
toStateValue<T, C>
. A rough sketch of the APIs is as follows:Note that this description is slightly inaccurate, since it pretends that the
WorkingSet
accepts aStorageValue
as an argument. In reality, theWorkingSet
accepts the raw type and calls theStorageValue
constructor internally - so we would need to add generics to theWorkingSet::set
function as well.Option 2: Add a new
RawStateValue
type; add afrom_bytes
implementation toStorageKey
andStorageValue
.The text was updated successfully, but these errors were encountered: