From 2a14aa9da00385ba9aadbfcd7d62bc8c6fae2656 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 | 28 +++++------ integration-tests/src/tests/credentials.rs | 1 + pallets/funding/Cargo.toml | 2 +- pallets/on-slash-vesting/Cargo.toml | 2 +- runtimes/polimec/Cargo.toml | 11 ++++- runtimes/polimec/build.rs | 13 +++++- runtimes/polimec/src/lib.rs | 2 + scripts/zombienet/polimec-paseo-local.toml | 2 +- 10 files changed, 96 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48f0a31f5..83bfc9dc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4607,6 +4607,7 @@ dependencies = [ "asset-hub-polkadot-runtime", "cumulus-pallet-xcm", "cumulus-primitives-core", + "frame-metadata-hash-extension", "frame-support", "frame-system", "itertools 0.11.0", @@ -5864,6 +5865,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" @@ -8784,6 +8799,7 @@ dependencies = [ "cumulus-primitives-utility", "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -12718,6 +12734,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" @@ -12744,6 +12783,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" @@ -14700,13 +14745,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 91a3f5f38..3dfc45a81 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 @@ -88,6 +89,7 @@ std = [ "asset-hub-polkadot-runtime/std", "cumulus-pallet-xcm/std", "cumulus-primitives-core/std", + "frame-metadata-hash-extension/std", "frame-support/std", "frame-system/std", "itertools/use_std", @@ -142,18 +144,6 @@ std = [ development-settings = [ "polimec-runtime/development-settings" ] runtime-benchmarks = [ "asset-hub-polkadot-runtime/runtime-benchmarks", - "polkadot-runtime/runtime-benchmarks", - "penpal-runtime/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-dispenser/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-funding/runtime-benchmarks", - "pallet-linear-release/runtime-benchmarks", - "pallet-parachain-staking/runtime-benchmarks", - "polimec-receiver/runtime-benchmarks", - "polimec-common/runtime-benchmarks", - "polimec-common-test-utils/runtime-benchmarks", - "polimec-runtime/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", @@ -161,21 +151,33 @@ runtime-benchmarks = [ "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-dispenser/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-funding/runtime-benchmarks", "pallet-im-online/runtime-benchmarks", + "pallet-linear-release/runtime-benchmarks", "pallet-membership/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-parachain-staking/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-staking/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", + "penpal-runtime/runtime-benchmarks", + "polimec-common-test-utils/runtime-benchmarks", + "polimec-common/runtime-benchmarks", + "polimec-receiver/runtime-benchmarks", + "polimec-runtime/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", + "polkadot-runtime/runtime-benchmarks", "polkadot-service/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks" + "xcm-executor/runtime-benchmarks", ] 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/pallets/funding/Cargo.toml b/pallets/funding/Cargo.toml index b9bbf8ebf..247e98e2b 100644 --- a/pallets/funding/Cargo.toml +++ b/pallets/funding/Cargo.toml @@ -101,6 +101,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "itertools/use_alloc", + "on-slash-vesting/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-linear-release/runtime-benchmarks", @@ -114,7 +115,6 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "on-slash-vesting/runtime-benchmarks" ] try-runtime = [ "frame-support/try-runtime", diff --git a/pallets/on-slash-vesting/Cargo.toml b/pallets/on-slash-vesting/Cargo.toml index fc668a065..78777e040 100644 --- a/pallets/on-slash-vesting/Cargo.toml +++ b/pallets/on-slash-vesting/Cargo.toml @@ -46,5 +46,5 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", - "sp-runtime/runtime-benchmarks" + "sp-runtime/runtime-benchmarks", ] diff --git a/runtimes/polimec/Cargo.toml b/runtimes/polimec/Cargo.toml index 63c0b724d..fd5af08e6 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 @@ -124,6 +125,7 @@ std = [ "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-support/std", "frame-system-benchmarking?/std", "frame-system-rpc-runtime-api/std", @@ -181,6 +183,7 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "xcm-builder/std", "xcm-executor/std", "xcm/std", @@ -197,6 +200,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", + "on-slash-vesting/runtime-benchmarks", "orml-oracle/runtime-benchmarks", "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", @@ -228,7 +232,6 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "on-slash-vesting/runtime-benchmarks" ] try-runtime = [ @@ -279,8 +282,12 @@ try-runtime = [ # 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 = [ + "metadata-hash", "pallet-funding/on-chain-release-build", "sp-api/disable-logging", ] 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| { diff --git a/scripts/zombienet/polimec-paseo-local.toml b/scripts/zombienet/polimec-paseo-local.toml index ecac63573..db2df7309 100644 --- a/scripts/zombienet/polimec-paseo-local.toml +++ b/scripts/zombienet/polimec-paseo-local.toml @@ -20,7 +20,7 @@ chain_spec_path = "./scripts/zombienet/relay-chain-specs/paseo-local.plain.json" [[parachains]] id = 3344 -chain = "polimec-paseo" +chain = "polimec-paseo-local" [[parachains.collators]] name = "collator1"