-
Notifications
You must be signed in to change notification settings - Fork 480
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
impl original_storage in SubstrateStackState #871
impl original_storage in SubstrateStackState #871
Conversation
@@ -629,6 +643,15 @@ where | |||
} | |||
|
|||
fn set_storage(&mut self, address: H160, index: H256, value: H256) { |
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.
Add a check beforehand that:
- If
self.original_storage
does not contain the key, - and the to-set-value is the same as the current value.
Skip inserting into the original_storage.
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.
If self.original_storage does not contain the key,
That's whatif let Vacant(e) = self.original_storage.entry(...)
does, which was recommanded by clippy instead ofcontains
theninsert
.
and the to-set-value is the same as the current value.
Yeah, can add this check to not insert for same value as original.
// in the transaction. | ||
use sp_std::collections::btree_map::Entry::Vacant; | ||
if let Vacant(e) = self.original_storage.entry((address, index)) { | ||
let original = <AccountStorages<T>>::get(address, index); |
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.
Use self.storage
here to keep it consistent.
let original = <AccountStorages<T>>::get(address, index); | |
let original = self.storage(address, index); |
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.
Cannot use self.storage
as we're already borrowing self with self.original_storage.entry
. Seems better to keep <AccountStorages<T>>::get
than fetching the value every time even when the entry is not vacant.
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.
Grumble otherwise LGTM.
408fbe3
to
018eb95
Compare
* handle original_storage * only cache original_storage in set_storage * test * clippy * remove RefCell * don't write to cache if = to original
* handle original_storage * only cache original_storage in set_storage * test * clippy * remove RefCell * don't write to cache if = to original
Implement
original_storage
which previously returnedNone
everytime.