From 4eb68fe119688727ebdd2fedb295cb0886ff101b 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/funding/src/lib.rs | 14 +++--- pallets/on-slash-vesting/Cargo.toml | 2 +- pallets/on-slash-vesting/src/mock.rs | 2 - pallets/on-slash-vesting/src/test.rs | 1 - runtimes/polimec/Cargo.toml | 11 ++++- runtimes/polimec/build.rs | 13 +++++- runtimes/polimec/src/lib.rs | 2 + runtimes/polimec/src/xcm_config.rs | 4 +- scripts/zombienet/polimec-paseo-local.toml | 2 +- 14 files changed, 105 insertions(+), 32 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/funding/src/lib.rs b/pallets/funding/src/lib.rs index c5c0b530b..117ab002e 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -29,8 +29,8 @@ //! There are 3 types of users in Polimec: //! - **Issuers**: They create projects and are responsible for their success. //! - **Evaluators**: They are incentivized to assess projects accurately by locking their PLMC. If at least 10% of its -//! target funding (in USD) is locked in PLMC, a project is given access to the funding round. Evaluators are either -//! rewarded in contribution tokens if the project gets funded, or have their PLMC slashed otherwise. +//! target funding (in USD) is locked in PLMC, a project is given access to the funding round. Evaluators are either +//! rewarded in contribution tokens if the project gets funded, or have their PLMC slashed otherwise. //! - **Participants**: They contribute financially to projects by locking PLMC and paying out USDT/USDC/DOT, and are rewarded in contribution tokens. //! //! Users need to go through a KYC/AML by a third party in order to use the protocol. This process classifies them @@ -52,15 +52,15 @@ //! 10) **Remainder Round Start**: After a defined [period](::CommunityRoundDuration), the remainder round starts. //! 11) **Contribute**: Participants with winning bids can also contribute at the weighted average price with the [`contribute`](Pallet::contribute) extrinsic. //! 12) **Funding End**: Anyone can end the project with the [`end_project`](Pallet::end_project) extrinsic after the defined end block. -//! The project will now be considered Failed if it reached <=33% of its target funding in USD, and Successful otherwise. +//! The project will now be considered Failed if it reached <=33% of its target funding in USD, and Successful otherwise. //! 13) **Settlement Start**: Anyone can start the settlement process with the [`start_settlement`](Pallet::start_settlement) extrinsic after the defined end block. //! 14) **Settle Evaluation**: Anyone can now settle an evaluation with the [`settle_evaluation`](Pallet::settle_evaluation) extrinsic. -//! This will unlock the PLMC bonded, and either apply a slash to the PLMC, or reward CTs to the evaluator. +//! This will unlock the PLMC bonded, and either apply a slash to the PLMC, or reward CTs to the evaluator. //! 15) **Settle Bid**: Anyone can now settle a bid with the [`settle_bid`](Pallet::settle_bid) extrinsic. -//! This will set a vesting schedule on the PLMC bonded, and pay out the funding assets to the issuer. It will also issue refunds in case the bid failed, -//! or the price paid was higher than the weighted average price. +//! This will set a vesting schedule on the PLMC bonded, and pay out the funding assets to the issuer. It will also issue refunds in case the bid failed, +//! or the price paid was higher than the weighted average price. //! 16) **Settle Contribution**: Anyone can now settle a contribution with the [`settle_contribution`](Pallet::settle_contribution) extrinsic. -//! This will set a vesting schedule on the PLMC bonded, and pay out the funding assets to the issuer. +//! This will set a vesting schedule on the PLMC bonded, and pay out the funding assets to the issuer. //! 17) **Settlement End**: Anyone can now mark the project settlement as finished by calling the [`mark_project_as_settled`](Pallet::mark_project_as_settled) extrinsic. //! 18) **Migration Start**: Once the issuer has tokens to distribute on mainnet, he can start the migration process with the [`start_offchain`](Pallet::start_offchain_migration) extrinsic. //! 19) **Confirm Migration**: The issuer has to mark each participant's CTs as migrated with the [`confirm_offchain_migration`](Pallet::confirm_offchain_migration) extrinsic. 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/pallets/on-slash-vesting/src/mock.rs b/pallets/on-slash-vesting/src/mock.rs index 0e7aebb80..c227403b0 100644 --- a/pallets/on-slash-vesting/src/mock.rs +++ b/pallets/on-slash-vesting/src/mock.rs @@ -65,8 +65,6 @@ impl pallet_balances::Config for TestRuntime { } impl pallet_vesting::Config for TestRuntime { - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkReason = BenchmarkReason; type BlockNumberProvider = System; type BlockNumberToBalance = ConvertInto; type Currency = Balances; diff --git a/pallets/on-slash-vesting/src/test.rs b/pallets/on-slash-vesting/src/test.rs index 25947965e..f64498142 100644 --- a/pallets/on-slash-vesting/src/test.rs +++ b/pallets/on-slash-vesting/src/test.rs @@ -59,7 +59,6 @@ fn multiple_schedules() { assert_ok!(>::hold(&MockRuntimeHoldReason::Reason, &1u64, 100u128)); assert_eq!(PalletBalances::usable_balance(1), 0); - PalletSystem::set_block_number(3); // Unlock 10*2 + 65*2 + 5*2 + 20*2 = 200 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/runtimes/polimec/src/xcm_config.rs b/runtimes/polimec/src/xcm_config.rs index 852035f65..0f419d94c 100644 --- a/runtimes/polimec/src/xcm_config.rs +++ b/runtimes/polimec/src/xcm_config.rs @@ -17,7 +17,7 @@ use super::{ AccountId, AllPalletsWithSystem, AssetId as AssetIdPalletAssets, Balance, Balances, EnsureRoot, ForeignAssets, Funding, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - ToTreasury, TreasuryAccount, Vec, WeightToFee, XcmpQueue, + ToTreasury, TreasuryAccount, Vec, WeightToFee, }; use core::marker::PhantomData; use cumulus_primitives_core::ParaId; @@ -320,7 +320,7 @@ pub type XcmRouter = ( // Two routers - use UMP to communicate with the relay chain: cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. - XcmpQueue, + super::XcmpQueue, ); #[cfg(feature = "runtime-benchmarks")] pub type XcmRouter = DummyXcmSender; 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"