Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Metadata Validation #478

Merged
merged 173 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
12313d7
metadata: Implement MetadataHashable for deterministic hashing
lexnv Mar 14, 2022
707a5e5
metadata: Hash `scale_info::Field`
lexnv Mar 14, 2022
3353583
metadata: Hash `scale_info::Variant`
lexnv Mar 14, 2022
ebc588a
metadata: Hash `scale_info::TypeDef`
lexnv Mar 14, 2022
dc727fc
metadata: Hash pallet metadata
lexnv Mar 14, 2022
4690ac0
metadata: Avoid data representation collision via unique identifiers
lexnv Mar 14, 2022
8178351
metadata: Finalize hashing on recursive types
lexnv Mar 14, 2022
b60ebdf
metadata: Cache recursive calls
lexnv Mar 14, 2022
a9b1447
metadata: Move `MetadataHashable` to codegen to avoid cyclic dependency
lexnv Mar 16, 2022
3ece9e3
codegen: Add pallet unique hash
lexnv Mar 16, 2022
c64cc60
metadata: Wrap metadata as owned
lexnv Mar 16, 2022
a24da9a
subxt: Use MetadataHashable wrapper for clients
lexnv Mar 16, 2022
05f1bc8
subxt: Generate runtime pallet uid from metadata
lexnv Mar 16, 2022
b98a93c
Validate metadata compatibility at the pallet level
lexnv Mar 16, 2022
73befba
Update polkadot.rs
lexnv Mar 16, 2022
e576ab2
Modify examples and tests for the new API
lexnv Mar 16, 2022
76f2c9c
codegen: Implement metadata uid
lexnv Mar 17, 2022
58f743c
Update polkadot with TryFrom implementation
lexnv Mar 17, 2022
ea9e233
client: Change `to_runtime_api` to reflect TryFrom changes
lexnv Mar 17, 2022
f9d9956
client: Skip full metadata validation option
lexnv Mar 17, 2022
0ed1f43
codegen: Add option to skip pallet validation for TransactionApi
lexnv Mar 17, 2022
f5665f7
codegen: Add option to skip pallet validation for StorageApi
lexnv Mar 17, 2022
b36555f
Update polkadot.rs with ability to skip pallet validation
lexnv Mar 17, 2022
e8e8792
codegen: Change `MetadataHashable` to per function implementation
lexnv Mar 17, 2022
86b1c7e
codegen: Use metadata hashes functions
lexnv Mar 17, 2022
c0ecf32
subxt: Use metadata hashes functions
lexnv Mar 17, 2022
4431c22
codegen: Make `get_type_uid` private
lexnv Mar 17, 2022
1fa9db4
codegen, subxt: Rename metadata functions `*_uid` to `*_hash`
lexnv Mar 17, 2022
2d6e906
codegen: Update `get_field_hash` to use `codec::Encode`
lexnv Mar 17, 2022
4da2e0e
subxt: Update polkadot.rs
lexnv Mar 17, 2022
ce7a6d7
codegen, subxt: Move metadata check from client to subxt::Metadata
lexnv Mar 18, 2022
7033233
codegen, subxt: Rename metadata check functions to follow `*_hash` na…
lexnv Mar 18, 2022
ed51cd8
codegen: Update polkadot.rs to reflect naming changes
lexnv Mar 18, 2022
0d500eb
codegen: Use `encode_to` for metadata generation
lexnv Mar 18, 2022
1c2f986
codegen: Update polkadot.rs to reflect `encode_to` changes
lexnv Mar 18, 2022
02bb231
codegen: Specific name for visited set
lexnv Mar 18, 2022
13e6112
metadata: Provide cache to hashing functions
lexnv Mar 18, 2022
d388598
metadata: Compute metadata hash by sorted pallets
lexnv Mar 21, 2022
5e6a21d
metadata: Get extrinsic hash
lexnv Mar 21, 2022
45c6453
metadata: Extend metadata hash with extrinsic and metadata type
lexnv Mar 21, 2022
5eb41c9
metadata: Add cache as metadata parameter
lexnv Mar 21, 2022
e33f33a
codegen, subxt: Update metadata hash to use cache
lexnv Mar 21, 2022
c5d89a3
metadata: Implement Default trait for MetadataHasherCache
lexnv Mar 21, 2022
e7af28f
metadata: Add cache for pallets
lexnv Mar 21, 2022
e0779bd
metadata: Move functionality to metadata crate
lexnv Mar 21, 2022
953c031
codegen, subxt: Use subxt-metadata crate
lexnv Mar 21, 2022
b865f18
codegen: Remove metdata hashing functionality
lexnv Mar 21, 2022
26216fa
metadata: Add documentation
lexnv Mar 21, 2022
aad7d2d
metadata: Fix vector capacity to include extrinisc and type hash
lexnv Mar 21, 2022
5de8e83
metadata: Add empty CLI
lexnv Mar 22, 2022
3877505
metadata-cli: Fetch metadata from substrate nodes
lexnv Mar 22, 2022
1809cc7
metadata-cli: Log metadata hashes of provided nodes
lexnv Mar 22, 2022
1957e56
metadata-cli: Group compatible nodes by metadata
lexnv Mar 22, 2022
9e32361
metadata-cli: Simplify hash map insertion
lexnv Mar 22, 2022
70aa7c1
metadata-cli: Move full metadata check to function
lexnv Mar 22, 2022
bfa9c8f
metadata-cli: Group metadata validation at the pallet level
lexnv Mar 22, 2022
c7a1e27
subxt: Persist metadata cache
lexnv Mar 23, 2022
ca8c22c
metadata: Move compatibility cli from subxt-metadata to subxt-cli
lexnv Mar 23, 2022
776250e
metadata: Remove cli from subxt-metadata
lexnv Mar 23, 2022
1c600ee
cli: Fix clippy
lexnv Mar 23, 2022
95a6134
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Mar 23, 2022
beee3f1
metadata: Fix compatible metadata when pallets are registered in diff…
lexnv Mar 23, 2022
84e049e
tests: Handle result of pallet hashing
lexnv Mar 24, 2022
6635423
metadata: Remove type cache for deterministic hashing
lexnv Mar 24, 2022
1fe787d
metadata: Add test assets from `substrate-node-template` tag `polkado…
lexnv Mar 24, 2022
20055e5
metadata-tests: Check cache hashing for Balances pallet
lexnv Mar 24, 2022
7a9b8e5
metadata: Fix `get_type_hash` clippy issue
lexnv Mar 24, 2022
931fcdb
metadata-tests: Compare one time cache with persistent cache
lexnv Mar 24, 2022
c9ed131
metadata-test: Check metadata hash populates cache for pallets
lexnv Mar 24, 2022
43ae4db
metadata-tests: Simplify `cache_deterministic_hash` test
lexnv Mar 24, 2022
f9ca06d
metadata-tests: Check deterministic metadata for different order pallets
lexnv Mar 24, 2022
09e74d2
metadata: Fix clippy
lexnv Mar 24, 2022
57771e8
codegen: Implement TransactionApiUnchecked for skipping pallet valida…
lexnv Mar 24, 2022
f3f4d72
codegen: Implement StorageApiUnchecked for skipping pallet validation
lexnv Mar 25, 2022
9e4c62c
codegen: Remove skip_pallet_validation boolean
lexnv Mar 25, 2022
f92383c
subxt: Implement ClientUnchecked for skipping metadata validation
lexnv Mar 25, 2022
07cf5f2
Update polkadot.rs
lexnv Mar 25, 2022
6baa8e8
Update examples of rpc_call to skip metadata
lexnv Mar 25, 2022
8378086
subxt: Remove heck dependency
lexnv Mar 28, 2022
5fa5df8
codegen: Add pallet name as an identifier for pallet hashing
lexnv Mar 28, 2022
8da1497
metadata: Implement MetadataHashDetails
lexnv Mar 28, 2022
62a7eec
metadata: Adjust testing to `MetadataHashDetails` interface
lexnv Mar 28, 2022
f026078
codegen: Remove extra `pallet_name`
lexnv Mar 28, 2022
31c016c
subxt: Update polkadot.rs
lexnv Mar 28, 2022
8fcf824
subxt: Fix clippy issue
lexnv Mar 28, 2022
816e916
codegen: Change StorageApi to support `_unchecked` methods
lexnv Mar 29, 2022
58fd3e3
codegen: Change TransactionApi to support `_unchecked` methods
lexnv Mar 29, 2022
e0ef532
subxt: Switch back from `TryFrom` to `From` for `subxt::Client`
lexnv Mar 29, 2022
b0061e4
codegen, subxt: Remove `ClientUnchecked`
lexnv Mar 29, 2022
5ecf7b7
codegen: Expose `validate_metadata` as validation of compatibility me…
lexnv Mar 29, 2022
392da6d
examples: Update to the new interface
lexnv Mar 30, 2022
f2e8dfc
subxt: Update test integration to latest interface
lexnv Mar 30, 2022
f8df12a
subxt: Update polkadot.rs
lexnv Mar 30, 2022
467d707
metadata/tests: Check different pallet index order
lexnv Mar 31, 2022
d20bcd0
metadata/tests: Check recursive type hashing
lexnv Mar 31, 2022
e042c05
metadata/tests: Check recursive types registered in different order
lexnv Mar 31, 2022
b3c4029
metadata/tests: Fix recursive types warning
lexnv Mar 31, 2022
1900091
metadata/tests: Remove test assets
lexnv Mar 31, 2022
252c4d1
metadata/tests: Extend tests to verify cached pallet values
lexnv Mar 31, 2022
964f92c
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Mar 31, 2022
9278811
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 4, 2022
551c595
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 4, 2022
db8fdfb
examples: Add metadata compatiblity example
lexnv Apr 4, 2022
d25c912
examples: Revert balance_transfer to initial form
lexnv Apr 4, 2022
5fb0cdd
codegen: Add ConstantsApi metadata check
lexnv Apr 4, 2022
7293531
tests: Modify tests to accomodate ConstantsApi changes
lexnv Apr 4, 2022
a5415b8
examples: Modify verified version
lexnv Apr 4, 2022
ce05435
subxt: Generate polkadot.rs from `0.9.18-4542a603cc-aarch64-macos`
lexnv Apr 4, 2022
ba95ac8
examples: Update polkadot_metadata.scale from `0.9.18-4542a603cc-aarc…
lexnv Apr 4, 2022
1efd776
metadata: Update documentation
lexnv Apr 4, 2022
dc3b106
tests: Modify default pallet usage
lexnv Apr 4, 2022
bb0b838
metadata/tests: Remove hex dependency
lexnv Apr 4, 2022
3a2d695
metadata/tests: Add MetadataTestType to capture complex types
lexnv Apr 4, 2022
853ba6f
metadata/tests: Update tests to use complex types
lexnv Apr 4, 2022
f0a2b75
metadata/tests: Check metadata correctness via extending pallets
lexnv Apr 4, 2022
545dfd0
metadata/tests: Extend pallet hash with Events
lexnv Apr 4, 2022
63b32bc
metadata/tests: Extend pallet hash with constants
lexnv Apr 4, 2022
7d55527
metadata/tests: Extend pallet hash with error
lexnv Apr 4, 2022
4e30b52
examples: Extend metadata compatibiliy with StorageApi and ConstantsApi
lexnv Apr 4, 2022
dab2beb
Modify comments and documentation
lexnv Apr 5, 2022
a152c6b
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 6, 2022
4af15fe
metadata: Benchmarks for full validation and pallet validation
lexnv Apr 6, 2022
74d3bc8
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 6, 2022
58cbc3f
metadata/benches: Fix clippy
lexnv Apr 7, 2022
efa5df1
metadata: Hash metadata just by inspecting the provided pallets
lexnv Apr 7, 2022
414dee6
metadata: Make pallets generic over T for `AsRef<str>`
lexnv Apr 7, 2022
7396595
codegen: Expose the name of the pallets composing the metadata
lexnv Apr 7, 2022
7d1adc3
subxt/tests: Update polkadot.rs with pallets name
lexnv Apr 7, 2022
1f5c5f4
codegen: Obtain metadata hash only by inspecting pallets
lexnv Apr 7, 2022
cbc3727
codegen,subxt: Extend the metadata hash to utilize just pallets
lexnv Apr 7, 2022
a82fad2
subxt/tests: Update polkadot.rs with client metadata has per pallet
lexnv Apr 7, 2022
c96606a
metadata/tests: Test `get_metadata_per_pallet_hash` correctness
lexnv Apr 7, 2022
c558df4
metadata: Fix clippy
lexnv Apr 7, 2022
a6f5650
metadata/benches: Fix decode of metadata
lexnv Apr 7, 2022
8f57e20
metadata: Fix clippy
lexnv Apr 7, 2022
23b382f
[static metadata] validate storage, calls and constants per call (#507)
jsdw Apr 8, 2022
9a08a84
Fix clippy
lexnv Apr 8, 2022
6cbebc9
bench the per-call metadata functions
jsdw Apr 8, 2022
fd4d425
metadata: Add test for `node_template_runtime_variant`
lexnv Apr 8, 2022
640b052
ensure criteron cli opts work
jsdw Apr 8, 2022
1323696
group benchmarks and avoid unwrap issues
jsdw Apr 8, 2022
9a7bbbc
metadata: Check template runtime for handling the pallet swap order case
lexnv Apr 8, 2022
5548b5a
Merge remote-tracking branch 'origin/398_static_md_check' into 398_st…
lexnv Apr 8, 2022
fd00319
metadata: Remove debug logs
lexnv Apr 8, 2022
a0e3b6c
metadata: Optimise by removing field's name and type_name and type's …
lexnv Apr 8, 2022
0ce19bb
metadata: Refactor `get_type_hash` to break recursion earlier
lexnv Apr 8, 2022
eb051a9
subxt: Add tests for `hash_cache`
lexnv Apr 8, 2022
cb2de4a
subxt: Add tests for checking Metadata Inner cache
lexnv Apr 8, 2022
e4e2866
metadata: Check semantic changes inside enum and struct fields
lexnv Apr 11, 2022
f65dabc
metadata: Add enums named differently with compatible semantic meaning
lexnv Apr 11, 2022
6c776eb
metadata: Guard testing of release versions for `node_template_runtime`
lexnv Apr 11, 2022
9c46526
Improve documentation
lexnv Apr 11, 2022
b713993
Update polkadot.rs
lexnv Apr 11, 2022
2d55752
metadata/tests: Manually construct type of `node_template_runtimeL::C…
lexnv Apr 11, 2022
79ea3fe
no more special Call handling, avoid a little cloning, and actually s…
jsdw Apr 13, 2022
a1f9038
remove unused deps and fmt
jsdw Apr 13, 2022
9691f51
RuntimeMetadataLastVersion => RuntimeMetadataV14
jsdw Apr 13, 2022
fd7aa62
remove a bunch of allocations in the metadata hashing, speed up from …
jsdw Apr 13, 2022
a658d6f
update release docs to release metadata crate too
jsdw Apr 13, 2022
06241f4
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 26, 2022
8c4aca6
subxt: Remove codegen dependency
lexnv Apr 26, 2022
0f7a770
subxt: Replace std RwLock with parking_lot
lexnv Apr 26, 2022
e355ec6
subxt/tests: Add ws address to `TestNodeProcess`
lexnv Apr 26, 2022
73be46c
subxt/tests: Add metadata validation integration test
lexnv Apr 26, 2022
b4c0185
subxt: Allow setting metadata on the ClientBuilder
lexnv Apr 26, 2022
2a625a9
subxt/tests: Check incompatible metadatas
lexnv Apr 26, 2022
633c3f0
metadata: Fix constant hashing for deterministic output
lexnv Apr 26, 2022
542dec6
subxt/tests: Check metadata validation for constants
lexnv Apr 26, 2022
74be005
subxt/tests: Test validation for calls
lexnv Apr 27, 2022
83f0ba4
subxt/tests: Test validation for storage
lexnv Apr 27, 2022
1abd3ca
Merge remote-tracking branch 'origin/master' into 398_static_md_check
lexnv Apr 27, 2022
b0e8b4c
subxt: Expose `set_metadata` for testing only
lexnv Apr 27, 2022
460c18c
subxt: Guard metadata tests under integration-tests
lexnv Apr 28, 2022
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
2 changes: 2 additions & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
darling = "0.13.0"
frame-metadata = "15.0.0"
heck = "0.4.0"
lazy_static = "1.4.0"
proc-macro2 = "1.0.24"
proc-macro-crate = "0.1.5"
proc-macro-error = "1.0.4"
quote = "1.0.8"
syn = "1.0.58"
scale-info = { version = "2.0.0", features = ["bit-vec"] }
sp-core = { version = "6.0.0" }

[dev-dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
Expand Down
253 changes: 253 additions & 0 deletions codegen/src/api/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// This file is part of subxt.
//
// subxt is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// subxt is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

//! Wrapper to obtain unique deterministic hashed identifiers from portable type ids.
//!
//! # Note
//!
//! Used to determine API compatibility between generated interface and dynamic metadata.

use codec::Encode;
use frame_metadata::{
RuntimeMetadataLastVersion,
StorageEntryType,
};
use scale_info::{
form::PortableForm,
Field,
TypeDef,
Variant,
};
use std::{
collections::{
HashMap,
HashSet,
},
sync::Mutex,
};

use lazy_static::lazy_static;

#[derive(Clone, Debug)]
pub struct MetadataHashable {
metadata: RuntimeMetadataLastVersion,
}

#[repr(u8)]
enum MetadataHashableIDs {
Field,
Variant,
TypeDef,
Type,
Pallet,
}

impl MetadataHashable {
pub fn new(metadata: RuntimeMetadataLastVersion) -> Self {
Self { metadata }
}

pub fn metadata(&self) -> &RuntimeMetadataLastVersion {
&self.metadata
}

fn hash(bytes: &[u8]) -> [u8; 32] {
sp_core::hashing::sha2_256(bytes)
}

fn get_field_uid(
&self,
field: &Field<PortableForm>,
set: &mut HashSet<u32>,
) -> [u8; 32] {
let mut bytes = vec![MetadataHashableIDs::Field as u8];

if let Some(name) = field.name() {
bytes.extend(name.as_bytes());
}
if let Some(ty_name) = field.type_name() {
bytes.extend(ty_name.as_bytes());
}
bytes.extend(self.get_type_uid_internal(field.ty().id(), set));

MetadataHashable::hash(&bytes)
}

fn get_variant_uid(
&self,
var: &Variant<PortableForm>,
set: &mut HashSet<u32>,
) -> [u8; 32] {
let mut bytes = vec![MetadataHashableIDs::Variant as u8];

bytes.extend(var.name().as_bytes());
for field in var.fields() {
bytes.extend(self.get_field_uid(field, set));
}

MetadataHashable::hash(&bytes)
}

fn get_type_def_uid(
lexnv marked this conversation as resolved.
Show resolved Hide resolved
&self,
ty_def: &TypeDef<PortableForm>,
set: &mut HashSet<u32>,
) -> [u8; 32] {
let mut bytes = vec![MetadataHashableIDs::TypeDef as u8];

let data = match ty_def {
TypeDef::Composite(composite) => {
let mut bytes = Vec::new();
for field in composite.fields() {
bytes.extend(self.get_field_uid(field, set));
}
bytes
}
TypeDef::Variant(variant) => {
let mut bytes = Vec::new();
for var in variant.variants() {
bytes.extend(self.get_variant_uid(var, set));
}
bytes
}
TypeDef::Sequence(sequence) => {
let mut bytes = Vec::new();
bytes.extend(self.get_type_uid_internal(sequence.type_param().id(), set));
bytes
}
TypeDef::Array(array) => {
let mut bytes = Vec::new();
bytes.extend(array.len().to_be_bytes());
bytes.extend(self.get_type_uid_internal(array.type_param().id(), set));
bytes
}
TypeDef::Tuple(tuple) => {
let mut bytes = Vec::new();
for field in tuple.fields() {
bytes.extend(self.get_type_uid_internal(field.id(), set));
}
bytes
}
TypeDef::Primitive(primitive) => {
let mut bytes = Vec::new();
bytes.extend(primitive.encode());
bytes
}
TypeDef::Compact(compact) => {
let mut bytes = Vec::new();
bytes.extend(self.get_type_uid_internal(compact.type_param().id(), set));
bytes
}
TypeDef::BitSequence(bitseq) => {
let mut bytes = Vec::new();
bytes.extend(
self.get_type_uid_internal(bitseq.bit_order_type().id(), set),
);
bytes.extend(
self.get_type_uid_internal(bitseq.bit_store_type().id(), set),
);
bytes
}
};
bytes.extend(data);
MetadataHashable::hash(&bytes)
}

fn get_type_uid_internal(&self, id: u32, set: &mut HashSet<u32>) -> [u8; 32] {
lazy_static! {
static ref CACHED_UID: Mutex<HashMap<u32, [u8; 32]>> =
jsdw marked this conversation as resolved.
Show resolved Hide resolved
Mutex::new(HashMap::new());
}

if let Some(cached) = CACHED_UID.lock().unwrap().get(&id) {
return *cached
}

let ty = self.metadata.types.resolve(id).unwrap();

let mut bytes = vec![MetadataHashableIDs::Type as u8];
bytes.extend(ty.path().segments().concat().into_bytes());
// Guard against recursive types
if !set.insert(id) {
return MetadataHashable::hash(&bytes)
}

let ty_def = ty.type_def();
bytes.extend(self.get_type_def_uid(ty_def, set));

let uid = MetadataHashable::hash(&bytes);
CACHED_UID.lock().unwrap().insert(id, uid);
uid
}

pub fn get_type_uid(&self, id: u32) -> [u8; 32] {
let mut set = HashSet::<u32>::new();
self.get_type_uid_internal(id, &mut set)
}

pub fn get_pallet_uid(
lexnv marked this conversation as resolved.
Show resolved Hide resolved
&self,
pallet: &frame_metadata::PalletMetadata<PortableForm>,
) -> [u8; 32] {
let mut bytes = vec![MetadataHashableIDs::Pallet as u8];
let mut set = HashSet::<u32>::new();

if let Some(ref calls) = pallet.calls {
bytes.extend(self.get_type_uid_internal(calls.ty.id(), &mut set));
}
if let Some(ref event) = pallet.event {
bytes.extend(self.get_type_uid_internal(event.ty.id(), &mut set));
}
for constant in pallet.constants.iter() {
bytes.extend(constant.name.as_bytes());
bytes.extend(&constant.value);
bytes.extend(self.get_type_uid_internal(constant.ty.id(), &mut set));
}
if let Some(ref error) = pallet.error {
bytes.extend(self.get_type_uid_internal(error.ty.id(), &mut set));
}
if let Some(ref storage) = pallet.storage {
bytes.extend(storage.prefix.as_bytes());
for entry in storage.entries.iter() {
bytes.extend(entry.name.as_bytes());
bytes.extend(entry.modifier.encode());
match &entry.ty {
StorageEntryType::Plain(ty) => {
bytes.extend(self.get_type_uid_internal(ty.id(), &mut set));
}
StorageEntryType::Map {
hashers,
key,
value,
} => {
bytes.extend(hashers.encode());
bytes.extend(self.get_type_uid_internal(key.id(), &mut set));
bytes.extend(self.get_type_uid_internal(value.id(), &mut set));
}
}
bytes.extend(&entry.default);
}
}

MetadataHashable::hash(&bytes)
}

pub fn get_metadata_uid(&self) -> [u8; 32] {
// Note: Order by pallets and use `get_pallet_uid`.
let bytes = self.metadata.encode();
MetadataHashable::hash(&bytes)
}
}
Loading