mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +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:
@@ -42,7 +42,7 @@ mod tests {
|
||||
use state_machine::TestExternalities as CoreTestExternalities;
|
||||
use primitives::{
|
||||
Blake2Hasher, NeverNativeValue, NativeOrEncoded, map,
|
||||
traits::{CodeExecutor, Externalities}, storage::well_known_keys,
|
||||
traits::{CodeExecutor, Externalities}, storage::{well_known_keys, Storage},
|
||||
};
|
||||
use sp_runtime::{
|
||||
Fixed64, traits::{Header as HeaderT, Hash as HashT, Convert}, ApplyExtrinsicResult,
|
||||
@@ -143,20 +143,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_with_foreign_code_gives_error() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
|
||||
vec![0u8; 32]
|
||||
}
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
|
||||
vec![0u8; 32]
|
||||
}
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -179,20 +182,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bad_extrinsic_with_native_equivalent_code_gives_error() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
|
||||
vec![0u8; 32]
|
||||
}
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
69_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => {
|
||||
vec![0u8; 32]
|
||||
}
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -215,16 +221,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_native_equivalent_code_gives_ok() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -254,16 +263,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_with_foreign_code_gives_ok() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -828,16 +840,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn panic_execution_gives_error() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(BLOATY_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
0_u128.encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -860,16 +875,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn successful_execution_gives_ok() {
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(111 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let r = executor_call::<NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
@@ -1037,19 +1055,22 @@ mod tests {
|
||||
// - 1 MILLICENTS in substrate node.
|
||||
// - 1 milli-dot based on current polkadot runtime.
|
||||
// (this baed on assigning 0.1 CENT to the cheapest tx with `weight = 100`)
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, (map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(100 * DOLLARS).encode()
|
||||
},
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(bob()) => {
|
||||
(10 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(110 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
], map![]));
|
||||
let mut t = TestExternalities::<Blake2Hasher>::new_with_code(COMPACT_CODE, Storage {
|
||||
top: map![
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(alice()) => {
|
||||
(100 * DOLLARS).encode()
|
||||
},
|
||||
<balances::FreeBalance<Runtime>>::hashed_key_for(bob()) => {
|
||||
(10 * DOLLARS).encode()
|
||||
},
|
||||
<balances::TotalIssuance<Runtime>>::hashed_key().to_vec() => {
|
||||
(110 * DOLLARS).encode()
|
||||
},
|
||||
<indices::NextEnumSet<Runtime>>::hashed_key().to_vec() => vec![0u8; 16],
|
||||
<system::BlockHash<Runtime>>::hashed_key_for(0) => vec![0u8; 32]
|
||||
],
|
||||
children: map![],
|
||||
});
|
||||
|
||||
let tip = 1_000_000;
|
||||
let xt = sign(CheckedExtrinsic {
|
||||
|
||||
Reference in New Issue
Block a user