mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +00:00
Companion for substrate#9732 (#678)
* state-update4 branch * new ref * Update to latest. * update deps * switch to host state version * update * fmt * up * remove trie patch * remove patch * fmt * update * set state_versions in runtimes * state version from storage * state version from storage * seedling compat * restore lock * update lockfile for substrate * update lockfile for polkadot Co-authored-by: parity-processbot <>
This commit is contained in:
Generated
+251
-250
File diff suppressed because it is too large
Load Diff
@@ -430,8 +430,8 @@ mod tests {
|
||||
assert_eq!(1, *block.header().number());
|
||||
|
||||
// Ensure that we did not include `:code` in the proof.
|
||||
let db = block
|
||||
.storage_proof()
|
||||
let proof = block.storage_proof();
|
||||
let db = proof
|
||||
.to_storage_proof::<BlakeTwo256>(Some(header.state_root()))
|
||||
.unwrap()
|
||||
.0
|
||||
|
||||
@@ -21,21 +21,26 @@ use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero
|
||||
/// Generate the genesis block from a given ChainSpec.
|
||||
pub fn generate_genesis_block<Block: BlockT>(
|
||||
chain_spec: &Box<dyn ChainSpec>,
|
||||
genesis_state_version: sp_runtime::StateVersion,
|
||||
) -> Result<Block, String> {
|
||||
let storage = chain_spec.build_storage()?;
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
genesis_state_version,
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||
genesis_state_version,
|
||||
);
|
||||
|
||||
let extrinsics_root =
|
||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
||||
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
Vec::new(),
|
||||
sp_runtime::StateVersion::V0,
|
||||
);
|
||||
|
||||
Ok(Block::new(
|
||||
<<Block as BlockT>::Header as HeaderT>::new(
|
||||
|
||||
@@ -371,6 +371,7 @@ mod tests {
|
||||
impl_version: 1,
|
||||
apis: sp_version::create_apis_vec!([]),
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
};
|
||||
pub const ParachainId: ParaId = ParaId::new(200);
|
||||
pub const ReservedXcmpWeight: Weight = 0;
|
||||
|
||||
@@ -63,6 +63,7 @@ parameter_types! {
|
||||
impl_version: 1,
|
||||
apis: sp_version::create_apis_vec!([]),
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
};
|
||||
pub const ParachainId: ParaId = ParaId::new(200);
|
||||
pub const ReservedXcmpWeight: Weight = 0;
|
||||
|
||||
@@ -26,7 +26,7 @@ use polkadot_parachain::primitives::{HeadData, ValidationParams, ValidationResul
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
use sp_core::storage::ChildInfo;
|
||||
use sp_core::storage::{ChildInfo, StateVersion};
|
||||
use sp_externalities::{set_and_run_with_externalities, Externalities};
|
||||
use sp_trie::MemoryDB;
|
||||
|
||||
@@ -68,7 +68,7 @@ where
|
||||
|
||||
// Uncompress
|
||||
let mut db = MemoryDB::default();
|
||||
let root = match sp_trie::decode_compact::<sp_trie::Layout<HashFor<B>>, _, _>(
|
||||
let root = match sp_trie::decode_compact::<sp_trie::LayoutV1<HashFor<B>>, _, _>(
|
||||
&mut db,
|
||||
storage_proof.iter_compact_encoded_nodes(),
|
||||
Some(parent_head.state_root()),
|
||||
@@ -221,8 +221,8 @@ fn host_storage_clear(key: &[u8]) {
|
||||
with_externalities(|ext| ext.place_storage(key.to_vec(), None))
|
||||
}
|
||||
|
||||
fn host_storage_root() -> Vec<u8> {
|
||||
with_externalities(|ext| ext.storage_root())
|
||||
fn host_storage_root(version: StateVersion) -> Vec<u8> {
|
||||
with_externalities(|ext| ext.storage_root(version))
|
||||
}
|
||||
|
||||
fn host_storage_clear_prefix(prefix: &[u8], limit: Option<u32>) -> KillStorageResult {
|
||||
@@ -327,9 +327,9 @@ fn host_default_child_storage_clear_prefix(
|
||||
})
|
||||
}
|
||||
|
||||
fn host_default_child_storage_root(storage_key: &[u8]) -> Vec<u8> {
|
||||
fn host_default_child_storage_root(storage_key: &[u8], version: StateVersion) -> Vec<u8> {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
with_externalities(|ext| ext.child_storage_root(&child_info))
|
||||
with_externalities(|ext| ext.child_storage_root(&child_info, version))
|
||||
}
|
||||
|
||||
fn host_default_child_storage_next_key(storage_key: &[u8], key: &[u8]) -> Option<Vec<u8>> {
|
||||
|
||||
@@ -192,8 +192,9 @@ pub fn run() -> Result<()> {
|
||||
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
|
||||
let _ = builder.init();
|
||||
|
||||
let block: Block =
|
||||
generate_genesis_block(&load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
|
||||
let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;
|
||||
let state_version = Cli::native_runtime_version(&spec).state_version();
|
||||
let block: Block = generate_genesis_block(&spec, state_version)?;
|
||||
let raw_header = block.header().encode();
|
||||
let output_buf = if params.raw {
|
||||
raw_header
|
||||
@@ -274,8 +275,10 @@ pub fn run() -> Result<()> {
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
||||
|
||||
let block: Block =
|
||||
generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
|
||||
let state_version =
|
||||
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
|
||||
let block: Block = generate_genesis_block(&config.chain_spec, state_version)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
let tokio_handle = config.tokio_handle.clone();
|
||||
|
||||
@@ -180,6 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
};
|
||||
|
||||
/// This determines the average expected block time that we are targeting.
|
||||
|
||||
@@ -97,6 +97,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
pub const MILLISECS_PER_BLOCK: u64 = 12000;
|
||||
|
||||
@@ -60,6 +60,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
|
||||
@@ -71,6 +71,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
|
||||
@@ -361,8 +361,10 @@ pub fn run() -> Result<()> {
|
||||
builder.with_profiling(sc_tracing::TracingReceiver::Log, "");
|
||||
let _ = builder.init();
|
||||
|
||||
let block: crate::service::Block =
|
||||
generate_genesis_block(&load_spec(¶ms.chain.clone().unwrap_or_default())?)?;
|
||||
let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;
|
||||
let state_version = Cli::native_runtime_version(&spec).state_version();
|
||||
|
||||
let block: crate::service::Block = generate_genesis_block(&spec, state_version)?;
|
||||
let raw_header = block.header().encode();
|
||||
let output_buf = if params.raw {
|
||||
raw_header
|
||||
@@ -468,8 +470,12 @@ pub fn run() -> Result<()> {
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);
|
||||
|
||||
let state_version =
|
||||
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
|
||||
|
||||
let block: crate::service::Block =
|
||||
generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
|
||||
generate_genesis_block(&config.chain_spec, state_version)
|
||||
.map_err(|e| format!("{:?}", e))?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
let tokio_handle = config.tokio_handle.clone();
|
||||
|
||||
@@ -94,6 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 3,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
|
||||
@@ -94,6 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 3,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
|
||||
@@ -95,6 +95,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 4,
|
||||
state_version: 0,
|
||||
};
|
||||
|
||||
/// The version information used to identify this runtime when compiled natively.
|
||||
|
||||
@@ -118,6 +118,7 @@ impl RelayStateSproofBuilder {
|
||||
self,
|
||||
) -> (polkadot_primitives::v1::Hash, sp_state_machine::StorageProof) {
|
||||
let (db, root) = MemoryDB::<HashFor<polkadot_primitives::v1::Block>>::default_with_root();
|
||||
let state_version = Default::default(); // for test using default.
|
||||
let mut backend = sp_state_machine::TrieBackend::new(db, root);
|
||||
|
||||
let mut relevant_keys = Vec::new();
|
||||
@@ -126,7 +127,7 @@ impl RelayStateSproofBuilder {
|
||||
|
||||
let mut insert = |key: Vec<u8>, value: Vec<u8>| {
|
||||
relevant_keys.push(key.clone());
|
||||
backend.insert(vec![(None, vec![(key, Some(value))])]);
|
||||
backend.insert(vec![(None, vec![(key, Some(value))])], state_version);
|
||||
};
|
||||
|
||||
insert(relay_chain::well_known_keys::ACTIVE_CONFIG.to_vec(), self.host_config.encode());
|
||||
|
||||
@@ -94,6 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
};
|
||||
|
||||
#[cfg(feature = "increment-spec-version")]
|
||||
@@ -107,6 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_version: 1,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
transaction_version: 1,
|
||||
state_version: 1,
|
||||
};
|
||||
|
||||
pub const MILLISECS_PER_BLOCK: u64 = 12000;
|
||||
|
||||
@@ -24,7 +24,8 @@ use sp_runtime::traits::Block as BlockT;
|
||||
/// Returns the initial head data for a parachain ID.
|
||||
pub fn initial_head_data(para_id: ParaId) -> HeadData {
|
||||
let spec = Box::new(crate::chain_spec::get_chain_spec(para_id));
|
||||
let block: Block = generate_genesis_block(&(spec as Box<_>)).unwrap();
|
||||
let block: Block =
|
||||
generate_genesis_block(&(spec as Box<_>), sp_runtime::StateVersion::V1).unwrap();
|
||||
let genesis_state = block.header().encode();
|
||||
genesis_state.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user