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

Provide a StorageVec datastructure #1995

Merged
merged 37 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7b0b5ca
design draft
xermicus Nov 2, 2023
e05f98a
basic tests
xermicus Nov 2, 2023
be69ee7
cache the length
xermicus Nov 6, 2023
65d9ea6
get and set
xermicus Nov 6, 2023
a5e04d6
Merge branch 'master' into storage-vec
xermicus Nov 15, 2023
ac73b3f
add clear
xermicus Nov 15, 2023
ab05008
add basic integration test
xermicus Nov 15, 2023
3616b6f
add fallible methods
xermicus Nov 15, 2023
3013112
tests for fallible ops
xermicus Nov 15, 2023
e29edd0
improve clear tests
xermicus Nov 15, 2023
bd03135
fmt
xermicus Nov 15, 2023
ec4e745
spellcheck
xermicus Nov 15, 2023
63f6166
fmt
xermicus Nov 15, 2023
b3a564c
do not alias
xermicus Nov 15, 2023
439f31e
spellcheck
xermicus Nov 16, 2023
45a5776
peek
xermicus Nov 16, 2023
e49b846
make example more meaningful
xermicus Nov 17, 2023
d7abe1f
Merge branch 'master' into storage-vec
xermicus Nov 17, 2023
b0980af
add to mother
xermicus Nov 17, 2023
c87ac98
rm stale toolchain files
xermicus Nov 17, 2023
afe08f0
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
f01d430
code review
xermicus Nov 29, 2023
a0257bd
impl FromIter for StorageVec
xermicus Nov 29, 2023
634f77c
clippy
xermicus Nov 29, 2023
703430a
remove unneeded impl from slice and fix UI tests
xermicus Nov 29, 2023
50271bb
bump scale dep
xermicus Nov 29, 2023
5c2cb4e
ui
xermicus Nov 29, 2023
dc24fb9
put the cached len into a cell so we do not rely on writing operation…
xermicus Nov 29, 2023
3348363
keep None length if the vec does not exist
xermicus Nov 29, 2023
2b15422
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
07e0e2b
changelog
xermicus Nov 29, 2023
b36ae42
improve peek test
xermicus Nov 29, 2023
f53eb73
add dev note regarding cached len
xermicus Nov 29, 2023
7e161ff
Merge branch 'master' into storage-vec
xermicus Nov 29, 2023
b3dc029
Merge branch 'master' into storage-vec
xermicus Nov 30, 2023
7a12c1e
Update crates/storage/src/lazy/vec.rs
xermicus Nov 30, 2023
1d9b7d2
fmt
xermicus Nov 30, 2023
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
7 changes: 7 additions & 0 deletions .config/cargo_spellcheck.dic
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ payability
unpayable
initializer
WebSocket/S
StorageVec
KiB
GB
BufferTooSmall
KeyNotFound
ink_env
^
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Linter: `no_main` lint - [#2001](https://github.com/paritytech/ink/pull/2001)
- Clean E2E configuration parsing - [#1922](https://github.com/paritytech/ink/pull/1922)
- Make `set_code_hash` generic - [#1906](https://github.com/paritytech/ink/pull/1906)
- Provide a `StorageVec` datastructure built on top of `Lazy` - [#1995](https://github.com/paritytech/ink/pull/1955)

### Changed
- Messages return `TypeSpec` directly - #[1999](https://github.com/paritytech/ink/pull/1999)
Expand Down
1 change: 1 addition & 0 deletions crates/ink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod storage {
pub use ink_storage::{
Lazy,
Mapping,
StorageVec,
};
}

Expand Down
8 changes: 5 additions & 3 deletions crates/storage/src/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
//! extra care has to be taken when operating directly on them.

mod mapping;
mod vec;

#[doc(inline)]
pub use self::mapping::Mapping;
pub use self::vec::StorageVec;

use crate::traits::{
AutoKey,
Expand Down Expand Up @@ -159,15 +161,15 @@ where
let key_size = <Key as Storable>::encoded_size(&KeyType::KEY);

if key_size >= ink_env::BUFFER_SIZE {
return Some(Err(ink_env::Error::BufferTooSmall))
return Some(Err(ink_env::Error::BufferTooSmall));
}

let value_size: usize = ink_env::contains_contract_storage(&KeyType::KEY)?
.try_into()
.expect("targets of less than 32bit pointer size are not supported; qed");

if key_size.saturating_add(value_size) > ink_env::BUFFER_SIZE {
return Some(Err(ink_env::Error::BufferTooSmall))
return Some(Err(ink_env::Error::BufferTooSmall));
}

self.get().map(Ok)
Expand All @@ -191,7 +193,7 @@ where
let value_size = <V as Storable>::encoded_size(value);

if key_size.saturating_add(value_size) > ink_env::BUFFER_SIZE {
return Err(ink_env::Error::BufferTooSmall)
return Err(ink_env::Error::BufferTooSmall);
};

self.set(value);
Expand Down
Loading