From ff9f101b6dcaebecc841127d8fbc58e80cba329c Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Mon, 9 Sep 2024 14:14:57 +0200 Subject: [PATCH] Add Ledger support --- Cargo.lock | 54 +++++++++++++++++++ Cargo.toml | 1 + integration-tests/Cargo.toml | 1 + integration-tests/src/tests/credentials.rs | 1 + .../src/tests/evaluator_slash_sideffects.rs | 13 ++--- runtimes/polimec/Cargo.toml | 12 ++++- runtimes/polimec/build.rs | 13 ++++- runtimes/polimec/src/lib.rs | 2 + 8 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b74d6534..52d7e4360 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4606,6 +4606,7 @@ dependencies = [ "asset-hub-polkadot-runtime", "cumulus-pallet-xcm", "cumulus-primitives-core", + "frame-metadata-hash-extension", "frame-support", "frame-system", "itertools 0.11.0", @@ -5863,6 +5864,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -8783,6 +8798,7 @@ dependencies = [ "cumulus-primitives-utility", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -12717,6 +12733,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.3" @@ -12743,6 +12782,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.23" @@ -14699,13 +14744,22 @@ version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dc993ad871b63fbba60362f3ea86583f5e7e1256e8fdcb3b5b249c9ead354bf" dependencies = [ + "array-bytes", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", "polkavm-linker", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing", + "sp-version", "strum 0.26.3", "tempfile", "toml 0.8.15", diff --git a/Cargo.toml b/Cargo.toml index 8e93ee393..951f2d8d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -119,6 +119,7 @@ frame-system = { version = "35.0.0", default-features = false } frame-system-rpc-runtime-api = { version = "33.0.0", default-features = false } frame-system-benchmarking = { version = "35.0.0", default-features = false } frame-try-runtime = { version = "0.41.0", default-features = false } +frame-metadata-hash-extension = { version = "0.3.0", default-features = false } sp-api = { version = "33.0.0", default-features = false } sp-debug-derive = { version = "14.0.0", default-features = false } sp-std = { version = "14.0.0", default-features = false } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 69a8d18b7..1c848f2de 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -74,6 +74,7 @@ itertools.workspace = true pallet-democracy.workspace = true pallet-scheduler.workspace = true pallet-treasury.workspace = true +frame-metadata-hash-extension.workspace = true # Runtimes polkadot-runtime.workspace = true diff --git a/integration-tests/src/tests/credentials.rs b/integration-tests/src/tests/credentials.rs index d4c1c174c..81d9b49a6 100644 --- a/integration-tests/src/tests/credentials.rs +++ b/integration-tests/src/tests/credentials.rs @@ -79,6 +79,7 @@ fn dispenser_signed_extensions_pass_for_new_account() { pallet_dispenser::extensions::CheckNonce::::from(0u32), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0u64.into()).into(), + frame_metadata_hash_extension::CheckMetadataHash::::new(true), ); assert_err!( extra.validate(&who, &paid_call, &paid_call.get_dispatch_info(), 0), diff --git a/integration-tests/src/tests/evaluator_slash_sideffects.rs b/integration-tests/src/tests/evaluator_slash_sideffects.rs index ab291160c..c5d927a57 100644 --- a/integration-tests/src/tests/evaluator_slash_sideffects.rs +++ b/integration-tests/src/tests/evaluator_slash_sideffects.rs @@ -1,21 +1,14 @@ use crate::{tests::defaults::*, *}; -use frame_support::{ - traits::{ - fungible::Mutate, - }, -}; +use frame_support::traits::fungible::Mutate; use frame_system::{pallet_prelude::BlockNumberFor, Account}; use macros::generate_accounts; use pallet_balances::AccountData; use pallet_funding::*; use pallet_vesting::VestingInfo; -use polimec_common::{USD_UNIT}; +use polimec_common::USD_UNIT; use polimec_runtime::PLMC; use sp_arithmetic::Perquintill; -use sp_runtime::{ - FixedU128, - MultiAddress::Id, -}; +use sp_runtime::{FixedU128, MultiAddress::Id}; generate_accounts!(STASH, ALICE, BOB, CHARLIE, DAVE, ISSUER); diff --git a/runtimes/polimec/Cargo.toml b/runtimes/polimec/Cargo.toml index bfe2d8b38..39f56ee9d 100644 --- a/runtimes/polimec/Cargo.toml +++ b/runtimes/polimec/Cargo.toml @@ -14,7 +14,7 @@ version.workspace = true workspace = true [build-dependencies] -substrate-wasm-builder.workspace = true +substrate-wasm-builder = { workspace = true, optional = true } [dependencies] parity-scale-codec = { workspace= true, default-features = false, features = [ @@ -81,6 +81,7 @@ sp-std.workspace = true sp-transaction-pool.workspace = true sp-version.workspace = true sp-genesis-builder.workspace = true +frame-metadata-hash-extension.workspace = true # Polkadot pallet-xcm.workspace = true @@ -183,6 +184,8 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", + "substrate-wasm-builder", + "frame-metadata-hash-extension/std" ] runtime-benchmarks = [ @@ -276,6 +279,11 @@ try-runtime = [ # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = [ "sp-api/disable-logging", "pallet-funding/on-chain-release-build" ] +on-chain-release-build = [ "sp-api/disable-logging", "pallet-funding/on-chain-release-build", "metadata-hash" ] development-settings = [ "shared-configuration/development-settings" ] + +# Enable the metadata hash generation in the wasm-builder +metadata-hash = [ + "substrate-wasm-builder?/metadata-hash", +] diff --git a/runtimes/polimec/build.rs b/runtimes/polimec/build.rs index fcbbf573c..d8e369ce5 100644 --- a/runtimes/polimec/build.rs +++ b/runtimes/polimec/build.rs @@ -14,8 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use substrate_wasm_builder::WasmBuilder; +#[cfg(all(feature = "std", feature = "metadata-hash"))] +fn main() { + substrate_wasm_builder::WasmBuilder::init_with_defaults().enable_metadata_hash("PLMC", 10).build(); +} +#[cfg(all(feature = "std", not(feature = "metadata-hash")))] fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build(); + substrate_wasm_builder::WasmBuilder::build_using_defaults(); } + +/// The wasm builder is deactivated when compiling +/// this crate for wasm to speed up the compilation. +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/runtimes/polimec/src/lib.rs b/runtimes/polimec/src/lib.rs index 953c3ed85..db0447098 100644 --- a/runtimes/polimec/src/lib.rs +++ b/runtimes/polimec/src/lib.rs @@ -149,6 +149,7 @@ pub type SignedExtra = ( Runtime, pallet_transaction_payment::ChargeTransactionPayment, >, + frame_metadata_hash_extension::CheckMetadataHash, ); /// Unchecked extrinsic type as expected by this runtime. @@ -901,6 +902,7 @@ where pallet_dispenser::extensions::SkipCheckIfFeeless::from( pallet_transaction_payment::ChargeTransactionPayment::::from(tip), ), + frame_metadata_hash_extension::CheckMetadataHash::::new(true), ); let raw_payload = generic::SignedPayload::new(call, extra) .map_err(|e| {