-
Notifications
You must be signed in to change notification settings - Fork 371
Add storage_append to runtime #92
Conversation
Forked at: 3acb6d0 Parent branch: origin/master
coriolinus
left a comment
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 I understand what this is doing, but it looks like a self-contained change; it's not obvious to me why adding the storage_append method fixes things.
|
It's one of the method of the runtime. If the method is not declared, it falls back to the default implementation that just panics. Literally a runtime exception XD |
|
@bkchr Is there any reason not to merge this immediately? |
| let mut value_vec = Vec::with_capacity(1); | ||
| value_vec.push(EncodeOpaqueValue(value)); | ||
|
|
||
| if let Some(Some(item)) = self.overlay.remove(&key_vec) { |
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.
You want to use the entry api here.
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 don't think I want this time. I'm doing a remove to extract the value to transform it and re-insert it in the hashmap. I don't need a mutable reference here
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.
You want it ;) sp_std::mem::take is your friend.
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.
Probably fixed in here: #92 (comment)
Sometimes even I take some time to review prs :D |
| fn storage_append(&mut self, key: &[u8], value: Vec<u8>) { | ||
| let value_vec = sp_std::vec![EncodeOpaqueValue(value)]; | ||
| let current_value = self.overlay.entry(key.to_vec()).or_default(); | ||
|
|
||
| if let Some(item) = sp_std::mem::take(current_value) { | ||
| *current_value = Some(match Vec::<EncodeOpaqueValue>::append_or_new(item, &value_vec) { | ||
| Ok(item) => item, | ||
| Err(_) => value_vec.encode(), | ||
| }); | ||
| } else { | ||
| *current_value = Some(value_vec.encode()); | ||
| } | ||
| } |
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.
Implementation with the entry api instead of remove/insert. Is it good? 😅 I guess since it doesn't remove and then re-insert, this saves an allocation
Check if the container is running and finished syncing the parachain
No description provided.