mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +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:
@@ -50,6 +50,7 @@ use runtime_version::NativeVersion;
|
||||
use runtime_support::{impl_outer_origin, parameter_types, weights::Weight};
|
||||
use inherents::{CheckInherentsResult, InherentData};
|
||||
use cfg_if::cfg_if;
|
||||
use primitives::storage::ChildType;
|
||||
|
||||
// Ensure Babe and Aura use the same crypto to simplify things a bit.
|
||||
pub use babe_primitives::AuthorityId;
|
||||
@@ -910,21 +911,37 @@ fn test_read_storage() {
|
||||
|
||||
fn test_read_child_storage() {
|
||||
const CHILD_KEY: &[u8] = b":child_storage:default:read_child_storage";
|
||||
const UNIQUE_ID: &[u8] = b":unique_id";
|
||||
const KEY: &[u8] = b":read_child_storage";
|
||||
sp_io::storage::child_set(CHILD_KEY, KEY, b"test");
|
||||
sp_io::storage::child_set(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
KEY,
|
||||
b"test",
|
||||
);
|
||||
|
||||
let mut v = [0u8; 4];
|
||||
let r = sp_io::storage::child_read(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
KEY,
|
||||
&mut v,
|
||||
0
|
||||
0,
|
||||
);
|
||||
assert_eq!(r, Some(4));
|
||||
assert_eq!(&v, b"test");
|
||||
|
||||
let mut v = [0u8; 4];
|
||||
let r = sp_io::storage::child_read(CHILD_KEY, KEY, &mut v, 8);
|
||||
let r = sp_io::storage::child_read(
|
||||
CHILD_KEY,
|
||||
UNIQUE_ID,
|
||||
ChildType::CryptoUniqueId as u32,
|
||||
KEY,
|
||||
&mut v,
|
||||
8,
|
||||
);
|
||||
assert_eq!(r, Some(4));
|
||||
assert_eq!(&v, &[0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user