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

Leftovers when clearing storage of nested Lazy-like structures #580

Closed
cmichi opened this issue Nov 16, 2020 · 0 comments · Fixed by #583
Closed

Leftovers when clearing storage of nested Lazy-like structures #580

cmichi opened this issue Nov 16, 2020 · 0 comments · Fixed by #583
Assignees
Labels
A-ink_storage [ink_storage] Work Item C-bug Something isn't working P-high High priority issue.

Comments

@cmichi
Copy link
Collaborator

cmichi commented Nov 16, 2020

I found a bug whereby we have leftovers in storage for nested Lazy-like structs.

In the example below Vec.elems: LazyIndexMap is the offender, though e.g. our HashMap is also affected by the bug.

#[test]
fn bug() {
    ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
        // given
        let root_key = Key::from([0x42; 32]);
        let mut vec: Lazy<StorageVec<u32>> = Lazy::new(StorageVec::new());
        vec.push(13u32);
        SpreadLayout::push_spread(&vec, &mut KeyPtr::from(root_key));
        let _ = <Lazy<StorageVec<u32>> as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key));

        // when
        SpreadLayout::clear_spread(&vec, &mut KeyPtr::from(root_key));

        // then
        let storage_used = ink_env::test::get_contract_storage_used::<
            ink_env::DefaultEnvironment,
        >(&contract_id()).expect("used storage must be returned");
        assert_eq!(storage_used, 0);

        Ok(())
    }).unwrap()
}

Fails with

thread 'collections::vec::tests::bug' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', crates/storage/src/collections/vec/tests.rs:413:9
@cmichi cmichi added C-bug Something isn't working A-ink_storage [ink_storage] Work Item P-high High priority issue. labels Nov 16, 2020
@cmichi cmichi self-assigned this Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item C-bug Something isn't working P-high High priority issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant