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

Commit

Permalink
Companion for substrate#9732 (#4104)
Browse files Browse the repository at this point in the history
* merge master (do not compile)

* fix

* lock

* update lock

* Update to refactoring.

* runtime version

* fmt

* remove trie patch

* remove patch

* No layout alias for bridge proof.

* update depupdate depss

* No switch until migration.

* master lock

* test

* test

* Revert "test"

This reverts commit 57325ef.

* Revert "test"

This reverts commit ce74d0e.

* rename feature

* state version as parameter, use the feature only on runtimes.

* update

* update to state version in runtime

* state version from storage

* update lockfile for substrate

Co-authored-by: parity-processbot <>
  • Loading branch information
cheme authored Dec 24, 2021
1 parent 339758f commit a22d434
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 193 deletions.
348 changes: 175 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,5 @@ polkadot = { path = "/usr/bin/polkadot" }
[package.metadata.rpm.files]
"../scripts/packaging/polkadot.service" = { path = "/usr/lib/systemd/system/polkadot.service", mode = "644" }


[package.metadata.spellcheck]
config = "./scripts/gitlab/spellcheck.toml"
1 change: 1 addition & 0 deletions bridges/primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
state_version: 0,
};

// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo.
Expand Down
26 changes: 16 additions & 10 deletions bridges/primitives/runtime/src/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;
use sp_trie::{read_trie_value, Layout, MemoryDB, StorageProof};
use sp_trie::{read_trie_value, LayoutV1, MemoryDB, StorageProof};

/// This struct is used to read storage values from a subset of a Merklized database. The "proof"
/// is a subset of the nodes in the Merkle structure of the database, so that it provides
Expand Down Expand Up @@ -52,7 +52,8 @@ where
/// Reads a value from the available subset of storage. If the value cannot be read due to an
/// incomplete or otherwise invalid proof, this returns an error.
pub fn read_value(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error> {
read_trie_value::<Layout<H>, _>(&self.db, &self.root, key)
// LayoutV1 or LayoutV0 is identical for proof that only read values.
read_trie_value::<LayoutV1<H>, _>(&self.db, &self.root, key)
.map_err(|_| Error::StorageValueUnavailable)
}
}
Expand All @@ -70,15 +71,20 @@ pub enum Error {
pub fn craft_valid_storage_proof() -> (sp_core::H256, StorageProof) {
use sp_state_machine::{backend::Backend, prove_read, InMemoryBackend};

let state_version = sp_runtime::StateVersion::default();

// construct storage proof
let backend = <InMemoryBackend<sp_core::Blake2Hasher>>::from(vec![
(None, vec![(b"key1".to_vec(), Some(b"value1".to_vec()))]),
(None, vec![(b"key2".to_vec(), Some(b"value2".to_vec()))]),
(None, vec![(b"key3".to_vec(), Some(b"value3".to_vec()))]),
// Value is too big to fit in a branch node
(None, vec![(b"key11".to_vec(), Some(vec![0u8; 32]))]),
]);
let root = backend.storage_root(std::iter::empty()).0;
let backend = <InMemoryBackend<sp_core::Blake2Hasher>>::from((
vec![
(None, vec![(b"key1".to_vec(), Some(b"value1".to_vec()))]),
(None, vec![(b"key2".to_vec(), Some(b"value2".to_vec()))]),
(None, vec![(b"key3".to_vec(), Some(b"value3".to_vec()))]),
// Value is too big to fit in a branch node
(None, vec![(b"key11".to_vec(), Some(vec![0u8; 32]))]),
],
state_version,
));
let root = backend.storage_root(std::iter::empty(), state_version).0;
let proof = StorageProof::new(
prove_read(backend, &[&b"key1"[..], &b"key2"[..], &b"key22"[..]])
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion erasure-coding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use polkadot_primitives::v0::{self, BlakeTwo256, Hash as H256, HashT};
use sp_core::Blake2Hasher;
use thiserror::Error;
use trie::{
trie_types::{TrieDB, TrieDBMut},
trie_types::{TrieDB, TrieDBMutV0 as TrieDBMut},
MemoryDB, Trie, TrieMut, EMPTY_PREFIX,
};

Expand Down
4 changes: 2 additions & 2 deletions node/core/pvf/src/executor_intf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("place_child_storage: unsupported feature for parachain validation")
}

fn storage_root(&mut self) -> Vec<u8> {
fn storage_root(&mut self, _: sp_core::storage::StateVersion) -> Vec<u8> {
panic!("storage_root: unsupported feature for parachain validation")
}

fn child_storage_root(&mut self, _: &ChildInfo) -> Vec<u8> {
fn child_storage_root(&mut self, _: &ChildInfo, _: sp_core::storage::StateVersion) -> Vec<u8> {
panic!("child_storage_root: unsupported feature for parachain validation")
}

Expand Down
1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ frame-support-test = { git = "https://github.com/paritytech/substrate", branch =
pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie-db = "0.23.0"
serde_json = "1.0.73"
libsecp256k1 = "0.7.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../primitives/test-helpers" }
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ disable-runtime-api = []
on-chain-release-build = [
"sp-api/disable-logging",
]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
1 change: 1 addition & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]],
transaction_version: 8,
state_version: 0,
};

/// The BABE epoch configuration at genesis.
Expand Down
3 changes: 2 additions & 1 deletion runtime/parachains/src/runtime_api_impl/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
fn current_relay_parent<T: frame_system::Config>(
) -> (<T as frame_system::Config>::BlockNumber, <T as frame_system::Config>::Hash) {
use parity_scale_codec::Decode as _;
let state_version = <frame_system::Pallet<T>>::runtime_version().state_version();
let relay_parent_number = <frame_system::Pallet<T>>::block_number();
let relay_parent_storage_root = T::Hash::decode(&mut &sp_io::storage::root()[..])
let relay_parent_storage_root = T::Hash::decode(&mut &sp_io::storage::root(state_version)[..])
.expect("storage root must decode to the Hash type; qed");
(relay_parent_number, relay_parent_storage_root)
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ hex-literal = "0.3.4"
tiny-keccak = "2.0.2"
keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
trie-db = "0.22.3"
trie-db = "0.23.0"
serde_json = "1.0.73"
separator = "0.4.1"

Expand Down Expand Up @@ -257,4 +257,4 @@ disable-runtime-api = []
on-chain-release-build = [
"sp-api/disable-logging",
]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
1 change: 1 addition & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]],
transaction_version: 9,
state_version: 0,
};

/// The BABE epoch configuration at genesis.
Expand Down
2 changes: 1 addition & 1 deletion runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@ try-runtime = [
"pallet-multisig/try-runtime",
]

runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
1 change: 1 addition & 0 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")]
apis: sp_version::create_apis_vec![[]],
transaction_version: 0,
state_version: 0,
};

/// The BABE epoch configuration at genesis.
Expand Down
1 change: 1 addition & 0 deletions runtime/test-runtime/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: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ try-runtime = [
# runtime without clashing with the runtime API exported functions
# in WASM.
disable-runtime-api = []
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
1 change: 1 addition & 0 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
#[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]],
transaction_version: 8,
state_version: 0,
};

/// The BABE epoch configuration at genesis.
Expand Down

0 comments on commit a22d434

Please sign in to comment.