Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion for substrate#9732 #678

Merged
merged 38 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ea2bd33
state-update4 branch
cheme May 26, 2021
f24327c
new ref
cheme Sep 6, 2021
632555f
Merge branch 'master' into state-update4
cheme Sep 6, 2021
ddc1bb5
Update to latest.
cheme Sep 6, 2021
8b80694
update deps
cheme Sep 9, 2021
3c8fda6
switch to host state version
cheme Sep 9, 2021
1178e23
Merge branch 'master' into state-update4-host2, and update deps
cheme Oct 18, 2021
dc198de
update
cheme Oct 18, 2021
e17b8f2
fmt
cheme Oct 18, 2021
36fdd7b
up
cheme Oct 18, 2021
4d4a725
remove trie patch
cheme Oct 19, 2021
bc1b944
remove patch
cheme Oct 19, 2021
b5212ed
Merge branch 'master' into state-update4-host2
cheme Oct 19, 2021
16ba8bc
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Oct 19, 2021
eb70526
Merge branch 'master' into state-update4-host2
cheme Oct 20, 2021
bed4004
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Oct 20, 2021
1085ddc
Merge branch 'master' into state-update4-host2
cheme Oct 21, 2021
6025981
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Oct 21, 2021
0a21f84
Merge branch 'master' into state-update4-host2
cheme Nov 8, 2021
555779d
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Nov 8, 2021
972181d
Merge branch 'master' into state-update4-host2
cheme Dec 13, 2021
f17c1ad
Merge branch 'master' into state-update4-host2
cheme Dec 13, 2021
bea9c63
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Dec 13, 2021
8421179
Merge branch 'master' into state-update4-host2
cheme Dec 16, 2021
f640329
fmt
cheme Dec 16, 2021
cec7b16
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Dec 16, 2021
2b733aa
update
cheme Dec 17, 2021
f9084c5
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Dec 17, 2021
19df925
set state_versions in runtimes
cheme Dec 20, 2021
9f5f5fe
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Dec 20, 2021
be49317
state version from storage
cheme Dec 21, 2021
c4740a4
state version from storage
cheme Dec 21, 2021
f105b7c
seedling compat
cheme Dec 22, 2021
4665c0c
Merge branch 'state-update4-host2' into state-update4-host2-nopatch
cheme Dec 22, 2021
799edb2
restore lock
cheme Dec 23, 2021
1d24b6d
Merge branch 'master' into state-update4-host2-nopatch
cheme Dec 24, 2021
05e0861
update lockfile for substrate
Dec 24, 2021
7869bae
update lockfile for polkadot
Dec 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
501 changes: 251 additions & 250 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions client/service/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not fetch the runtime version from the code in the genesis state? As we do this in Substrate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first idea, but current code need an executor (for compatibility I think), so ends up being really easier to use this way.
You think it is a must have, or can we keep it this way (seems only use from commands at this point)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is not really future proof.

) -> 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(
Expand Down
1 change: 1 addition & 0 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pallets/parachain-system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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>> {
Expand Down
11 changes: 7 additions & 4 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params.chain.clone().unwrap_or_default())?)?;
let spec = load_spec(&params.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
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions parachain-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/rococo-parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/seedling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions polkadot-parachains/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params.chain.clone().unwrap_or_default())?)?;
let spec = load_spec(&params.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
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/statemint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot-parachains/westmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion test/relay-sproof-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/service/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}