Unverified Commit c79e4bdf authored by cheme's avatar cheme Committed by GitHub
Browse files

Companion to child trie api change #4857 (#950)

parent 5ac55efc
Pipeline #88799 failed with stages
in 1 minute and 48 seconds
This diff is collapsed.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
use std::any::{TypeId, Any}; use std::any::{TypeId, Any};
use crate::primitives::{ValidationParams, ValidationResult, UpwardMessage}; use crate::primitives::{ValidationParams, ValidationResult, UpwardMessage};
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use sp_core::storage::{ChildStorageKey, ChildInfo}; use sp_core::storage::ChildInfo;
use sp_core::traits::CallInWasm; use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _; use sp_wasm_interface::HostFunctions as _;
...@@ -205,15 +205,15 @@ impl sp_externalities::Externalities for ValidationExternalities { ...@@ -205,15 +205,15 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("storage_hash: unsupported feature for parachain validation") panic!("storage_hash: unsupported feature for parachain validation")
} }
fn child_storage_hash(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> { fn child_storage_hash(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
panic!("child_storage_hash: unsupported feature for parachain validation") panic!("child_storage_hash: unsupported feature for parachain validation")
} }
fn child_storage(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> { fn child_storage(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
panic!("child_storage: unsupported feature for parachain validation") panic!("child_storage: unsupported feature for parachain validation")
} }
fn kill_child_storage(&mut self, _: ChildStorageKey, _: ChildInfo) { fn kill_child_storage(&mut self, _: &ChildInfo) {
panic!("kill_child_storage: unsupported feature for parachain validation") panic!("kill_child_storage: unsupported feature for parachain validation")
} }
...@@ -221,7 +221,7 @@ impl sp_externalities::Externalities for ValidationExternalities { ...@@ -221,7 +221,7 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("clear_prefix: unsupported feature for parachain validation") panic!("clear_prefix: unsupported feature for parachain validation")
} }
fn clear_child_prefix(&mut self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) { fn clear_child_prefix(&mut self, _: &ChildInfo, _: &[u8]) {
panic!("clear_child_prefix: unsupported feature for parachain validation") panic!("clear_child_prefix: unsupported feature for parachain validation")
} }
...@@ -229,7 +229,7 @@ impl sp_externalities::Externalities for ValidationExternalities { ...@@ -229,7 +229,7 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("place_storage: unsupported feature for parachain validation") panic!("place_storage: unsupported feature for parachain validation")
} }
fn place_child_storage(&mut self, _: ChildStorageKey, _: ChildInfo, _: Vec<u8>, _: Option<Vec<u8>>) { fn place_child_storage(&mut self, _: &ChildInfo, _: Vec<u8>, _: Option<Vec<u8>>) {
panic!("place_child_storage: unsupported feature for parachain validation") panic!("place_child_storage: unsupported feature for parachain validation")
} }
...@@ -241,7 +241,7 @@ impl sp_externalities::Externalities for ValidationExternalities { ...@@ -241,7 +241,7 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("storage_root: unsupported feature for parachain validation") panic!("storage_root: unsupported feature for parachain validation")
} }
fn child_storage_root(&mut self, _: ChildStorageKey) -> Vec<u8> { fn child_storage_root(&mut self, _: &ChildInfo) -> Vec<u8> {
panic!("child_storage_root: unsupported feature for parachain validation") panic!("child_storage_root: unsupported feature for parachain validation")
} }
...@@ -249,7 +249,7 @@ impl sp_externalities::Externalities for ValidationExternalities { ...@@ -249,7 +249,7 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("storage_changes_root: unsupported feature for parachain validation") panic!("storage_changes_root: unsupported feature for parachain validation")
} }
fn next_child_storage_key(&self, _: ChildStorageKey, _: ChildInfo, _: &[u8]) -> Option<Vec<u8>> { fn next_child_storage_key(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
panic!("next_child_storage_key: unsupported feature for parachain validation") panic!("next_child_storage_key: unsupported feature for parachain validation")
} }
......
...@@ -80,7 +80,6 @@ use sp_runtime::{ModuleId, ...@@ -80,7 +80,6 @@ use sp_runtime::{ModuleId,
use crate::slots; use crate::slots;
use codec::{Encode, Decode}; use codec::{Encode, Decode};
use sp_std::vec::Vec; use sp_std::vec::Vec;
use sp_core::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
use primitives::parachain::{Id as ParaId, HeadData}; use primitives::parachain::{Id as ParaId, HeadData};
const MODULE_ID: ModuleId = ModuleId(*b"py/cfund"); const MODULE_ID: ModuleId = ModuleId(*b"py/cfund");
...@@ -529,46 +528,30 @@ impl<T: Trait> Module<T> { ...@@ -529,46 +528,30 @@ impl<T: Trait> Module<T> {
MODULE_ID.into_sub_account(index) MODULE_ID.into_sub_account(index)
} }
pub fn id_from_index(index: FundIndex) -> Vec<u8> { pub fn id_from_index(index: FundIndex) -> child::ChildInfo {
let mut buf = Vec::new(); let mut buf = Vec::new();
buf.extend_from_slice(b"crowdfund"); buf.extend_from_slice(b"crowdfund");
buf.extend_from_slice(&index.to_le_bytes()[..]); buf.extend_from_slice(&index.to_le_bytes()[..]);
child::ChildInfo::new_default(T::Hashing::hash(&buf[..]).as_ref())
CHILD_STORAGE_KEY_PREFIX.into_iter()
.chain(b"default:")
.chain(T::Hashing::hash(&buf[..]).as_ref().into_iter())
.cloned()
.collect()
}
/// Child trie unique id for a crowdfund is built from the hash part of the fund id.
pub fn trie_unique_id(fund_id: &[u8]) -> child::ChildInfo {
let start = CHILD_STORAGE_KEY_PREFIX.len() + b"default:".len();
child::ChildInfo::new_default(&fund_id[start..])
} }
pub fn contribution_put(index: FundIndex, who: &T::AccountId, balance: &BalanceOf<T>) { pub fn contribution_put(index: FundIndex, who: &T::AccountId, balance: &BalanceOf<T>) {
let id = Self::id_from_index(index); who.using_encoded(|b| child::put(&Self::id_from_index(index), b, balance));
who.using_encoded(|b| child::put(id.as_ref(), Self::trie_unique_id(id.as_ref()), b, balance));
} }
pub fn contribution_get(index: FundIndex, who: &T::AccountId) -> BalanceOf<T> { pub fn contribution_get(index: FundIndex, who: &T::AccountId) -> BalanceOf<T> {
let id = Self::id_from_index(index);
who.using_encoded(|b| child::get_or_default::<BalanceOf<T>>( who.using_encoded(|b| child::get_or_default::<BalanceOf<T>>(
id.as_ref(), &Self::id_from_index(index),
Self::trie_unique_id(id.as_ref()),
b, b,
)) ))
} }
pub fn contribution_kill(index: FundIndex, who: &T::AccountId) { pub fn contribution_kill(index: FundIndex, who: &T::AccountId) {
let id = Self::id_from_index(index); who.using_encoded(|b| child::kill(&Self::id_from_index(index), b));
who.using_encoded(|b| child::kill(id.as_ref(), Self::trie_unique_id(id.as_ref()), b));
} }
pub fn crowdfund_kill(index: FundIndex) { pub fn crowdfund_kill(index: FundIndex) {
let id = Self::id_from_index(index); child::kill_storage(&Self::id_from_index(index));
child::kill_storage(id.as_ref(), Self::trie_unique_id(id.as_ref()));
} }
} }
......
...@@ -84,7 +84,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -84,7 +84,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"), spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"), impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2, authoring_version: 2,
spec_version: 1058, spec_version: 1059,
impl_version: 0, impl_version: 0,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
......
...@@ -86,7 +86,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -86,7 +86,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polkadot"), spec_name: create_runtime_str!("polkadot"),
impl_name: create_runtime_str!("parity-polkadot"), impl_name: create_runtime_str!("parity-polkadot"),
authoring_version: 2, authoring_version: 2,
spec_version: 1007, spec_version: 1008,
impl_version: 0, impl_version: 0,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
......
...@@ -118,7 +118,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters { ...@@ -118,7 +118,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters {
let mut storage = self.genesis_config().genesis_map(); let mut storage = self.genesis_config().genesis_map();
let child_roots = storage.children.iter().map(|(sk, child_content)| { let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root( let state_root = <<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect() child_content.data.clone().into_iter().collect()
); );
...@@ -198,7 +198,7 @@ pub trait TestClientBuilderExt<B>: Sized { ...@@ -198,7 +198,7 @@ pub trait TestClientBuilderExt<B>: Sized {
let key = key.into(); let key = key.into();
assert!(!storage_key.is_empty()); assert!(!storage_key.is_empty());
assert!(!key.is_empty()); assert!(!key.is_empty());
self.genesis_init_mut().extra_storage.children self.genesis_init_mut().extra_storage.children_default
.entry(storage_key) .entry(storage_key)
.or_insert_with(|| StorageChild { .or_insert_with(|| StorageChild {
data: Default::default(), data: Default::default(),
......
...@@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -80,7 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polkadot-test-runtime"), spec_name: create_runtime_str!("polkadot-test-runtime"),
impl_name: create_runtime_str!("parity-polkadot-test-runtime"), impl_name: create_runtime_str!("parity-polkadot-test-runtime"),
authoring_version: 2, authoring_version: 2,
spec_version: 1050, spec_version: 1051,
impl_version: 0, impl_version: 0,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
......
...@@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westend"), spec_name: create_runtime_str!("westend"),
impl_name: create_runtime_str!("parity-westend"), impl_name: create_runtime_str!("parity-westend"),
authoring_version: 2, authoring_version: 2,
spec_version: 3, spec_version: 4,
impl_version: 0, impl_version: 0,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
transaction_version: 1, transaction_version: 1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment