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

Secondary indexes support #557

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a7e7e19
Basic indexed_bucket compiles
ethanfrey Oct 1, 2020
0190384
Test query by index... fail
ethanfrey Oct 1, 2020
cce8040
Basic index query works
ethanfrey Oct 1, 2020
29ab5e5
Only export when iterator feature enabled
ethanfrey Oct 1, 2020
564a055
WIP: Add multiple indexes - mutable/lifetime issue
ethanfrey Oct 1, 2020
af066c0
Add support for multiple secondary indexes
ethanfrey Oct 1, 2020
c199e68
Pull more code into Core
ethanfrey Oct 1, 2020
b00e778
Test two different indexes
ethanfrey Oct 1, 2020
54442d2
Fix clippy warnings
ethanfrey Oct 1, 2020
b950d01
Only store namespace as &[u8]
ethanfrey Oct 2, 2020
5aa9cbc
MultiIndex using trait
ethanfrey Oct 2, 2020
54d79de
Implement UniqueIndex
ethanfrey Oct 2, 2020
c265ff5
Implement index-specific getters
ethanfrey Oct 2, 2020
06c0858
Properly query unique indexes
ethanfrey Oct 3, 2020
b913301
Less alloc on creating indexes
ethanfrey Oct 3, 2020
dfe0616
Separate index implementation from IndexedBucket
ethanfrey Oct 3, 2020
3c9ddba
Remove intermediate steps in IndexedBucket/Core
ethanfrey Oct 3, 2020
c9bfe67
Move index-specific logic out of Core
ethanfrey Oct 3, 2020
9987396
Fix clippy warnings
ethanfrey Oct 3, 2020
7cb6f0b
Fixed clippy for real
ethanfrey Oct 3, 2020
021ee9e
Pull out index functions
ethanfrey Oct 3, 2020
7836f6b
Test and enforce unique index
ethanfrey Oct 3, 2020
355dfa1
Ensure multi-index properly updated
ethanfrey Oct 3, 2020
a36cda5
Update Bucket to be more compatible with Core
ethanfrey Oct 3, 2020
120921f
Bucket and ReadOnlyBucket pass tests
ethanfrey Oct 3, 2020
569c788
IndexedBucket and Indexes use Bucket not Core
ethanfrey Oct 3, 2020
68f6805
Remove multilevel constructors
ethanfrey Oct 3, 2020
166253b
Add Pk2 and Pk3 as examples of composite keys
ethanfrey Oct 3, 2020
2ac9a95
Cleanup Pks a bit, add range mapper
ethanfrey Oct 3, 2020
cb80d06
Prototype of range_prefixed for scanning part of a composite index
ethanfrey Oct 3, 2020
e1ac2c1
Less allocations in PrimaryKeys
ethanfrey Oct 4, 2020
7e74d25
Test usage with Pk2 and minor cleanup
ethanfrey Oct 4, 2020
89a6c1f
Update CHANGELOG and MIGRATING
ethanfrey Oct 4, 2020
01935e5
Merge pull request #558 from CosmWasm/merge-core-and-bucket
ethanfrey Oct 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
namespace in `PrefixedStorage::new`, `PrefixedStorage::multilevel`,
`ReadonlyPrefixedStorage::new`, `ReadonlyPrefixedStorage::multilevel`,
`prefixed` and `prefixed_read`.
- Remove `Bucket::multilevel` as it was a misnomer. Provide support for
composite `PrimaryKey`s in storage, using `Pk2` and `Pk3` for 2 or 3 items
keys. Add `Bucket::range_prefixed` to provide the first section(s) of the
composite key and iterate under that.
- Bucket stores all data under `(namespace, "_pk", key)`, where the first two
are length-prefixed. This is a different layout from previous form
where it was `(namespace, key)` and this is intended to support co-existence
with `IndexedBucket`. (It only changes the raw storage layout, APIs don't change).

**cosmwasm-vm**

Expand Down
46 changes: 46 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,52 @@ major releases of `cosmwasm`. Note that you can also view the
})
```

- Remove `Bukcet::multilevel` constructor. The bucket now has exactly one namespace
and if we need `multilevel`, it was really to provide composite primary keys.
We now do that explicitly in a way that allows better compatibility
with `IndexedBucket`. The test `bucket_with_composite_pk` in `bucket.rs` is
a good (tested) example of the new API.

```rust
// before (from cw20-base)
pub fn allowances<'a, S: Storage>(
storage: &'a mut S,
owner: &CanonicalAddr,
) -> Bucket<'a, S, AllowanceResponse> {
Bucket::multilevel(&[PREFIX_ALLOWANCE, owner.as_slice()], storage)
}

allowances(&mut deps.storage, owner_raw).update(spender_raw.as_slice(), |allow| {
// code omitted...
})?;

let allowances: StdResult<Vec<AllowanceInfo>> = allowances_read(&deps.storage, &owner_raw)
.range(start.as_deref(), None, Order::Ascending)
.take(limit)
.map(|item| {
// code omitted...
})
.collect();

// after
pub fn allowances<S: Storage>(storage: &mut S) -> Bucket<S, AllowanceResponse> {
Bucket::new(PREFIX_ALLOWANCE, storage)
}

allowances(&mut deps.storage).update(&Pk2(owner_raw.as_slice(), spender_raw.as_slice()).pk(), |allow| {
// code omitted...
})?;

let allowances: StdResult<Vec<AllowanceInfo>> = allowances(&deps.storage)
.range_prefixed(owner_raw.as_slice(), start.as_deref(), None, Order::Ascending)
.take(limit)
.map(|item| {
// code omitted...
})
.collect();
```


## 0.9 -> 0.10

Integration tests:
Expand Down
Loading