Skip to content
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

Full deserialization for range #432

Merged
merged 62 commits into from
Oct 4, 2021
Merged

Full deserialization for range #432

merged 62 commits into from
Oct 4, 2021

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Sep 17, 2021

Closes #198.

First (working) attempt at deserializing range result keys.

TODO:

  • Naming
    • Proper naming for the new range and Prefix functionality. Perhaps range_de, PrefixDe?
    • Proper naming for Pair2. Perhaps consolidating Pair2 and Pair into one (with default args for both key and value). (See Make Pair more extensible cosmwasm#1101)
    • Better internal naming of deserialization functions, associated types, etc. Perhaps renaming deserialize_kv - > deserialize_v, and deserialize2_kv -> deserialize_kv.
    • Better naming for Deserializable. Perhaps DeserializeOwned (although confusing with serde).
    • Put Prefix2 into its own module? Consolidate Prefix and Prefix2 (default K = Vec<u8>) (Follow-up PR Prefix consolidation #439)?
  • keys() deserialization (keys_de).
  • Implement range_de for the other iterables (IndexedMap, IndexedSnapshotMap, and the indexes). (Add range_de to Map-like structs #461)
  • Make prefix_de deserialization (i.e. suffixes deserialization) work. (Follow-up PR Working prefix_de #434).
  • Lifetimes / references. Currently only owned approach (Follow / take a look at serde's approach here). (Add non-owned range_de #463)
  • Implement Deserializable for other types.
    • String types.
    • Integer types.
    • Tuples.
    • ...
  • Unit testing. (wip)

@maurolacy maurolacy force-pushed the 198-better-range-prefix branch from 3a0b46f to a7e9925 Compare September 17, 2021 16:09
@maurolacy maurolacy changed the title Range full deserialization Full deserialization for range Sep 17, 2021
@maurolacy maurolacy force-pushed the 198-better-range-prefix branch from a7e9925 to e38738c Compare September 18, 2021 19:58
This was referenced Sep 18, 2021
@maurolacy maurolacy marked this pull request as ready for review September 18, 2021 21:08
@maurolacy maurolacy force-pushed the 198-better-range-prefix branch 2 times, most recently from 6d3b05d to dd186b0 Compare September 19, 2021 23:18
@maurolacy maurolacy changed the base branch from main to range-no-prefix September 19, 2021 23:20
@maurolacy
Copy link
Contributor Author

This is now "rebased", and properly supporting the no-iterator feature.

Base automatically changed from range-no-prefix to main September 20, 2021 06:51
ethanfrey
ethanfrey previously approved these changes Sep 20, 2021
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good implementation.

I would prefer improved names and some other details, but I think you have a few PRs coming on top that will fix that. Approving for merge, with the condition these comments are addressed in a future PR.

packages/storage-plus/src/iter_helpers.rs Show resolved Hide resolved
packages/storage-plus/src/map.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/map.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/prefix.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/prefix.rs Outdated Show resolved Hide resolved
@ethanfrey
Copy link
Member

Please take a look at #446
This adds type-safe ranges.

I think using Bound<Vec<u8>> with no connection to the Map keys. And then using joined_keys and such manually is just a recipe for disaster. You may be able to clean up that PR, but I think the idea of creating Bounds with some K: PrimaryKey or K: Prefixer will catch a whole lot of issues when writing code.

I know the crux of your PR is to add more deserialisation (of K), but I think while doing some of you work, and removing EmptyPrefix, you went more in the direction of people just manually appending prefixes.

@maurolacy maurolacy mentioned this pull request Sep 30, 2021
@CosmWasm CosmWasm deleted a comment from hashedone Sep 30, 2021
@ethanfrey
Copy link
Member

Is this ready for a deep review?
When all this stuff is updated, ping me, and I can do one pass over this. But I don't want to while it is still a WIP

@maurolacy
Copy link
Contributor Author

Is this ready for a deep review?

I think so, yes.

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big one!

First, I like the type changes - both KeyDeserializer (nicer naming) and the additions to PrimaryKey.

I also like the addition of key information to Prefix.

Added some cleanup comments, and maybe some redundancy can be removed, but I think just one pass with some polish and this can be merged.

I think there is more than can be done to enhance it (in other PRs).

  • properly handling prefix_range_de
  • deprecating range and promoting range_de as the standard case (I would almost be in favor of just renaming them now and break everything once... range -> range_raw and range_de -> range.
  • replace KeyDeserializer::from_slice(&[u8]) with KeyDeserializer::from_vec(Vec<u8>). When we call it, we can consume the Vec and save a clone. See deserialize_kv
  • Add range_de types to "Map-like" structs (Indexed, Snapshot)
  • Simplify usage in many contracts where we use range and custom parsing (but could now use range_de)

No need to handle that in this PR. Tackle what you can and make an issue for the items you will put into other PRs.

packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/de.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/de.rs Show resolved Hide resolved
packages/storage-plus/src/de.rs Show resolved Hide resolved
packages/storage-plus/src/de.rs Show resolved Hide resolved
packages/storage-plus/src/map.rs Show resolved Hide resolved
packages/storage-plus/src/map.rs Show resolved Hide resolved
packages/storage-plus/src/prefix.rs Outdated Show resolved Hide resolved
packages/storage-plus/src/prefix.rs Show resolved Hide resolved
packages/storage-plus/src/prefix.rs Show resolved Hide resolved
@maurolacy
Copy link
Contributor Author

maurolacy commented Oct 1, 2021

I think there is more than can be done to enhance it (in other PRs).

  • properly handling prefix_range_de

Yes. Will do in a follow-up. (done)

  • deprecating range and promoting range_de as the standard case (I would almost be in favor of just renaming them now and break everything once... range -> range_raw and range_de -> range.

I would love to do that renaming. Let's do it in a follow-up, just to better handle the breaking change. (#460).

  • replace KeyDeserializer::from_slice(&[u8]) with KeyDeserializer::from_vec(Vec<u8>). When we call it, we can consume the Vec and save a clone. See deserialize_kv

Will do in a follow-up. (#464)

  • Add range_de types to "Map-like" structs (Indexed, Snapshot)

Another follow-up. (#461)

  • Simplify usage in many contracts where we use range and custom parsing (but could now use range_de)

For sure. I would do this as part of the breaking change from range -> range_raw. (#461)

No need to handle that in this PR. Tackle what you can and make an issue for the items you will put into other PRs.

Good review, thanks. Will create the follow-up issues and link them here. (done)

@maurolacy
Copy link
Contributor Author

Will add unit tests for key deserialization, and I think then we can merge this.

@ethanfrey
Copy link
Member

Sounds good.

If you can get a 🟢 from the CI, I'm happy to merge it. Let's do this and

Replace KeyDeserializer::from_slice(&[u8]) with KeyDeserializer::from_vec(Vec). When we call it, we can consume the Vec and save a clone. See deserialize_kv. (From #464)

And update to final cosmwasm release. Then we can cut a v0.10.0

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.
let's merge

Some(StdError::GenericErr { .. })
));

// More bytes fails too
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@ethanfrey ethanfrey dismissed hashedone’s stale review October 4, 2021 11:19

outdated, changes already made

Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approval in case the last one was marked as stale

@maurolacy maurolacy merged commit e64d54b into main Oct 4, 2021
@maurolacy maurolacy deleted the 198-better-range-prefix branch October 4, 2021 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better return values from range/prefix
4 participants