Make nested Lazy's clear storage properly#583
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #583 +/- ##
==========================================
- Coverage 67.86% 67.78% -0.08%
==========================================
Files 155 155
Lines 6895 6914 +19
==========================================
+ Hits 4679 4687 +8
- Misses 2216 2227 +11
Continue to review full report at Codecov.
|
Collaborator
|
Good catch! The fixed fn clear_spread(&self, ptr: &mut KeyPtr) {
let root_key = ExtKeyPtr::next_for::<Self>(ptr);
match <T as SpreadLayout>::REQUIRES_DEEP_CLEAN_UP {
true => {
// Load from storage and then clear:
clear_spread_root_opt::<T, _>(root_key, || self.get())
}
false => {
// Clear without loading from storage:
let footprint = <T as SpreadLayout>::FOOTPRINT;
assert!(footprint <= 16); // magic number
let mut key_ptr = KeyPtr::from(*root_key);
for _ in 0..footprint {
ink_env::clear_contract_storage(key_ptr.advance_by(1));
}
}
}
} |
Robbepop
requested changes
Nov 17, 2020
Co-authored-by: Hero Bird <robin.freyler@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #580.
The bug is that a
Lazydoesn't clear up it's inner cell forclear_spread, if the inner cell has not been loaded. This can easily happen with nestedLazy's ‒ likeLazy<Lazy<…>>.But also we often use
Lazyin storage structs likeStorageHashMap<…>(withvalues: LazyHashMap<…>‒ if these structs are then wrapped in aLazythere is already a nestedLazy.SmallVec,Vec,Stashor other storage structs which have this bug if they are wrapped in aLazy.The way I fixed this for now will probably lead to some discussion and I'm open for other approaches.