mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 14:47:55 +00:00
Check storage_key for validity (#2316)
* Intro `ChildStorageKey` for checked child keys * Get rid of Into in Externalities trait * Use Cow in ChildStorageKey * Fix tests for state-machine. * Clean * child_storage_root always return a value * Don't return Option from Ext::child_storage_root * Return 42 in child_storage_root * Return CHILD_STORAGE_KEY_PREFIX from trie id gen * Bump spec and impl version. * Require `:default:` in `is_child_trie_key_valid` * Add `default:` prefix. * Introduce `into_owned` for `ChildStorageKey`. * Add documentation. * Fix state-machine tests * Remove outdated TODO I check out with Emeric and he is ok with that * child_storage_root is infailable * Nit * Move assert after check. * Apply suggestions from @DemiMarie-parity Co-Authored-By: pepyakin <s.pepyakin@gmail.com> * Formatting nit in core/executor/src/wasm_executor.rs Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * Formatting nits from @thiolliere
This commit is contained in:
@@ -25,7 +25,7 @@ use crate::backend::InMemory;
|
||||
use crate::changes_trie::{compute_changes_trie_root, InMemoryStorage as ChangesTrieInMemoryStorage, AnchorBlockId};
|
||||
use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES};
|
||||
use parity_codec::Encode;
|
||||
use super::{Externalities, OverlayedChanges};
|
||||
use super::{ChildStorageKey, Externalities, OverlayedChanges};
|
||||
|
||||
/// Simple HashMap-based Externalities impl.
|
||||
pub struct TestExternalities<H: Hasher> where H::Out: HeapSizeOf {
|
||||
@@ -122,8 +122,8 @@ impl<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord + He
|
||||
self.storage(key)
|
||||
}
|
||||
|
||||
fn child_storage(&self, storage_key: &[u8], key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.changes.child_storage(storage_key, key)?.map(Vec::from)
|
||||
fn child_storage(&self, storage_key: ChildStorageKey<H>, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.changes.child_storage(storage_key.as_ref(), key)?.map(Vec::from)
|
||||
}
|
||||
|
||||
fn place_storage(&mut self, key: Vec<u8>, maybe_value: Option<Vec<u8>>) {
|
||||
@@ -139,14 +139,12 @@ impl<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord + He
|
||||
}
|
||||
}
|
||||
|
||||
fn place_child_storage(&mut self, storage_key: Vec<u8>, key: Vec<u8>, value: Option<Vec<u8>>) -> bool {
|
||||
self.changes.set_child_storage(storage_key, key, value);
|
||||
// TODO place_child_storage and set_child_storage should always be valid (create child on set)?
|
||||
true
|
||||
fn place_child_storage(&mut self, storage_key: ChildStorageKey<H>, key: Vec<u8>, value: Option<Vec<u8>>) {
|
||||
self.changes.set_child_storage(storage_key.into_owned(), key, value);
|
||||
}
|
||||
|
||||
fn kill_child_storage(&mut self, storage_key: &[u8]) {
|
||||
self.changes.clear_child_storage(storage_key);
|
||||
fn kill_child_storage(&mut self, storage_key: ChildStorageKey<H>) {
|
||||
self.changes.clear_child_storage(storage_key.as_ref());
|
||||
}
|
||||
|
||||
fn clear_prefix(&mut self, prefix: &[u8]) {
|
||||
@@ -160,8 +158,8 @@ impl<H: Hasher> Externalities<H> for TestExternalities<H> where H::Out: Ord + He
|
||||
trie_root::<H, _, _, _>(self.inner.clone())
|
||||
}
|
||||
|
||||
fn child_storage_root(&mut self, _storage_key: &[u8]) -> Option<Vec<u8>> {
|
||||
None
|
||||
fn child_storage_root(&mut self, _storage_key: ChildStorageKey<H>) -> Vec<u8> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option<H::Out> {
|
||||
|
||||
Reference in New Issue
Block a user