-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Task] Allow storing arbitrary bytes in Storage
#918
Comments
I would prefer not to burden So, something like: async fn blob_set(&self, did: &IotaDID, value: &[u8]) -> Result<()>;
async fn blob_get(&self, did: &IotaDID) -> Result<Vec<u8>>; That might be less efficient when only part of the blob is required, but it avoids complexity for implementers in my opinion. |
I see your point, keyed storage might have advantages when it comes to upgradability / backwards-compatibility though. Let's come to a consensus before on this before going ahead with implementation. |
Interesting point. The downside of that approach is the performance issues of having to deserialize the entire blob to get to individual parts. If there's one big struct ( I suppose we could use the single-blob-approach and add a level of indirection in the serialization and storing the individual fields in another struct, so something like this: {
"document": "594NNi9QJ39h512EP....",
"chainState": "CLhZjk4tr6McQdQH....",
} The field definitions of this struct would probably follow the pattern Maybe that's a sensible compromise to keep the interface simple for storage implementers while allowing (some) backwards-compatible changes? |
That's a problem even with the arbitrary key-value approach. My approach there might be to version the keys, e.g.
That would be my approach. I'm not overly concerned about the performance impact of accessing both fields instead of one-at-a-time, since it appears that We could explore whether zero-copy-deserialization could help too if accessing a sub-field of the single blob becomes a bottleneck. |
I think in the future we need to do that in any case. We still can break APIs until 1.0, and restructuring the storage will definitely be such a break which we would not need to make backwards-compatible, but we should set up the structure (e.g. with versioned keys/fields) so we can create backwards-compatible changes in the future. Edit: Se we are leaning towards a single object / blob with versioned keys? |
I was mostly concerned about the addition of a new field being a breaking change, but that is not the case with both the key-value and the nested-serialization-blob approach.
For this specific case I agree, but if we add a new field like one that holds keys marked for deletion (e.g. #757) then that would also be deserialized every time (only in the approach without nesting, to be clear). But since we're aligned on the nested blob and the versioned keys approach anyway, I think we can go ahead with that. |
Description
The current
Storage
trait has four methods dedicated to storing data structures used in theAccount
:Remove these methods in favor of two new methods that allow setting and getting of arbitrary bytes for some key.
async fn key_value_set(&self, did: &IotaDID, key: &str, value: &[u8]) -> Result<()>;
async fn key_value_get(&self, did: &IotaDID, key: &str) -> Result<Vec<u8>>;
The types are just naive suggestions. In the account, I would anticipate the methods to be called with
&'static str
values. For instance"IotaDocument"
is the identifier for theIotaDocument
data structure.Motivation
Require less breaking changes when changing what is stored in
Storage
, and makeStorage
more useful as a generic storage mechanism.We might want to store more data structures in the future, perhaps for #757, and this change enables this cleanly.
Resources
Link to any resources relevant for the task such as Issues, PRs, reference implementations, or specifications.
n/a
To-do list
Create a task-specific to-do list . Please link PRs that match the To-do list item behind the item after it has been submitted.
IotaDocument
s andChainState
s.Change checklist
Add an
x
to the boxes that are relevant to your changes, and delete any items that are not.The text was updated successfully, but these errors were encountered: