Metadata V15: Expose API to fetch metadata for version (#13287)

* impl_runtime_apis: Generate getters for `metadata_at` functions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime: Implement new `Metadata` runtime trait

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime: Move `metadata_at` functions to construct_runtime macro

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* contruct_runtime: Use `OpaqueMetadata` from hidden imports

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Add tests for the new API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Adjust metdata naming

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose `metadata-v14` feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose metadata only under feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose v14 metadata by default

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Expose metadata feature for testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Test metadata under different feature flags

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* client/tests: Adjust testing to reflect trait Metadata change

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Add intermediate representation types for metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Convert metadata to V14

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Add API to convert metadata to multiple versions

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata-ir: Expose V14 under feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Adjust to metadata IR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: More adjustments

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Guard v14 details under feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* CI: Ensure `quick-benchmarks` uses `metadata-v14`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Use `metadata-v14` for benchmarks

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust cargo fmt

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* kitchensink-runtime: Add feature flag for `metadata-v14`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Check crates locally

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Activate metadata-v14 for pallets

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Remove metadata-v14 feature flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/metadata_ir: Move `api.rs` to `mod.rs`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Handle latest metadata conversion via IR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Add constant for metadata version 14

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support/test: Fix merge conflict

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update frame/support/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/src/metadata_ir/mod.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/test/Cargo.toml

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/api/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* frame/metadata: Collect pallet documentation for MetadataIR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/tests: Check pallet documentation is propagated to MetadataIR

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* frame/support: Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Alexandru Vasile
2023-03-15 19:49:28 +02:00
committed by GitHub
parent 8945c1bd42
commit 1a88833d73
31 changed files with 1002 additions and 316 deletions
+9 -9
View File
@@ -17,7 +17,7 @@
//! Hash utilities.
use crate::metadata;
use crate::metadata_ir;
use codec::{Codec, MaxEncodedLen};
use sp_io::hashing::{blake2_128, blake2_256, twox_128, twox_256, twox_64};
use sp_std::prelude::Vec;
@@ -59,7 +59,7 @@ impl<T: Codec> Hashable for T {
/// Hasher to use to hash keys to insert to storage.
pub trait StorageHasher: 'static {
const METADATA: metadata::StorageHasher;
const METADATA: metadata_ir::StorageHasherIR;
type Output: AsRef<[u8]>;
fn hash(x: &[u8]) -> Self::Output;
@@ -80,7 +80,7 @@ pub trait ReversibleStorageHasher: StorageHasher {
/// Store the key directly.
pub struct Identity;
impl StorageHasher for Identity {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Identity;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Identity;
type Output = Vec<u8>;
fn hash(x: &[u8]) -> Vec<u8> {
x.to_vec()
@@ -98,7 +98,7 @@ impl ReversibleStorageHasher for Identity {
/// Hash storage keys with `concat(twox64(key), key)`
pub struct Twox64Concat;
impl StorageHasher for Twox64Concat {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox64Concat;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Twox64Concat;
type Output = Vec<u8>;
fn hash(x: &[u8]) -> Vec<u8> {
twox_64(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
@@ -120,7 +120,7 @@ impl ReversibleStorageHasher for Twox64Concat {
/// Hash storage keys with `concat(blake2_128(key), key)`
pub struct Blake2_128Concat;
impl StorageHasher for Blake2_128Concat {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_128Concat;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Blake2_128Concat;
type Output = Vec<u8>;
fn hash(x: &[u8]) -> Vec<u8> {
blake2_128(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
@@ -142,7 +142,7 @@ impl ReversibleStorageHasher for Blake2_128Concat {
/// Hash storage keys with blake2 128
pub struct Blake2_128;
impl StorageHasher for Blake2_128 {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_128;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Blake2_128;
type Output = [u8; 16];
fn hash(x: &[u8]) -> [u8; 16] {
blake2_128(x)
@@ -155,7 +155,7 @@ impl StorageHasher for Blake2_128 {
/// Hash storage keys with blake2 256
pub struct Blake2_256;
impl StorageHasher for Blake2_256 {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_256;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Blake2_256;
type Output = [u8; 32];
fn hash(x: &[u8]) -> [u8; 32] {
blake2_256(x)
@@ -168,7 +168,7 @@ impl StorageHasher for Blake2_256 {
/// Hash storage keys with twox 128
pub struct Twox128;
impl StorageHasher for Twox128 {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox128;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Twox128;
type Output = [u8; 16];
fn hash(x: &[u8]) -> [u8; 16] {
twox_128(x)
@@ -181,7 +181,7 @@ impl StorageHasher for Twox128 {
/// Hash storage keys with twox 256
pub struct Twox256;
impl StorageHasher for Twox256 {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox256;
const METADATA: metadata_ir::StorageHasherIR = metadata_ir::StorageHasherIR::Twox256;
type Output = [u8; 32];
fn hash(x: &[u8]) -> [u8; 32] {
twox_256(x)