mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
Fix key collision for child trie (#4162)
* In progress, runtime io must switch to future proof root + child_specific (unique id) + u32 type. * Switch interface, sr-io seems ok, rpc could use similar interface to sr-io, genesis json broken if there is child trie in existing encoding genesis. * test from previous implementation. * fix proving test. * Restore Keyspacedb from other branch, only apply to child trie. * Removing unneeded child_info from child root (child info are stored if things changed, otherwhise the root does not change). * Switch rpc to use same format as ext: more future proof. * use root from child info for trie backend essence. * Breaking long lines. * Update doc and clean pr a bit. * fix error type * Restore removed doc on merge and update sr-io doc. * Switch child storage api to use directly unique id, if managed id where to be put in place, the api will change at this time. * Clean deprecated host interface from child. * Removing assertion on child info (can fail depending on root memoization). * merging child info in the overlay when possible. * child iteration by prefix using child_info. * Using ChainInfo in frame support. ChainInfo gets redesign to avoid buffers allocation on every calls. * Add length of root to the data of child info. * comments * Encode compact. * Remove child info with root. * Fix try_update condition. * Comment Ext child root caching. * Replace tuples by struct with field * remove StorageTuple alias. * Fix doc tests, and remove StorageOverlay and ChildStorageOverlay aliases.
This commit is contained in:
@@ -38,7 +38,7 @@ pub use paste;
|
||||
pub use app_crypto;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use primitives::storage::{StorageOverlay, ChildrenStorageOverlay};
|
||||
pub use primitives::storage::{Storage, StorageChild};
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_std::convert::TryFrom;
|
||||
@@ -121,15 +121,15 @@ use crate::traits::IdentifyAccount;
|
||||
#[cfg(feature = "std")]
|
||||
pub trait BuildStorage: Sized {
|
||||
/// Build the storage out of this builder.
|
||||
fn build_storage(&self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> {
|
||||
let mut storage = (Default::default(), Default::default());
|
||||
fn build_storage(&self) -> Result<primitives::storage::Storage, String> {
|
||||
let mut storage = Default::default();
|
||||
self.assimilate_storage(&mut storage)?;
|
||||
Ok(storage)
|
||||
}
|
||||
/// Assimilate the storage for this module into pre-existing overlays.
|
||||
fn assimilate_storage(
|
||||
&self,
|
||||
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
|
||||
storage: &mut primitives::storage::Storage,
|
||||
) -> Result<(), String>;
|
||||
}
|
||||
|
||||
@@ -139,23 +139,26 @@ pub trait BuildModuleGenesisStorage<T, I>: Sized {
|
||||
/// Create the module genesis storage into the given `storage` and `child_storage`.
|
||||
fn build_module_genesis_storage(
|
||||
&self,
|
||||
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
|
||||
storage: &mut primitives::storage::Storage,
|
||||
) -> Result<(), String>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl BuildStorage for (StorageOverlay, ChildrenStorageOverlay) {
|
||||
impl BuildStorage for primitives::storage::Storage {
|
||||
fn assimilate_storage(
|
||||
&self,
|
||||
storage: &mut (StorageOverlay, ChildrenStorageOverlay),
|
||||
storage: &mut primitives::storage::Storage,
|
||||
)-> Result<(), String> {
|
||||
storage.0.extend(self.0.iter().map(|(k, v)| (k.clone(), v.clone())));
|
||||
for (k, other_map) in self.1.iter() {
|
||||
storage.top.extend(self.top.iter().map(|(k, v)| (k.clone(), v.clone())));
|
||||
for (k, other_map) in self.children.iter() {
|
||||
let k = k.clone();
|
||||
if let Some(map) = storage.1.get_mut(&k) {
|
||||
map.extend(other_map.iter().map(|(k, v)| (k.clone(), v.clone())));
|
||||
if let Some(map) = storage.children.get_mut(&k) {
|
||||
map.data.extend(other_map.data.iter().map(|(k, v)| (k.clone(), v.clone())));
|
||||
if !map.child_info.try_update(other_map.child_info.as_ref()) {
|
||||
return Err("Incompatible child info update".to_string());
|
||||
}
|
||||
} else {
|
||||
storage.1.insert(k, other_map.clone());
|
||||
storage.children.insert(k, other_map.clone());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -532,7 +535,7 @@ macro_rules! impl_outer_config {
|
||||
impl $crate::BuildStorage for $main {
|
||||
fn assimilate_storage(
|
||||
&self,
|
||||
storage: &mut ($crate::StorageOverlay, $crate::ChildrenStorageOverlay),
|
||||
storage: &mut $crate::Storage,
|
||||
) -> std::result::Result<(), String> {
|
||||
$(
|
||||
if let Some(ref extra) = self.[< $snake $(_ $instance )? >] {
|
||||
|
||||
Reference in New Issue
Block a user