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
Suppose we have serialized into some data (e.g. on disk in rocksdb, in contract state, or circulating in network). Then we want to upgrade this structure by adding another field:
This doesn't work very well when the type of f1 needs to change for example. Also this makes it a bit more difficult to distinguish between versions (you have to check whether something is None first).
The struct C can't be deserialized using this strategy, so we should enforce a harder constraint: "It will only work if any optional field are included at the back, and any other inner type doesn't use optional". (It can be relaxed a little bit, but not in a way that working with it is easy).
Unfortunately this feature has limited applications to near/NEPs#95. In practice most of the changes happens in fields deep inside some data structures or are changes to some variants on enums.
I should update my proposal, but it is more along the lines of introducing new traits BorshSerializeVersioned and BorshDeserializeVersioned that exposes the API:
Motivation
Suppose we have rust structure:
Suppose we have serialized into some data (e.g. on disk in rocksdb, in contract state, or circulating in network). Then we want to upgrade this structure by adding another field:
It would be extremely convenient for upgradability if we could deserialize old data using new Rust type.
Proposal
We can introduce
#[borsh_optional]
decorator that can be used like this:Then when we deserialize old data with this structure
f3
will beNone
, but when we deserialize new data using this structure it will beSome
.It will only work if optional fields are included at the back:
And the compilation should fail if the following situations:
CC @mfornet Since it might be relevant to near/NEPs#95
The text was updated successfully, but these errors were encountered: