Companion for substrate#9732 (#4104)

* 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 57325ef73332bf4b054aa4a667bb716fcf8a0d89.

* Revert "test"

This reverts commit ce74d0e2062806f72c0e9e9ca07b14165f43521e.

* 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 <>
This commit is contained in:
cheme
2021-12-24 10:27:35 +01:00
committed by GitHub
parent 0349595894
commit 48dc675047
17 changed files with 208 additions and 193 deletions
+175 -173
View File
File diff suppressed because it is too large Load Diff
-1
View File
@@ -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"
@@ -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.
@@ -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
@@ -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)
}
}
@@ -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()
+1 -1
View File
@@ -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,
};
+2 -2
View File
@@ -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")
}
+1
View File
@@ -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" }
+1
View File
@@ -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.
@@ -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)
}
+1 -1
View File
@@ -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"
+1
View File
@@ -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.
+1
View File
@@ -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.
+1
View File
@@ -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.
+1
View File
@@ -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.