-
Notifications
You must be signed in to change notification settings - Fork 60
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
Allow updates to all item slots #737
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
43a72a5
reuse the SLOT_LAYOUT_COMMITMENT_INDEX constant
hackaugusto bc8c6f7
type to -> too
hackaugusto a85cb20
add api to create SlotItem
hackaugusto 7535010
replaced castings in favor of conversions
hackaugusto 2e0b7fd
add serde for StorageSlotType
hackaugusto 824715f
add comments to AccountStorage::new
hackaugusto fdf9e63
added layout_commitment util
hackaugusto 12f4692
use StorageMap serde
hackaugusto 456af4e
allow any slot item to be updated
hackaugusto c56cddf
Apply account delta storage maps (#738)
Dominik1999 9c6f4ec
last test:
Dominik1999 c5e5fe7
some refactorings
Dominik1999 33a16f4
adding a set_map_item in Rust
Dominik1999 eafa5c3
refactor: minor changes to storage mutator validation code
bobbinth ec24a37
chore: pacified clippy
bobbinth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,7 +203,8 @@ impl AccountStorage { | |
let slots = SimpleSmt::<STORAGE_TREE_DEPTH>::with_leaves(entries) | ||
.map_err(AccountError::DuplicateStorageItems)?; | ||
|
||
if maps.len() > num_maps { | ||
// make sure the number of provide maps matches the number of map slots | ||
if maps.len() != num_maps { | ||
return Err(AccountError::StorageMapTooManyMaps { | ||
expected: num_maps, | ||
actual: maps.len(), | ||
|
@@ -263,13 +264,8 @@ impl AccountStorage { | |
/// - The updates violate storage layout constraints. | ||
/// - The updated value has an arity different from 0. | ||
pub(super) fn apply_delta(&mut self, delta: &AccountStorageDelta) -> Result<(), AccountError> { | ||
for &slot_idx in delta.cleared_items.iter() { | ||
self.set_item(slot_idx, Word::default())?; | ||
} | ||
|
||
for &(slot_idx, slot_value) in delta.updated_items.iter() { | ||
self.set_item(slot_idx, slot_value)?; | ||
} | ||
// --- update storage maps -------------------------------------------- | ||
|
||
for &(slot_idx, ref map_delta) in delta.updated_maps.iter() { | ||
// layout commitment slot cannot be updated | ||
|
@@ -283,6 +279,18 @@ impl AccountStorage { | |
storage_map.apply_delta(map_delta)?; | ||
} | ||
|
||
// --- update storage slots ------------------------------------------- | ||
// this will also update roots of updated storage maps, and thus should be run after we | ||
// update storage maps - otherwise the roots won't match | ||
|
||
for &slot_idx in delta.cleared_items.iter() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've also added this code which ensures that slots corresponding to storage maps can be set only to the roots of these maps. So, if we try to update the roots first (before updating the maps themselves), the assertion would get triggered. |
||
self.set_item(slot_idx, Word::default())?; | ||
} | ||
|
||
for &(slot_idx, slot_value) in delta.updated_items.iter() { | ||
self.set_item(slot_idx, slot_value)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -318,6 +326,12 @@ impl AccountStorage { | |
actual: value_arity, | ||
}); | ||
} | ||
|
||
// make sure the value matches the root of the corresponding storage map | ||
// TODO: we should remove handling of storage map updates from set_item(); | ||
// once this is done, these checks would not be necessary | ||
let storage_map = self.maps.get(&index).expect("storage map not found"); | ||
assert_eq!(storage_map.root(), value.into()); | ||
}, | ||
slot_type => Err(AccountError::StorageSlotArrayNotAllowed(index, slot_type))?, | ||
} | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the order doesn't matter, the storage root update is queued in
updated_items
and the maps update inupdated_maps
. Both are triggered in MASM inset_map_item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In combination with the code I linked above, the order does matter (otherwise tests won't pass). But also, this code is separate from MASM: when executing MASM we are building the delta, here we are applying it - which happens later.