From 9b47df543767bd28976956dcdf4a162e2a1b0ef3 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 12:42:54 +0200 Subject: [PATCH 01/69] init of integration --- Cargo.lock | 250 +++++++----- Cargo.toml | 3 + xcm-simulator/Cargo.toml | 60 +++ xcm-simulator/src/lib.rs | 653 +++++++++++++++++++++++++++++++ xcm-simulator/src/parachain.rs | 470 ++++++++++++++++++++++ xcm-simulator/src/relay_chain.rs | 295 ++++++++++++++ 6 files changed, 1643 insertions(+), 88 deletions(-) create mode 100644 xcm-simulator/Cargo.toml create mode 100644 xcm-simulator/src/lib.rs create mode 100644 xcm-simulator/src/parachain.rs create mode 100644 xcm-simulator/src/relay_chain.rs diff --git a/Cargo.lock b/Cargo.lock index 49971e44..00c5a60b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -466,7 +466,7 @@ dependencies = [ "ark-ff", "ark-serialize", "ark-std", - "ark-transcript", + "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", "digest 0.10.7", "getrandom_or_panic", "zeroize", @@ -506,6 +506,20 @@ dependencies = [ "rayon", ] +[[package]] +name = "ark-transcript" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "563084372d89271122bd743ef0a608179726f5fad0566008ba55bd0f756489b8" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "digest 0.10.7", + "rand_core 0.6.4", + "sha3", +] + [[package]] name = "ark-transcript" version = "0.0.2" @@ -764,7 +778,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -809,7 +823,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -937,7 +951,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -1442,7 +1456,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -1502,7 +1516,7 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" dependencies = [ "ark-ec", "ark-ff", @@ -1511,8 +1525,7 @@ dependencies = [ "ark-std", "fflonk", "getrandom_or_panic", - "merlin", - "rand_chacha 0.3.1", + "rand_core 0.6.4", ] [[package]] @@ -2155,7 +2168,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2478,7 +2491,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2518,7 +2531,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2535,7 +2548,7 @@ checksum = "35de3b547387863c8f82013c4f79f1c2162edee956383e4089e1d04c18c4f16c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2629,7 +2642,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2642,7 +2655,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2731,7 +2744,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2745,7 +2758,7 @@ dependencies = [ "ark-secret-scalar", "ark-serialize", "ark-std", - "ark-transcript", + "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", "arrayvec 0.7.4", "zeroize", ] @@ -2771,7 +2784,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.74", + "syn 2.0.79", "termcolor", "toml 0.8.19", "walkdir", @@ -2976,7 +2989,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2996,7 +3009,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3007,7 +3020,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3223,7 +3236,7 @@ dependencies = [ "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3829,7 +3842,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3952,7 +3965,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3964,7 +3977,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3974,7 +3987,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -4164,7 +4177,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -5018,7 +5031,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6046,7 +6059,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6060,7 +6073,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6071,7 +6084,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6082,7 +6095,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6327,7 +6340,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6459,7 +6472,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "synstructure 0.13.1", ] @@ -6507,7 +6520,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6816,7 +6829,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6899,7 +6912,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8112,7 +8125,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8269,6 +8282,21 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", ] +[[package]] +name = "pallet-uniques" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", +] + [[package]] name = "pallet-utility" version = "28.0.0" @@ -8601,7 +8629,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8642,7 +8670,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -9812,7 +9840,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -9822,7 +9850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10021,7 +10049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10114,7 +10142,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10160,7 +10188,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10228,7 +10256,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10354,9 +10382,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -10562,7 +10590,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10657,18 +10685,18 @@ dependencies = [ [[package]] name = "ring" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" dependencies = [ "ark-ec", "ark-ff", "ark-poly", "ark-serialize", "ark-std", + "ark-transcript 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.7.4", "blake2 0.10.6", "common", "fflonk", - "merlin", ] [[package]] @@ -11253,7 +11281,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -12256,7 +12284,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -12535,9 +12563,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -12553,13 +12581,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13007,7 +13035,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13243,7 +13271,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13280,7 +13308,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13299,17 +13327,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13325,7 +13353,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "environmental", "parity-scale-codec", @@ -13540,7 +13568,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13566,20 +13594,20 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "Inflector", "expander 2.2.1", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13661,7 +13689,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" [[package]] name = "sp-storage" @@ -13678,7 +13706,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13713,7 +13741,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ "parity-scale-codec", "tracing", @@ -13792,7 +13820,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13810,8 +13838,9 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" dependencies = [ + "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -14192,7 +14221,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14343,9 +14372,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.74" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -14372,7 +14401,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14476,7 +14505,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14487,7 +14516,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14630,7 +14659,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14825,7 +14854,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14868,7 +14897,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -15319,7 +15348,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -15353,7 +15382,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -16259,7 +16288,52 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", +] + +[[package]] +name = "xcm-simulator" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" +dependencies = [ + "frame-support", + "parity-scale-codec", + "paste", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "sp-io", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "xcm-simulator-example" +version = "7.0.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-message-queue", + "pallet-uniques", + "pallet-xcm", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-simulator", ] [[package]] @@ -16303,7 +16377,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -16323,7 +16397,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f1c60bb5..01d12606 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ description = "The LAOS parachain node." repository = "https://github.com/freeverseio/laos.git" homepage = "https://www.laosfoundation.io" authors = ["Freeverse"] +edition = "2021" version = "0.22.0" [workspace] @@ -14,6 +15,7 @@ members = [ "pallets/*", "precompiles/*", "primitives", + "xcm-simulator", ] [workspace.dependencies] @@ -207,6 +209,7 @@ cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branc staging-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } staging-xcm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } staging-xcm-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-simulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } # (native) polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0" } diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml new file mode 100644 index 00000000..5741ac87 --- /dev/null +++ b/xcm-simulator/Cargo.toml @@ -0,0 +1,60 @@ +[package] +name = "xcm-simulator-example" +description = "Examples of xcm-simulator usage." +authors.workspace = true +edition.workspace = true +version = "7.0.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1" } +scale-info = { version = "2.11.1", features = ["derive"] } +log = { workspace = true } + +frame-system = { workspace = true } +frame-support = { workspace = true } +pallet-balances = { workspace = true } +pallet-message-queue = { workspace = true } +# pallet-uniques = { workspace = true } +sp-std = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-io = { workspace = true } +sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } + +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-simulator = { workspace = true } +pallet-xcm = { workspace = true } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +polkadot-core-primitives = { workspace = true } +polkadot-runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } + +[features] +default = ["std"] +std = [ + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "pallet-message-queue/std", + "pallet-xcm/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-parachains/std", + "sp-runtime/std", + "sp-tracing/std", + "pallet-uniques/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +# "xcm-builder/runtime-benchmarks", +# "xcm-executor/runtime-benchmarks", +] diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs new file mode 100644 index 00000000..56e204bf --- /dev/null +++ b/xcm-simulator/src/lib.rs @@ -0,0 +1,653 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +mod parachain; +mod relay_chain; + +use sp_runtime::BuildStorage; +use sp_tracing; +use xcm::prelude::*; +use xcm_executor::traits::ConvertLocation; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); +pub const INITIAL_BALANCE: u128 = 1_000_000_000; + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(2), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + RuntimeCall = relay_chain::RuntimeCall, + RuntimeEvent = relay_chain::RuntimeEvent, + XcmConfig = relay_chain::XcmConfig, + MessageQueue = relay_chain::MessageQueue, + System = relay_chain::System, + new_ext = relay_ext(), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + ], + } +} + +pub fn parent_account_id() -> parachain::AccountId { + let location = (Parent,); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn child_account_id(para: u32) -> relay_chain::AccountId { + let location = (Parachain(para),); + relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> relay_chain::AccountId { + let location = (Parachain(para), AccountId32 { network: None, id: who.into() }); + relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn sibling_account_account_id(para: u32, who: sp_runtime::AccountId32) -> parachain::AccountId { + let location = (Parent, Parachain(para), AccountId32 { network: None, id: who.into() }); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn parent_account_account_id(who: sp_runtime::AccountId32) -> parachain::AccountId { + let location = (Parent, AccountId32 { network: None, id: who.into() }); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_BALANCE), (parent_account_id(), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + sp_tracing::try_init_simple(); + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext() -> sp_io::TestExternalities { + use relay_chain::{Runtime, RuntimeOrigin, System, Uniques}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (ALICE, INITIAL_BALANCE), + (child_account_id(1), INITIAL_BALANCE), + (child_account_id(2), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + assert_eq!(Uniques::force_create(RuntimeOrigin::root(), 1, ALICE, true), Ok(())); + assert_eq!(Uniques::mint(RuntimeOrigin::signed(ALICE), 1, 42, child_account_id(1)), Ok(())); + }); + ext +} + +pub type RelayChainPalletXcm = pallet_xcm::Pallet; +pub type ParachainPalletXcm = pallet_xcm::Pallet; + +#[cfg(test)] +mod tests { + use super::*; + + use codec::Encode; + use frame_support::{assert_ok, weights::Weight}; + use xcm::latest::QueryResponseInfo; + use xcm_simulator::TestExt; + + // Helper function for forming buy execution message + fn buy_execution(fees: impl Into) -> Instruction { + BuyExecution { fees: fees.into(), weight_limit: Unlimited } + } + + #[test] + fn remote_account_ids_work() { + child_account_account_id(1, ALICE); + sibling_account_account_id(1, ALICE); + parent_account_account_id(ALICE); + } + + #[test] + fn dmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::send_xcm( + Here, + Parachain(1), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaA::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn ump() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn xcmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + (Parent, Parachain(2)), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaB::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn reserve_transfer() { + MockNet::reset(); + + let withdraw_amount = 123; + + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(ALICE), + Box::new(Parachain(1).into()), + Box::new(AccountId32 { network: None, id: ALICE.into() }.into()), + Box::new((Here, withdraw_amount).into()), + 0, + Unlimited, + )); + assert_eq!( + relay_chain::Balances::free_balance(&child_account_id(1)), + INITIAL_BALANCE + withdraw_amount + ); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALICE), + INITIAL_BALANCE + withdraw_amount + ); + }); + } + + #[test] + fn remote_locking_and_unlocking() { + MockNet::reset(); + + let locked_amount = 100; + + ParaB::execute_with(|| { + let message = Xcm(vec![LockAsset { + asset: (Here, locked_amount).into(), + unlocker: Parachain(1).into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + assert_eq!( + relay_chain::Balances::locks(&child_account_id(2)), + vec![BalanceLock { + id: *b"py/xcmlk", + amount: locked_amount, + reasons: Reasons::All + }] + ); + }); + + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![NoteUnlockable { + owner: (Parent, Parachain(2)).into(), + asset: (Parent, locked_amount).into() + }])] + ); + }); + + ParaB::execute_with(|| { + // Request unlocking part of the funds on the relay chain + let message = Xcm(vec![RequestUnlock { + asset: (Parent, locked_amount - 50).into(), + locker: Parent.into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, (Parent, Parachain(1)), message)); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + // Lock is reduced + assert_eq!( + relay_chain::Balances::locks(&child_account_id(2)), + vec![BalanceLock { + id: *b"py/xcmlk", + amount: locked_amount - 50, + reasons: Reasons::All + }] + ); + }); + } + + /// Scenario: + /// A parachain transfers an NFT resident on the relay chain to another parachain account. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn withdraw_and_deposit_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(1))); + }); + + ParaA::execute_with(|| { + let message = Xcm(vec![TransferAsset { + assets: (GeneralIndex(1), 42u32).into(), + beneficiary: Parachain(2).into(), + }]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message)); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(2))); + }); + } + + /// Scenario: + /// The relay-chain teleports an NFT to a parachain. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn teleport_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + // Mint the NFT (1, 69) and give it to our "parachain#1 alias". + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 1, + 69, + child_account_account_id(1, ALICE), + )); + // The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be + // withdrawable by Alice on the parachain. + assert_eq!( + relay_chain::Uniques::owner(1, 69), + Some(child_account_account_id(1, ALICE)) + ); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(1)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + // IRL Alice would probably just execute this locally on the Relay-chain, but we can't + // easily do that here since we only send between chains. + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(1), 69u32).into()), + InitiateTeleport { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send teleport + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 69), None); + }); + } + + /// Scenario: + /// The relay-chain transfers an NFT into a parachain's sovereign account, who then mints a + /// trustless-backed-derived locally. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn reserve_asset_transfer_nft() { + sp_tracing::init_for_tests(); + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!( + relay_chain::Uniques::owner(2, 69), + Some(child_account_account_id(1, ALICE)) + ); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(2)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send transfer + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + log::debug!(target: "xcm-executor", "Hello"); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_id(1))); + }); + } + + /// Scenario: + /// The relay-chain creates an asset class on a parachain and then Alice transfers her NFT into + /// that parachain's sovereign account, who then mints a trustless-backed-derivative locally. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn reserve_asset_class_create_and_reserve_transfer() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!( + relay_chain::Uniques::owner(2, 69), + Some(child_account_account_id(1, ALICE)) + ); + + let message = Xcm(vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: Weight::from_parts(1_000_000_000, 1024 * 1024), + call: parachain::RuntimeCall::from( + pallet_uniques::Call::::create { + collection: (Parent, 2u64).into(), + admin: parent_account_id(), + }, + ) + .encode() + .into(), + }]); + // Send creation. + assert_ok!(RelayChainPalletXcm::send_xcm(Here, Parachain(1), message)); + }); + ParaA::execute_with(|| { + // Then transfer + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!(parachain::Balances::reserved_balance(&parent_account_id()), 1000); + assert_eq!( + parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), + Some(parent_account_id()) + ); + }); + } + + /// Scenario: + /// A parachain transfers funds on the relay chain to another parachain account. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn withdraw_and_deposit() { + MockNet::reset(); + + let send_amount = 10; + + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); + } + + /// Scenario: + /// A parachain wants to be notified that a transfer worked correctly. + /// It sends a `QueryHolding` after the deposit to get notified on success. + /// + /// Asserts that the balances are updated correctly and the expected XCM is sent. + #[test] + fn query_holding() { + MockNet::reset(); + + let send_amount = 10; + let query_id_set = 1234; + + // Send a message which fully succeeds on the relay chain + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ReportHolding { + response_info: QueryResponseInfo { + destination: Parachain(1).into(), + query_id: query_id_set, + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + }, + assets: All.into(), + }, + ]); + // Send withdraw and deposit with query holding + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); + }); + + // Check that transfer was executed + Relay::execute_with(|| { + // Withdraw executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + // Deposit executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); + + // Check that QueryResponse message was received + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![QueryResponse { + query_id: query_id_set, + response: Response::Assets(Assets::new()), + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + querier: Some(Here.into()), + }])], + ); + }); + } +} diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs new file mode 100644 index 00000000..41e62596 --- /dev/null +++ b/xcm-simulator/src/parachain.rs @@ -0,0 +1,470 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use codec::{Decode, Encode}; +use core::marker::PhantomData; +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +}; + +use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; +use sp_runtime::{ + traits::{Get, Hash, IdentityLookup}, + AccountId32, +}; +use sp_std::prelude::*; + +use pallet_xcm::XcmPassthrough; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain_primitives::primitives::{ + DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; +use xcm::{latest::prelude::*, VersionedXcm}; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, + EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, + NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{ + traits::{ConvertLocation, JustTry}, + Config, XcmExecutor, +}; + +pub type SovereignAccountOf = ( + SiblingParachainConvertsVia, + AccountId32Aliases, + ParentIsPreset, +); + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +#[cfg(feature = "runtime-benchmarks")] +pub struct UniquesHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_uniques::BenchmarkHelper for UniquesHelper { + fn collection(i: u16) -> Location { + GeneralIndex(i as u128).into() + } + fn item(i: u16) -> AssetInstance { + AssetInstance::Index(i as u128) + } +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = Location; + type ItemId = AssetInstance; + type Currency = Balances; + type CreateOrigin = ForeignCreators; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = frame_support::traits::ConstU128<1_000>; + type ItemDeposit = frame_support::traits::ConstU128<1_000>; + type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; + type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; + type DepositPerByte = frame_support::traits::ConstU128<1>; + type StringLimit = ConstU32<64>; + type KeyLimit = ConstU32<64>; + type ValueLimit = ConstU32<128>; + type Locker = (); + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = UniquesHelper; +} + +// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins +// which are locations containing the class location. +pub struct ForeignCreators; +impl EnsureOriginWithArg for ForeignCreators { + type Success = AccountId; + + fn try_origin( + o: RuntimeOrigin, + a: &Location, + ) -> sp_std::result::Result { + let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; + if !a.starts_with(&origin_location) { + return Err(o) + } + SovereignAccountOf::convert_location(&origin_location).ok_or(o) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(a: &Location) -> Result { + Ok(pallet_xcm::Origin::Xcm(a.clone()).into()) + } +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); +} + +pub type LocationToAccountId = ( + ParentIsPreset, + SiblingParachainConvertsVia, + AccountId32Aliases, + Account32Hash<(), AccountId>, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + SignedAccountId32AsNative, + XcmPassthrough, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); + pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub ForeignPrefix: Location = (Parent,).into(); +} + +pub type LocalAssetTransactor = ( + FungibleAdapter, LocationToAccountId, AccountId, ()>, + NonFungiblesAdapter< + ForeignUniques, + ConvertedConcreteId, + SovereignAccountOf, + AccountId, + NoChecking, + (), + >, +); + +pub type XcmRouter = EnsureDecodableXcm>; +pub type Barrier = AllowUnpaidExecutionFrom; + +parameter_types! { + pub NftCollectionOne: AssetFilter + = Wild(AllOf { fun: WildNonFungible, id: AssetId((Parent, GeneralIndex(1)).into()) }); + pub NftCollectionOneForRelay: (AssetFilter, Location) + = (NftCollectionOne::get(), (Parent,).into()); +} +pub type TrustedTeleporters = xcm_builder::Case; +pub type TrustedReserves = EverythingBut>; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = (NativeAsset, TrustedReserves); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => + (Ok(used), Event::Fail(Some(hash), error)), + } + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +pub struct TrustedLockerCase(PhantomData); +impl> ContainsPair for TrustedLockerCase { + fn contains(origin: &Location, asset: &Asset) -> bool { + let (o, a) = T::get(); + a.matches(asset) && &o == origin + } +} + +parameter_types! { + pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); +} + +pub type TrustedLockers = TrustedLockerCase; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = TrustedLockers; + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + PolkadotXcm: pallet_xcm, + ForeignUniques: pallet_uniques, + } +); diff --git a/xcm-simulator/src/relay_chain.rs b/xcm-simulator/src/relay_chain.rs new file mode 100644 index 00000000..b41df3cf --- /dev/null +++ b/xcm-simulator/src/relay_chain.rs @@ -0,0 +1,295 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{AsEnsureOriginWithArg, Everything, Nothing, ProcessMessage, ProcessMessageError}, + weights::{Weight, WeightMeter}, +}; + +use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; +use sp_runtime::{traits::IdentityLookup, AccountId32}; + +use polkadot_parachain_primitives::primitives::Id as ParaId; +use polkadot_runtime_parachains::{ + configuration, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, shared, +}; +use xcm::latest::prelude::*; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + ConvertedConcreteId, EnsureDecodableXcm, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NoChecking, NonFungiblesAdapter, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = u32; + type ItemId = u32; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = frame_support::traits::ConstU128<1_000>; + type ItemDeposit = frame_support::traits::ConstU128<1_000>; + type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; + type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; + type DepositPerByte = frame_support::traits::ConstU128<1>; + type StringLimit = ConstU32<64>; + type KeyLimit = ConstU32<64>; + type ValueLimit = ConstU32<128>; + type Locker = (); + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub const TokenLocation: Location = Here.into_location(); + pub RelayNetwork: NetworkId = ByGenesis([0; 32]); + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorLocation = RelayNetwork::get().into(); + pub UnitWeightCost: u64 = 1_000; +} + +pub type LocationToAccountId = ( + ChildParachainConvertsVia, + AccountId32Aliases, + Account32Hash<(), AccountId>, +); + +pub type LocalAssetTransactor = ( + FungibleAdapter, LocationToAccountId, AccountId, ()>, + NonFungiblesAdapter< + Uniques, + ConvertedConcreteId, JustTry>, + LocationToAccountId, + AccountId, + NoChecking, + (), + >, +); + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000); + pub TokensPerSecondPerByte: (AssetId, u128, u128) = + (AssetId(TokenLocation::get()), 1_000_000_000_000, 1024 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub type XcmRouter = EnsureDecodableXcm; +pub type Barrier = AllowUnpaidExecutionFrom; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = XcmPallet; + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +impl origin::Config for Runtime {} + +type Block = frame_system::mocking::MockBlock; + +parameter_types! { + /// Amount of weight that can be spent per block to service messages. + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet. +pub struct MessageProcessor; +impl ProcessMessage for MessageProcessor { + type Origin = AggregateMessageOrigin; + + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + let para = match origin { + AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, + }; + xcm_builder::ProcessXcmMessage::< + Junction, + xcm_executor::XcmExecutor, + RuntimeCall, + >::process_message(message, Junction::Parachain(para.into()), meter, id) + } +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type IdleMaxServiceWeight = (); + type MessageProcessor = MessageProcessor; + type QueueChangeHandler = (); + type QueuePausedQuery = (); + type WeightInfo = (); +} + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + XcmPallet: pallet_xcm, + Uniques: pallet_uniques, + MessageQueue: pallet_message_queue, + } +); From a3bf09ffdc890a48d6590127d6decb1e0ce7a165 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 12:47:34 +0200 Subject: [PATCH 02/69] test cxm-simultor moved --- Cargo.toml | 2 +- .../laos/src/tests/xcm-simulator}/Cargo.toml | 0 .../laos/src/tests/xcm-simulator}/src/lib.rs | 0 .../laos/src/tests/xcm-simulator}/src/parachain.rs | 0 .../laos/src/tests/xcm-simulator}/src/relay_chain.rs | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {xcm-simulator => runtime/laos/src/tests/xcm-simulator}/Cargo.toml (100%) rename {xcm-simulator => runtime/laos/src/tests/xcm-simulator}/src/lib.rs (100%) rename {xcm-simulator => runtime/laos/src/tests/xcm-simulator}/src/parachain.rs (100%) rename {xcm-simulator => runtime/laos/src/tests/xcm-simulator}/src/relay_chain.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 01d12606..86254069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ resolver = "2" members = [ "node", "runtime/*", + "runtime/laos/src/tests/xcm-simulator", "pallets/*", "precompiles/*", "primitives", - "xcm-simulator", ] [workspace.dependencies] diff --git a/xcm-simulator/Cargo.toml b/runtime/laos/src/tests/xcm-simulator/Cargo.toml similarity index 100% rename from xcm-simulator/Cargo.toml rename to runtime/laos/src/tests/xcm-simulator/Cargo.toml diff --git a/xcm-simulator/src/lib.rs b/runtime/laos/src/tests/xcm-simulator/src/lib.rs similarity index 100% rename from xcm-simulator/src/lib.rs rename to runtime/laos/src/tests/xcm-simulator/src/lib.rs diff --git a/xcm-simulator/src/parachain.rs b/runtime/laos/src/tests/xcm-simulator/src/parachain.rs similarity index 100% rename from xcm-simulator/src/parachain.rs rename to runtime/laos/src/tests/xcm-simulator/src/parachain.rs diff --git a/xcm-simulator/src/relay_chain.rs b/runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs similarity index 100% rename from xcm-simulator/src/relay_chain.rs rename to runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs From 7ea35327115701dcab4bd674ac7277d7386187bd Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 13:06:57 +0200 Subject: [PATCH 03/69] add laos-runtime dep --- runtime/laos/src/tests/xcm-simulator/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/laos/src/tests/xcm-simulator/Cargo.toml b/runtime/laos/src/tests/xcm-simulator/Cargo.toml index 5741ac87..68cc3f54 100644 --- a/runtime/laos/src/tests/xcm-simulator/Cargo.toml +++ b/runtime/laos/src/tests/xcm-simulator/Cargo.toml @@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1" } scale-info = { version = "2.11.1", features = ["derive"] } log = { workspace = true } +laos-runtime = { workspace = true } frame-system = { workspace = true } frame-support = { workspace = true } pallet-balances = { workspace = true } @@ -44,6 +45,7 @@ std = [ "sp-runtime/std", "sp-tracing/std", "pallet-uniques/std", + "laos-runtime/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", From cc124912f00245c5f92d9b36588dbae60e62b405 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 13:19:53 +0200 Subject: [PATCH 04/69] renaming staging packages --- Cargo.lock | 31 +- Cargo.toml | 18 +- node/Cargo.toml | 2 +- node/src/chain_spec/mod.rs | 2 +- runtime/laos/Cargo.toml | 33 +- runtime/laos/src/configs/mod.rs | 2 +- runtime/laos/src/configs/xcm_config.rs | 10 +- runtime/laos/src/configs/xcm_message_queue.rs | 4 +- runtime/laos/src/lib.rs | 2 +- runtime/laos/src/tests/mod.rs | 2 + .../laos/src/tests/xcm-simulator/Cargo.toml | 62 -- .../laos/src/tests/xcm-simulator/src/lib.rs | 653 ------------------ .../src/tests/xcm-simulator/src/parachain.rs | 470 ------------- .../tests/xcm-simulator/src/relay_chain.rs | 295 -------- 14 files changed, 36 insertions(+), 1550 deletions(-) delete mode 100644 runtime/laos/src/tests/xcm-simulator/Cargo.toml delete mode 100644 runtime/laos/src/tests/xcm-simulator/src/lib.rs delete mode 100644 runtime/laos/src/tests/xcm-simulator/src/parachain.rs delete mode 100644 runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs diff --git a/Cargo.lock b/Cargo.lock index 00c5a60b..0f632073 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5302,11 +5302,13 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", + "pallet-uniques", "pallet-utility", "pallet-vesting", "pallet-xcm", "parachains-common", "parity-scale-codec", + "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", "polkadot-runtime-parachains", @@ -5335,6 +5337,7 @@ dependencies = [ "staging-xcm-executor", "substrate-wasm-builder", "test-utils", + "xcm-simulator", ] [[package]] @@ -8287,7 +8290,6 @@ name = "pallet-uniques" version = "28.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "log", @@ -16309,33 +16311,6 @@ dependencies = [ "staging-xcm-executor", ] -[[package]] -name = "xcm-simulator-example" -version = "7.0.0" -dependencies = [ - "frame-support", - "frame-system", - "log", - "pallet-balances", - "pallet-message-queue", - "pallet-uniques", - "pallet-xcm", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-parachains", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "xcm-simulator", -] - [[package]] name = "yamux" version = "0.10.2" diff --git a/Cargo.toml b/Cargo.toml index 86254069..ab82da72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ resolver = "2" members = [ "node", "runtime/*", - "runtime/laos/src/tests/xcm-simulator", "pallets/*", "precompiles/*", "primitives", @@ -178,7 +177,7 @@ cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/pol cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } cumulus-primitives-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -staging-parachain-info = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +parachain-info = { package = "staging-parachain-info", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } # (native) @@ -206,24 +205,15 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch # XCM # (wasm) cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -staging-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -staging-xcm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -staging-xcm-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } xcm-simulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } # (native) polkadot-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0" } polkadot-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0" } -# Orml -# (wasm) -# TODO This code has been commented out when upgrading polkadot-sdk from v1.1.0 to 1.6.0 -# because conflicts with orml-trait crate and currently XCM is not used. It should be -# uncommented and fixed when XCM is used in the runtime. -# orml-traits = { version = "0.7.0", default-features = false } -# orml-xcm-support = { version = "0.7.0", default-features = false } -# orml-xtokens = { version = "0.7.0", default-features = false } - # Other pallets # (wasm) substrate-fixed = { git = "https://github.com/encointer/substrate-fixed", default-features = false } diff --git a/node/Cargo.toml b/node/Cargo.toml index b7117008..ed144e1a 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -54,7 +54,7 @@ substrate-prometheus-endpoint = { workspace = true } polkadot-cli = { workspace = true, features = ["rococo-native"] } polkadot-service = { workspace = true, features = ["rococo-native"] } polkadot-primitives = { workspace = true } -staging-xcm = { workspace = true } +xcm = { workspace = true } laos-primitives = { workspace = true } # Cumulus diff --git a/node/src/chain_spec/mod.rs b/node/src/chain_spec/mod.rs index 83db9f8d..b137a46f 100644 --- a/node/src/chain_spec/mod.rs +++ b/node/src/chain_spec/mod.rs @@ -23,7 +23,7 @@ pub mod laos; mod predefined_accounts; /// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = staging_xcm::prelude::XCM_VERSION; +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; /// Helper function to generate a crypto pair from seed fn get_from_seed(seed: &str) -> ::Public { diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index f9bd0b5e..b4ebf5cd 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -77,9 +77,9 @@ pallet-precompiles-benchmark = { workspace = true } pallet-xcm = { workspace = true } polkadot-runtime-common = { workspace = true } polkadot-parachain-primitives = { workspace = true } -staging-xcm = { workspace = true } -staging-xcm-builder = { workspace = true } -staging-xcm-executor = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } @@ -90,7 +90,7 @@ cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } -staging-parachain-info = { workspace = true } +parachain-info = { workspace = true } parachains-common = { workspace = true } # Frontier @@ -114,16 +114,15 @@ precompile-utils = { workspace = true } [dev-dependencies] precompile-utils = { workspace = true, features = ["testing"] } evm = { workspace = true } -# TODO This code has been commented out when upgrading polkadot-sdk from v1.1.0 to 1.6.0 -# because conflicts with orml-trait crate and currently XCM is not used. It should be -# uncommented and fixed when XCM is used in the runtime. -# orml-traits = { workspace = true } -# orml-xtokens = { workspace = true, features = ["std"] } -# orml-xcm-support = { workspace = true, features = ["std"] } polkadot-runtime-parachains = { workspace = true } pallet-assets = { workspace = true } test-utils = { workspace = true } ethereum = { workspace = true } +xcm-simulator = { workspace = true } +pallet-xcm = { workspace = true } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +polkadot-core-primitives = { workspace = true } +polkadot-parachain-primitives = { workspace = true } [features] fast-runtime=[] @@ -168,7 +167,7 @@ std = [ "pallet-precompiles-benchmark/std", "pallet-transaction-payment/std", "pallet-xcm/std", - "staging-parachain-info/std", + "parachain-info/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "sp-api/std", @@ -185,9 +184,9 @@ std = [ "sp-version/std", "sp-weights/std", "sp-genesis-builder/std", - "staging-xcm-builder/std", - "staging-xcm-executor/std", - "staging-xcm/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", "substrate-wasm-builder", # Frontier "fp-evm/std", @@ -237,7 +236,7 @@ runtime-benchmarks = [ "pallet-elections-phragmen/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "staging-xcm-builder/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", @@ -247,7 +246,7 @@ runtime-benchmarks = [ "pallet-sudo/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", - "staging-xcm-executor/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", "pallet-asset-metadata-extender/runtime-benchmarks", "pallet-vesting/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", @@ -285,7 +284,7 @@ try-runtime = [ "pallet-treasury/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-xcm/try-runtime", - "staging-parachain-info/try-runtime", + "parachain-info/try-runtime", "pallet-evm/try-runtime", "pallet-evm-chain-id/try-runtime", "pallet-ethereum/try-runtime", diff --git a/runtime/laos/src/configs/mod.rs b/runtime/laos/src/configs/mod.rs index adc426cc..8f2550fe 100644 --- a/runtime/laos/src/configs/mod.rs +++ b/runtime/laos/src/configs/mod.rs @@ -57,4 +57,4 @@ parameter_types! { impl cumulus_pallet_aura_ext::Config for Runtime {} impl pallet_evm_chain_id::Config for Runtime {} -impl staging_parachain_info::Config for Runtime {} +impl parachain_info::Config for Runtime {} diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index 06e9ff85..03177878 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -28,8 +28,8 @@ use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; use pallet_xcm::XcmPassthrough; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::TryConvert; -use staging_xcm::latest::prelude::*; -use staging_xcm_builder::{ +use xcm::latest::prelude::*; +use xcm_builder::{ AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, @@ -37,7 +37,7 @@ use staging_xcm_builder::{ SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, }; -use staging_xcm_executor::XcmExecutor; +use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); @@ -128,7 +128,7 @@ pub type Barrier = TrailingSetTopicAsId< >; pub struct XcmConfig; -impl staging_xcm_executor::Config for XcmConfig { +impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; // How to withdraw and deposit an asset. @@ -171,7 +171,7 @@ pub type LocalOriginToLocation = SignedToAccountId20, // ..and XCMP to communicate with the sibling chains. diff --git a/runtime/laos/src/configs/xcm_message_queue.rs b/runtime/laos/src/configs/xcm_message_queue.rs index 02b7ed6b..86a9a5b7 100644 --- a/runtime/laos/src/configs/xcm_message_queue.rs +++ b/runtime/laos/src/configs/xcm_message_queue.rs @@ -23,9 +23,9 @@ impl pallet_message_queue::Config for Runtime { type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor; #[cfg(not(feature = "runtime-benchmarks"))] - type MessageProcessor = staging_xcm_builder::ProcessXcmMessage< + type MessageProcessor = xcm_builder::ProcessXcmMessage< AggregateMessageOrigin, - staging_xcm_executor::XcmExecutor, + xcm_executor::XcmExecutor, crate::RuntimeCall, >; type Size = u32; diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index de8af928..56ee9489 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -104,7 +104,7 @@ construct_runtime!( System: frame_system = 0, ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, - ParachainInfo: staging_parachain_info = 3, + ParachainInfo: parachain_info = 3, Sudo: pallet_sudo = 4, Utility: pallet_utility = 5, Multisig: pallet_multisig = 6, diff --git a/runtime/laos/src/tests/mod.rs b/runtime/laos/src/tests/mod.rs index 35b9a8e7..e7379ffa 100644 --- a/runtime/laos/src/tests/mod.rs +++ b/runtime/laos/src/tests/mod.rs @@ -18,6 +18,8 @@ mod precompile_tests; mod version_tests; +// mod xcm_simulator; + use core::str::FromStr; use sp_runtime::BuildStorage; diff --git a/runtime/laos/src/tests/xcm-simulator/Cargo.toml b/runtime/laos/src/tests/xcm-simulator/Cargo.toml deleted file mode 100644 index 68cc3f54..00000000 --- a/runtime/laos/src/tests/xcm-simulator/Cargo.toml +++ /dev/null @@ -1,62 +0,0 @@ -[package] -name = "xcm-simulator-example" -description = "Examples of xcm-simulator usage." -authors.workspace = true -edition.workspace = true -version = "7.0.0" - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1" } -scale-info = { version = "2.11.1", features = ["derive"] } -log = { workspace = true } - -laos-runtime = { workspace = true } -frame-system = { workspace = true } -frame-support = { workspace = true } -pallet-balances = { workspace = true } -pallet-message-queue = { workspace = true } -# pallet-uniques = { workspace = true } -sp-std = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } -sp-io = { workspace = true } -sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } - -xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-simulator = { workspace = true } -pallet-xcm = { workspace = true } -pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -polkadot-core-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-parachain-primitives = { workspace = true } - -[features] -default = ["std"] -std = [ - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "pallet-message-queue/std", - "pallet-xcm/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-parachains/std", - "sp-runtime/std", - "sp-tracing/std", - "pallet-uniques/std", - "laos-runtime/std", -] -runtime-benchmarks = [ - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-parachains/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -# "xcm-builder/runtime-benchmarks", -# "xcm-executor/runtime-benchmarks", -] diff --git a/runtime/laos/src/tests/xcm-simulator/src/lib.rs b/runtime/laos/src/tests/xcm-simulator/src/lib.rs deleted file mode 100644 index 56e204bf..00000000 --- a/runtime/laos/src/tests/xcm-simulator/src/lib.rs +++ /dev/null @@ -1,653 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot 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. - -// Polkadot 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 Polkadot. If not, see . - -mod parachain; -mod relay_chain; - -use sp_runtime::BuildStorage; -use sp_tracing; -use xcm::prelude::*; -use xcm_executor::traits::ConvertLocation; -use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; - -pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); -pub const INITIAL_BALANCE: u128 = 1_000_000_000; - -decl_test_parachain! { - pub struct ParaA { - Runtime = parachain::Runtime, - XcmpMessageHandler = parachain::MsgQueue, - DmpMessageHandler = parachain::MsgQueue, - new_ext = para_ext(1), - } -} - -decl_test_parachain! { - pub struct ParaB { - Runtime = parachain::Runtime, - XcmpMessageHandler = parachain::MsgQueue, - DmpMessageHandler = parachain::MsgQueue, - new_ext = para_ext(2), - } -} - -decl_test_relay_chain! { - pub struct Relay { - Runtime = relay_chain::Runtime, - RuntimeCall = relay_chain::RuntimeCall, - RuntimeEvent = relay_chain::RuntimeEvent, - XcmConfig = relay_chain::XcmConfig, - MessageQueue = relay_chain::MessageQueue, - System = relay_chain::System, - new_ext = relay_ext(), - } -} - -decl_test_network! { - pub struct MockNet { - relay_chain = Relay, - parachains = vec![ - (1, ParaA), - (2, ParaB), - ], - } -} - -pub fn parent_account_id() -> parachain::AccountId { - let location = (Parent,); - parachain::LocationToAccountId::convert_location(&location.into()).unwrap() -} - -pub fn child_account_id(para: u32) -> relay_chain::AccountId { - let location = (Parachain(para),); - relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() -} - -pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> relay_chain::AccountId { - let location = (Parachain(para), AccountId32 { network: None, id: who.into() }); - relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() -} - -pub fn sibling_account_account_id(para: u32, who: sp_runtime::AccountId32) -> parachain::AccountId { - let location = (Parent, Parachain(para), AccountId32 { network: None, id: who.into() }); - parachain::LocationToAccountId::convert_location(&location.into()).unwrap() -} - -pub fn parent_account_account_id(who: sp_runtime::AccountId32) -> parachain::AccountId { - let location = (Parent, AccountId32 { network: None, id: who.into() }); - parachain::LocationToAccountId::convert_location(&location.into()).unwrap() -} - -pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { - use parachain::{MsgQueue, Runtime, System}; - - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_BALANCE), (parent_account_id(), INITIAL_BALANCE)], - } - .assimilate_storage(&mut t) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| { - sp_tracing::try_init_simple(); - System::set_block_number(1); - MsgQueue::set_para_id(para_id.into()); - }); - ext -} - -pub fn relay_ext() -> sp_io::TestExternalities { - use relay_chain::{Runtime, RuntimeOrigin, System, Uniques}; - - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (ALICE, INITIAL_BALANCE), - (child_account_id(1), INITIAL_BALANCE), - (child_account_id(2), INITIAL_BALANCE), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| { - System::set_block_number(1); - assert_eq!(Uniques::force_create(RuntimeOrigin::root(), 1, ALICE, true), Ok(())); - assert_eq!(Uniques::mint(RuntimeOrigin::signed(ALICE), 1, 42, child_account_id(1)), Ok(())); - }); - ext -} - -pub type RelayChainPalletXcm = pallet_xcm::Pallet; -pub type ParachainPalletXcm = pallet_xcm::Pallet; - -#[cfg(test)] -mod tests { - use super::*; - - use codec::Encode; - use frame_support::{assert_ok, weights::Weight}; - use xcm::latest::QueryResponseInfo; - use xcm_simulator::TestExt; - - // Helper function for forming buy execution message - fn buy_execution(fees: impl Into) -> Instruction { - BuyExecution { fees: fees.into(), weight_limit: Unlimited } - } - - #[test] - fn remote_account_ids_work() { - child_account_account_id(1, ALICE); - sibling_account_account_id(1, ALICE); - parent_account_account_id(ALICE); - } - - #[test] - fn dmp() { - MockNet::reset(); - - let remark = parachain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::send_xcm( - Here, - Parachain(1), - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - ParaA::execute_with(|| { - use parachain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn ump() { - MockNet::reset(); - - let remark = relay_chain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Here, - Parent, - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - Relay::execute_with(|| { - use relay_chain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn xcmp() { - MockNet::reset(); - - let remark = parachain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Here, - (Parent, Parachain(2)), - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - ParaB::execute_with(|| { - use parachain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn reserve_transfer() { - MockNet::reset(); - - let withdraw_amount = 123; - - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( - relay_chain::RuntimeOrigin::signed(ALICE), - Box::new(Parachain(1).into()), - Box::new(AccountId32 { network: None, id: ALICE.into() }.into()), - Box::new((Here, withdraw_amount).into()), - 0, - Unlimited, - )); - assert_eq!( - relay_chain::Balances::free_balance(&child_account_id(1)), - INITIAL_BALANCE + withdraw_amount - ); - }); - - ParaA::execute_with(|| { - // free execution, full amount received - assert_eq!( - pallet_balances::Pallet::::free_balance(&ALICE), - INITIAL_BALANCE + withdraw_amount - ); - }); - } - - #[test] - fn remote_locking_and_unlocking() { - MockNet::reset(); - - let locked_amount = 100; - - ParaB::execute_with(|| { - let message = Xcm(vec![LockAsset { - asset: (Here, locked_amount).into(), - unlocker: Parachain(1).into(), - }]); - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); - }); - - Relay::execute_with(|| { - use pallet_balances::{BalanceLock, Reasons}; - assert_eq!( - relay_chain::Balances::locks(&child_account_id(2)), - vec![BalanceLock { - id: *b"py/xcmlk", - amount: locked_amount, - reasons: Reasons::All - }] - ); - }); - - ParaA::execute_with(|| { - assert_eq!( - parachain::MsgQueue::received_dmp(), - vec![Xcm(vec![NoteUnlockable { - owner: (Parent, Parachain(2)).into(), - asset: (Parent, locked_amount).into() - }])] - ); - }); - - ParaB::execute_with(|| { - // Request unlocking part of the funds on the relay chain - let message = Xcm(vec![RequestUnlock { - asset: (Parent, locked_amount - 50).into(), - locker: Parent.into(), - }]); - assert_ok!(ParachainPalletXcm::send_xcm(Here, (Parent, Parachain(1)), message)); - }); - - Relay::execute_with(|| { - use pallet_balances::{BalanceLock, Reasons}; - // Lock is reduced - assert_eq!( - relay_chain::Balances::locks(&child_account_id(2)), - vec![BalanceLock { - id: *b"py/xcmlk", - amount: locked_amount - 50, - reasons: Reasons::All - }] - ); - }); - } - - /// Scenario: - /// A parachain transfers an NFT resident on the relay chain to another parachain account. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn withdraw_and_deposit_nft() { - MockNet::reset(); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(1))); - }); - - ParaA::execute_with(|| { - let message = Xcm(vec![TransferAsset { - assets: (GeneralIndex(1), 42u32).into(), - beneficiary: Parachain(2).into(), - }]); - // Send withdraw and deposit - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message)); - }); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(2))); - }); - } - - /// Scenario: - /// The relay-chain teleports an NFT to a parachain. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn teleport_nft() { - MockNet::reset(); - - Relay::execute_with(|| { - // Mint the NFT (1, 69) and give it to our "parachain#1 alias". - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 1, - 69, - child_account_account_id(1, ALICE), - )); - // The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be - // withdrawable by Alice on the parachain. - assert_eq!( - relay_chain::Uniques::owner(1, 69), - Some(child_account_account_id(1, ALICE)) - ); - }); - ParaA::execute_with(|| { - assert_ok!(parachain::ForeignUniques::force_create( - parachain::RuntimeOrigin::root(), - (Parent, GeneralIndex(1)).into(), - ALICE, - false, - )); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), - None, - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); - - // IRL Alice would probably just execute this locally on the Relay-chain, but we can't - // easily do that here since we only send between chains. - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(1), 69u32).into()), - InitiateTeleport { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - // Send teleport - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), - Some(ALICE), - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); - }); - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 69), None); - }); - } - - /// Scenario: - /// The relay-chain transfers an NFT into a parachain's sovereign account, who then mints a - /// trustless-backed-derived locally. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn reserve_asset_transfer_nft() { - sp_tracing::init_for_tests(); - MockNet::reset(); - - Relay::execute_with(|| { - assert_ok!(relay_chain::Uniques::force_create( - relay_chain::RuntimeOrigin::root(), - 2, - ALICE, - false - )); - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 2, - 69, - child_account_account_id(1, ALICE) - )); - assert_eq!( - relay_chain::Uniques::owner(2, 69), - Some(child_account_account_id(1, ALICE)) - ); - }); - ParaA::execute_with(|| { - assert_ok!(parachain::ForeignUniques::force_create( - parachain::RuntimeOrigin::root(), - (Parent, GeneralIndex(2)).into(), - ALICE, - false, - )); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), - None, - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); - - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(2), 69u32).into()), - DepositReserveAsset { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - // Send transfer - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - log::debug!(target: "xcm-executor", "Hello"); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), - Some(ALICE), - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); - }); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_id(1))); - }); - } - - /// Scenario: - /// The relay-chain creates an asset class on a parachain and then Alice transfers her NFT into - /// that parachain's sovereign account, who then mints a trustless-backed-derivative locally. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn reserve_asset_class_create_and_reserve_transfer() { - MockNet::reset(); - - Relay::execute_with(|| { - assert_ok!(relay_chain::Uniques::force_create( - relay_chain::RuntimeOrigin::root(), - 2, - ALICE, - false - )); - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 2, - 69, - child_account_account_id(1, ALICE) - )); - assert_eq!( - relay_chain::Uniques::owner(2, 69), - Some(child_account_account_id(1, ALICE)) - ); - - let message = Xcm(vec![Transact { - origin_kind: OriginKind::Xcm, - require_weight_at_most: Weight::from_parts(1_000_000_000, 1024 * 1024), - call: parachain::RuntimeCall::from( - pallet_uniques::Call::::create { - collection: (Parent, 2u64).into(), - admin: parent_account_id(), - }, - ) - .encode() - .into(), - }]); - // Send creation. - assert_ok!(RelayChainPalletXcm::send_xcm(Here, Parachain(1), message)); - }); - ParaA::execute_with(|| { - // Then transfer - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(2), 69u32).into()), - DepositReserveAsset { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - assert_eq!(parachain::Balances::reserved_balance(&parent_account_id()), 1000); - assert_eq!( - parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), - Some(parent_account_id()) - ); - }); - } - - /// Scenario: - /// A parachain transfers funds on the relay chain to another parachain account. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn withdraw_and_deposit() { - MockNet::reset(); - - let send_amount = 10; - - ParaA::execute_with(|| { - let message = Xcm(vec![ - WithdrawAsset((Here, send_amount).into()), - buy_execution((Here, send_amount)), - DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, - ]); - // Send withdraw and deposit - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); - }); - - Relay::execute_with(|| { - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(1)), - INITIAL_BALANCE - send_amount - ); - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(2)), - INITIAL_BALANCE + send_amount - ); - }); - } - - /// Scenario: - /// A parachain wants to be notified that a transfer worked correctly. - /// It sends a `QueryHolding` after the deposit to get notified on success. - /// - /// Asserts that the balances are updated correctly and the expected XCM is sent. - #[test] - fn query_holding() { - MockNet::reset(); - - let send_amount = 10; - let query_id_set = 1234; - - // Send a message which fully succeeds on the relay chain - ParaA::execute_with(|| { - let message = Xcm(vec![ - WithdrawAsset((Here, send_amount).into()), - buy_execution((Here, send_amount)), - DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, - ReportHolding { - response_info: QueryResponseInfo { - destination: Parachain(1).into(), - query_id: query_id_set, - max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), - }, - assets: All.into(), - }, - ]); - // Send withdraw and deposit with query holding - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); - }); - - // Check that transfer was executed - Relay::execute_with(|| { - // Withdraw executed - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(1)), - INITIAL_BALANCE - send_amount - ); - // Deposit executed - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(2)), - INITIAL_BALANCE + send_amount - ); - }); - - // Check that QueryResponse message was received - ParaA::execute_with(|| { - assert_eq!( - parachain::MsgQueue::received_dmp(), - vec![Xcm(vec![QueryResponse { - query_id: query_id_set, - response: Response::Assets(Assets::new()), - max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), - querier: Some(Here.into()), - }])], - ); - }); - } -} diff --git a/runtime/laos/src/tests/xcm-simulator/src/parachain.rs b/runtime/laos/src/tests/xcm-simulator/src/parachain.rs deleted file mode 100644 index 41e62596..00000000 --- a/runtime/laos/src/tests/xcm-simulator/src/parachain.rs +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot 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. - -// Polkadot 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 Polkadot. If not, see . - -//! Parachain runtime mock. - -use codec::{Decode, Encode}; -use core::marker::PhantomData; -use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, - weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, -}; - -use frame_system::EnsureRoot; -use sp_core::{ConstU32, H256}; -use sp_runtime::{ - traits::{Get, Hash, IdentityLookup}, - AccountId32, -}; -use sp_std::prelude::*; - -use pallet_xcm::XcmPassthrough; -use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, -}; -use xcm::{latest::prelude::*, VersionedXcm}; -use xcm_builder::{ - Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, - EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, - NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{ - traits::{ConvertLocation, JustTry}, - Config, XcmExecutor, -}; - -pub type SovereignAccountOf = ( - SiblingParachainConvertsVia, - AccountId32Aliases, - ParentIsPreset, -); - -pub type AccountId = AccountId32; -pub type Balance = u128; - -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type FreezeIdentifier = (); - type MaxFreezes = ConstU32<0>; -} - -#[cfg(feature = "runtime-benchmarks")] -pub struct UniquesHelper; -#[cfg(feature = "runtime-benchmarks")] -impl pallet_uniques::BenchmarkHelper for UniquesHelper { - fn collection(i: u16) -> Location { - GeneralIndex(i as u128).into() - } - fn item(i: u16) -> AssetInstance { - AssetInstance::Index(i as u128) - } -} - -impl pallet_uniques::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type CollectionId = Location; - type ItemId = AssetInstance; - type Currency = Balances; - type CreateOrigin = ForeignCreators; - type ForceOrigin = frame_system::EnsureRoot; - type CollectionDeposit = frame_support::traits::ConstU128<1_000>; - type ItemDeposit = frame_support::traits::ConstU128<1_000>; - type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; - type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; - type DepositPerByte = frame_support::traits::ConstU128<1>; - type StringLimit = ConstU32<64>; - type KeyLimit = ConstU32<64>; - type ValueLimit = ConstU32<128>; - type Locker = (); - type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type Helper = UniquesHelper; -} - -// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins -// which are locations containing the class location. -pub struct ForeignCreators; -impl EnsureOriginWithArg for ForeignCreators { - type Success = AccountId; - - fn try_origin( - o: RuntimeOrigin, - a: &Location, - ) -> sp_std::result::Result { - let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; - if !a.starts_with(&origin_location) { - return Err(o) - } - SovereignAccountOf::convert_location(&origin_location).ok_or(o) - } - - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin(a: &Location) -> Result { - Ok(pallet_xcm::Origin::Xcm(a.clone()).into()) - } -} - -parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} - -parameter_types! { - pub const KsmLocation: Location = Location::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Kusama; - pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); -} - -pub type LocationToAccountId = ( - ParentIsPreset, - SiblingParachainConvertsVia, - AccountId32Aliases, - Account32Hash<(), AccountId>, -); - -pub type XcmOriginToCallOrigin = ( - SovereignSignedViaLocation, - SignedAccountId32AsNative, - XcmPassthrough, -); - -parameter_types! { - pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); - pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; - pub ForeignPrefix: Location = (Parent,).into(); -} - -pub type LocalAssetTransactor = ( - FungibleAdapter, LocationToAccountId, AccountId, ()>, - NonFungiblesAdapter< - ForeignUniques, - ConvertedConcreteId, - SovereignAccountOf, - AccountId, - NoChecking, - (), - >, -); - -pub type XcmRouter = EnsureDecodableXcm>; -pub type Barrier = AllowUnpaidExecutionFrom; - -parameter_types! { - pub NftCollectionOne: AssetFilter - = Wild(AllOf { fun: WildNonFungible, id: AssetId((Parent, GeneralIndex(1)).into()) }); - pub NftCollectionOneForRelay: (AssetFilter, Location) - = (NftCollectionOne::get(), (Parent,).into()); -} -pub type TrustedTeleporters = xcm_builder::Case; -pub type TrustedReserves = EverythingBut>; - -pub struct XcmConfig; -impl Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = (NativeAsset, TrustedReserves); - type IsTeleporter = TrustedTeleporters; - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; - type ResponseHandler = (); - type AssetTrap = (); - type AssetLocker = PolkadotXcm; - type AssetExchanger = (); - type AssetClaims = (); - type SubscriptionService = (); - type PalletInstancesInfo = (); - type FeeManager = (); - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); -} - -#[frame_support::pallet] -pub mod mock_msg_queue { - use super::*; - use frame_support::pallet_prelude::*; - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type XcmExecutor: ExecuteXcm; - } - - #[pallet::call] - impl Pallet {} - - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::storage] - #[pallet::getter(fn parachain_id)] - pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - - #[pallet::storage] - #[pallet::getter(fn received_dmp)] - /// A queue of received DMP messages - pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; - - impl Get for Pallet { - fn get() -> ParaId { - Self::parachain_id() - } - } - - pub type MessageId = [u8; 32]; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - // XCMP - /// Some XCM was executed OK. - Success(Option), - /// Some XCM failed. - Fail(Option, XcmError), - /// Bad XCM version used. - BadVersion(Option), - /// Bad XCM format used. - BadFormat(Option), - - // DMP - /// Downward message is invalid XCM. - InvalidFormat(MessageId), - /// Downward message is unsupported version of XCM. - UnsupportedVersion(MessageId), - /// Downward message executed with the given outcome. - ExecutedDownward(MessageId, Outcome), - } - - impl Pallet { - pub fn set_para_id(para_id: ParaId) { - ParachainId::::put(para_id); - } - - fn handle_xcmp_message( - sender: ParaId, - _sent_at: RelayBlockNumber, - xcm: VersionedXcm, - max_weight: Weight, - ) -> Result { - let hash = Encode::using_encoded(&xcm, T::Hashing::hash); - let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); - let (result, event) = match Xcm::::try_from(xcm) { - Ok(xcm) => { - let location = (Parent, Parachain(sender.into())); - match T::XcmExecutor::prepare_and_execute( - location, - xcm, - &mut message_hash, - max_weight, - Weight::zero(), - ) { - Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), - Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), - // As far as the caller is concerned, this was dispatched without error, so - // we just report the weight used. - Outcome::Incomplete { used, error } => - (Ok(used), Event::Fail(Some(hash), error)), - } - }, - Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), - }; - Self::deposit_event(event); - result - } - } - - impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - max_weight: Weight, - ) -> Weight { - for (sender, sent_at, data) in iter { - let mut data_ref = data; - let _ = XcmpMessageFormat::decode(&mut data_ref) - .expect("Simulator encodes with versioned xcm format; qed"); - - let mut remaining_fragments = data_ref; - while !remaining_fragments.is_empty() { - if let Ok(xcm) = - VersionedXcm::::decode(&mut remaining_fragments) - { - let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); - } else { - debug_assert!(false, "Invalid incoming XCMP message data"); - } - } - } - max_weight - } - } - - impl DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - for (_i, (_sent_at, data)) in iter.enumerate() { - let mut id = sp_io::hashing::blake2_256(&data[..]); - let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); - match maybe_versioned { - Err(_) => { - Self::deposit_event(Event::InvalidFormat(id)); - }, - Ok(versioned) => match Xcm::try_from(versioned) { - Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), - Ok(x) => { - let outcome = T::XcmExecutor::prepare_and_execute( - Parent, - x.clone(), - &mut id, - limit, - Weight::zero(), - ); - >::append(x); - Self::deposit_event(Event::ExecutedDownward(id, outcome)); - }, - }, - } - } - limit - } - } -} - -impl mock_msg_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - -pub type LocalOriginToLocation = SignedToAccountId32; - -pub struct TrustedLockerCase(PhantomData); -impl> ContainsPair for TrustedLockerCase { - fn contains(origin: &Location, asset: &Asset) -> bool { - let (o, a) = T::get(); - a.matches(asset) && &o == origin - } -} - -parameter_types! { - pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); -} - -pub type TrustedLockers = TrustedLockerCase; - -impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Everything; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Nothing; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = TrustedLockers; - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); - type WeightInfo = pallet_xcm::TestWeightInfo; - type AdminOrigin = EnsureRoot; -} - -type Block = frame_system::mocking::MockBlock; - -construct_runtime!( - pub enum Runtime - { - System: frame_system, - Balances: pallet_balances, - MsgQueue: mock_msg_queue, - PolkadotXcm: pallet_xcm, - ForeignUniques: pallet_uniques, - } -); diff --git a/runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs b/runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs deleted file mode 100644 index b41df3cf..00000000 --- a/runtime/laos/src/tests/xcm-simulator/src/relay_chain.rs +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Polkadot. - -// Polkadot 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. - -// Polkadot 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 Polkadot. If not, see . - -//! Relay chain runtime mock. - -use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{AsEnsureOriginWithArg, Everything, Nothing, ProcessMessage, ProcessMessageError}, - weights::{Weight, WeightMeter}, -}; - -use frame_system::EnsureRoot; -use sp_core::{ConstU32, H256}; -use sp_runtime::{traits::IdentityLookup, AccountId32}; - -use polkadot_parachain_primitives::primitives::Id as ParaId; -use polkadot_runtime_parachains::{ - configuration, - inclusion::{AggregateMessageOrigin, UmpQueueId}, - origin, shared, -}; -use xcm::latest::prelude::*; -use xcm_builder::{ - Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, - ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, - ConvertedConcreteId, EnsureDecodableXcm, FixedRateOfFungible, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NoChecking, NonFungiblesAdapter, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{traits::JustTry, Config, XcmExecutor}; - -pub type AccountId = AccountId32; -pub type Balance = u128; - -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type FreezeIdentifier = (); - type MaxFreezes = ConstU32<0>; -} - -impl pallet_uniques::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type CollectionId = u32; - type ItemId = u32; - type Currency = Balances; - type CreateOrigin = AsEnsureOriginWithArg>; - type ForceOrigin = frame_system::EnsureRoot; - type CollectionDeposit = frame_support::traits::ConstU128<1_000>; - type ItemDeposit = frame_support::traits::ConstU128<1_000>; - type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; - type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; - type DepositPerByte = frame_support::traits::ConstU128<1>; - type StringLimit = ConstU32<64>; - type KeyLimit = ConstU32<64>; - type ValueLimit = ConstU32<128>; - type Locker = (); - type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type Helper = (); -} - -impl shared::Config for Runtime { - type DisabledValidators = (); -} - -impl configuration::Config for Runtime { - type WeightInfo = configuration::TestWeightInfo; -} - -parameter_types! { - pub const TokenLocation: Location = Here.into_location(); - pub RelayNetwork: NetworkId = ByGenesis([0; 32]); - pub const AnyNetwork: Option = None; - pub UniversalLocation: InteriorLocation = RelayNetwork::get().into(); - pub UnitWeightCost: u64 = 1_000; -} - -pub type LocationToAccountId = ( - ChildParachainConvertsVia, - AccountId32Aliases, - Account32Hash<(), AccountId>, -); - -pub type LocalAssetTransactor = ( - FungibleAdapter, LocationToAccountId, AccountId, ()>, - NonFungiblesAdapter< - Uniques, - ConvertedConcreteId, JustTry>, - LocationToAccountId, - AccountId, - NoChecking, - (), - >, -); - -type LocalOriginConverter = ( - SovereignSignedViaLocation, - ChildParachainAsNative, - SignedAccountId32AsNative, - ChildSystemParachainAsSuperuser, -); - -parameter_types! { - pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000); - pub TokensPerSecondPerByte: (AssetId, u128, u128) = - (AssetId(TokenLocation::get()), 1_000_000_000_000, 1024 * 1024); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; -} - -pub type XcmRouter = EnsureDecodableXcm; -pub type Barrier = AllowUnpaidExecutionFrom; - -pub struct XcmConfig; -impl Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = LocalOriginConverter; - type IsReserve = (); - type IsTeleporter = (); - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; - type ResponseHandler = (); - type AssetTrap = (); - type AssetLocker = XcmPallet; - type AssetExchanger = (); - type AssetClaims = (); - type SubscriptionService = (); - type PalletInstancesInfo = (); - type FeeManager = (); - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); -} - -pub type LocalOriginToLocation = SignedToAccountId32; - -impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmRouter = XcmRouter; - // Anyone can execute XCM messages locally... - type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = IsConcrete; - type TrustedLockers = (); - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); - type WeightInfo = pallet_xcm::TestWeightInfo; - type AdminOrigin = EnsureRoot; -} - -parameter_types! { - pub const FirstMessageFactorPercent: u64 = 100; -} - -impl origin::Config for Runtime {} - -type Block = frame_system::mocking::MockBlock; - -parameter_types! { - /// Amount of weight that can be spent per block to service messages. - pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); - pub const MessageQueueHeapSize: u32 = 65_536; - pub const MessageQueueMaxStale: u32 = 16; -} - -/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet. -pub struct MessageProcessor; -impl ProcessMessage for MessageProcessor { - type Origin = AggregateMessageOrigin; - - fn process_message( - message: &[u8], - origin: Self::Origin, - meter: &mut WeightMeter, - id: &mut [u8; 32], - ) -> Result { - let para = match origin { - AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, - }; - xcm_builder::ProcessXcmMessage::< - Junction, - xcm_executor::XcmExecutor, - RuntimeCall, - >::process_message(message, Junction::Parachain(para.into()), meter, id) - } -} - -impl pallet_message_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type Size = u32; - type HeapSize = MessageQueueHeapSize; - type MaxStale = MessageQueueMaxStale; - type ServiceWeight = MessageQueueServiceWeight; - type IdleMaxServiceWeight = (); - type MessageProcessor = MessageProcessor; - type QueueChangeHandler = (); - type QueuePausedQuery = (); - type WeightInfo = (); -} - -construct_runtime!( - pub enum Runtime - { - System: frame_system, - Balances: pallet_balances, - ParasOrigin: origin, - XcmPallet: pallet_xcm, - Uniques: pallet_uniques, - MessageQueue: pallet_message_queue, - } -); From 3044832b3f4f5b09ca732a1fad764185da930e2f Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 13:20:16 +0200 Subject: [PATCH 05/69] add simulator --- runtime/laos/src/tests/mod.rs | 2 +- .../src/tests/xcm_simulator/Cargo.toml_old | 62 ++ runtime/laos/src/tests/xcm_simulator/mod.rs | 653 ++++++++++++++++++ .../laos/src/tests/xcm_simulator/parachain.rs | 470 +++++++++++++ .../src/tests/xcm_simulator/relay_chain.rs | 295 ++++++++ 5 files changed, 1481 insertions(+), 1 deletion(-) create mode 100644 runtime/laos/src/tests/xcm_simulator/Cargo.toml_old create mode 100644 runtime/laos/src/tests/xcm_simulator/mod.rs create mode 100644 runtime/laos/src/tests/xcm_simulator/parachain.rs create mode 100644 runtime/laos/src/tests/xcm_simulator/relay_chain.rs diff --git a/runtime/laos/src/tests/mod.rs b/runtime/laos/src/tests/mod.rs index e7379ffa..5135b745 100644 --- a/runtime/laos/src/tests/mod.rs +++ b/runtime/laos/src/tests/mod.rs @@ -18,7 +18,7 @@ mod precompile_tests; mod version_tests; -// mod xcm_simulator; +mod xcm_simulator; use core::str::FromStr; use sp_runtime::BuildStorage; diff --git a/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old b/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old new file mode 100644 index 00000000..68cc3f54 --- /dev/null +++ b/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old @@ -0,0 +1,62 @@ +[package] +name = "xcm-simulator-example" +description = "Examples of xcm-simulator usage." +authors.workspace = true +edition.workspace = true +version = "7.0.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1" } +scale-info = { version = "2.11.1", features = ["derive"] } +log = { workspace = true } + +laos-runtime = { workspace = true } +frame-system = { workspace = true } +frame-support = { workspace = true } +pallet-balances = { workspace = true } +pallet-message-queue = { workspace = true } +# pallet-uniques = { workspace = true } +sp-std = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-io = { workspace = true } +sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } + +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-simulator = { workspace = true } +pallet-xcm = { workspace = true } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +polkadot-core-primitives = { workspace = true } +polkadot-runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } + +[features] +default = ["std"] +std = [ + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "pallet-message-queue/std", + "pallet-xcm/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-parachains/std", + "sp-runtime/std", + "sp-tracing/std", + "pallet-uniques/std", + "laos-runtime/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +# "xcm-builder/runtime-benchmarks", +# "xcm-executor/runtime-benchmarks", +] diff --git a/runtime/laos/src/tests/xcm_simulator/mod.rs b/runtime/laos/src/tests/xcm_simulator/mod.rs new file mode 100644 index 00000000..56e204bf --- /dev/null +++ b/runtime/laos/src/tests/xcm_simulator/mod.rs @@ -0,0 +1,653 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +mod parachain; +mod relay_chain; + +use sp_runtime::BuildStorage; +use sp_tracing; +use xcm::prelude::*; +use xcm_executor::traits::ConvertLocation; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); +pub const INITIAL_BALANCE: u128 = 1_000_000_000; + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(2), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + RuntimeCall = relay_chain::RuntimeCall, + RuntimeEvent = relay_chain::RuntimeEvent, + XcmConfig = relay_chain::XcmConfig, + MessageQueue = relay_chain::MessageQueue, + System = relay_chain::System, + new_ext = relay_ext(), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + ], + } +} + +pub fn parent_account_id() -> parachain::AccountId { + let location = (Parent,); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn child_account_id(para: u32) -> relay_chain::AccountId { + let location = (Parachain(para),); + relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn child_account_account_id(para: u32, who: sp_runtime::AccountId32) -> relay_chain::AccountId { + let location = (Parachain(para), AccountId32 { network: None, id: who.into() }); + relay_chain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn sibling_account_account_id(para: u32, who: sp_runtime::AccountId32) -> parachain::AccountId { + let location = (Parent, Parachain(para), AccountId32 { network: None, id: who.into() }); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn parent_account_account_id(who: sp_runtime::AccountId32) -> parachain::AccountId { + let location = (Parent, AccountId32 { network: None, id: who.into() }); + parachain::LocationToAccountId::convert_location(&location.into()).unwrap() +} + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_BALANCE), (parent_account_id(), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + sp_tracing::try_init_simple(); + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext() -> sp_io::TestExternalities { + use relay_chain::{Runtime, RuntimeOrigin, System, Uniques}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (ALICE, INITIAL_BALANCE), + (child_account_id(1), INITIAL_BALANCE), + (child_account_id(2), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + assert_eq!(Uniques::force_create(RuntimeOrigin::root(), 1, ALICE, true), Ok(())); + assert_eq!(Uniques::mint(RuntimeOrigin::signed(ALICE), 1, 42, child_account_id(1)), Ok(())); + }); + ext +} + +pub type RelayChainPalletXcm = pallet_xcm::Pallet; +pub type ParachainPalletXcm = pallet_xcm::Pallet; + +#[cfg(test)] +mod tests { + use super::*; + + use codec::Encode; + use frame_support::{assert_ok, weights::Weight}; + use xcm::latest::QueryResponseInfo; + use xcm_simulator::TestExt; + + // Helper function for forming buy execution message + fn buy_execution(fees: impl Into) -> Instruction { + BuyExecution { fees: fees.into(), weight_limit: Unlimited } + } + + #[test] + fn remote_account_ids_work() { + child_account_account_id(1, ALICE); + sibling_account_account_id(1, ALICE); + parent_account_account_id(ALICE); + } + + #[test] + fn dmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::send_xcm( + Here, + Parachain(1), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaA::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn ump() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn xcmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + (Parent, Parachain(2)), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaB::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + + #[test] + fn reserve_transfer() { + MockNet::reset(); + + let withdraw_amount = 123; + + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(ALICE), + Box::new(Parachain(1).into()), + Box::new(AccountId32 { network: None, id: ALICE.into() }.into()), + Box::new((Here, withdraw_amount).into()), + 0, + Unlimited, + )); + assert_eq!( + relay_chain::Balances::free_balance(&child_account_id(1)), + INITIAL_BALANCE + withdraw_amount + ); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALICE), + INITIAL_BALANCE + withdraw_amount + ); + }); + } + + #[test] + fn remote_locking_and_unlocking() { + MockNet::reset(); + + let locked_amount = 100; + + ParaB::execute_with(|| { + let message = Xcm(vec![LockAsset { + asset: (Here, locked_amount).into(), + unlocker: Parachain(1).into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + assert_eq!( + relay_chain::Balances::locks(&child_account_id(2)), + vec![BalanceLock { + id: *b"py/xcmlk", + amount: locked_amount, + reasons: Reasons::All + }] + ); + }); + + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![NoteUnlockable { + owner: (Parent, Parachain(2)).into(), + asset: (Parent, locked_amount).into() + }])] + ); + }); + + ParaB::execute_with(|| { + // Request unlocking part of the funds on the relay chain + let message = Xcm(vec![RequestUnlock { + asset: (Parent, locked_amount - 50).into(), + locker: Parent.into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, (Parent, Parachain(1)), message)); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + // Lock is reduced + assert_eq!( + relay_chain::Balances::locks(&child_account_id(2)), + vec![BalanceLock { + id: *b"py/xcmlk", + amount: locked_amount - 50, + reasons: Reasons::All + }] + ); + }); + } + + /// Scenario: + /// A parachain transfers an NFT resident on the relay chain to another parachain account. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn withdraw_and_deposit_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(1))); + }); + + ParaA::execute_with(|| { + let message = Xcm(vec![TransferAsset { + assets: (GeneralIndex(1), 42u32).into(), + beneficiary: Parachain(2).into(), + }]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message)); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(2))); + }); + } + + /// Scenario: + /// The relay-chain teleports an NFT to a parachain. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn teleport_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + // Mint the NFT (1, 69) and give it to our "parachain#1 alias". + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 1, + 69, + child_account_account_id(1, ALICE), + )); + // The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be + // withdrawable by Alice on the parachain. + assert_eq!( + relay_chain::Uniques::owner(1, 69), + Some(child_account_account_id(1, ALICE)) + ); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(1)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + // IRL Alice would probably just execute this locally on the Relay-chain, but we can't + // easily do that here since we only send between chains. + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(1), 69u32).into()), + InitiateTeleport { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send teleport + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 69), None); + }); + } + + /// Scenario: + /// The relay-chain transfers an NFT into a parachain's sovereign account, who then mints a + /// trustless-backed-derived locally. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn reserve_asset_transfer_nft() { + sp_tracing::init_for_tests(); + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!( + relay_chain::Uniques::owner(2, 69), + Some(child_account_account_id(1, ALICE)) + ); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(2)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send transfer + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + log::debug!(target: "xcm-executor", "Hello"); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_id(1))); + }); + } + + /// Scenario: + /// The relay-chain creates an asset class on a parachain and then Alice transfers her NFT into + /// that parachain's sovereign account, who then mints a trustless-backed-derivative locally. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn reserve_asset_class_create_and_reserve_transfer() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!( + relay_chain::Uniques::owner(2, 69), + Some(child_account_account_id(1, ALICE)) + ); + + let message = Xcm(vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: Weight::from_parts(1_000_000_000, 1024 * 1024), + call: parachain::RuntimeCall::from( + pallet_uniques::Call::::create { + collection: (Parent, 2u64).into(), + admin: parent_account_id(), + }, + ) + .encode() + .into(), + }]); + // Send creation. + assert_ok!(RelayChainPalletXcm::send_xcm(Here, Parachain(1), message)); + }); + ParaA::execute_with(|| { + // Then transfer + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!(parachain::Balances::reserved_balance(&parent_account_id()), 1000); + assert_eq!( + parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), + Some(parent_account_id()) + ); + }); + } + + /// Scenario: + /// A parachain transfers funds on the relay chain to another parachain account. + /// + /// Asserts that the parachain accounts are updated as expected. + #[test] + fn withdraw_and_deposit() { + MockNet::reset(); + + let send_amount = 10; + + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); + } + + /// Scenario: + /// A parachain wants to be notified that a transfer worked correctly. + /// It sends a `QueryHolding` after the deposit to get notified on success. + /// + /// Asserts that the balances are updated correctly and the expected XCM is sent. + #[test] + fn query_holding() { + MockNet::reset(); + + let send_amount = 10; + let query_id_set = 1234; + + // Send a message which fully succeeds on the relay chain + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ReportHolding { + response_info: QueryResponseInfo { + destination: Parachain(1).into(), + query_id: query_id_set, + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + }, + assets: All.into(), + }, + ]); + // Send withdraw and deposit with query holding + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); + }); + + // Check that transfer was executed + Relay::execute_with(|| { + // Withdraw executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + // Deposit executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); + + // Check that QueryResponse message was received + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![QueryResponse { + query_id: query_id_set, + response: Response::Assets(Assets::new()), + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + querier: Some(Here.into()), + }])], + ); + }); + } +} diff --git a/runtime/laos/src/tests/xcm_simulator/parachain.rs b/runtime/laos/src/tests/xcm_simulator/parachain.rs new file mode 100644 index 00000000..41e62596 --- /dev/null +++ b/runtime/laos/src/tests/xcm_simulator/parachain.rs @@ -0,0 +1,470 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use codec::{Decode, Encode}; +use core::marker::PhantomData; +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +}; + +use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; +use sp_runtime::{ + traits::{Get, Hash, IdentityLookup}, + AccountId32, +}; +use sp_std::prelude::*; + +use pallet_xcm::XcmPassthrough; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain_primitives::primitives::{ + DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; +use xcm::{latest::prelude::*, VersionedXcm}; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, + EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, + NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{ + traits::{ConvertLocation, JustTry}, + Config, XcmExecutor, +}; + +pub type SovereignAccountOf = ( + SiblingParachainConvertsVia, + AccountId32Aliases, + ParentIsPreset, +); + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +#[cfg(feature = "runtime-benchmarks")] +pub struct UniquesHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_uniques::BenchmarkHelper for UniquesHelper { + fn collection(i: u16) -> Location { + GeneralIndex(i as u128).into() + } + fn item(i: u16) -> AssetInstance { + AssetInstance::Index(i as u128) + } +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = Location; + type ItemId = AssetInstance; + type Currency = Balances; + type CreateOrigin = ForeignCreators; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = frame_support::traits::ConstU128<1_000>; + type ItemDeposit = frame_support::traits::ConstU128<1_000>; + type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; + type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; + type DepositPerByte = frame_support::traits::ConstU128<1>; + type StringLimit = ConstU32<64>; + type KeyLimit = ConstU32<64>; + type ValueLimit = ConstU32<128>; + type Locker = (); + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = UniquesHelper; +} + +// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins +// which are locations containing the class location. +pub struct ForeignCreators; +impl EnsureOriginWithArg for ForeignCreators { + type Success = AccountId; + + fn try_origin( + o: RuntimeOrigin, + a: &Location, + ) -> sp_std::result::Result { + let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; + if !a.starts_with(&origin_location) { + return Err(o) + } + SovereignAccountOf::convert_location(&origin_location).ok_or(o) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(a: &Location) -> Result { + Ok(pallet_xcm::Origin::Xcm(a.clone()).into()) + } +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); +} + +pub type LocationToAccountId = ( + ParentIsPreset, + SiblingParachainConvertsVia, + AccountId32Aliases, + Account32Hash<(), AccountId>, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + SignedAccountId32AsNative, + XcmPassthrough, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); + pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub ForeignPrefix: Location = (Parent,).into(); +} + +pub type LocalAssetTransactor = ( + FungibleAdapter, LocationToAccountId, AccountId, ()>, + NonFungiblesAdapter< + ForeignUniques, + ConvertedConcreteId, + SovereignAccountOf, + AccountId, + NoChecking, + (), + >, +); + +pub type XcmRouter = EnsureDecodableXcm>; +pub type Barrier = AllowUnpaidExecutionFrom; + +parameter_types! { + pub NftCollectionOne: AssetFilter + = Wild(AllOf { fun: WildNonFungible, id: AssetId((Parent, GeneralIndex(1)).into()) }); + pub NftCollectionOneForRelay: (AssetFilter, Location) + = (NftCollectionOne::get(), (Parent,).into()); +} +pub type TrustedTeleporters = xcm_builder::Case; +pub type TrustedReserves = EverythingBut>; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = (NativeAsset, TrustedReserves); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => + (Ok(used), Event::Fail(Some(hash), error)), + } + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +pub struct TrustedLockerCase(PhantomData); +impl> ContainsPair for TrustedLockerCase { + fn contains(origin: &Location, asset: &Asset) -> bool { + let (o, a) = T::get(); + a.matches(asset) && &o == origin + } +} + +parameter_types! { + pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); +} + +pub type TrustedLockers = TrustedLockerCase; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = TrustedLockers; + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + PolkadotXcm: pallet_xcm, + ForeignUniques: pallet_uniques, + } +); diff --git a/runtime/laos/src/tests/xcm_simulator/relay_chain.rs b/runtime/laos/src/tests/xcm_simulator/relay_chain.rs new file mode 100644 index 00000000..b41df3cf --- /dev/null +++ b/runtime/laos/src/tests/xcm_simulator/relay_chain.rs @@ -0,0 +1,295 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{AsEnsureOriginWithArg, Everything, Nothing, ProcessMessage, ProcessMessageError}, + weights::{Weight, WeightMeter}, +}; + +use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; +use sp_runtime::{traits::IdentityLookup, AccountId32}; + +use polkadot_parachain_primitives::primitives::Id as ParaId; +use polkadot_runtime_parachains::{ + configuration, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, shared, +}; +use xcm::latest::prelude::*; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + ConvertedConcreteId, EnsureDecodableXcm, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NoChecking, NonFungiblesAdapter, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = u32; + type ItemId = u32; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = frame_support::traits::ConstU128<1_000>; + type ItemDeposit = frame_support::traits::ConstU128<1_000>; + type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; + type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; + type DepositPerByte = frame_support::traits::ConstU128<1>; + type StringLimit = ConstU32<64>; + type KeyLimit = ConstU32<64>; + type ValueLimit = ConstU32<128>; + type Locker = (); + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub const TokenLocation: Location = Here.into_location(); + pub RelayNetwork: NetworkId = ByGenesis([0; 32]); + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorLocation = RelayNetwork::get().into(); + pub UnitWeightCost: u64 = 1_000; +} + +pub type LocationToAccountId = ( + ChildParachainConvertsVia, + AccountId32Aliases, + Account32Hash<(), AccountId>, +); + +pub type LocalAssetTransactor = ( + FungibleAdapter, LocationToAccountId, AccountId, ()>, + NonFungiblesAdapter< + Uniques, + ConvertedConcreteId, JustTry>, + LocationToAccountId, + AccountId, + NoChecking, + (), + >, +); + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000); + pub TokensPerSecondPerByte: (AssetId, u128, u128) = + (AssetId(TokenLocation::get()), 1_000_000_000_000, 1024 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub type XcmRouter = EnsureDecodableXcm; +pub type Barrier = AllowUnpaidExecutionFrom; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = XcmPallet; + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +impl origin::Config for Runtime {} + +type Block = frame_system::mocking::MockBlock; + +parameter_types! { + /// Amount of weight that can be spent per block to service messages. + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +/// Message processor to handle any messages that were enqueued into the `MessageQueue` pallet. +pub struct MessageProcessor; +impl ProcessMessage for MessageProcessor { + type Origin = AggregateMessageOrigin; + + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + let para = match origin { + AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, + }; + xcm_builder::ProcessXcmMessage::< + Junction, + xcm_executor::XcmExecutor, + RuntimeCall, + >::process_message(message, Junction::Parachain(para.into()), meter, id) + } +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type IdleMaxServiceWeight = (); + type MessageProcessor = MessageProcessor; + type QueueChangeHandler = (); + type QueuePausedQuery = (); + type WeightInfo = (); +} + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + XcmPallet: pallet_xcm, + Uniques: pallet_uniques, + MessageQueue: pallet_message_queue, + } +); From b20e6778f624ee794ae921faf48fc973f6652db6 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 13:22:15 +0200 Subject: [PATCH 06/69] simulator example integrated --- Cargo.lock | 1 + runtime/laos/Cargo.toml | 1 + .../src/tests/xcm_simulator/Cargo.toml_old | 62 ------------------- runtime/laos/src/tests/xcm_simulator/mod.rs | 2 +- .../laos/src/tests/xcm_simulator/parachain.rs | 2 +- 5 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 runtime/laos/src/tests/xcm_simulator/Cargo.toml_old diff --git a/Cargo.lock b/Cargo.lock index 0f632073..f43d398c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5328,6 +5328,7 @@ dependencies = [ "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", "sp-transaction-pool", "sp-version", "sp-weights", diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index b4ebf5cd..892dac88 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -123,6 +123,7 @@ pallet-xcm = { workspace = true } pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } polkadot-core-primitives = { workspace = true } polkadot-parachain-primitives = { workspace = true } +sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } [features] fast-runtime=[] diff --git a/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old b/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old deleted file mode 100644 index 68cc3f54..00000000 --- a/runtime/laos/src/tests/xcm_simulator/Cargo.toml_old +++ /dev/null @@ -1,62 +0,0 @@ -[package] -name = "xcm-simulator-example" -description = "Examples of xcm-simulator usage." -authors.workspace = true -edition.workspace = true -version = "7.0.0" - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1" } -scale-info = { version = "2.11.1", features = ["derive"] } -log = { workspace = true } - -laos-runtime = { workspace = true } -frame-system = { workspace = true } -frame-support = { workspace = true } -pallet-balances = { workspace = true } -pallet-message-queue = { workspace = true } -# pallet-uniques = { workspace = true } -sp-std = { workspace = true } -sp-core = { workspace = true } -sp-runtime = { workspace = true } -sp-io = { workspace = true } -sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } - -xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-simulator = { workspace = true } -pallet-xcm = { workspace = true } -pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -polkadot-core-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-parachain-primitives = { workspace = true } - -[features] -default = ["std"] -std = [ - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "pallet-message-queue/std", - "pallet-xcm/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-parachains/std", - "sp-runtime/std", - "sp-tracing/std", - "pallet-uniques/std", - "laos-runtime/std", -] -runtime-benchmarks = [ - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - "polkadot-runtime-parachains/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -# "xcm-builder/runtime-benchmarks", -# "xcm-executor/runtime-benchmarks", -] diff --git a/runtime/laos/src/tests/xcm_simulator/mod.rs b/runtime/laos/src/tests/xcm_simulator/mod.rs index 56e204bf..42d30b92 100644 --- a/runtime/laos/src/tests/xcm_simulator/mod.rs +++ b/runtime/laos/src/tests/xcm_simulator/mod.rs @@ -142,7 +142,7 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet; mod tests { use super::*; - use codec::Encode; + use parity_scale_codec::Encode; use frame_support::{assert_ok, weights::Weight}; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; diff --git a/runtime/laos/src/tests/xcm_simulator/parachain.rs b/runtime/laos/src/tests/xcm_simulator/parachain.rs index 41e62596..6e6fda74 100644 --- a/runtime/laos/src/tests/xcm_simulator/parachain.rs +++ b/runtime/laos/src/tests/xcm_simulator/parachain.rs @@ -16,7 +16,7 @@ //! Parachain runtime mock. -use codec::{Decode, Encode}; +use parity_scale_codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, derive_impl, parameter_types, From 87b10080bb5f8874e3ef2f417bafc59b1407ddd2 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 13:27:10 +0200 Subject: [PATCH 07/69] simulator example integrated --- runtime/laos/src/tests/xcm_simulator/parachain.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/laos/src/tests/xcm_simulator/parachain.rs b/runtime/laos/src/tests/xcm_simulator/parachain.rs index 6e6fda74..38c46c99 100644 --- a/runtime/laos/src/tests/xcm_simulator/parachain.rs +++ b/runtime/laos/src/tests/xcm_simulator/parachain.rs @@ -96,6 +96,7 @@ parameter_types! { pub const MaxReserves: u32 = 50; } +mod configs; impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; From 0a1112b09e45d148be85ba63b1c679f8d6b3802a Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 14:01:14 +0200 Subject: [PATCH 08/69] integrate simultaor --- Cargo.lock | 28 +++++++++ Cargo.toml | 1 + runtime/laos/src/tests/mod.rs | 1 - xcm-simulator/Cargo.toml | 60 +++++++++++++++++++ .../mod.rs => xcm-simulator/src/lib.rs | 2 +- .../src}/parachain.rs | 3 +- .../src}/relay_chain.rs | 0 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 xcm-simulator/Cargo.toml rename runtime/laos/src/tests/xcm_simulator/mod.rs => xcm-simulator/src/lib.rs (99%) rename {runtime/laos/src/tests/xcm_simulator => xcm-simulator/src}/parachain.rs (99%) rename {runtime/laos/src/tests/xcm_simulator => xcm-simulator/src}/relay_chain.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f43d398c..60f50721 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8291,6 +8291,7 @@ name = "pallet-uniques" version = "28.0.0" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -16312,6 +16313,33 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "xcm-simulator-example" +version = "7.0.0" +dependencies = [ + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-message-queue", + "pallet-uniques", + "pallet-xcm", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-simulator", +] + [[package]] name = "yamux" version = "0.10.2" diff --git a/Cargo.toml b/Cargo.toml index ab82da72..2d5d9046 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ members = [ "pallets/*", "precompiles/*", "primitives", + "xcm-simulator" ] [workspace.dependencies] diff --git a/runtime/laos/src/tests/mod.rs b/runtime/laos/src/tests/mod.rs index 5135b745..1c9a7e7f 100644 --- a/runtime/laos/src/tests/mod.rs +++ b/runtime/laos/src/tests/mod.rs @@ -18,7 +18,6 @@ mod precompile_tests; mod version_tests; -mod xcm_simulator; use core::str::FromStr; use sp_runtime::BuildStorage; diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml new file mode 100644 index 00000000..5741ac87 --- /dev/null +++ b/xcm-simulator/Cargo.toml @@ -0,0 +1,60 @@ +[package] +name = "xcm-simulator-example" +description = "Examples of xcm-simulator usage." +authors.workspace = true +edition.workspace = true +version = "7.0.0" + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1" } +scale-info = { version = "2.11.1", features = ["derive"] } +log = { workspace = true } + +frame-system = { workspace = true } +frame-support = { workspace = true } +pallet-balances = { workspace = true } +pallet-message-queue = { workspace = true } +# pallet-uniques = { workspace = true } +sp-std = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-io = { workspace = true } +sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } + +xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm-simulator = { workspace = true } +pallet-xcm = { workspace = true } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +polkadot-core-primitives = { workspace = true } +polkadot-runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } + +[features] +default = ["std"] +std = [ + "frame-support/std", + "frame-system/std", + "pallet-balances/std", + "pallet-message-queue/std", + "pallet-xcm/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-parachains/std", + "sp-runtime/std", + "sp-tracing/std", + "pallet-uniques/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-runtime-parachains/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +# "xcm-builder/runtime-benchmarks", +# "xcm-executor/runtime-benchmarks", +] diff --git a/runtime/laos/src/tests/xcm_simulator/mod.rs b/xcm-simulator/src/lib.rs similarity index 99% rename from runtime/laos/src/tests/xcm_simulator/mod.rs rename to xcm-simulator/src/lib.rs index 42d30b92..56e204bf 100644 --- a/runtime/laos/src/tests/xcm_simulator/mod.rs +++ b/xcm-simulator/src/lib.rs @@ -142,7 +142,7 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet; mod tests { use super::*; - use parity_scale_codec::Encode; + use codec::Encode; use frame_support::{assert_ok, weights::Weight}; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; diff --git a/runtime/laos/src/tests/xcm_simulator/parachain.rs b/xcm-simulator/src/parachain.rs similarity index 99% rename from runtime/laos/src/tests/xcm_simulator/parachain.rs rename to xcm-simulator/src/parachain.rs index 38c46c99..41e62596 100644 --- a/runtime/laos/src/tests/xcm_simulator/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -16,7 +16,7 @@ //! Parachain runtime mock. -use parity_scale_codec::{Decode, Encode}; +use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, derive_impl, parameter_types, @@ -96,7 +96,6 @@ parameter_types! { pub const MaxReserves: u32 = 50; } -mod configs; impl pallet_balances::Config for Runtime { type MaxLocks = MaxLocks; type Balance = Balance; diff --git a/runtime/laos/src/tests/xcm_simulator/relay_chain.rs b/xcm-simulator/src/relay_chain.rs similarity index 100% rename from runtime/laos/src/tests/xcm_simulator/relay_chain.rs rename to xcm-simulator/src/relay_chain.rs From d3639ef37d50366476f177aef6f56e3a05735bfd Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 14:02:48 +0200 Subject: [PATCH 09/69] integrate simultaor --- xcm-simulator/Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 5741ac87..68cc3f54 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "3.6.1" } scale-info = { version = "2.11.1", features = ["derive"] } log = { workspace = true } +laos-runtime = { workspace = true } frame-system = { workspace = true } frame-support = { workspace = true } pallet-balances = { workspace = true } @@ -44,6 +45,7 @@ std = [ "sp-runtime/std", "sp-tracing/std", "pallet-uniques/std", + "laos-runtime/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", From bfa6894ad3ce2349fce60094bb37f2d0d38b8c9b Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 15:01:13 +0200 Subject: [PATCH 10/69] starign point --- Cargo.lock | 4 +--- runtime/laos/Cargo.toml | 5 ----- xcm-simulator/src/lib.rs | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60f50721..ba5c5e77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5302,13 +5302,11 @@ dependencies = [ "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", - "pallet-uniques", "pallet-utility", "pallet-vesting", "pallet-xcm", "parachains-common", "parity-scale-codec", - "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", "polkadot-runtime-parachains", @@ -5328,7 +5326,6 @@ dependencies = [ "sp-session", "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", "sp-transaction-pool", "sp-version", "sp-weights", @@ -16319,6 +16316,7 @@ version = "7.0.0" dependencies = [ "frame-support", "frame-system", + "laos-runtime", "log", "pallet-balances", "pallet-message-queue", diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index 892dac88..77ac0528 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -119,11 +119,6 @@ pallet-assets = { workspace = true } test-utils = { workspace = true } ethereum = { workspace = true } xcm-simulator = { workspace = true } -pallet-xcm = { workspace = true } -pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -polkadot-core-primitives = { workspace = true } -polkadot-parachain-primitives = { workspace = true } -sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } [features] fast-runtime=[] diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 56e204bf..ec954c6f 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -28,7 +28,7 @@ pub const INITIAL_BALANCE: u128 = 1_000_000_000; decl_test_parachain! { pub struct ParaA { - Runtime = parachain::Runtime, + Runtime = laos_runtime::Runtime, XcmpMessageHandler = parachain::MsgQueue, DmpMessageHandler = parachain::MsgQueue, new_ext = para_ext(1), From dc53594456f3d8c241c79ab0aaba0f5f35eab32d Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 15:02:51 +0200 Subject: [PATCH 11/69] starign point --- runtime/laos/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index 56ee9489..8ef096e4 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -129,6 +129,7 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm = 32, // DmpQueue: cumulus_pallet_dmp_queue = 33, MessageQueue: pallet_message_queue = 34, + MsgQueue: xcm_simulator::pallet::MsgQueue = 35, // Governance Council: pallet_collective:: = 40, From a2c129d123b0de703a2f7d9bf6359f3720c61e51 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 16:04:21 +0200 Subject: [PATCH 12/69] active DmpMessage --- Cargo.lock | 17 +++++++++++++++++ runtime/laos/Cargo.toml | 2 +- runtime/laos/src/lib.rs | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba5c5e77..173168ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7734,6 +7734,23 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", ] +[[package]] +name = "pallet-mock-msg-queue" +version = "0.0.0" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "scale-info", + "sp-io", + "sp-runtime", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + [[package]] name = "pallet-multisig" version = "28.0.0" diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index 77ac0528..eb928869 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -110,6 +110,7 @@ pallet-evm-precompile-blake2 = { workspace = true } pallet-evm-precompile-parachain-staking = { workspace = true } precompile-utils = { workspace = true } +xcm-simulator = { workspace = true } [dev-dependencies] precompile-utils = { workspace = true, features = ["testing"] } @@ -118,7 +119,6 @@ polkadot-runtime-parachains = { workspace = true } pallet-assets = { workspace = true } test-utils = { workspace = true } ethereum = { workspace = true } -xcm-simulator = { workspace = true } [features] fast-runtime=[] diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index 8ef096e4..4e0be133 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -96,6 +96,8 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } +impl xcm_simulator::mock_msg_queue::Config for Runtime {} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -129,7 +131,7 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm = 32, // DmpQueue: cumulus_pallet_dmp_queue = 33, MessageQueue: pallet_message_queue = 34, - MsgQueue: xcm_simulator::pallet::MsgQueue = 35, + // MsgQueue: xcm_simulator::pallet::MsgQueue = 35, // Governance Council: pallet_collective:: = 40, From 0c3b14fe9267fd180bc98628757913245e093b68 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 16:05:47 +0200 Subject: [PATCH 13/69] added mock msg queue --- pallets/mock-msq-queue/Cargo.toml | 56 +++++++++ pallets/mock-msq-queue/README.md | 1 + pallets/mock-msq-queue/src/lib.rs | 181 ++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+) create mode 100644 pallets/mock-msq-queue/Cargo.toml create mode 100644 pallets/mock-msq-queue/README.md create mode 100644 pallets/mock-msq-queue/src/lib.rs diff --git a/pallets/mock-msq-queue/Cargo.toml b/pallets/mock-msq-queue/Cargo.toml new file mode 100644 index 00000000..f6de6544 --- /dev/null +++ b/pallets/mock-msq-queue/Cargo.toml @@ -0,0 +1,56 @@ +[package] +name = "pallet-mock-msg-queue" +description = "FRAME pallet template for defining custom runtime logic." +version = "0.0.0" +license = "MIT-0" +authors.workspace = true +homepage.workspace = true +repository.workspace = true +edition.workspace = true +publish = false + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ + "derive", +] } +scale-info = { version = "2.11.1", default-features = false, features = [ + "derive", +] } + +# frame deps +frame-support = { workspace = true } +frame-system = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +xcm = { workspace = true } +xcm-executor = { workspace = true } +xcm-builder = { workspace = true } +polkadot-parachain-primitives = { workspace = true } +polkadot-core-primitives = { workspace = true } + +[features] +default = ["std"] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", +] +std = [ + "codec/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "sp-io/std", + "sp-runtime/std", + "xcm/std", + "xcm-executor/std", + "xcm-builder/std", + "polkadot-parachain-primitives/std", + "polkadot-core-primitives/std" +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", +] diff --git a/pallets/mock-msq-queue/README.md b/pallets/mock-msq-queue/README.md new file mode 100644 index 00000000..9e4dc552 --- /dev/null +++ b/pallets/mock-msq-queue/README.md @@ -0,0 +1 @@ +License: MIT-0 diff --git a/pallets/mock-msq-queue/src/lib.rs b/pallets/mock-msq-queue/src/lib.rs new file mode 100644 index 00000000..be2c5d1f --- /dev/null +++ b/pallets/mock-msq-queue/src/lib.rs @@ -0,0 +1,181 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +/// Edit this file to define custom logic or remove it if it is not needed. +/// Learn more about FRAME and the core library of Substrate FRAME pallets: +/// +pub use pallet::*; +use polkadot_parachain_primitives::primitives::{ + DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use xcm::{latest::prelude::*, VersionedXcm}; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, + EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, + NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{ + traits::{ConvertLocation, JustTry}, + Config, XcmExecutor, +}; +use sp_runtime::{ + traits::{Get, Hash, IdentityLookup}, + AccountId32, +}; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + use frame_support::StorageHasher; +use frame_support::sp_runtime::traits::Block; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => + (Ok(used), Event::Fail(Some(hash), error)), + } + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + // impl XcmpMessageHandler for Pallet { + // fn handle_xcmp_messages<'a, I: Iterator>( + // iter: I, + // max_weight: Weight, + // ) -> Weight { + // for (sender, sent_at, data) in iter { + // let mut data_ref = data; + // let _ = XcmpMessageFormat::decode(&mut data_ref) + // .expect("Simulator encodes with versioned xcm format; qed"); + + // let mut remaining_fragments = data_ref; + // while !remaining_fragments.is_empty() { + // if let Ok(xcm) = + // VersionedXcm::::decode(&mut remaining_fragments) + // { + // let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + // } else { + // debug_assert!(false, "Invalid incoming XCMP message data"); + // } + // } + // } + // max_weight + // } + // } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} From 96031262c997c31804100c970ee78911666791fb Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 16:09:31 +0200 Subject: [PATCH 14/69] pallet mock msg queue compiling --- pallets/mock-msq-queue/src/lib.rs | 70 ++++++++++++------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/pallets/mock-msq-queue/src/lib.rs b/pallets/mock-msq-queue/src/lib.rs index be2c5d1f..72a9bc9d 100644 --- a/pallets/mock-msq-queue/src/lib.rs +++ b/pallets/mock-msq-queue/src/lib.rs @@ -4,33 +4,17 @@ /// Learn more about FRAME and the core library of Substrate FRAME pallets: /// pub use pallet::*; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, + DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, }; -use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use sp_runtime::traits::{Get, Hash}; use xcm::{latest::prelude::*, VersionedXcm}; -use xcm_builder::{ - Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, - EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, - NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{ - traits::{ConvertLocation, JustTry}, - Config, XcmExecutor, -}; -use sp_runtime::{ - traits::{Get, Hash, IdentityLookup}, - AccountId32, -}; #[frame_support::pallet] pub mod pallet { use super::*; use frame_support::pallet_prelude::*; - use frame_support::StorageHasher; -use frame_support::sp_runtime::traits::Block; #[pallet::config] pub trait Config: frame_system::Config { @@ -122,30 +106,30 @@ use frame_support::sp_runtime::traits::Block; } } - // impl XcmpMessageHandler for Pallet { - // fn handle_xcmp_messages<'a, I: Iterator>( - // iter: I, - // max_weight: Weight, - // ) -> Weight { - // for (sender, sent_at, data) in iter { - // let mut data_ref = data; - // let _ = XcmpMessageFormat::decode(&mut data_ref) - // .expect("Simulator encodes with versioned xcm format; qed"); - - // let mut remaining_fragments = data_ref; - // while !remaining_fragments.is_empty() { - // if let Ok(xcm) = - // VersionedXcm::::decode(&mut remaining_fragments) - // { - // let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); - // } else { - // debug_assert!(false, "Invalid incoming XCMP message data"); - // } - // } - // } - // max_weight - // } - // } + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } impl DmpMessageHandler for Pallet { fn handle_dmp_messages( From e9f51a28cec5e0b2255cd63b5f0d9edb18cd7d64 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 16:20:13 +0200 Subject: [PATCH 15/69] thinking to the runtime --- Cargo.lock | 2 +- Cargo.toml | 1 + pallets/{mock-msq-queue => mock-msg-queue}/Cargo.toml | 0 pallets/{mock-msq-queue => mock-msg-queue}/README.md | 0 pallets/{mock-msq-queue => mock-msg-queue}/src/lib.rs | 4 +--- runtime/laos/Cargo.toml | 2 +- runtime/laos/src/lib.rs | 2 -- 7 files changed, 4 insertions(+), 7 deletions(-) rename pallets/{mock-msq-queue => mock-msg-queue}/Cargo.toml (100%) rename pallets/{mock-msq-queue => mock-msg-queue}/README.md (100%) rename pallets/{mock-msq-queue => mock-msg-queue}/src/lib.rs (95%) diff --git a/Cargo.lock b/Cargo.lock index 173168ab..7e27bfce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5290,6 +5290,7 @@ dependencies = [ "pallet-laos-evolution", "pallet-membership", "pallet-message-queue", + "pallet-mock-msg-queue", "pallet-multisig", "pallet-parachain-staking", "pallet-precompiles-benchmark", @@ -5335,7 +5336,6 @@ dependencies = [ "staging-xcm-executor", "substrate-wasm-builder", "test-utils", - "xcm-simulator", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2d5d9046..29a946a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,6 +226,7 @@ pallet-asset-metadata-extender = { path = "./pallets/asset-metadata-extender", d pallet-parachain-staking = { path = "./pallets/parachain-staking", default-features = false } pallet-evm-precompile-parachain-staking = { path = "./precompiles/parachain-staking", default-features = false } pallet-precompiles-benchmark = { path = "./pallets/precompiles-benchmark", default-features = false} +pallet-mock-msg-queue = { path = "./pallets/mock-msg-queue", default-features = false} # Primitives laos-primitives = { path = "./primitives", default-features = false } diff --git a/pallets/mock-msq-queue/Cargo.toml b/pallets/mock-msg-queue/Cargo.toml similarity index 100% rename from pallets/mock-msq-queue/Cargo.toml rename to pallets/mock-msg-queue/Cargo.toml diff --git a/pallets/mock-msq-queue/README.md b/pallets/mock-msg-queue/README.md similarity index 100% rename from pallets/mock-msq-queue/README.md rename to pallets/mock-msg-queue/README.md diff --git a/pallets/mock-msq-queue/src/lib.rs b/pallets/mock-msg-queue/src/lib.rs similarity index 95% rename from pallets/mock-msq-queue/src/lib.rs rename to pallets/mock-msg-queue/src/lib.rs index 72a9bc9d..0bcaa643 100644 --- a/pallets/mock-msq-queue/src/lib.rs +++ b/pallets/mock-msg-queue/src/lib.rs @@ -1,13 +1,11 @@ #![cfg_attr(not(feature = "std"), no_std)] -/// Edit this file to define custom logic or remove it if it is not needed. -/// Learn more about FRAME and the core library of Substrate FRAME pallets: -/// pub use pallet::*; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, }; +use scale_info::prelude::vec::Vec; use sp_runtime::traits::{Get, Hash}; use xcm::{latest::prelude::*, VersionedXcm}; diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index eb928869..87b66d73 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -71,6 +71,7 @@ pallet-asset-metadata-extender = { workspace = true } pallet-laos-evolution = { workspace = true } pallet-parachain-staking = { workspace = true } pallet-precompiles-benchmark = { workspace = true } +pallet-mock-msg-queue = { workspace = true } # Polkadot @@ -110,7 +111,6 @@ pallet-evm-precompile-blake2 = { workspace = true } pallet-evm-precompile-parachain-staking = { workspace = true } precompile-utils = { workspace = true } -xcm-simulator = { workspace = true } [dev-dependencies] precompile-utils = { workspace = true, features = ["testing"] } diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index 4e0be133..905e17e2 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -96,8 +96,6 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -impl xcm_simulator::mock_msg_queue::Config for Runtime {} - // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime From b2253d334d3d74694b458f8570a32850218f63de Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 1 Oct 2024 16:33:46 +0200 Subject: [PATCH 16/69] refactoring --- pallets/mock-msg-queue/src/lib.rs | 10 +++++----- runtime/laos/Cargo.toml | 1 + runtime/laos/src/configs/xcm_config.rs | 5 +++++ runtime/laos/src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pallets/mock-msg-queue/src/lib.rs b/pallets/mock-msg-queue/src/lib.rs index 0bcaa643..15c0306a 100644 --- a/pallets/mock-msg-queue/src/lib.rs +++ b/pallets/mock-msg-queue/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] +use frame_support::pallet_prelude::*; pub use pallet::*; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ @@ -12,7 +13,10 @@ use xcm::{latest::prelude::*, VersionedXcm}; #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); #[pallet::config] pub trait Config: frame_system::Config { @@ -23,10 +27,6 @@ pub mod pallet { #[pallet::call] impl Pallet {} - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - #[pallet::storage] #[pallet::getter(fn parachain_id)] pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index 87b66d73..f9703b21 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -155,6 +155,7 @@ std = [ "pallet-scheduler/std", "pallet-laos-evolution/std", "pallet-asset-metadata-extender/std", + "pallet-mock-msg-queue/std", "pallet-multisig/std", "pallet-timestamp/std", "pallet-identity/std", diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index 03177878..449a3854 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -210,6 +210,11 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; } +impl pallet_mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index 905e17e2..595e33f8 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -129,7 +129,7 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm = 32, // DmpQueue: cumulus_pallet_dmp_queue = 33, MessageQueue: pallet_message_queue = 34, - // MsgQueue: xcm_simulator::pallet::MsgQueue = 35, + // MsgQueue: pallet_mock_msg_queue = 35, // Governance Council: pallet_collective:: = 40, From 0549f0fde864e9cb1fd83a73c0b835cd8340d20f Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 10:42:06 +0200 Subject: [PATCH 17/69] xcm-simulator copiles --- Cargo.lock | 2 +- runtime/laos/Cargo.toml | 1 + runtime/laos/src/configs/xcm_config.rs | 20 +++++++++++--------- runtime/laos/src/lib.rs | 2 +- xcm-simulator/Cargo.toml | 2 -- xcm-simulator/src/lib.rs | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e27bfce..9479b8d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5336,6 +5336,7 @@ dependencies = [ "staging-xcm-executor", "substrate-wasm-builder", "test-utils", + "xcm-simulator", ] [[package]] @@ -16333,7 +16334,6 @@ version = "7.0.0" dependencies = [ "frame-support", "frame-system", - "laos-runtime", "log", "pallet-balances", "pallet-message-queue", diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index f9703b21..37417b93 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -93,6 +93,7 @@ cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } +xcm-simulator = { workspace = true } # Frontier fp-evm = { workspace = true } diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index 449a3854..6e9d6552 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -16,7 +16,7 @@ use crate::{ types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, ParachainInfo, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, MsgQueue, }; use core::marker::PhantomData; use frame_support::{ @@ -41,11 +41,12 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); - pub const RelayNetwork: Option = None; + pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. - pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + // pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -171,12 +172,13 @@ pub type LocalOriginToLocation = SignedToAccountId20, - // ..and XCMP to communicate with the sibling chains. - crate::XcmpQueue, -)>; +// pub type XcmRouter = xcm_builder::WithUniqueTopic<( +// // Two routers - use UMP to communicate with the relay chain: +// cumulus_primitives_utility::ParentAsUmp, +// // ..and XCMP to communicate with the sibling chains. +// crate::XcmpQueue, +// )>; +pub type XcmRouter = xcm_builder::EnsureDecodableXcm>; impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index 595e33f8..ae527b3b 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -129,7 +129,7 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm = 32, // DmpQueue: cumulus_pallet_dmp_queue = 33, MessageQueue: pallet_message_queue = 34, - // MsgQueue: pallet_mock_msg_queue = 35, + MsgQueue: pallet_mock_msg_queue = 35, // Governance Council: pallet_collective:: = 40, diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 68cc3f54..5741ac87 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -10,7 +10,6 @@ codec = { package = "parity-scale-codec", version = "3.6.1" } scale-info = { version = "2.11.1", features = ["derive"] } log = { workspace = true } -laos-runtime = { workspace = true } frame-system = { workspace = true } frame-support = { workspace = true } pallet-balances = { workspace = true } @@ -45,7 +44,6 @@ std = [ "sp-runtime/std", "sp-tracing/std", "pallet-uniques/std", - "laos-runtime/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index ec954c6f..56e204bf 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -28,7 +28,7 @@ pub const INITIAL_BALANCE: u128 = 1_000_000_000; decl_test_parachain! { pub struct ParaA { - Runtime = laos_runtime::Runtime, + Runtime = parachain::Runtime, XcmpMessageHandler = parachain::MsgQueue, DmpMessageHandler = parachain::MsgQueue, new_ext = para_ext(1), From 002b0b52e110558b5754fde5e18ecc3b6ef300d9 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 10:43:58 +0200 Subject: [PATCH 18/69] added laosish --- runtime/laos/src/configs/xcm_config.rs | 4 ++-- xcm-simulator/src/lib.rs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index 6e9d6552..c6c70c6c 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -15,8 +15,8 @@ // along with LAOS. If not, see . use crate::{ - types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, ParachainInfo, PolkadotXcm, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, MsgQueue, + types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, }; use core::marker::PhantomData; use frame_support::{ diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 56e204bf..9d935c1d 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . +mod laosish; mod parachain; mod relay_chain; @@ -28,9 +29,9 @@ pub const INITIAL_BALANCE: u128 = 1_000_000_000; decl_test_parachain! { pub struct ParaA { - Runtime = parachain::Runtime, - XcmpMessageHandler = parachain::MsgQueue, - DmpMessageHandler = parachain::MsgQueue, + Runtime = laosish::Runtime, + XcmpMessageHandler = laosish::MsgQueue, + DmpMessageHandler = laosish::MsgQueue, new_ext = para_ext(1), } } From 1346f8573e53932321852a7eb448eaea502a2dc5 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 10:44:08 +0200 Subject: [PATCH 19/69] added laosish --- xcm-simulator/src/laosish.rs | 470 +++++++++++++++++++++++++++++++++++ 1 file changed, 470 insertions(+) create mode 100644 xcm-simulator/src/laosish.rs diff --git a/xcm-simulator/src/laosish.rs b/xcm-simulator/src/laosish.rs new file mode 100644 index 00000000..41e62596 --- /dev/null +++ b/xcm-simulator/src/laosish.rs @@ -0,0 +1,470 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use codec::{Decode, Encode}; +use core::marker::PhantomData; +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +}; + +use frame_system::EnsureRoot; +use sp_core::{ConstU32, H256}; +use sp_runtime::{ + traits::{Get, Hash, IdentityLookup}, + AccountId32, +}; +use sp_std::prelude::*; + +use pallet_xcm::XcmPassthrough; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain_primitives::primitives::{ + DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; +use xcm::{latest::prelude::*, VersionedXcm}; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, + EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, + NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, +}; +use xcm_executor::{ + traits::{ConvertLocation, JustTry}, + Config, XcmExecutor, +}; + +pub type SovereignAccountOf = ( + SiblingParachainConvertsVia, + AccountId32Aliases, + ParentIsPreset, +); + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +#[cfg(feature = "runtime-benchmarks")] +pub struct UniquesHelper; +#[cfg(feature = "runtime-benchmarks")] +impl pallet_uniques::BenchmarkHelper for UniquesHelper { + fn collection(i: u16) -> Location { + GeneralIndex(i as u128).into() + } + fn item(i: u16) -> AssetInstance { + AssetInstance::Index(i as u128) + } +} + +impl pallet_uniques::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CollectionId = Location; + type ItemId = AssetInstance; + type Currency = Balances; + type CreateOrigin = ForeignCreators; + type ForceOrigin = frame_system::EnsureRoot; + type CollectionDeposit = frame_support::traits::ConstU128<1_000>; + type ItemDeposit = frame_support::traits::ConstU128<1_000>; + type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; + type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; + type DepositPerByte = frame_support::traits::ConstU128<1>; + type StringLimit = ConstU32<64>; + type KeyLimit = ConstU32<64>; + type ValueLimit = ConstU32<128>; + type Locker = (); + type WeightInfo = (); + #[cfg(feature = "runtime-benchmarks")] + type Helper = UniquesHelper; +} + +// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins +// which are locations containing the class location. +pub struct ForeignCreators; +impl EnsureOriginWithArg for ForeignCreators { + type Success = AccountId; + + fn try_origin( + o: RuntimeOrigin, + a: &Location, + ) -> sp_std::result::Result { + let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; + if !a.starts_with(&origin_location) { + return Err(o) + } + SovereignAccountOf::convert_location(&origin_location).ok_or(o) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(a: &Location) -> Result { + Ok(pallet_xcm::Origin::Xcm(a.clone()).into()) + } +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); +} + +pub type LocationToAccountId = ( + ParentIsPreset, + SiblingParachainConvertsVia, + AccountId32Aliases, + Account32Hash<(), AccountId>, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + SignedAccountId32AsNative, + XcmPassthrough, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); + pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub ForeignPrefix: Location = (Parent,).into(); +} + +pub type LocalAssetTransactor = ( + FungibleAdapter, LocationToAccountId, AccountId, ()>, + NonFungiblesAdapter< + ForeignUniques, + ConvertedConcreteId, + SovereignAccountOf, + AccountId, + NoChecking, + (), + >, +); + +pub type XcmRouter = EnsureDecodableXcm>; +pub type Barrier = AllowUnpaidExecutionFrom; + +parameter_types! { + pub NftCollectionOne: AssetFilter + = Wild(AllOf { fun: WildNonFungible, id: AssetId((Parent, GeneralIndex(1)).into()) }); + pub NftCollectionOneForRelay: (AssetFilter, Location) + = (NftCollectionOne::get(), (Parent,).into()); +} +pub type TrustedTeleporters = xcm_builder::Case; +pub type TrustedReserves = EverythingBut>; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = (NativeAsset, TrustedReserves); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = PolkadotXcm; + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => + (Ok(used), Event::Fail(Some(hash), error)), + } + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +pub struct TrustedLockerCase(PhantomData); +impl> ContainsPair for TrustedLockerCase { + fn contains(origin: &Location, asset: &Asset) -> bool { + let (o, a) = T::get(); + a.matches(asset) && &o == origin + } +} + +parameter_types! { + pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); +} + +pub type TrustedLockers = TrustedLockerCase; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = TrustedLockers; + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + PolkadotXcm: pallet_xcm, + ForeignUniques: pallet_uniques, + } +); From ff84856a0cc1866535313bbc873458154e074261 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:31:01 +0200 Subject: [PATCH 20/69] starting laosish --- primitives/Cargo.toml | 1 + xcm-simulator/Cargo.toml | 20 +- xcm-simulator/src/laosish/configs/balances.rs | 51 +++ xcm-simulator/src/laosish/configs/mod.rs | 2 + xcm-simulator/src/laosish/configs/system.rs | 342 ++++++++++++++++++ .../src/{laosish.rs => laosish/mod.rs} | 0 6 files changed, 411 insertions(+), 5 deletions(-) create mode 100644 xcm-simulator/src/laosish/configs/balances.rs create mode 100644 xcm-simulator/src/laosish/configs/mod.rs create mode 100644 xcm-simulator/src/laosish/configs/system.rs rename xcm-simulator/src/{laosish.rs => laosish/mod.rs} (100%) diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 41d51ada..ba70b1f4 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -29,4 +29,5 @@ std = [ "fp-account/std", "sp-consensus-aura/std", "cumulus-primitives-core/std", + "parachains-common/std" ] diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 5741ac87..c80e7699 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -6,8 +6,8 @@ edition.workspace = true version = "7.0.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1" } -scale-info = { version = "2.11.1", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } +scale-info = { workspace = true } log = { workspace = true } frame-system = { workspace = true } @@ -21,15 +21,16 @@ sp-runtime = { workspace = true } sp-io = { workspace = true } sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +xcm = { workspace = true } +xcm-executor = { workspace = true } +xcm-builder = { workspace = true } xcm-simulator = { workspace = true } pallet-xcm = { workspace = true } pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } polkadot-core-primitives = { workspace = true } polkadot-runtime-parachains = { workspace = true } polkadot-parachain-primitives = { workspace = true } +#laos-primitives = { workspace = true } [features] default = ["std"] @@ -44,6 +45,15 @@ std = [ "sp-runtime/std", "sp-tracing/std", "pallet-uniques/std", +# "laos-primitives/std", + "sp-std/std", + "sp-io/std", + "sp-core/std", + "sp-runtime/std", + "polkadot-core-primitives/std", + "xcm/std", + "xcm-builder/std", + "xcm-executor/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", diff --git a/xcm-simulator/src/laosish/configs/balances.rs b/xcm-simulator/src/laosish/configs/balances.rs new file mode 100644 index 00000000..44de12f5 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/balances.rs @@ -0,0 +1,51 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::laosish::{ + Balance, Runtime, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, System, +}; +use frame_support::parameter_types; + +parameter_types! { + /// The minimum amount required to keep an account open, set to zero in this case. + /// + /// While it's generally advised to have this value greater than zero to avoid potential + /// DoS vectors, we set it to zero here due to specific concerns about relay attacks. + /// In such attacks, the reset of the nonce upon account deletion can be exploited. + /// By setting the ExistentialDeposit to zero, we prevent the scenario where an account's + /// balance drops to a level that would trigger its deletion and subsequent nonce reset. + pub const ExistentialDeposit: Balance = 0; + pub const MaxLocks: u32 = 50; + pub const MaxFreezes: u32 = 50; + pub const MaxHolds: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type FreezeIdentifier = RuntimeFreezeReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type RuntimeHoldReason = RuntimeHoldReason; + type MaxFreezes = MaxFreezes; + type WeightInfo = pallet_balances::weights::SubstrateWeight; // See: https://github.com/freeverseio/laos/pull/533#issuecomment-2034913428 +} diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs new file mode 100644 index 00000000..3ccd7e69 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -0,0 +1,2 @@ +mod balances; +// mod system; diff --git a/xcm-simulator/src/laosish/configs/system.rs b/xcm-simulator/src/laosish/configs/system.rs new file mode 100644 index 00000000..1eb5a1a0 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/system.rs @@ -0,0 +1,342 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::laosish::{ + weights::RocksDbWeight, AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, RuntimeTask, RuntimeVersion, VERSION, +}; +use frame_support::{parameter_types, traits::Everything}; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; + +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + pub const SS58Prefix: u16 = 42; + pub const BlockHashCount: u32 = 256; +} + +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// The block type + type Block = Block; + /// The type for hashing blocks and tries. + type Hash = laos_primitives::Hash; + /// The type for storing how many extrinsics an account has signed. + type Nonce = laos_primitives::Nonce; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// The aggregated RuntimeTask type. + type RuntimeTask = RuntimeTask; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = BlockHashCount; + /// Runtime version. + type Version = Version; + /// Converts a module to an index of this module in the runtime. + type PalletInfo = PalletInfo; + /// The data to be stored in an account. + type AccountData = pallet_balances::AccountData; + /// What to do if a new account is created. + type OnNewAccount = (); + /// What to do if an account is fully reaped from the system. + type OnKilledAccount = (); + /// The weight of database operations that the runtime can invoke. + type DbWeight = RocksDbWeight; + /// The basic call filter to use in dispatchable. + type BaseCallFilter = Everything; + /// Weight information for the extrinsics of this pallet. + type SystemWeightInfo = (); + /// Block & extrinsics weights: base values and limits. + type BlockWeights = laos_primitives::RuntimeBlockWeights; + /// The maximum length of a block (in bytes). + type BlockLength = laos_primitives::RuntimeBlockLength; + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = SS58Prefix; + /// The action to take on a Runtime Upgrade + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); +} + +// tests +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + currency::UNIT, + tests::{new_test_ext, ExtBuilder, ALICE, BOB}, + }; + use core::str::FromStr; + use frame_support::{assert_err, assert_ok, dispatch::PostDispatchInfo, pallet_prelude::Pays}; + use pallet_ethereum::Transaction; + use sp_core::{H160, H256, U256}; + use sp_runtime::{ + traits::Dispatchable, + DispatchError::{BadOrigin, Other}, + }; + + #[test] + fn transfer_should_be_allowed() { + let alice = AccountId::from_str(ALICE).unwrap(); + + ExtBuilder::default() + .with_balances(vec![(alice, 1000 * UNIT)]) + .build() + .execute_with(|| { + let to_account = AccountId::from_str(BOB).unwrap(); + let transfer_amount = 100; + let call = RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { + dest: to_account, + value: transfer_amount, + }); + assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); + }); + } + + #[test] + fn transfer_all_should_be_allowed() { + let alice = AccountId::from_str(ALICE).unwrap(); + + ExtBuilder::default() + .with_balances(vec![(alice, 1000 * UNIT)]) + .build() + .execute_with(|| { + let to_account = AccountId::from_str(BOB).unwrap(); + let call = RuntimeCall::Balances(pallet_balances::Call::transfer_all { + dest: to_account, + keep_alive: false, + }); + assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); + }); + } + + #[test] + fn transfer_keep_alive_should_be_allowed() { + let alice = AccountId::from_str(ALICE).unwrap(); + + ExtBuilder::default() + .with_balances(vec![(alice, 1000 * UNIT)]) + .build() + .execute_with(|| { + let to_account = AccountId::from_str(BOB).unwrap(); + let transfer_amount = 1000000000000000000; + + let call = RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { + dest: to_account, + value: transfer_amount, + }); + assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); + }); + } + + #[test] + fn transfer_allow_death_should_be_allowed() { + let alice = AccountId::from_str(ALICE).unwrap(); + + ExtBuilder::default() + .with_balances(vec![(alice, 1000 * UNIT)]) + .build() + .execute_with(|| { + let to_account = AccountId::from_str(BOB).unwrap(); + let transfer_amount = 100; + + let call = RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { + dest: to_account, + value: transfer_amount, + }); + assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); + }); + } + + #[test] + fn vested_transfer_should_be_allowed() { + let alice = AccountId::from_str(ALICE).unwrap(); + + ExtBuilder::default() + .with_balances(vec![(alice, 100000 * UNIT)]) + .build() + .execute_with(|| { + let to_account = AccountId::from_str(BOB).unwrap(); + let transfer_amount = 1000000000000000000; + let per_block = 10; + let starting_block = 100; + + let vesting_schedule = + pallet_vesting::VestingInfo::new(transfer_amount, per_block, starting_block); + + let call = RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { + target: to_account, + schedule: vesting_schedule, + }); + assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); + }); + } + + #[test] + fn join_candidates_should_be_allowed() { + new_test_ext().execute_with(|| { + let account = AccountId::from_str(ALICE).unwrap(); + let stake = 20_000 * UNIT; + + assert_ok!(pallet_balances::Pallet::::force_set_balance( + RuntimeOrigin::root(), + account, + stake + )); + + let call = + RuntimeCall::ParachainStaking(pallet_parachain_staking::Call::join_candidates { + bond: stake, + candidate_count: 32, + }); + + assert_ok!(call.dispatch(RuntimeOrigin::signed(account))); + }); + } + + #[test] + fn evm_create_should_be_allowed() { + new_test_ext().execute_with(|| { + let account = AccountId::from_str(ALICE).unwrap(); + + let call = RuntimeCall::EVM(pallet_evm::Call::create { + source: H160::from(account.0), + init: vec![], + gas_limit: 100_000, + max_fee_per_gas: U256::from(100_000), + max_priority_fee_per_gas: None, + nonce: None, + access_list: vec![], + value: U256::zero(), + }); + + assert_err!( + call.dispatch(RuntimeOrigin::signed(account)), + sp_runtime::DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, + error: BadOrigin, + } + ); + + let call_2 = RuntimeCall::EVM(pallet_evm::Call::create2 { + source: H160::from(account.0), + init: vec![], + salt: H256::zero(), + gas_limit: 100_000, + max_fee_per_gas: U256::from(100_000), + max_priority_fee_per_gas: None, + nonce: None, + access_list: vec![], + value: U256::zero(), + }); + + assert_err!( + call_2.dispatch(RuntimeOrigin::signed(account)), + sp_runtime::DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, + error: BadOrigin, + } + ); + }); + } + + #[test] + fn evm_call_should_be_allowed() { + new_test_ext().execute_with(|| { + let account = AccountId::from_str(ALICE).unwrap(); + + let call = RuntimeCall::EVM(pallet_evm::Call::call { + source: H160::from(account.0), + target: H160([0x2; 20]), + value: U256::zero(), + input: vec![], + gas_limit: 100_000, + max_fee_per_gas: U256::from(100_000), + max_priority_fee_per_gas: None, + nonce: None, + access_list: vec![], + }); + + assert_err!( + call.dispatch(RuntimeOrigin::signed(account)), + sp_runtime::DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, + error: BadOrigin, + } + ); + }); + } + + #[test] + fn evm_withdraw_should_be_allowed() { + new_test_ext().execute_with(|| { + let call = + RuntimeCall::EVM(pallet_evm::Call::withdraw { address: H160([0x2; 20]), value: 0 }); + let account = AccountId::from_str(ALICE).unwrap(); + + assert_err!( + call.dispatch(RuntimeOrigin::signed(account)), + sp_runtime::DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, + error: BadOrigin, + } + ); + }); + } + + #[test] + fn ethereum_transact_should_be_allowed() { + new_test_ext().execute_with(|| { + let call = RuntimeCall::Ethereum(pallet_ethereum::Call::transact { + transaction: Transaction::Legacy(ethereum::LegacyTransaction { + nonce: U256::zero(), + gas_price: U256::zero(), + gas_limit: U256::from(100_000), + action: ethereum::TransactionAction::Call(H160::zero()), + value: U256::zero(), + input: vec![], + signature: ethereum::TransactionSignature::new( + 123, + H256::from_low_u64_be(1), + H256::from_low_u64_be(2), + ) + .unwrap(), + }), + }); + + let account = AccountId::from_str(ALICE).unwrap(); + + assert_err!( + call.dispatch(RuntimeOrigin::signed(account)), + sp_runtime::DispatchErrorWithPostInfo { + post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, + error: Other("bad origin: expected to be an Ethereum transaction"), + } + ); + }); + } +} diff --git a/xcm-simulator/src/laosish.rs b/xcm-simulator/src/laosish/mod.rs similarity index 100% rename from xcm-simulator/src/laosish.rs rename to xcm-simulator/src/laosish/mod.rs From b52d16136449964e8d67dedd5aa852daafc880e4 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:32:16 +0200 Subject: [PATCH 21/69] laos-primitives feature fix --- Cargo.lock | 1 + xcm-simulator/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9479b8d1..c04ce9eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16334,6 +16334,7 @@ version = "7.0.0" dependencies = [ "frame-support", "frame-system", + "laos-primitives", "log", "pallet-balances", "pallet-message-queue", diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index c80e7699..052345c9 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -30,7 +30,7 @@ pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = polkadot-core-primitives = { workspace = true } polkadot-runtime-parachains = { workspace = true } polkadot-parachain-primitives = { workspace = true } -#laos-primitives = { workspace = true } +laos-primitives = { workspace = true } [features] default = ["std"] @@ -45,7 +45,7 @@ std = [ "sp-runtime/std", "sp-tracing/std", "pallet-uniques/std", -# "laos-primitives/std", + "laos-primitives/std", "sp-std/std", "sp-io/std", "sp-core/std", From 0c77ccb3bc4e8c736e88fc4bc5b50760fd8defcc Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:33:39 +0200 Subject: [PATCH 22/69] laosish has lso balances --- xcm-simulator/src/laosish/mod.rs | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 41e62596..02a059f9 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -16,6 +16,8 @@ //! Parachain runtime mock. +mod configs; + use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ @@ -90,28 +92,6 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type FreezeIdentifier = (); - type MaxFreezes = ConstU32<0>; -} - #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; #[cfg(feature = "runtime-benchmarks")] From 0a142d4aabbbc873fd5c67e8046263a75070971f Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:42:36 +0200 Subject: [PATCH 23/69] laosish uses laos system --- xcm-simulator/src/laosish/configs/mod.rs | 2 +- xcm-simulator/src/laosish/configs/system.rs | 270 +------------------- xcm-simulator/src/laosish/mod.rs | 37 +-- 3 files changed, 9 insertions(+), 300 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 3ccd7e69..0a7d46f9 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,2 +1,2 @@ mod balances; -// mod system; +mod system; diff --git a/xcm-simulator/src/laosish/configs/system.rs b/xcm-simulator/src/laosish/configs/system.rs index 1eb5a1a0..e853005c 100644 --- a/xcm-simulator/src/laosish/configs/system.rs +++ b/xcm-simulator/src/laosish/configs/system.rs @@ -15,14 +15,13 @@ // along with LAOS. If not, see . use crate::laosish::{ - weights::RocksDbWeight, AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, RuntimeTask, RuntimeVersion, VERSION, + AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + RuntimeTask, }; use frame_support::{parameter_types, traits::Everything}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; parameter_types! { - pub const Version: RuntimeVersion = VERSION; pub const SS58Prefix: u16 = 42; pub const BlockHashCount: u32 = 256; } @@ -51,7 +50,7 @@ impl frame_system::Config for Runtime { /// Maximum number of block number to block hash mappings to keep (oldest pruned first). type BlockHashCount = BlockHashCount; /// Runtime version. - type Version = Version; + type Version = (); /// Converts a module to an index of this module in the runtime. type PalletInfo = PalletInfo; /// The data to be stored in an account. @@ -61,7 +60,7 @@ impl frame_system::Config for Runtime { /// What to do if an account is fully reaped from the system. type OnKilledAccount = (); /// The weight of database operations that the runtime can invoke. - type DbWeight = RocksDbWeight; + type DbWeight = (); /// The basic call filter to use in dispatchable. type BaseCallFilter = Everything; /// Weight information for the extrinsics of this pallet. @@ -73,7 +72,7 @@ impl frame_system::Config for Runtime { /// This is used as an identifier of the chain. 42 is the generic substrate prefix. type SS58Prefix = SS58Prefix; /// The action to take on a Runtime Upgrade - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type OnSetCode = (); type MaxConsumers = frame_support::traits::ConstU32<16>; type SingleBlockMigrations = (); type MultiBlockMigrator = (); @@ -81,262 +80,3 @@ impl frame_system::Config for Runtime { type PostInherents = (); type PostTransactions = (); } - -// tests -#[cfg(test)] -mod tests { - use super::*; - use crate::{ - currency::UNIT, - tests::{new_test_ext, ExtBuilder, ALICE, BOB}, - }; - use core::str::FromStr; - use frame_support::{assert_err, assert_ok, dispatch::PostDispatchInfo, pallet_prelude::Pays}; - use pallet_ethereum::Transaction; - use sp_core::{H160, H256, U256}; - use sp_runtime::{ - traits::Dispatchable, - DispatchError::{BadOrigin, Other}, - }; - - #[test] - fn transfer_should_be_allowed() { - let alice = AccountId::from_str(ALICE).unwrap(); - - ExtBuilder::default() - .with_balances(vec![(alice, 1000 * UNIT)]) - .build() - .execute_with(|| { - let to_account = AccountId::from_str(BOB).unwrap(); - let transfer_amount = 100; - let call = RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { - dest: to_account, - value: transfer_amount, - }); - assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); - }); - } - - #[test] - fn transfer_all_should_be_allowed() { - let alice = AccountId::from_str(ALICE).unwrap(); - - ExtBuilder::default() - .with_balances(vec![(alice, 1000 * UNIT)]) - .build() - .execute_with(|| { - let to_account = AccountId::from_str(BOB).unwrap(); - let call = RuntimeCall::Balances(pallet_balances::Call::transfer_all { - dest: to_account, - keep_alive: false, - }); - assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); - }); - } - - #[test] - fn transfer_keep_alive_should_be_allowed() { - let alice = AccountId::from_str(ALICE).unwrap(); - - ExtBuilder::default() - .with_balances(vec![(alice, 1000 * UNIT)]) - .build() - .execute_with(|| { - let to_account = AccountId::from_str(BOB).unwrap(); - let transfer_amount = 1000000000000000000; - - let call = RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { - dest: to_account, - value: transfer_amount, - }); - assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); - }); - } - - #[test] - fn transfer_allow_death_should_be_allowed() { - let alice = AccountId::from_str(ALICE).unwrap(); - - ExtBuilder::default() - .with_balances(vec![(alice, 1000 * UNIT)]) - .build() - .execute_with(|| { - let to_account = AccountId::from_str(BOB).unwrap(); - let transfer_amount = 100; - - let call = RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { - dest: to_account, - value: transfer_amount, - }); - assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); - }); - } - - #[test] - fn vested_transfer_should_be_allowed() { - let alice = AccountId::from_str(ALICE).unwrap(); - - ExtBuilder::default() - .with_balances(vec![(alice, 100000 * UNIT)]) - .build() - .execute_with(|| { - let to_account = AccountId::from_str(BOB).unwrap(); - let transfer_amount = 1000000000000000000; - let per_block = 10; - let starting_block = 100; - - let vesting_schedule = - pallet_vesting::VestingInfo::new(transfer_amount, per_block, starting_block); - - let call = RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { - target: to_account, - schedule: vesting_schedule, - }); - assert_ok!(call.dispatch(RuntimeOrigin::signed(alice))); - }); - } - - #[test] - fn join_candidates_should_be_allowed() { - new_test_ext().execute_with(|| { - let account = AccountId::from_str(ALICE).unwrap(); - let stake = 20_000 * UNIT; - - assert_ok!(pallet_balances::Pallet::::force_set_balance( - RuntimeOrigin::root(), - account, - stake - )); - - let call = - RuntimeCall::ParachainStaking(pallet_parachain_staking::Call::join_candidates { - bond: stake, - candidate_count: 32, - }); - - assert_ok!(call.dispatch(RuntimeOrigin::signed(account))); - }); - } - - #[test] - fn evm_create_should_be_allowed() { - new_test_ext().execute_with(|| { - let account = AccountId::from_str(ALICE).unwrap(); - - let call = RuntimeCall::EVM(pallet_evm::Call::create { - source: H160::from(account.0), - init: vec![], - gas_limit: 100_000, - max_fee_per_gas: U256::from(100_000), - max_priority_fee_per_gas: None, - nonce: None, - access_list: vec![], - value: U256::zero(), - }); - - assert_err!( - call.dispatch(RuntimeOrigin::signed(account)), - sp_runtime::DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, - error: BadOrigin, - } - ); - - let call_2 = RuntimeCall::EVM(pallet_evm::Call::create2 { - source: H160::from(account.0), - init: vec![], - salt: H256::zero(), - gas_limit: 100_000, - max_fee_per_gas: U256::from(100_000), - max_priority_fee_per_gas: None, - nonce: None, - access_list: vec![], - value: U256::zero(), - }); - - assert_err!( - call_2.dispatch(RuntimeOrigin::signed(account)), - sp_runtime::DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, - error: BadOrigin, - } - ); - }); - } - - #[test] - fn evm_call_should_be_allowed() { - new_test_ext().execute_with(|| { - let account = AccountId::from_str(ALICE).unwrap(); - - let call = RuntimeCall::EVM(pallet_evm::Call::call { - source: H160::from(account.0), - target: H160([0x2; 20]), - value: U256::zero(), - input: vec![], - gas_limit: 100_000, - max_fee_per_gas: U256::from(100_000), - max_priority_fee_per_gas: None, - nonce: None, - access_list: vec![], - }); - - assert_err!( - call.dispatch(RuntimeOrigin::signed(account)), - sp_runtime::DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, - error: BadOrigin, - } - ); - }); - } - - #[test] - fn evm_withdraw_should_be_allowed() { - new_test_ext().execute_with(|| { - let call = - RuntimeCall::EVM(pallet_evm::Call::withdraw { address: H160([0x2; 20]), value: 0 }); - let account = AccountId::from_str(ALICE).unwrap(); - - assert_err!( - call.dispatch(RuntimeOrigin::signed(account)), - sp_runtime::DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, - error: BadOrigin, - } - ); - }); - } - - #[test] - fn ethereum_transact_should_be_allowed() { - new_test_ext().execute_with(|| { - let call = RuntimeCall::Ethereum(pallet_ethereum::Call::transact { - transaction: Transaction::Legacy(ethereum::LegacyTransaction { - nonce: U256::zero(), - gas_price: U256::zero(), - gas_limit: U256::from(100_000), - action: ethereum::TransactionAction::Call(H160::zero()), - value: U256::zero(), - input: vec![], - signature: ethereum::TransactionSignature::new( - 123, - H256::from_low_u64_be(1), - H256::from_low_u64_be(2), - ) - .unwrap(), - }), - }); - - let account = AccountId::from_str(ALICE).unwrap(); - - assert_err!( - call.dispatch(RuntimeOrigin::signed(account)), - sp_runtime::DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { actual_weight: None, pays_fee: Pays::Yes }, - error: Other("bad origin: expected to be an Ethereum transaction"), - } - ); - }); - } -} diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 02a059f9..8aa19a9a 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -21,15 +21,15 @@ mod configs; use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ - construct_runtime, derive_impl, parameter_types, + construct_runtime, parameter_types, traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; use frame_system::EnsureRoot; -use sp_core::{ConstU32, H256}; +use sp_core::ConstU32; use sp_runtime::{ - traits::{Get, Hash, IdentityLookup}, + traits::{Get, Hash}, AccountId32, }; use sp_std::prelude::*; @@ -61,37 +61,6 @@ pub type SovereignAccountOf = ( pub type AccountId = AccountId32; pub type Balance = u128; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} - #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; #[cfg(feature = "runtime-benchmarks")] From 76bec1b6cf8c7762015bca2e457e1e17d2599c50 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:48:01 +0200 Subject: [PATCH 24/69] rollback xcm_config --- runtime/laos/src/configs/xcm_config.rs | 23 ++++++++--------------- xcm-simulator/src/laosish/configs/mod.rs | 1 + 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index c6c70c6c..7aff6598 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -41,12 +41,11 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub const RelayNetwork: Option = None; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. - // pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); - pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -172,13 +171,12 @@ pub type LocalOriginToLocation = SignedToAccountId20, -// // ..and XCMP to communicate with the sibling chains. -// crate::XcmpQueue, -// )>; -pub type XcmRouter = xcm_builder::EnsureDecodableXcm>; +pub type XcmRouter = staging_xcm_builder::WithUniqueTopic<( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + crate::XcmpQueue, +)>; impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -212,11 +210,6 @@ impl cumulus_pallet_xcm::Config for Runtime { type XcmExecutor = XcmExecutor; } -impl pallet_mock_msg_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 0a7d46f9..cea9e1df 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,2 +1,3 @@ mod balances; mod system; +mod xcm_config; From 30f43ef83d4b9eb6135ecc94fa6695530df83244 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:49:29 +0200 Subject: [PATCH 25/69] add laosish xcm_config --- .../src/laosish/configs/xcm_config.rs | 233 ++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 xcm-simulator/src/laosish/configs/xcm_config.rs diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs new file mode 100644 index 00000000..7aff6598 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -0,0 +1,233 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::{ + types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, +}; +use core::marker::PhantomData; +use frame_support::{ + parameter_types, + traits::{ConstU32, Contains, Everything, Nothing, OriginTrait}, + weights::Weight, +}; +use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; +use pallet_xcm::XcmPassthrough; +use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::traits::TryConvert; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, + FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WithComputedOrigin, +}; +use xcm_executor::XcmExecutor; + +parameter_types! { + pub const RelayLocation: Location = Location::parent(); + pub const RelayNetwork: Option = None; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain + // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. + pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); +} + +/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the parent `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId20` origins just alias directly to `AccountId`. + AccountKey20Aliases, +); + +/// Means for transacting assets on this chain. +pub type LocalAssetTransactor = FungibleAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Do a simple pun to convert an AccountId20 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports. + (), +>; + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognized. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognized. + SiblingParachainAsNative, + // Native signed account converter; this just converts an `AccountId20` origin into a normal + // `RuntimeOrigin::Signed` origin of the same 20-byte value. + SignedAccountKey20AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct ParentOrParentsExecutivePlurality; +impl Contains for ParentOrParentsExecutivePlurality { + fn contains(location: &Location) -> bool { + matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }])) + } +} + +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, +>; + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); // Teleporting is disabled. + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = UsingComponents< + ::WeightToFee, + RelayLocation, + AccountId, + Balances, + ToAuthor, + >; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId20; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = staging_xcm_builder::WithUniqueTopic<( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + crate::XcmpQueue, +)>; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // ^ Override for AdvertisedXcmVersion default + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub struct SignedToAccountId20( + PhantomData<(RuntimeOrigin, AccountId, Network)>, +); +impl< + RuntimeOrigin: OriginTrait + Clone, + AccountId: Into<[u8; 20]>, + Network: frame_support::traits::Get>, + > TryConvert for SignedToAccountId20 +where + RuntimeOrigin::PalletsOrigin: From> + + TryInto, Error = RuntimeOrigin::PalletsOrigin>, +{ + fn try_convert(o: RuntimeOrigin) -> Result { + o.try_with_caller(|caller| match caller.try_into() { + Ok(SystemRawOrigin::Signed(who)) => + Ok(Junction::AccountKey20 { network: Network::get(), key: who.into() }.into()), + Ok(other) => Err(other.into()), + Err(other) => Err(other), + }) + } +} From e2cfca92982c853feb2e59a040076e1052a0d68f Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 11:55:09 +0200 Subject: [PATCH 26/69] added types --- .../src/laosish/configs/xcm_config.rs | 6 +-- xcm-simulator/src/laosish/mod.rs | 1 + .../src/laosish/types/account_id_to_h160.rs | 34 +++++++++++++++ xcm-simulator/src/laosish/types/mod.rs | 23 ++++++++++ xcm-simulator/src/laosish/types/to_author.rs | 36 ++++++++++++++++ .../laosish/types/transaction_converter.rs | 43 +++++++++++++++++++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 xcm-simulator/src/laosish/types/account_id_to_h160.rs create mode 100644 xcm-simulator/src/laosish/types/mod.rs create mode 100644 xcm-simulator/src/laosish/types/to_author.rs create mode 100644 xcm-simulator/src/laosish/types/transaction_converter.rs diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 7aff6598..4298cb91 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with LAOS. If not, see . -use crate::{ +use crate::laosish::{ types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, }; @@ -173,9 +173,9 @@ pub type LocalOriginToLocation = SignedToAccountId20, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. - crate::XcmpQueue, + crate::laosish::XcmpQueue, )>; impl pallet_xcm::Config for Runtime { diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 8aa19a9a..1c2f46d6 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -17,6 +17,7 @@ //! Parachain runtime mock. mod configs; +mod types; use codec::{Decode, Encode}; use core::marker::PhantomData; diff --git a/xcm-simulator/src/laosish/types/account_id_to_h160.rs b/xcm-simulator/src/laosish/types/account_id_to_h160.rs new file mode 100644 index 00000000..20387378 --- /dev/null +++ b/xcm-simulator/src/laosish/types/account_id_to_h160.rs @@ -0,0 +1,34 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::AccountId; +use sp_core::H160; +use sp_runtime::traits::{Convert, ConvertBack}; + +/// Converts [`AccountId`] to [`H160`] +pub struct AccountIdToH160; + +impl Convert for AccountIdToH160 { + fn convert(account_id: AccountId) -> H160 { + H160(account_id.0) + } +} + +impl ConvertBack for AccountIdToH160 { + fn convert_back(account_id: H160) -> AccountId { + AccountId::from(account_id) + } +} diff --git a/xcm-simulator/src/laosish/types/mod.rs b/xcm-simulator/src/laosish/types/mod.rs new file mode 100644 index 00000000..a652eb10 --- /dev/null +++ b/xcm-simulator/src/laosish/types/mod.rs @@ -0,0 +1,23 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +mod account_id_to_h160; +mod to_author; +mod transaction_converter; + +pub(crate) use account_id_to_h160::AccountIdToH160; +pub(crate) use to_author::ToAuthor; +pub use transaction_converter::TransactionConverter; diff --git a/xcm-simulator/src/laosish/types/to_author.rs b/xcm-simulator/src/laosish/types/to_author.rs new file mode 100644 index 00000000..b1e74004 --- /dev/null +++ b/xcm-simulator/src/laosish/types/to_author.rs @@ -0,0 +1,36 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::PhantomData; +use frame_support::traits::{ + fungible::{Balanced, Credit}, + OnUnbalanced, +}; + +/// Logic for the author to get a portion of fees. +pub struct ToAuthor(PhantomData); +impl OnUnbalanced>> for ToAuthor +where + R: pallet_balances::Config + pallet_authorship::Config, +{ + fn on_nonzero_unbalanced( + amount: Credit<::AccountId, pallet_balances::Pallet>, + ) { + if let Some(author) = >::author() { + let _ = >::resolve(&author, amount); + } + } +} diff --git a/xcm-simulator/src/laosish/types/transaction_converter.rs b/xcm-simulator/src/laosish/types/transaction_converter.rs new file mode 100644 index 00000000..9e13142a --- /dev/null +++ b/xcm-simulator/src/laosish/types/transaction_converter.rs @@ -0,0 +1,43 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::{opaque, Runtime, UncheckedExtrinsic}; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Clone)] +pub struct TransactionConverter; + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } +} + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction( + &self, + transaction: pallet_ethereum::Transaction, + ) -> opaque::UncheckedExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } +} From e4765245ecda67d186f3a1707f57b257f45b3d68 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 15:48:45 +0200 Subject: [PATCH 27/69] using accountid20 --- Cargo.lock | 65 +++++ xcm-simulator/Cargo.toml | 193 ++++++++++++++- .../src/{laosish/mod.rs => laosish.rs} | 156 +++++++----- xcm-simulator/src/laosish/configs/balances.rs | 51 ---- xcm-simulator/src/laosish/configs/mod.rs | 3 - xcm-simulator/src/laosish/configs/system.rs | 82 ------ .../src/laosish/configs/xcm_config.rs | 233 ------------------ .../src/laosish/types/account_id_to_h160.rs | 34 --- xcm-simulator/src/laosish/types/mod.rs | 23 -- xcm-simulator/src/laosish/types/to_author.rs | 36 --- .../laosish/types/transaction_converter.rs | 43 ---- 11 files changed, 334 insertions(+), 585 deletions(-) rename xcm-simulator/src/{laosish/mod.rs => laosish.rs} (79%) delete mode 100644 xcm-simulator/src/laosish/configs/balances.rs delete mode 100644 xcm-simulator/src/laosish/configs/mod.rs delete mode 100644 xcm-simulator/src/laosish/configs/system.rs delete mode 100644 xcm-simulator/src/laosish/configs/xcm_config.rs delete mode 100644 xcm-simulator/src/laosish/types/account_id_to_h160.rs delete mode 100644 xcm-simulator/src/laosish/types/mod.rs delete mode 100644 xcm-simulator/src/laosish/types/to_author.rs delete mode 100644 xcm-simulator/src/laosish/types/transaction_converter.rs diff --git a/Cargo.lock b/Cargo.lock index c04ce9eb..ae45cde9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16332,24 +16332,89 @@ dependencies = [ name = "xcm-simulator-example" version = "7.0.0" dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "frame-benchmarking", + "frame-executive", "frame-support", "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex", "laos-primitives", "log", + "pallet-asset-metadata-extender", + "pallet-aura", + "pallet-authorship", "pallet-balances", + "pallet-base-fee", + "pallet-collective", + "pallet-democracy", + "pallet-elections-phragmen", + "pallet-ethereum", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-evm-precompile-blake2", + "pallet-evm-precompile-bn128", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-parachain-staking", + "pallet-evm-precompile-simple", + "pallet-identity", + "pallet-laos-evolution", + "pallet-membership", "pallet-message-queue", + "pallet-mock-msg-queue", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompiles-benchmark", + "pallet-preimage", + "pallet-proxy", + "pallet-scheduler", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", "pallet-uniques", + "pallet-utility", + "pallet-vesting", "pallet-xcm", + "parachains-common", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain-primitives", + "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-consensus-slots", "sp-core", + "sp-genesis-builder", + "sp-inherents", "sp-io", + "sp-offchain", "sp-runtime", + "sp-session", + "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "sp-transaction-pool", + "sp-version", + "sp-weights", + "staging-parachain-info", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 052345c9..f9787678 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -10,31 +10,114 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = scale-info = { workspace = true } log = { workspace = true } -frame-system = { workspace = true } +sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +polkadot-runtime-parachains = { workspace = true } +polkadot-core-primitives = { workspace = true } +laos-primitives = { workspace = true } + +# Substrate +frame-benchmarking = { workspace = true, optional = true } +frame-executive = { workspace = true } frame-support = { workspace = true } -pallet-balances = { workspace = true } +frame-system = { workspace = true } +frame-system-benchmarking = { workspace = true, optional = true } +frame-system-rpc-runtime-api = { workspace = true } +frame-try-runtime = { workspace = true, optional = true } +pallet-aura = { workspace = true } +pallet-scheduler = { workspace = true } +pallet-authorship = { workspace = true } +pallet-balances = { workspace = true , features = ["insecure_zero_ed"] } pallet-message-queue = { workspace = true } -# pallet-uniques = { workspace = true } -sp-std = { workspace = true } +pallet-multisig = { workspace = true } +pallet-session = { workspace = true } +pallet-identity = { workspace = true } +pallet-sudo = { workspace = true } +pallet-democracy = { workspace = true } +pallet-treasury = { workspace = true } +pallet-preimage = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-collective = { workspace = true } +pallet-membership ={ workspace = true } +pallet-elections-phragmen = { workspace = true } +pallet-transaction-payment = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-vesting = { workspace = true } +pallet-proxy = { workspace = true } +pallet-utility = { workspace = true } +sp-api = { workspace = true } +sp-io = { workspace = true } +sp-block-builder = { workspace = true } +sp-consensus-aura = { workspace = true } +sp-consensus-slots = { workspace = true } sp-core = { workspace = true } +sp-inherents = { workspace = true } +sp-offchain = { workspace = true } sp-runtime = { workspace = true } -sp-io = { workspace = true } -sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +sp-session = { workspace = true } +sp-std = { workspace = true } +sp-transaction-pool = { workspace = true } +sp-version = { workspace = true } +sp-staking = { workspace = true } +sp-weights ={ workspace = true } +sp-genesis-builder ={ workspace = true } + +pallet-asset-metadata-extender = { workspace = true } +pallet-laos-evolution = { workspace = true } +pallet-parachain-staking = { workspace = true } +pallet-precompiles-benchmark = { workspace = true } +pallet-mock-msg-queue = { workspace = true } + +# Polkadot +pallet-xcm = { workspace = true } +polkadot-runtime-common = { workspace = true } +polkadot-parachain-primitives = { workspace = true } xcm = { workspace = true } -xcm-executor = { workspace = true } xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Cumulus +cumulus-pallet-aura-ext = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-session-benchmarking = { workspace = true, optional = true} +cumulus-pallet-xcm = { workspace = true } +cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-core = { workspace = true } +cumulus-primitives-timestamp = { workspace = true } +cumulus-primitives-utility = { workspace = true } +parachain-info = { workspace = true } +parachains-common = { workspace = true } xcm-simulator = { workspace = true } -pallet-xcm = { workspace = true } -pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -polkadot-core-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-parachain-primitives = { workspace = true } -laos-primitives = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +fp-rpc = { workspace = true } +fp-self-contained = { workspace = true, features = ["serde"] } + +# Frontier FRAME +pallet-base-fee = { workspace = true } +pallet-evm = { workspace = true } +pallet-ethereum = { workspace = true } +pallet-evm-chain-id = { workspace = true } +pallet-evm-precompile-modexp = { workspace = true } +pallet-evm-precompile-simple = { workspace = true } +pallet-evm-precompile-bn128 = { workspace = true } +pallet-evm-precompile-blake2 = { workspace = true } +pallet-evm-precompile-parachain-staking = { workspace = true } + + +hex = { workspace = true } [features] default = ["std"] std = [ + "cumulus-primitives-utility/std", + "cumulus-pallet-parachain-system/std", + "pallet-transaction-payment/std", + "fp-rpc/std", + "cumulus-pallet-xcm/std", + "parachain-info/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -54,6 +137,90 @@ std = [ "xcm/std", "xcm-builder/std", "xcm-executor/std", + "scale-info/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "pallet-message-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "parachains-common/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-elections-phragmen/std", + "pallet-session/std", + "pallet-democracy/std", + "pallet-sudo/std", + "pallet-treasury/std", + "pallet-collective/std", + "pallet-membership/std", + "pallet-preimage/std", + "pallet-scheduler/std", + "pallet-laos-evolution/std", + "pallet-asset-metadata-extender/std", + "pallet-mock-msg-queue/std", + "pallet-multisig/std", + "pallet-timestamp/std", + "pallet-identity/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-vesting/std", + "pallet-precompiles-benchmark/std", + "pallet-transaction-payment/std", + "pallet-xcm/std", + "parachain-info/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-io/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-weights/std", + "sp-genesis-builder/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", + # Frontier + "fp-evm/std", + "fp-rpc/std", + "fp-self-contained/std", + # Frontier FRAME + "pallet-base-fee/std", + "pallet-ethereum/std", + "pallet-evm/std", + "pallet-evm-chain-id/std", + "pallet-evm-precompile-modexp/std", + "pallet-evm-precompile-simple/std", + "pallet-evm-precompile-bn128/std", + "pallet-evm-precompile-blake2/std", + "pallet-evm-precompile-parachain-staking/std", + "cumulus-pallet-session-benchmarking?/std", + "frame-benchmarking?/std", + "frame-system-benchmarking?/std", + "frame-try-runtime?/std", + # Bridge deps, + "laos-primitives/std", + "hex/std", + "pallet-parachain-staking/std", + "log/std", + "sp-consensus-slots/std", + "sp-staking/std", + "pallet-utility/std", + "pallet-proxy/std", ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish.rs similarity index 79% rename from xcm-simulator/src/laosish/mod.rs rename to xcm-simulator/src/laosish.rs index 1c2f46d6..0072aae0 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish.rs @@ -16,21 +16,19 @@ //! Parachain runtime mock. -mod configs; -mod types; - use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ - construct_runtime, parameter_types, - traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, + construct_runtime, derive_impl, parameter_types, + traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, OriginTrait, EverythingBut, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; +use sp_runtime::traits::TryConvert; -use frame_system::EnsureRoot; -use sp_core::ConstU32; +use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; +use sp_core::{ConstU32, H256}; use sp_runtime::{ - traits::{Get, Hash}, + traits::{Get, Hash, IdentityLookup}, AccountId32, }; use sp_std::prelude::*; @@ -42,6 +40,7 @@ use polkadot_parachain_primitives::primitives::{ }; use xcm::{latest::prelude::*, VersionedXcm}; use xcm_builder::{ + AccountKey20Aliases, Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, @@ -59,8 +58,61 @@ pub type SovereignAccountOf = ( ParentIsPreset, ); -pub type AccountId = AccountId32; -pub type Balance = u128; +pub type AccountId = laos_primitives::AccountId; +pub type Balance = laos_primitives::Balance; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; @@ -74,50 +126,6 @@ impl pallet_uniques::BenchmarkHelper for UniquesHelper } } -impl pallet_uniques::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type CollectionId = Location; - type ItemId = AssetInstance; - type Currency = Balances; - type CreateOrigin = ForeignCreators; - type ForceOrigin = frame_system::EnsureRoot; - type CollectionDeposit = frame_support::traits::ConstU128<1_000>; - type ItemDeposit = frame_support::traits::ConstU128<1_000>; - type MetadataDepositBase = frame_support::traits::ConstU128<1_000>; - type AttributeDepositBase = frame_support::traits::ConstU128<1_000>; - type DepositPerByte = frame_support::traits::ConstU128<1>; - type StringLimit = ConstU32<64>; - type KeyLimit = ConstU32<64>; - type ValueLimit = ConstU32<128>; - type Locker = (); - type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type Helper = UniquesHelper; -} - -// `EnsureOriginWithArg` impl for `CreateOrigin` which allows only XCM origins -// which are locations containing the class location. -pub struct ForeignCreators; -impl EnsureOriginWithArg for ForeignCreators { - type Success = AccountId; - - fn try_origin( - o: RuntimeOrigin, - a: &Location, - ) -> sp_std::result::Result { - let origin_location = pallet_xcm::EnsureXcm::::try_origin(o.clone())?; - if !a.starts_with(&origin_location) { - return Err(o) - } - SovereignAccountOf::convert_location(&origin_location).ok_or(o) - } - - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin(a: &Location) -> Result { - Ok(pallet_xcm::Origin::Xcm(a.clone()).into()) - } -} - parameter_types! { pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); @@ -132,13 +140,13 @@ parameter_types! { pub type LocationToAccountId = ( ParentIsPreset, SiblingParachainConvertsVia, - AccountId32Aliases, - Account32Hash<(), AccountId>, + // Straight up local `AccountId20` origins just alias directly to `AccountId`. + AccountKey20Aliases, ); pub type XcmOriginToCallOrigin = ( SovereignSignedViaLocation, - SignedAccountId32AsNative, + // SignedAccountId32AsNative, XcmPassthrough, ); @@ -152,14 +160,6 @@ parameter_types! { pub type LocalAssetTransactor = ( FungibleAdapter, LocationToAccountId, AccountId, ()>, - NonFungiblesAdapter< - ForeignUniques, - ConvertedConcreteId, - SovereignAccountOf, - AccountId, - NoChecking, - (), - >, ); pub type XcmRouter = EnsureDecodableXcm>; @@ -364,7 +364,30 @@ impl mock_msg_queue::Config for Runtime { type XcmExecutor = XcmExecutor; } -pub type LocalOriginToLocation = SignedToAccountId32; +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId20; + +pub struct SignedToAccountId20( + PhantomData<(RuntimeOrigin, AccountId, Network)>, +); +impl< + RuntimeOrigin: OriginTrait + Clone, + AccountId: Into<[u8; 20]>, + Network: frame_support::traits::Get>, + > TryConvert for SignedToAccountId20 +where + RuntimeOrigin::PalletsOrigin: From> + + TryInto, Error = RuntimeOrigin::PalletsOrigin>, +{ + fn try_convert(o: RuntimeOrigin) -> Result { + o.try_with_caller(|caller| match caller.try_into() { + Ok(SystemRawOrigin::Signed(who)) => + Ok(Junction::AccountKey20 { network: Network::get(), key: who.into() }.into()), + Ok(other) => Err(other.into()), + Err(other) => Err(other), + }) + } +} pub struct TrustedLockerCase(PhantomData); impl> ContainsPair for TrustedLockerCase { @@ -415,6 +438,5 @@ construct_runtime!( Balances: pallet_balances, MsgQueue: mock_msg_queue, PolkadotXcm: pallet_xcm, - ForeignUniques: pallet_uniques, } ); diff --git a/xcm-simulator/src/laosish/configs/balances.rs b/xcm-simulator/src/laosish/configs/balances.rs deleted file mode 100644 index 44de12f5..00000000 --- a/xcm-simulator/src/laosish/configs/balances.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::laosish::{ - Balance, Runtime, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, System, -}; -use frame_support::parameter_types; - -parameter_types! { - /// The minimum amount required to keep an account open, set to zero in this case. - /// - /// While it's generally advised to have this value greater than zero to avoid potential - /// DoS vectors, we set it to zero here due to specific concerns about relay attacks. - /// In such attacks, the reset of the nonce upon account deletion can be exploited. - /// By setting the ExistentialDeposit to zero, we prevent the scenario where an account's - /// balance drops to a level that would trigger its deletion and subsequent nonce reset. - pub const ExistentialDeposit: Balance = 0; - pub const MaxLocks: u32 = 50; - pub const MaxFreezes: u32 = 50; - pub const MaxHolds: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type FreezeIdentifier = RuntimeFreezeReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type RuntimeHoldReason = RuntimeHoldReason; - type MaxFreezes = MaxFreezes; - type WeightInfo = pallet_balances::weights::SubstrateWeight; // See: https://github.com/freeverseio/laos/pull/533#issuecomment-2034913428 -} diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs deleted file mode 100644 index cea9e1df..00000000 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod balances; -mod system; -mod xcm_config; diff --git a/xcm-simulator/src/laosish/configs/system.rs b/xcm-simulator/src/laosish/configs/system.rs deleted file mode 100644 index e853005c..00000000 --- a/xcm-simulator/src/laosish/configs/system.rs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::laosish::{ - AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, - RuntimeTask, -}; -use frame_support::{parameter_types, traits::Everything}; -use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; - -parameter_types! { - pub const SS58Prefix: u16 = 42; - pub const BlockHashCount: u32 = 256; -} - -impl frame_system::Config for Runtime { - /// The identifier used to distinguish between accounts. - type AccountId = AccountId; - /// The aggregated dispatch type that is available for extrinsics. - type RuntimeCall = RuntimeCall; - /// The lookup mechanism to get account ID from whatever is passed in dispatchers. - type Lookup = IdentityLookup; - /// The block type - type Block = Block; - /// The type for hashing blocks and tries. - type Hash = laos_primitives::Hash; - /// The type for storing how many extrinsics an account has signed. - type Nonce = laos_primitives::Nonce; - /// The hashing algorithm used. - type Hashing = BlakeTwo256; - /// The ubiquitous event type. - type RuntimeEvent = RuntimeEvent; - /// The ubiquitous origin type. - type RuntimeOrigin = RuntimeOrigin; - /// The aggregated RuntimeTask type. - type RuntimeTask = RuntimeTask; - /// Maximum number of block number to block hash mappings to keep (oldest pruned first). - type BlockHashCount = BlockHashCount; - /// Runtime version. - type Version = (); - /// Converts a module to an index of this module in the runtime. - type PalletInfo = PalletInfo; - /// The data to be stored in an account. - type AccountData = pallet_balances::AccountData; - /// What to do if a new account is created. - type OnNewAccount = (); - /// What to do if an account is fully reaped from the system. - type OnKilledAccount = (); - /// The weight of database operations that the runtime can invoke. - type DbWeight = (); - /// The basic call filter to use in dispatchable. - type BaseCallFilter = Everything; - /// Weight information for the extrinsics of this pallet. - type SystemWeightInfo = (); - /// Block & extrinsics weights: base values and limits. - type BlockWeights = laos_primitives::RuntimeBlockWeights; - /// The maximum length of a block (in bytes). - type BlockLength = laos_primitives::RuntimeBlockLength; - /// This is used as an identifier of the chain. 42 is the generic substrate prefix. - type SS58Prefix = SS58Prefix; - /// The action to take on a Runtime Upgrade - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; - type SingleBlockMigrations = (); - type MultiBlockMigrator = (); - type PreInherents = (); - type PostInherents = (); - type PostTransactions = (); -} diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs deleted file mode 100644 index 4298cb91..00000000 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::laosish::{ - types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, -}; -use core::marker::PhantomData; -use frame_support::{ - parameter_types, - traits::{ConstU32, Contains, Everything, Nothing, OriginTrait}, - weights::Weight, -}; -use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; -use pallet_xcm::XcmPassthrough; -use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::traits::TryConvert; -use xcm::latest::prelude::*; -use xcm_builder::{ - AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, -}; -use xcm_executor::XcmExecutor; - -parameter_types! { - pub const RelayLocation: Location = Location::parent(); - pub const RelayNetwork: Option = None; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain - // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. - pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); -} - -/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used -/// when determining ownership of accounts for asset transacting and when attempting to use XCM -/// `Transact` in order to determine the dispatch Origin. -pub type LocationToAccountId = ( - // The parent (Relay-chain) origin converts to the parent `AccountId`. - ParentIsPreset, - // Sibling parachain origins convert to AccountId via the `ParaId::into`. - SiblingParachainConvertsVia, - // Straight up local `AccountId20` origins just alias directly to `AccountId`. - AccountKey20Aliases, -); - -/// Means for transacting assets on this chain. -pub type LocalAssetTransactor = FungibleAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // Do a simple pun to convert an AccountId20 Location into a native chain account ID: - LocationToAccountId, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We don't track any teleports. - (), ->; - -/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, -/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can -/// biases the kind of local `Origin` it will become. -pub type XcmOriginToTransactDispatchOrigin = ( - // Sovereign account converter; this attempts to derive an `AccountId` from the origin location - // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for - // foreign chains who want to have a local sovereign account on this chain which they control. - SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when - // recognized. - RelayChainAsNative, - // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // recognized. - SiblingParachainAsNative, - // Native signed account converter; this just converts an `AccountId20` origin into a normal - // `RuntimeOrigin::Signed` origin of the same 20-byte value. - SignedAccountKey20AsNative, - // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. - XcmPassthrough, -); - -parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; -} - -pub struct ParentOrParentsExecutivePlurality; -impl Contains for ParentOrParentsExecutivePlurality { - fn contains(location: &Location) -> bool { - matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }])) - } -} - -pub type Barrier = TrailingSetTopicAsId< - DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - WithComputedOrigin< - ( - AllowTopLevelPaidExecutionFrom, - AllowExplicitUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), - UniversalLocation, - ConstU32<8>, - >, - ), - >, ->; - -pub struct XcmConfig; -impl xcm_executor::Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - // How to withdraw and deposit an asset. - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; - type IsTeleporter = (); // Teleporting is disabled. - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = UsingComponents< - ::WeightToFee, - RelayLocation, - AccountId, - Balances, - ToAuthor, - >; - type ResponseHandler = PolkadotXcm; - type AssetTrap = PolkadotXcm; - type AssetClaims = PolkadotXcm; - type SubscriptionService = PolkadotXcm; - type PalletInstancesInfo = AllPalletsWithSystem; - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type AssetLocker = (); - type AssetExchanger = (); - type FeeManager = (); - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); -} - -/// No local origins on this chain are allowed to dispatch XCM sends/executions. -pub type LocalOriginToLocation = SignedToAccountId20; - -/// The means for routing XCM messages which are not for local execution into the right message -/// queues. -pub type XcmRouter = staging_xcm_builder::WithUniqueTopic<( - // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, - // ..and XCMP to communicate with the sibling chains. - crate::laosish::XcmpQueue, -)>; - -impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Nothing; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - // ^ Override for AdvertisedXcmVersion default - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = (); - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<8>; - type WeightInfo = pallet_xcm::TestWeightInfo; - type AdminOrigin = EnsureRoot; - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); -} - -impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - -pub struct SignedToAccountId20( - PhantomData<(RuntimeOrigin, AccountId, Network)>, -); -impl< - RuntimeOrigin: OriginTrait + Clone, - AccountId: Into<[u8; 20]>, - Network: frame_support::traits::Get>, - > TryConvert for SignedToAccountId20 -where - RuntimeOrigin::PalletsOrigin: From> - + TryInto, Error = RuntimeOrigin::PalletsOrigin>, -{ - fn try_convert(o: RuntimeOrigin) -> Result { - o.try_with_caller(|caller| match caller.try_into() { - Ok(SystemRawOrigin::Signed(who)) => - Ok(Junction::AccountKey20 { network: Network::get(), key: who.into() }.into()), - Ok(other) => Err(other.into()), - Err(other) => Err(other), - }) - } -} diff --git a/xcm-simulator/src/laosish/types/account_id_to_h160.rs b/xcm-simulator/src/laosish/types/account_id_to_h160.rs deleted file mode 100644 index 20387378..00000000 --- a/xcm-simulator/src/laosish/types/account_id_to_h160.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::AccountId; -use sp_core::H160; -use sp_runtime::traits::{Convert, ConvertBack}; - -/// Converts [`AccountId`] to [`H160`] -pub struct AccountIdToH160; - -impl Convert for AccountIdToH160 { - fn convert(account_id: AccountId) -> H160 { - H160(account_id.0) - } -} - -impl ConvertBack for AccountIdToH160 { - fn convert_back(account_id: H160) -> AccountId { - AccountId::from(account_id) - } -} diff --git a/xcm-simulator/src/laosish/types/mod.rs b/xcm-simulator/src/laosish/types/mod.rs deleted file mode 100644 index a652eb10..00000000 --- a/xcm-simulator/src/laosish/types/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -mod account_id_to_h160; -mod to_author; -mod transaction_converter; - -pub(crate) use account_id_to_h160::AccountIdToH160; -pub(crate) use to_author::ToAuthor; -pub use transaction_converter::TransactionConverter; diff --git a/xcm-simulator/src/laosish/types/to_author.rs b/xcm-simulator/src/laosish/types/to_author.rs deleted file mode 100644 index b1e74004..00000000 --- a/xcm-simulator/src/laosish/types/to_author.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::PhantomData; -use frame_support::traits::{ - fungible::{Balanced, Credit}, - OnUnbalanced, -}; - -/// Logic for the author to get a portion of fees. -pub struct ToAuthor(PhantomData); -impl OnUnbalanced>> for ToAuthor -where - R: pallet_balances::Config + pallet_authorship::Config, -{ - fn on_nonzero_unbalanced( - amount: Credit<::AccountId, pallet_balances::Pallet>, - ) { - if let Some(author) = >::author() { - let _ = >::resolve(&author, amount); - } - } -} diff --git a/xcm-simulator/src/laosish/types/transaction_converter.rs b/xcm-simulator/src/laosish/types/transaction_converter.rs deleted file mode 100644 index 9e13142a..00000000 --- a/xcm-simulator/src/laosish/types/transaction_converter.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2023-2024 Freeverse.io -// This file is part of LAOS. - -// LAOS 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. - -// LAOS 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 LAOS. If not, see . - -use crate::{opaque, Runtime, UncheckedExtrinsic}; -use parity_scale_codec::{Decode, Encode}; - -#[derive(Clone)] -pub struct TransactionConverter; - -impl fp_rpc::ConvertTransaction for TransactionConverter { - fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { - UncheckedExtrinsic::new_unsigned( - pallet_ethereum::Call::::transact { transaction }.into(), - ) - } -} - -impl fp_rpc::ConvertTransaction for TransactionConverter { - fn convert_transaction( - &self, - transaction: pallet_ethereum::Transaction, - ) -> opaque::UncheckedExtrinsic { - let extrinsic = UncheckedExtrinsic::new_unsigned( - pallet_ethereum::Call::::transact { transaction }.into(), - ); - let encoded = extrinsic.encode(); - opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) - .expect("Encoded extrinsic is always valid") - } -} From a1e7137636f0ae993f45b13754da1e613ea37228 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 15:51:20 +0200 Subject: [PATCH 28/69] using accountid20 --- xcm-simulator/src/laosish.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xcm-simulator/src/laosish.rs b/xcm-simulator/src/laosish.rs index 0072aae0..5862ba29 100644 --- a/xcm-simulator/src/laosish.rs +++ b/xcm-simulator/src/laosish.rs @@ -61,9 +61,9 @@ pub type SovereignAccountOf = ( pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { From e0c35557d5e5f87a154c49be44dce975354ba081 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:07:25 +0200 Subject: [PATCH 29/69] balances is from laos --- xcm-simulator/src/laosish/configs/balances.rs | 51 +++++++++++++ xcm-simulator/src/laosish/configs/mod.rs | 1 + .../src/{laosish.rs => laosish/mod.rs} | 74 ++++++------------- 3 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 xcm-simulator/src/laosish/configs/balances.rs create mode 100644 xcm-simulator/src/laosish/configs/mod.rs rename xcm-simulator/src/{laosish.rs => laosish/mod.rs} (86%) diff --git a/xcm-simulator/src/laosish/configs/balances.rs b/xcm-simulator/src/laosish/configs/balances.rs new file mode 100644 index 00000000..44de12f5 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/balances.rs @@ -0,0 +1,51 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::laosish::{ + Balance, Runtime, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, System, +}; +use frame_support::parameter_types; + +parameter_types! { + /// The minimum amount required to keep an account open, set to zero in this case. + /// + /// While it's generally advised to have this value greater than zero to avoid potential + /// DoS vectors, we set it to zero here due to specific concerns about relay attacks. + /// In such attacks, the reset of the nonce upon account deletion can be exploited. + /// By setting the ExistentialDeposit to zero, we prevent the scenario where an account's + /// balance drops to a level that would trigger its deletion and subsequent nonce reset. + pub const ExistentialDeposit: Balance = 0; + pub const MaxLocks: u32 = 50; + pub const MaxFreezes: u32 = 50; + pub const MaxHolds: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type FreezeIdentifier = RuntimeFreezeReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type RuntimeHoldReason = RuntimeHoldReason; + type MaxFreezes = MaxFreezes; + type WeightInfo = pallet_balances::weights::SubstrateWeight; // See: https://github.com/freeverseio/laos/pull/533#issuecomment-2034913428 +} diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs new file mode 100644 index 00000000..5e0f5078 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -0,0 +1 @@ +mod balances; diff --git a/xcm-simulator/src/laosish.rs b/xcm-simulator/src/laosish/mod.rs similarity index 86% rename from xcm-simulator/src/laosish.rs rename to xcm-simulator/src/laosish/mod.rs index 5862ba29..024b52c0 100644 --- a/xcm-simulator/src/laosish.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -16,11 +16,16 @@ //! Parachain runtime mock. +mod configs; + use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, derive_impl, parameter_types, - traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, OriginTrait, EverythingBut, Nothing}, + traits::{ + ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing, + OriginTrait, + }, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; use sp_runtime::traits::TryConvert; @@ -40,30 +45,23 @@ use polkadot_parachain_primitives::primitives::{ }; use xcm::{latest::prelude::*, VersionedXcm}; use xcm_builder::{ - AccountKey20Aliases, - Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, - EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, - FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NoChecking, - NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, + Account32Hash, AccountId32Aliases, AccountKey20Aliases, AllowUnpaidExecutionFrom, + ConvertedConcreteId, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, + NoChecking, NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, }; use xcm_executor::{ traits::{ConvertLocation, JustTry}, Config, XcmExecutor, }; -pub type SovereignAccountOf = ( - SiblingParachainConvertsVia, - AccountId32Aliases, - ParentIsPreset, -); - pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; -// parameter_types! { -// pub const BlockHashCount: u64 = 250; -// } +parameter_types! { + pub const BlockHashCount: u64 = 250; +} #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { @@ -92,28 +90,6 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } -parameter_types! { - pub ExistentialDeposit: Balance = 1; - pub const MaxLocks: u32 = 50; - pub const MaxReserves: u32 = 50; -} - -impl pallet_balances::Config for Runtime { - type MaxLocks = MaxLocks; - type Balance = Balance; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type WeightInfo = (); - type MaxReserves = MaxReserves; - type ReserveIdentifier = [u8; 8]; - type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type FreezeIdentifier = (); - type MaxFreezes = ConstU32<0>; -} - #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; #[cfg(feature = "runtime-benchmarks")] @@ -126,10 +102,11 @@ impl pallet_uniques::BenchmarkHelper for UniquesHelper } } -parameter_types! { - pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); - pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -} +// parameter_types! { +// pub const ReservedXcmpWeight: Weight = +// Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); pub const +// ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); +// } parameter_types! { pub const KsmLocation: Location = Location::parent(); @@ -158,9 +135,8 @@ parameter_types! { pub ForeignPrefix: Location = (Parent,).into(); } -pub type LocalAssetTransactor = ( - FungibleAdapter, LocationToAccountId, AccountId, ()>, -); +pub type LocalAssetTransactor = + (FungibleAdapter, LocationToAccountId, AccountId, ()>,); pub type XcmRouter = EnsureDecodableXcm>; pub type Barrier = AllowUnpaidExecutionFrom; @@ -397,12 +373,6 @@ impl> ContainsPair for TrustedL } } -parameter_types! { - pub RelayTokenForRelay: (Location, AssetFilter) = (Parent.into(), Wild(AllOf { id: AssetId(Parent.into()), fun: WildFungible })); -} - -pub type TrustedLockers = TrustedLockerCase; - impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SendXcmOrigin = EnsureXcmOrigin; @@ -420,7 +390,7 @@ impl pallet_xcm::Config for Runtime { type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances; type CurrencyMatcher = (); - type TrustedLockers = TrustedLockers; + type TrustedLockers = (); type SovereignAccountOf = LocationToAccountId; type MaxLockers = ConstU32<8>; type MaxRemoteLockConsumers = ConstU32<0>; From c3c31eeef316225504de22eaa06e25388d93231a Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:08:51 +0200 Subject: [PATCH 30/69] balances is from laos --- xcm-simulator/src/laosish/configs/mod.rs | 1 + xcm-simulator/src/laosish/mod.rs | 60 ++++++++++++------------ 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 5e0f5078..5867c2a8 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1 +1,2 @@ mod balances; +mod system; \ No newline at end of file diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 024b52c0..8c9d90e2 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -58,37 +58,38 @@ use xcm_executor::{ pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; +type Block = frame_system::mocking::MockBlock; -parameter_types! { - pub const BlockHashCount: u64 = 250; -} +// parameter_types! { +// pub const BlockHashCount: u64 = 250; +// } -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; -} +// #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +// impl frame_system::Config for Runtime { +// type RuntimeOrigin = RuntimeOrigin; +// type RuntimeCall = RuntimeCall; +// type Nonce = u64; +// type Hash = H256; +// type Hashing = ::sp_runtime::traits::BlakeTwo256; +// type AccountId = AccountId; +// type Lookup = IdentityLookup; +// type Block = Block; +// type RuntimeEvent = RuntimeEvent; +// type BlockHashCount = BlockHashCount; +// type BlockWeights = (); +// type BlockLength = (); +// type Version = (); +// type PalletInfo = PalletInfo; +// type AccountData = pallet_balances::AccountData; +// type OnNewAccount = (); +// type OnKilledAccount = (); +// type DbWeight = (); +// type BaseCallFilter = Everything; +// type SystemWeightInfo = (); +// type SS58Prefix = (); +// type OnSetCode = (); +// type MaxConsumers = ConstU32<16>; +// } #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; @@ -399,7 +400,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; } -type Block = frame_system::mocking::MockBlock; construct_runtime!( pub enum Runtime From 89a64141a9ab776ce6c4a11dc92051cf66fd977c Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:10:42 +0200 Subject: [PATCH 31/69] system by laos --- xcm-simulator/src/laosish/configs/mod.rs | 2 +- xcm-simulator/src/laosish/configs/system.rs | 82 +++++++++++++++++++++ xcm-simulator/src/laosish/mod.rs | 1 - 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 xcm-simulator/src/laosish/configs/system.rs diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 5867c2a8..0a7d46f9 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,2 +1,2 @@ mod balances; -mod system; \ No newline at end of file +mod system; diff --git a/xcm-simulator/src/laosish/configs/system.rs b/xcm-simulator/src/laosish/configs/system.rs new file mode 100644 index 00000000..9b9f29ee --- /dev/null +++ b/xcm-simulator/src/laosish/configs/system.rs @@ -0,0 +1,82 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::laosish::{ + AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, + RuntimeEvent, RuntimeOrigin, RuntimeTask, +}; +use frame_support::{parameter_types, traits::Everything}; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; + +parameter_types! { + pub const SS58Prefix: u16 = 42; + pub const BlockHashCount: u32 = 256; +} + +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// The block type + type Block = Block; + /// The type for hashing blocks and tries. + type Hash = laos_primitives::Hash; + /// The type for storing how many extrinsics an account has signed. + type Nonce = laos_primitives::Nonce; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// The aggregated RuntimeTask type. + type RuntimeTask = RuntimeTask; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = BlockHashCount; + /// Runtime version. + type Version = (); + /// Converts a module to an index of this module in the runtime. + type PalletInfo = PalletInfo; + /// The data to be stored in an account. + type AccountData = pallet_balances::AccountData; + /// What to do if a new account is created. + type OnNewAccount = (); + /// What to do if an account is fully reaped from the system. + type OnKilledAccount = (); + /// The weight of database operations that the runtime can invoke. + type DbWeight = (); + /// The basic call filter to use in dispatchable. + type BaseCallFilter = Everything; + /// Weight information for the extrinsics of this pallet. + type SystemWeightInfo = (); + /// Block & extrinsics weights: base values and limits. + type BlockWeights = laos_primitives::RuntimeBlockWeights; + /// The maximum length of a block (in bytes). + type BlockLength = laos_primitives::RuntimeBlockLength; + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = SS58Prefix; + /// The action to take on a Runtime Upgrade + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); +} diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 8c9d90e2..d07937cf 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -400,7 +400,6 @@ impl pallet_xcm::Config for Runtime { type AdminOrigin = EnsureRoot; } - construct_runtime!( pub enum Runtime { From 2d3057142c265a7c0d8c6e54a2b3a6028918c022 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:18:09 +0200 Subject: [PATCH 32/69] remove warning --- xcm-simulator/src/laosish/configs/system.rs | 4 +- xcm-simulator/src/laosish/mod.rs | 61 ++++----------------- 2 files changed, 12 insertions(+), 53 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/system.rs b/xcm-simulator/src/laosish/configs/system.rs index 9b9f29ee..e853005c 100644 --- a/xcm-simulator/src/laosish/configs/system.rs +++ b/xcm-simulator/src/laosish/configs/system.rs @@ -15,8 +15,8 @@ // along with LAOS. If not, see . use crate::laosish::{ - AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, RuntimeTask, + AccountId, Balance, Block, PalletInfo, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + RuntimeTask, }; use frame_support::{parameter_types, traits::Everything}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index d07937cf..81091581 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -21,21 +21,15 @@ mod configs; use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ - construct_runtime, derive_impl, parameter_types, - traits::{ - ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing, - OriginTrait, - }, - weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + construct_runtime, parameter_types, + traits::{ContainsPair, Everything, EverythingBut, Nothing, OriginTrait}, + weights::Weight, }; use sp_runtime::traits::TryConvert; use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; -use sp_core::{ConstU32, H256}; -use sp_runtime::{ - traits::{Get, Hash, IdentityLookup}, - AccountId32, -}; +use sp_core::ConstU32; +use sp_runtime::traits::{Get, Hash}; use sp_std::prelude::*; use pallet_xcm::XcmPassthrough; @@ -45,52 +39,17 @@ use polkadot_parachain_primitives::primitives::{ }; use xcm::{latest::prelude::*, VersionedXcm}; use xcm_builder::{ - Account32Hash, AccountId32Aliases, AccountKey20Aliases, AllowUnpaidExecutionFrom, - ConvertedConcreteId, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, - FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, - NoChecking, NonFungiblesAdapter, ParentIsPreset, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, -}; -use xcm_executor::{ - traits::{ConvertLocation, JustTry}, - Config, XcmExecutor, + AccountKey20Aliases, AllowUnpaidExecutionFrom, EnsureDecodableXcm, EnsureXcmOrigin, + FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, + IsConcrete, NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, + SovereignSignedViaLocation, }; +use xcm_executor::{Config, XcmExecutor}; pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; type Block = frame_system::mocking::MockBlock; -// parameter_types! { -// pub const BlockHashCount: u64 = 250; -// } - -// #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -// impl frame_system::Config for Runtime { -// type RuntimeOrigin = RuntimeOrigin; -// type RuntimeCall = RuntimeCall; -// type Nonce = u64; -// type Hash = H256; -// type Hashing = ::sp_runtime::traits::BlakeTwo256; -// type AccountId = AccountId; -// type Lookup = IdentityLookup; -// type Block = Block; -// type RuntimeEvent = RuntimeEvent; -// type BlockHashCount = BlockHashCount; -// type BlockWeights = (); -// type BlockLength = (); -// type Version = (); -// type PalletInfo = PalletInfo; -// type AccountData = pallet_balances::AccountData; -// type OnNewAccount = (); -// type OnKilledAccount = (); -// type DbWeight = (); -// type BaseCallFilter = Everything; -// type SystemWeightInfo = (); -// type SS58Prefix = (); -// type OnSetCode = (); -// type MaxConsumers = ConstU32<16>; -// } - #[cfg(feature = "runtime-benchmarks")] pub struct UniquesHelper; #[cfg(feature = "runtime-benchmarks")] From b6b086f97e0de98135b47a0db24acf076cdb83e8 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:20:59 +0200 Subject: [PATCH 33/69] removed unused code --- xcm-simulator/src/laosish/mod.rs | 41 ++++---------------------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 81091581..6de28860 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -22,7 +22,7 @@ use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, parameter_types, - traits::{ContainsPair, Everything, EverythingBut, Nothing, OriginTrait}, + traits::{ContainsPair, Everything, Nothing, OriginTrait}, weights::Weight, }; use sp_runtime::traits::TryConvert; @@ -50,24 +50,6 @@ pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; type Block = frame_system::mocking::MockBlock; -#[cfg(feature = "runtime-benchmarks")] -pub struct UniquesHelper; -#[cfg(feature = "runtime-benchmarks")] -impl pallet_uniques::BenchmarkHelper for UniquesHelper { - fn collection(i: u16) -> Location { - GeneralIndex(i as u128).into() - } - fn item(i: u16) -> AssetInstance { - AssetInstance::Index(i as u128) - } -} - -// parameter_types! { -// pub const ReservedXcmpWeight: Weight = -// Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); pub const -// ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); -// } - parameter_types! { pub const KsmLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; @@ -81,18 +63,14 @@ pub type LocationToAccountId = ( AccountKey20Aliases, ); -pub type XcmOriginToCallOrigin = ( - SovereignSignedViaLocation, - // SignedAccountId32AsNative, - XcmPassthrough, -); +pub type XcmOriginToCallOrigin = + (SovereignSignedViaLocation, XcmPassthrough); parameter_types! { pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub ForeignPrefix: Location = (Parent,).into(); } pub type LocalAssetTransactor = @@ -101,23 +79,14 @@ pub type LocalAssetTransactor = pub type XcmRouter = EnsureDecodableXcm>; pub type Barrier = AllowUnpaidExecutionFrom; -parameter_types! { - pub NftCollectionOne: AssetFilter - = Wild(AllOf { fun: WildNonFungible, id: AssetId((Parent, GeneralIndex(1)).into()) }); - pub NftCollectionOneForRelay: (AssetFilter, Location) - = (NftCollectionOne::get(), (Parent,).into()); -} -pub type TrustedTeleporters = xcm_builder::Case; -pub type TrustedReserves = EverythingBut>; - pub struct XcmConfig; impl Config for XcmConfig { type RuntimeCall = RuntimeCall; type XcmSender = XcmRouter; type AssetTransactor = LocalAssetTransactor; type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = (NativeAsset, TrustedReserves); - type IsTeleporter = TrustedTeleporters; + type IsReserve = NativeAsset; + type IsTeleporter = (); type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; From 3e6af1ed3e87b369b132abb44d32fd665434a54d Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:47:26 +0200 Subject: [PATCH 34/69] xcm_config integration --- xcm-simulator/src/laosish/configs/mod.rs | 1 + .../src/laosish/configs/xcm_config.rs | 227 ++++++++++++++++++ xcm-simulator/src/laosish/mod.rs | 69 +----- 3 files changed, 229 insertions(+), 68 deletions(-) create mode 100644 xcm-simulator/src/laosish/configs/xcm_config.rs diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 0a7d46f9..78dc5fb3 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,2 +1,3 @@ mod balances; mod system; +pub mod xcm_config; diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs new file mode 100644 index 00000000..800b9d12 --- /dev/null +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -0,0 +1,227 @@ +// Copyright 2023-2024 Freeverse.io +// This file is part of LAOS. + +// LAOS 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. + +// LAOS 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 LAOS. If not, see . + +use crate::laosish::{ + AccountId, AllPalletsWithSystem, Balances, KsmPerSecondPerByte, MsgQueue, ParachainInfo, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, +}; +use core::marker::PhantomData; +use frame_support::{ + parameter_types, + traits::{ConstU32, Contains, Everything, Nothing, OriginTrait}, + weights::Weight, +}; +use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; +use pallet_xcm::XcmPassthrough; +use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::traits::TryConvert; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, + ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WithComputedOrigin, +}; +use xcm_executor::XcmExecutor; + +parameter_types! { + pub const RelayLocation: Location = Location::parent(); + pub const RelayNetwork: Option = None; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain + // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. + pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); +} + +/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the parent `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId20` origins just alias directly to `AccountId`. + AccountKey20Aliases, +); + +/// Means for transacting assets on this chain. +pub type LocalAssetTransactor = FungibleAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Do a simple pun to convert an AccountId20 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports. + (), +>; + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognized. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognized. + SiblingParachainAsNative, + // Native signed account converter; this just converts an `AccountId20` origin into a normal + // `RuntimeOrigin::Signed` origin of the same 20-byte value. + SignedAccountKey20AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct ParentOrParentsExecutivePlurality; +impl Contains for ParentOrParentsExecutivePlurality { + fn contains(location: &Location) -> bool { + matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }])) + } +} + +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, +>; + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); // Teleporting is disabled. + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; + type HrmpNewChannelOpenRequestHandler = (); + type HrmpChannelAcceptedHandler = (); + type HrmpChannelClosingHandler = (); +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId20; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = staging_xcm_builder::WithUniqueTopic<( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + MsgQueue, +)>; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // ^ Override for AdvertisedXcmVersion default + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub struct SignedToAccountId20( + PhantomData<(RuntimeOrigin, AccountId, Network)>, +); +impl< + RuntimeOrigin: OriginTrait + Clone, + AccountId: Into<[u8; 20]>, + Network: frame_support::traits::Get>, + > TryConvert for SignedToAccountId20 +where + RuntimeOrigin::PalletsOrigin: From> + + TryInto, Error = RuntimeOrigin::PalletsOrigin>, +{ + fn try_convert(o: RuntimeOrigin) -> Result { + o.try_with_caller(|caller| match caller.try_into() { + Ok(SystemRawOrigin::Signed(who)) => + Ok(Junction::AccountKey20 { network: Network::get(), key: who.into() }.into()), + Ok(other) => Err(other.into()), + Err(other) => Err(other), + }) + } +} diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 6de28860..44462d29 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -67,48 +67,7 @@ pub type XcmOriginToCallOrigin = (SovereignSignedViaLocation, XcmPassthrough); parameter_types! { - pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); - pub const MaxInstructions: u32 = 100; - pub const MaxAssetsIntoHolding: u32 = 64; -} - -pub type LocalAssetTransactor = - (FungibleAdapter, LocationToAccountId, AccountId, ()>,); - -pub type XcmRouter = EnsureDecodableXcm>; -pub type Barrier = AllowUnpaidExecutionFrom; - -pub struct XcmConfig; -impl Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToCallOrigin; - type IsReserve = NativeAsset; - type IsTeleporter = (); - type UniversalLocation = UniversalLocation; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; - type ResponseHandler = (); - type AssetTrap = (); - type AssetLocker = PolkadotXcm; - type AssetExchanger = (); - type AssetClaims = (); - type SubscriptionService = (); - type PalletInstancesInfo = (); - type FeeManager = (); - type MaxAssetsIntoHolding = MaxAssetsIntoHolding; - type MessageExporter = (); - type UniversalAliases = Nothing; - type CallDispatcher = RuntimeCall; - type SafeCallFilter = Everything; - type Aliasers = Nothing; - type TransactionalProcessor = FrameTransactionalProcessor; - type HrmpNewChannelOpenRequestHandler = (); - type HrmpChannelAcceptedHandler = (); - type HrmpChannelClosingHandler = (); } #[frame_support::pallet] @@ -266,7 +225,7 @@ pub mod mock_msg_queue { impl mock_msg_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; + type XcmExecutor = XcmExecutor; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -302,32 +261,6 @@ impl> ContainsPair for TrustedL } } -impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Everything; - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Nothing; - type XcmReserveTransferFilter = Everything; - type Weigher = FixedWeightBounds; - type UniversalLocation = UniversalLocation; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; - type Currency = Balances; - type CurrencyMatcher = (); - type TrustedLockers = (); - type SovereignAccountOf = LocationToAccountId; - type MaxLockers = ConstU32<8>; - type MaxRemoteLockConsumers = ConstU32<0>; - type RemoteLockConsumerIdentifier = (); - type WeightInfo = pallet_xcm::TestWeightInfo; - type AdminOrigin = EnsureRoot; -} - construct_runtime!( pub enum Runtime { From fd47237bd22d35866301ea5b9377dea992f8a29a Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:55:11 +0200 Subject: [PATCH 35/69] removed mock --- Cargo.lock | 19 ---- Cargo.toml | 1 - pallets/mock-msg-queue/Cargo.toml | 56 ---------- pallets/mock-msg-queue/README.md | 1 - pallets/mock-msg-queue/src/lib.rs | 163 ------------------------------ runtime/laos/Cargo.toml | 2 - xcm-simulator/Cargo.toml | 2 - 7 files changed, 244 deletions(-) delete mode 100644 pallets/mock-msg-queue/Cargo.toml delete mode 100644 pallets/mock-msg-queue/README.md delete mode 100644 pallets/mock-msg-queue/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ae45cde9..71a453aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5290,7 +5290,6 @@ dependencies = [ "pallet-laos-evolution", "pallet-membership", "pallet-message-queue", - "pallet-mock-msg-queue", "pallet-multisig", "pallet-parachain-staking", "pallet-precompiles-benchmark", @@ -7735,23 +7734,6 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", ] -[[package]] -name = "pallet-mock-msg-queue" -version = "0.0.0" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "scale-info", - "sp-io", - "sp-runtime", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", -] - [[package]] name = "pallet-multisig" version = "28.0.0" @@ -16373,7 +16355,6 @@ dependencies = [ "pallet-laos-evolution", "pallet-membership", "pallet-message-queue", - "pallet-mock-msg-queue", "pallet-multisig", "pallet-parachain-staking", "pallet-precompiles-benchmark", diff --git a/Cargo.toml b/Cargo.toml index 29a946a6..2d5d9046 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,6 @@ pallet-asset-metadata-extender = { path = "./pallets/asset-metadata-extender", d pallet-parachain-staking = { path = "./pallets/parachain-staking", default-features = false } pallet-evm-precompile-parachain-staking = { path = "./precompiles/parachain-staking", default-features = false } pallet-precompiles-benchmark = { path = "./pallets/precompiles-benchmark", default-features = false} -pallet-mock-msg-queue = { path = "./pallets/mock-msg-queue", default-features = false} # Primitives laos-primitives = { path = "./primitives", default-features = false } diff --git a/pallets/mock-msg-queue/Cargo.toml b/pallets/mock-msg-queue/Cargo.toml deleted file mode 100644 index f6de6544..00000000 --- a/pallets/mock-msg-queue/Cargo.toml +++ /dev/null @@ -1,56 +0,0 @@ -[package] -name = "pallet-mock-msg-queue" -description = "FRAME pallet template for defining custom runtime logic." -version = "0.0.0" -license = "MIT-0" -authors.workspace = true -homepage.workspace = true -repository.workspace = true -edition.workspace = true -publish = false - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ - "derive", -] } -scale-info = { version = "2.11.1", default-features = false, features = [ - "derive", -] } - -# frame deps -frame-support = { workspace = true } -frame-system = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } -xcm = { workspace = true } -xcm-executor = { workspace = true } -xcm-builder = { workspace = true } -polkadot-parachain-primitives = { workspace = true } -polkadot-core-primitives = { workspace = true } - -[features] -default = ["std"] -runtime-benchmarks = [ - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", -] -std = [ - "codec/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "xcm/std", - "xcm-executor/std", - "xcm-builder/std", - "polkadot-parachain-primitives/std", - "polkadot-core-primitives/std" -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", -] diff --git a/pallets/mock-msg-queue/README.md b/pallets/mock-msg-queue/README.md deleted file mode 100644 index 9e4dc552..00000000 --- a/pallets/mock-msg-queue/README.md +++ /dev/null @@ -1 +0,0 @@ -License: MIT-0 diff --git a/pallets/mock-msg-queue/src/lib.rs b/pallets/mock-msg-queue/src/lib.rs deleted file mode 100644 index 15c0306a..00000000 --- a/pallets/mock-msg-queue/src/lib.rs +++ /dev/null @@ -1,163 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -use frame_support::pallet_prelude::*; -pub use pallet::*; -use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, -}; -use scale_info::prelude::vec::Vec; -use sp_runtime::traits::{Get, Hash}; -use xcm::{latest::prelude::*, VersionedXcm}; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type XcmExecutor: ExecuteXcm; - } - - #[pallet::call] - impl Pallet {} - - #[pallet::storage] - #[pallet::getter(fn parachain_id)] - pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - - #[pallet::storage] - #[pallet::getter(fn received_dmp)] - /// A queue of received DMP messages - pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; - - impl Get for Pallet { - fn get() -> ParaId { - Self::parachain_id() - } - } - - pub type MessageId = [u8; 32]; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - // XCMP - /// Some XCM was executed OK. - Success(Option), - /// Some XCM failed. - Fail(Option, XcmError), - /// Bad XCM version used. - BadVersion(Option), - /// Bad XCM format used. - BadFormat(Option), - - // DMP - /// Downward message is invalid XCM. - InvalidFormat(MessageId), - /// Downward message is unsupported version of XCM. - UnsupportedVersion(MessageId), - /// Downward message executed with the given outcome. - ExecutedDownward(MessageId, Outcome), - } - - impl Pallet { - pub fn set_para_id(para_id: ParaId) { - ParachainId::::put(para_id); - } - - fn handle_xcmp_message( - sender: ParaId, - _sent_at: RelayBlockNumber, - xcm: VersionedXcm, - max_weight: Weight, - ) -> Result { - let hash = Encode::using_encoded(&xcm, T::Hashing::hash); - let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); - let (result, event) = match Xcm::::try_from(xcm) { - Ok(xcm) => { - let location = (Parent, Parachain(sender.into())); - match T::XcmExecutor::prepare_and_execute( - location, - xcm, - &mut message_hash, - max_weight, - Weight::zero(), - ) { - Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), - Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), - // As far as the caller is concerned, this was dispatched without error, so - // we just report the weight used. - Outcome::Incomplete { used, error } => - (Ok(used), Event::Fail(Some(hash), error)), - } - }, - Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), - }; - Self::deposit_event(event); - result - } - } - - impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - max_weight: Weight, - ) -> Weight { - for (sender, sent_at, data) in iter { - let mut data_ref = data; - let _ = XcmpMessageFormat::decode(&mut data_ref) - .expect("Simulator encodes with versioned xcm format; qed"); - - let mut remaining_fragments = data_ref; - while !remaining_fragments.is_empty() { - if let Ok(xcm) = - VersionedXcm::::decode(&mut remaining_fragments) - { - let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); - } else { - debug_assert!(false, "Invalid incoming XCMP message data"); - } - } - } - max_weight - } - } - - impl DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - for (_i, (_sent_at, data)) in iter.enumerate() { - let mut id = sp_io::hashing::blake2_256(&data[..]); - let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); - match maybe_versioned { - Err(_) => { - Self::deposit_event(Event::InvalidFormat(id)); - }, - Ok(versioned) => match Xcm::try_from(versioned) { - Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), - Ok(x) => { - let outcome = T::XcmExecutor::prepare_and_execute( - Parent, - x.clone(), - &mut id, - limit, - Weight::zero(), - ); - >::append(x); - Self::deposit_event(Event::ExecutedDownward(id, outcome)); - }, - }, - } - } - limit - } - } -} diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index 37417b93..6c85b6c2 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -71,7 +71,6 @@ pallet-asset-metadata-extender = { workspace = true } pallet-laos-evolution = { workspace = true } pallet-parachain-staking = { workspace = true } pallet-precompiles-benchmark = { workspace = true } -pallet-mock-msg-queue = { workspace = true } # Polkadot @@ -156,7 +155,6 @@ std = [ "pallet-scheduler/std", "pallet-laos-evolution/std", "pallet-asset-metadata-extender/std", - "pallet-mock-msg-queue/std", "pallet-multisig/std", "pallet-timestamp/std", "pallet-identity/std", diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index f9787678..270da56d 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -66,7 +66,6 @@ pallet-asset-metadata-extender = { workspace = true } pallet-laos-evolution = { workspace = true } pallet-parachain-staking = { workspace = true } pallet-precompiles-benchmark = { workspace = true } -pallet-mock-msg-queue = { workspace = true } # Polkadot @@ -165,7 +164,6 @@ std = [ "pallet-scheduler/std", "pallet-laos-evolution/std", "pallet-asset-metadata-extender/std", - "pallet-mock-msg-queue/std", "pallet-multisig/std", "pallet-timestamp/std", "pallet-identity/std", From eb29d463273ba6d25b8fd57f63d7385d5de09a01 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Wed, 2 Oct 2024 16:57:36 +0200 Subject: [PATCH 36/69] rollback some changes --- runtime/laos/src/configs/xcm_config.rs | 4 ++-- runtime/laos/src/lib.rs | 1 - runtime/laos/src/tests/mod.rs | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/laos/src/configs/xcm_config.rs b/runtime/laos/src/configs/xcm_config.rs index 7aff6598..314fcdf9 100644 --- a/runtime/laos/src/configs/xcm_config.rs +++ b/runtime/laos/src/configs/xcm_config.rs @@ -15,8 +15,8 @@ // along with LAOS. If not, see . use crate::{ - types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, ParachainInfo, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, }; use core::marker::PhantomData; use frame_support::{ diff --git a/runtime/laos/src/lib.rs b/runtime/laos/src/lib.rs index ae527b3b..56ee9489 100644 --- a/runtime/laos/src/lib.rs +++ b/runtime/laos/src/lib.rs @@ -129,7 +129,6 @@ construct_runtime!( CumulusXcm: cumulus_pallet_xcm = 32, // DmpQueue: cumulus_pallet_dmp_queue = 33, MessageQueue: pallet_message_queue = 34, - MsgQueue: pallet_mock_msg_queue = 35, // Governance Council: pallet_collective:: = 40, diff --git a/runtime/laos/src/tests/mod.rs b/runtime/laos/src/tests/mod.rs index 1c9a7e7f..35b9a8e7 100644 --- a/runtime/laos/src/tests/mod.rs +++ b/runtime/laos/src/tests/mod.rs @@ -18,7 +18,6 @@ mod precompile_tests; mod version_tests; - use core::str::FromStr; use sp_runtime::BuildStorage; From 8885a9e952ed5c47e9ade42e75ac044fcbc8883d Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 10:28:27 +0200 Subject: [PATCH 37/69] remove staging_ --- xcm-simulator/src/laosish/configs/xcm_config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 800b9d12..6144a710 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -165,7 +165,7 @@ pub type LocalOriginToLocation = SignedToAccountId20, // ..and XCMP to communicate with the sibling chains. From 1ed113e7cc3440fe65b827e39f50be3a26817267 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 10:32:13 +0200 Subject: [PATCH 38/69] ParachainInfo integrated --- xcm-simulator/src/laosish/configs/mod.rs | 6 +++++- xcm-simulator/src/laosish/mod.rs | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index 78dc5fb3..d016b57a 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,3 +1,7 @@ mod balances; mod system; -pub mod xcm_config; +// pub mod xcm_config; + +use crate::laosish::Runtime; + +impl parachain_info::Config for Runtime {} diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 44462d29..1de9fe0e 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -225,7 +225,7 @@ pub mod mock_msg_queue { impl mock_msg_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; + type XcmExecutor = (); // XcmExecutor; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -265,8 +265,10 @@ construct_runtime!( pub enum Runtime { System: frame_system, + // ParachainSystem: cumulus_pallet_parachain_system, + ParachainInfo: parachain_info, Balances: pallet_balances, MsgQueue: mock_msg_queue, - PolkadotXcm: pallet_xcm, + // PolkadotXcm: pallet_xcm, } ); From 6e231208bbf92de25cbf43bfae7b0a426bd06016 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 10:40:05 +0200 Subject: [PATCH 39/69] facing xcm_cofig --- xcm-simulator/src/laosish/configs/mod.rs | 2 +- xcm-simulator/src/laosish/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/mod.rs b/xcm-simulator/src/laosish/configs/mod.rs index d016b57a..2d07fc85 100644 --- a/xcm-simulator/src/laosish/configs/mod.rs +++ b/xcm-simulator/src/laosish/configs/mod.rs @@ -1,6 +1,6 @@ mod balances; mod system; -// pub mod xcm_config; +pub mod xcm_config; use crate::laosish::Runtime; diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 1de9fe0e..04dfb6de 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -225,7 +225,7 @@ pub mod mock_msg_queue { impl mock_msg_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type XcmExecutor = (); // XcmExecutor; + type XcmExecutor = XcmExecutor; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -269,6 +269,6 @@ construct_runtime!( ParachainInfo: parachain_info, Balances: pallet_balances, MsgQueue: mock_msg_queue, - // PolkadotXcm: pallet_xcm, + PolkadotXcm: pallet_xcm, } ); From 4e71706b14ac6c1cf8a68d5b0c758f41999b0ba5 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 11:14:06 +0200 Subject: [PATCH 40/69] remove warning --- .../src/laosish/configs/xcm_config.rs | 31 ++++--------------- xcm-simulator/src/laosish/mod.rs | 29 +++-------------- 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 6144a710..e4e4966d 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -31,18 +31,18 @@ use sp_runtime::traits::TryConvert; use xcm::latest::prelude::*; use xcm_builder::{ AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, - DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedRateOfFungible, - FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, - ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + DenyReserveTransferToRelayChain, DenyThenTry, EnsureDecodableXcm, EnsureXcmOrigin, + FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, + IsConcrete, NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WithComputedOrigin, + WithComputedOrigin, }; use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = None; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); @@ -82,12 +82,6 @@ pub type XcmOriginToTransactDispatchOrigin = ( // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for // foreign chains who want to have a local sovereign account on this chain which they control. SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when - // recognized. - RelayChainAsNative, - // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // recognized. - SiblingParachainAsNative, // Native signed account converter; this just converts an `AccountId20` origin into a normal // `RuntimeOrigin::Signed` origin of the same 20-byte value. SignedAccountKey20AsNative, @@ -162,15 +156,7 @@ impl xcm_executor::Config for XcmConfig { /// No local origins on this chain are allowed to dispatch XCM sends/executions. pub type LocalOriginToLocation = SignedToAccountId20; - -/// The means for routing XCM messages which are not for local execution into the right message -/// queues. -pub type XcmRouter = xcm_builder::WithUniqueTopic<( - // Two routers - use UMP to communicate with the relay chain: - cumulus_primitives_utility::ParentAsUmp, - // ..and XCMP to communicate with the sibling chains. - MsgQueue, -)>; +pub type XcmRouter = EnsureDecodableXcm>; impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -199,11 +185,6 @@ impl pallet_xcm::Config for Runtime { type RemoteLockConsumerIdentifier = (); } -impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 04dfb6de..981dfc38 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -22,29 +22,21 @@ use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, parameter_types, - traits::{ContainsPair, Everything, Nothing, OriginTrait}, + traits::{ContainsPair, OriginTrait}, weights::Weight, }; use sp_runtime::traits::TryConvert; -use frame_system::{EnsureRoot, RawOrigin as SystemRawOrigin}; -use sp_core::ConstU32; +use frame_system::RawOrigin as SystemRawOrigin; use sp_runtime::traits::{Get, Hash}; use sp_std::prelude::*; -use pallet_xcm::XcmPassthrough; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, + DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, }; use xcm::{latest::prelude::*, VersionedXcm}; -use xcm_builder::{ - AccountKey20Aliases, AllowUnpaidExecutionFrom, EnsureDecodableXcm, EnsureXcmOrigin, - FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, - IsConcrete, NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, - SovereignSignedViaLocation, -}; -use xcm_executor::{Config, XcmExecutor}; +use xcm_executor::XcmExecutor; pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; @@ -56,16 +48,6 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); } -pub type LocationToAccountId = ( - ParentIsPreset, - SiblingParachainConvertsVia, - // Straight up local `AccountId20` origins just alias directly to `AccountId`. - AccountKey20Aliases, -); - -pub type XcmOriginToCallOrigin = - (SovereignSignedViaLocation, XcmPassthrough); - parameter_types! { pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); } @@ -228,9 +210,6 @@ impl mock_msg_queue::Config for Runtime { type XcmExecutor = XcmExecutor; } -/// No local origins on this chain are allowed to dispatch XCM sends/executions. -pub type LocalOriginToLocation = SignedToAccountId20; - pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); From ef19cfa7b558dc7660fa7d164a7ab11316acb014 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 12:21:20 +0200 Subject: [PATCH 41/69] fixing Cargo.toml --- Cargo.lock | 81 ++------------ Cargo.toml | 2 + xcm-simulator/Cargo.toml | 234 ++++++--------------------------------- 3 files changed, 46 insertions(+), 271 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71a453aa..71c5f9cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13272,7 +13272,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13334,7 +13334,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "proc-macro2", "quote", @@ -13354,7 +13354,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "environmental", "parity-scale-codec", @@ -13569,7 +13569,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13601,7 +13601,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "Inflector", "expander 2.2.1", @@ -13690,7 +13690,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" [[package]] name = "sp-storage" @@ -13707,7 +13707,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13742,7 +13742,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "parity-scale-codec", "tracing", @@ -13839,7 +13839,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8279d1046cca51a317dec15df5a9b29240545163" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -16314,87 +16314,24 @@ dependencies = [ name = "xcm-simulator-example" version = "7.0.0" dependencies = [ - "cumulus-pallet-aura-ext", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-timestamp", - "cumulus-primitives-utility", - "fp-evm", - "fp-rpc", - "fp-self-contained", - "frame-benchmarking", - "frame-executive", "frame-support", "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "hex", "laos-primitives", "log", - "pallet-asset-metadata-extender", - "pallet-aura", - "pallet-authorship", "pallet-balances", - "pallet-base-fee", - "pallet-collective", - "pallet-democracy", - "pallet-elections-phragmen", - "pallet-ethereum", - "pallet-evm", - "pallet-evm-chain-id", - "pallet-evm-precompile-blake2", - "pallet-evm-precompile-bn128", - "pallet-evm-precompile-modexp", - "pallet-evm-precompile-parachain-staking", - "pallet-evm-precompile-simple", - "pallet-identity", - "pallet-laos-evolution", - "pallet-membership", "pallet-message-queue", - "pallet-multisig", - "pallet-parachain-staking", - "pallet-precompiles-benchmark", - "pallet-preimage", - "pallet-proxy", - "pallet-scheduler", - "pallet-session", - "pallet-sudo", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-treasury", "pallet-uniques", - "pallet-utility", - "pallet-vesting", "pallet-xcm", - "parachains-common", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain-primitives", - "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-consensus-slots", "sp-core", - "sp-genesis-builder", - "sp-inherents", "sp-io", - "sp-offchain", "sp-runtime", - "sp-session", - "sp-staking", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "sp-transaction-pool", - "sp-version", - "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", diff --git a/Cargo.toml b/Cargo.toml index 2d5d9046..540f5be9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch sp-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } sp-weights ={ git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } sp-genesis-builder ={ git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +sp-tracing ={ git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } # (native) sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0" } @@ -125,6 +126,7 @@ pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } +pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } pallet-vesting = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 270da56d..f424b174 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -6,219 +6,55 @@ edition.workspace = true version = "7.0.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -scale-info = { workspace = true } +codec = { package = "parity-scale-codec", version = "3.6.1" } +scale-info = { version = "2.11.1", features = ["derive"] } log = { workspace = true } -sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.11.0", default-features = false } -polkadot-runtime-parachains = { workspace = true } -polkadot-core-primitives = { workspace = true } -laos-primitives = { workspace = true } - -# Substrate -frame-benchmarking = { workspace = true, optional = true } -frame-executive = { workspace = true } -frame-support = { workspace = true } frame-system = { workspace = true } -frame-system-benchmarking = { workspace = true, optional = true } -frame-system-rpc-runtime-api = { workspace = true } -frame-try-runtime = { workspace = true, optional = true } -pallet-aura = { workspace = true } -pallet-scheduler = { workspace = true } -pallet-authorship = { workspace = true } -pallet-balances = { workspace = true , features = ["insecure_zero_ed"] } +frame-support = { workspace = true } +pallet-balances = { workspace = true } pallet-message-queue = { workspace = true } -pallet-multisig = { workspace = true } -pallet-session = { workspace = true } -pallet-identity = { workspace = true } -pallet-sudo = { workspace = true } -pallet-democracy = { workspace = true } -pallet-treasury = { workspace = true } -pallet-preimage = { workspace = true } -pallet-timestamp = { workspace = true } -pallet-collective = { workspace = true } -pallet-membership ={ workspace = true } -pallet-elections-phragmen = { workspace = true } -pallet-transaction-payment = { workspace = true } -pallet-transaction-payment-rpc-runtime-api = { workspace = true } -pallet-vesting = { workspace = true } -pallet-proxy = { workspace = true } -pallet-utility = { workspace = true } -sp-api = { workspace = true } -sp-io = { workspace = true } -sp-block-builder = { workspace = true } -sp-consensus-aura = { workspace = true } -sp-consensus-slots = { workspace = true } +pallet-uniques = { workspace = true } +sp-std = { workspace = true } sp-core = { workspace = true } -sp-inherents = { workspace = true } -sp-offchain = { workspace = true } sp-runtime = { workspace = true } -sp-session = { workspace = true } -sp-std = { workspace = true } -sp-transaction-pool = { workspace = true } -sp-version = { workspace = true } -sp-staking = { workspace = true } -sp-weights ={ workspace = true } -sp-genesis-builder ={ workspace = true } - -pallet-asset-metadata-extender = { workspace = true } -pallet-laos-evolution = { workspace = true } -pallet-parachain-staking = { workspace = true } -pallet-precompiles-benchmark = { workspace = true } - +sp-io = { workspace = true } +sp-tracing = { workspace = true } -# Polkadot -pallet-xcm = { workspace = true } -polkadot-runtime-common = { workspace = true } -polkadot-parachain-primitives = { workspace = true } xcm = { workspace = true } -xcm-builder = { workspace = true } +xcm-simulator = { workspace = true } xcm-executor = { workspace = true } - -# Cumulus -cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } -cumulus-pallet-session-benchmarking = { workspace = true, optional = true} -cumulus-pallet-xcm = { workspace = true } -cumulus-pallet-xcmp-queue = { workspace = true } -cumulus-primitives-core = { workspace = true } -cumulus-primitives-timestamp = { workspace = true } -cumulus-primitives-utility = { workspace = true } +xcm-builder = { workspace = true } +pallet-xcm = { workspace = true } +polkadot-core-primitives = { workspace = true } +polkadot-runtime-parachains = { workspace = true } +polkadot-parachain-primitives = { workspace = true } +laos-primitives = { workspace = true } parachain-info = { workspace = true } -parachains-common = { workspace = true } -xcm-simulator = { workspace = true } - -# Frontier -fp-evm = { workspace = true } -fp-rpc = { workspace = true } -fp-self-contained = { workspace = true, features = ["serde"] } - -# Frontier FRAME -pallet-base-fee = { workspace = true } -pallet-evm = { workspace = true } -pallet-ethereum = { workspace = true } -pallet-evm-chain-id = { workspace = true } -pallet-evm-precompile-modexp = { workspace = true } -pallet-evm-precompile-simple = { workspace = true } -pallet-evm-precompile-bn128 = { workspace = true } -pallet-evm-precompile-blake2 = { workspace = true } -pallet-evm-precompile-parachain-staking = { workspace = true } - -hex = { workspace = true } [features] default = ["std"] std = [ - "cumulus-primitives-utility/std", - "cumulus-pallet-parachain-system/std", - "pallet-transaction-payment/std", - "fp-rpc/std", - "cumulus-pallet-xcm/std", "parachain-info/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "pallet-message-queue/std", - "pallet-xcm/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-parachains/std", - "sp-runtime/std", - "sp-tracing/std", - "pallet-uniques/std", "laos-primitives/std", - "sp-std/std", - "sp-io/std", - "sp-core/std", - "sp-runtime/std", - "polkadot-core-primitives/std", - "xcm/std", - "xcm-builder/std", - "xcm-executor/std", - "scale-info/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "pallet-message-queue/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "parachains-common/std", - "frame-executive/std", - "frame-support/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-elections-phragmen/std", - "pallet-session/std", - "pallet-democracy/std", - "pallet-sudo/std", - "pallet-treasury/std", - "pallet-collective/std", - "pallet-membership/std", - "pallet-preimage/std", - "pallet-scheduler/std", - "pallet-laos-evolution/std", - "pallet-asset-metadata-extender/std", - "pallet-multisig/std", - "pallet-timestamp/std", - "pallet-identity/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-vesting/std", - "pallet-precompiles-benchmark/std", - "pallet-transaction-payment/std", - "pallet-xcm/std", - "parachain-info/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-io/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "sp-weights/std", - "sp-genesis-builder/std", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", - # Frontier - "fp-evm/std", - "fp-rpc/std", - "fp-self-contained/std", - # Frontier FRAME - "pallet-base-fee/std", - "pallet-ethereum/std", - "pallet-evm/std", - "pallet-evm-chain-id/std", - "pallet-evm-precompile-modexp/std", - "pallet-evm-precompile-simple/std", - "pallet-evm-precompile-bn128/std", - "pallet-evm-precompile-blake2/std", - "pallet-evm-precompile-parachain-staking/std", - "cumulus-pallet-session-benchmarking?/std", - "frame-benchmarking?/std", - "frame-system-benchmarking?/std", - "frame-try-runtime?/std", - # Bridge deps, - "laos-primitives/std", - "hex/std", - "pallet-parachain-staking/std", - "log/std", - "sp-consensus-slots/std", - "sp-staking/std", - "pallet-utility/std", - "pallet-proxy/std", + "frame-system/std", + "frame-support/std", + "pallet-balances/std", + "pallet-message-queue/std", + "pallet-uniques/std", + "sp-std/std", + "sp-core/std", + "sp-runtime/std", + "sp-io/std", + "sp-tracing/std", + "xcm/std", + "xcm-executor/std", + "xcm-builder/std", + "pallet-xcm/std", + "polkadot-core-primitives/std", + "polkadot-runtime-parachains/std", + "polkadot-parachain-primitives/std" ] runtime-benchmarks = [ "frame-support/runtime-benchmarks", @@ -230,6 +66,6 @@ runtime-benchmarks = [ "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-parachains/runtime-benchmarks", "sp-runtime/runtime-benchmarks", -# "xcm-builder/runtime-benchmarks", -# "xcm-executor/runtime-benchmarks", -] + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", +] \ No newline at end of file From a14f538ee69e2bddd4b79d71a4d8ee7f884316d3 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 16:01:22 +0200 Subject: [PATCH 42/69] using Cargo.lock of main --- Cargo.lock | 253 +++++++++++++++++++---------------------------------- 1 file changed, 88 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71c5f9cb..49971e44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -466,7 +466,7 @@ dependencies = [ "ark-ff", "ark-serialize", "ark-std", - "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", + "ark-transcript", "digest 0.10.7", "getrandom_or_panic", "zeroize", @@ -506,20 +506,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "ark-transcript" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "563084372d89271122bd743ef0a608179726f5fad0566008ba55bd0f756489b8" -dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "digest 0.10.7", - "rand_core 0.6.4", - "sha3", -] - [[package]] name = "ark-transcript" version = "0.0.2" @@ -778,7 +764,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -823,7 +809,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -951,7 +937,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -1456,7 +1442,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -1516,7 +1502,7 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" +source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" dependencies = [ "ark-ec", "ark-ff", @@ -1525,7 +1511,8 @@ dependencies = [ "ark-std", "fflonk", "getrandom_or_panic", - "rand_core 0.6.4", + "merlin", + "rand_chacha 0.3.1", ] [[package]] @@ -2168,7 +2155,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2491,7 +2478,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2531,7 +2518,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2548,7 +2535,7 @@ checksum = "35de3b547387863c8f82013c4f79f1c2162edee956383e4089e1d04c18c4f16c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2642,7 +2629,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2655,7 +2642,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2744,7 +2731,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -2758,7 +2745,7 @@ dependencies = [ "ark-secret-scalar", "ark-serialize", "ark-std", - "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", + "ark-transcript", "arrayvec 0.7.4", "zeroize", ] @@ -2784,7 +2771,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.79", + "syn 2.0.74", "termcolor", "toml 0.8.19", "walkdir", @@ -2989,7 +2976,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3009,7 +2996,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3020,7 +3007,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3236,7 +3223,7 @@ dependencies = [ "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3842,7 +3829,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3965,7 +3952,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3977,7 +3964,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -3987,7 +3974,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -4177,7 +4164,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -5031,7 +5018,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -5335,7 +5322,6 @@ dependencies = [ "staging-xcm-executor", "substrate-wasm-builder", "test-utils", - "xcm-simulator", ] [[package]] @@ -6060,7 +6046,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6074,7 +6060,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6085,7 +6071,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6096,7 +6082,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6341,7 +6327,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6473,7 +6459,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", "synstructure 0.13.1", ] @@ -6521,7 +6507,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6830,7 +6816,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -6913,7 +6899,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -8126,7 +8112,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -8283,21 +8269,6 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", ] -[[package]] -name = "pallet-uniques" -version = "28.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", -] - [[package]] name = "pallet-utility" version = "28.0.0" @@ -8630,7 +8601,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -8671,7 +8642,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -9841,7 +9812,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -9851,7 +9822,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10050,7 +10021,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10143,7 +10114,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10189,7 +10160,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10257,7 +10228,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10383,9 +10354,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -10591,7 +10562,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -10686,18 +10657,18 @@ dependencies = [ [[package]] name = "ring" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" +source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" dependencies = [ "ark-ec", "ark-ff", "ark-poly", "ark-serialize", "ark-std", - "ark-transcript 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.7.4", "blake2 0.10.6", "common", "fflonk", + "merlin", ] [[package]] @@ -11282,7 +11253,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -12285,7 +12256,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -12564,9 +12535,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] @@ -12582,13 +12553,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13036,7 +13007,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13272,7 +13243,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13309,7 +13280,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13328,17 +13299,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13354,7 +13325,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "environmental", "parity-scale-codec", @@ -13569,7 +13540,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13595,20 +13566,20 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "Inflector", "expander 2.2.1", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13690,7 +13661,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" [[package]] name = "sp-storage" @@ -13707,7 +13678,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13742,7 +13713,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ "parity-scale-codec", "tracing", @@ -13821,7 +13792,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -13839,9 +13810,8 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" +source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" dependencies = [ - "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -14222,7 +14192,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14373,9 +14343,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" dependencies = [ "proc-macro2", "quote", @@ -14402,7 +14372,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14506,7 +14476,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14517,7 +14487,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14660,7 +14630,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14855,7 +14825,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -14898,7 +14868,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -15349,7 +15319,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", "wasm-bindgen-shared", ] @@ -15383,7 +15353,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -16289,54 +16259,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.79", -] - -[[package]] -name = "xcm-simulator" -version = "7.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" -dependencies = [ - "frame-support", - "parity-scale-codec", - "paste", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-parachains", - "sp-io", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", -] - -[[package]] -name = "xcm-simulator-example" -version = "7.0.0" -dependencies = [ - "frame-support", - "frame-system", - "laos-primitives", - "log", - "pallet-balances", - "pallet-message-queue", - "pallet-uniques", - "pallet-xcm", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-parachains", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", - "staging-parachain-info", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "xcm-simulator", + "syn 2.0.74", ] [[package]] @@ -16380,7 +16303,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] @@ -16400,7 +16323,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.74", ] [[package]] From f14517539d6e5324efcb113413781e942d0690b1 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 17:03:23 +0200 Subject: [PATCH 43/69] using workspace deps --- Cargo.lock | 252 ++++++++++++++++++++----------- runtime/laos/Cargo.toml | 1 - xcm-simulator/Cargo.toml | 4 +- xcm-simulator/src/laosish/mod.rs | 2 +- xcm-simulator/src/parachain.rs | 2 +- 5 files changed, 168 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 49971e44..bcf3961f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -466,7 +466,7 @@ dependencies = [ "ark-ff", "ark-serialize", "ark-std", - "ark-transcript", + "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", "digest 0.10.7", "getrandom_or_panic", "zeroize", @@ -506,6 +506,20 @@ dependencies = [ "rayon", ] +[[package]] +name = "ark-transcript" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "563084372d89271122bd743ef0a608179726f5fad0566008ba55bd0f756489b8" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "digest 0.10.7", + "rand_core 0.6.4", + "sha3", +] + [[package]] name = "ark-transcript" version = "0.0.2" @@ -764,7 +778,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -809,7 +823,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -937,7 +951,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -1442,7 +1456,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -1502,7 +1516,7 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" dependencies = [ "ark-ec", "ark-ff", @@ -1511,8 +1525,7 @@ dependencies = [ "ark-std", "fflonk", "getrandom_or_panic", - "merlin", - "rand_chacha 0.3.1", + "rand_core 0.6.4", ] [[package]] @@ -2155,7 +2168,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2478,7 +2491,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2518,7 +2531,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2535,7 +2548,7 @@ checksum = "35de3b547387863c8f82013c4f79f1c2162edee956383e4089e1d04c18c4f16c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2629,7 +2642,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2642,7 +2655,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2731,7 +2744,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2745,7 +2758,7 @@ dependencies = [ "ark-secret-scalar", "ark-serialize", "ark-std", - "ark-transcript", + "ark-transcript 0.0.2 (git+https://github.com/w3f/ring-vrf?rev=e9782f9)", "arrayvec 0.7.4", "zeroize", ] @@ -2771,7 +2784,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.74", + "syn 2.0.79", "termcolor", "toml 0.8.19", "walkdir", @@ -2976,7 +2989,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -2996,7 +3009,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3007,7 +3020,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3223,7 +3236,7 @@ dependencies = [ "prettyplease 0.2.20", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3829,7 +3842,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3952,7 +3965,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3964,7 +3977,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -3974,7 +3987,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -4164,7 +4177,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -5018,7 +5031,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6046,7 +6059,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6060,7 +6073,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6071,7 +6084,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6082,7 +6095,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6327,7 +6340,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6459,7 +6472,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "synstructure 0.13.1", ] @@ -6507,7 +6520,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6816,7 +6829,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -6899,7 +6912,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8112,7 +8125,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8269,6 +8282,21 @@ dependencies = [ "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", ] +[[package]] +name = "pallet-uniques" +version = "28.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", +] + [[package]] name = "pallet-utility" version = "28.0.0" @@ -8601,7 +8629,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -8642,7 +8670,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -9812,7 +9840,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -9822,7 +9850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10021,7 +10049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10114,7 +10142,7 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10160,7 +10188,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10228,7 +10256,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10354,9 +10382,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -10562,7 +10590,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -10657,18 +10685,18 @@ dependencies = [ [[package]] name = "ring" version = "0.1.0" -source = "git+https://github.com/w3f/ring-proof#665f5f51af5734c7b6d90b985dd6861d4c5b4752" +source = "git+https://github.com/w3f/ring-proof#652286c32f96beb9ce7f5793f5e2c2c923f63b73" dependencies = [ "ark-ec", "ark-ff", "ark-poly", "ark-serialize", "ark-std", + "ark-transcript 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.7.4", "blake2 0.10.6", "common", "fflonk", - "merlin", ] [[package]] @@ -11253,7 +11281,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -12256,7 +12284,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -12535,9 +12563,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -12553,13 +12581,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13007,7 +13035,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13243,7 +13271,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -13280,7 +13308,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "quote", "sp-crypto-hashing", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13299,17 +13327,17 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13325,7 +13353,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "environmental", "parity-scale-codec", @@ -13540,7 +13568,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13566,20 +13594,20 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "Inflector", "expander 2.2.1", "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13661,7 +13689,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" [[package]] name = "sp-storage" @@ -13678,7 +13706,7 @@ dependencies = [ [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13713,7 +13741,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ "parity-scale-codec", "tracing", @@ -13792,7 +13820,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -13810,8 +13838,9 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#4780e3d07ff23a49e8f0a508138f83eb6e0d36c6" +source = "git+https://github.com/paritytech/polkadot-sdk#8614dc0e055d06de4a3774ac1da0a422b33f34e2" dependencies = [ + "anyhow", "impl-trait-for-tuples", "log", "parity-scale-codec", @@ -14192,7 +14221,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14343,9 +14372,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.74" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -14372,7 +14401,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14476,7 +14505,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14487,7 +14516,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14630,7 +14659,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14825,7 +14854,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -14868,7 +14897,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -15319,7 +15348,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -15353,7 +15382,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -16259,7 +16288,54 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", +] + +[[package]] +name = "xcm-simulator" +version = "7.0.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0#8c8edacf8942298c3807a2e192860da9e7e4996a" +dependencies = [ + "frame-support", + "parity-scale-codec", + "paste", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "sp-io", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "xcm-simulator-example" +version = "7.0.0" +dependencies = [ + "frame-support", + "frame-system", + "laos-primitives", + "log", + "pallet-balances", + "pallet-message-queue", + "pallet-uniques", + "pallet-xcm", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "sp-tracing 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.11.0)", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-simulator", ] [[package]] @@ -16303,7 +16379,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] @@ -16323,7 +16399,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn 2.0.79", ] [[package]] diff --git a/runtime/laos/Cargo.toml b/runtime/laos/Cargo.toml index 6c85b6c2..74110597 100644 --- a/runtime/laos/Cargo.toml +++ b/runtime/laos/Cargo.toml @@ -92,7 +92,6 @@ cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -xcm-simulator = { workspace = true } # Frontier fp-evm = { workspace = true } diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index f424b174..bf71fa1e 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -6,8 +6,8 @@ edition.workspace = true version = "7.0.0" [dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1" } -scale-info = { version = "2.11.1", features = ["derive"] } +parity-scale-codec = { workspace = true } +scale-info = { workspace = true } log = { workspace = true } frame-system = { workspace = true } diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 981dfc38..36d21f28 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -18,13 +18,13 @@ mod configs; -use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, parameter_types, traits::{ContainsPair, OriginTrait}, weights::Weight, }; +use parity_scale_codec::{Decode, Encode}; use sp_runtime::traits::TryConvert; use frame_system::RawOrigin as SystemRawOrigin; diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index 41e62596..a681c1ce 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -16,13 +16,13 @@ //! Parachain runtime mock. -use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; +use parity_scale_codec::{Decode, Encode}; use frame_system::EnsureRoot; use sp_core::{ConstU32, H256}; From 558d2d85a0be52687dd47ba24e27c3cbfe5a0de1 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 17:08:40 +0200 Subject: [PATCH 44/69] fix comoilation --- xcm-simulator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 9d935c1d..560fb7d5 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -143,7 +143,7 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet; mod tests { use super::*; - use codec::Encode; + use parity_scale_codec::Encode; use frame_support::{assert_ok, weights::Weight}; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; From 9609540bb3a67d3f47a4eb442beedf6a68ba0038 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Thu, 3 Oct 2024 17:18:50 +0200 Subject: [PATCH 45/69] fmt --- xcm-simulator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 560fb7d5..bd4ac62b 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -143,8 +143,8 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet; mod tests { use super::*; - use parity_scale_codec::Encode; use frame_support::{assert_ok, weights::Weight}; + use parity_scale_codec::Encode; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; From b9534fe3826f6b5995b20e1281f7a9ef2c9cf369 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 10:01:43 +0200 Subject: [PATCH 46/69] refactoring --- xcm-simulator/src/laosish/configs/xcm_config.rs | 9 +++++++-- xcm-simulator/src/laosish/mod.rs | 7 ------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index e4e4966d..b00de44b 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -15,8 +15,8 @@ // along with LAOS. If not, see . use crate::laosish::{ - AccountId, AllPalletsWithSystem, Balances, KsmPerSecondPerByte, MsgQueue, ParachainInfo, - PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + mock_msg_queue, AccountId, AllPalletsWithSystem, Balances, KsmPerSecondPerByte, MsgQueue, + ParachainInfo, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, }; use core::marker::PhantomData; use frame_support::{ @@ -185,6 +185,11 @@ impl pallet_xcm::Config for Runtime { type RemoteLockConsumerIdentifier = (); } +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 36d21f28..34619e6c 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -36,7 +36,6 @@ use polkadot_parachain_primitives::primitives::{ DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, }; use xcm::{latest::prelude::*, VersionedXcm}; -use xcm_executor::XcmExecutor; pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; @@ -205,11 +204,6 @@ pub mod mock_msg_queue { } } -impl mock_msg_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; -} - pub struct SignedToAccountId20( PhantomData<(RuntimeOrigin, AccountId, Network)>, ); @@ -244,7 +238,6 @@ construct_runtime!( pub enum Runtime { System: frame_system, - // ParachainSystem: cumulus_pallet_parachain_system, ParachainInfo: parachain_info, Balances: pallet_balances, MsgQueue: mock_msg_queue, From 0a8a1f5030b61f5655e771a459dd0b38a7e953d0 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 10:57:59 +0200 Subject: [PATCH 47/69] add Laoish networjk --- xcm-simulator/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index bd4ac62b..a88864ba 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -29,9 +29,9 @@ pub const INITIAL_BALANCE: u128 = 1_000_000_000; decl_test_parachain! { pub struct ParaA { - Runtime = laosish::Runtime, - XcmpMessageHandler = laosish::MsgQueue, - DmpMessageHandler = laosish::MsgQueue, + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, new_ext = para_ext(1), } } @@ -45,6 +45,15 @@ decl_test_parachain! { } } +decl_test_parachain! { + pub struct Laosish { + Runtime = laosish::Runtime, + XcmpMessageHandler = laosish::MsgQueue, + DmpMessageHandler = laosish::MsgQueue, + new_ext = para_ext(3), + } +} + decl_test_relay_chain! { pub struct Relay { Runtime = relay_chain::Runtime, From 50b8c10419d1b22321ebcd871941d22de7e87c04 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 11:01:23 +0200 Subject: [PATCH 48/69] deactive insecure zero ED --- xcm-simulator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index bf71fa1e..c99896b9 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -12,7 +12,7 @@ log = { workspace = true } frame-system = { workspace = true } frame-support = { workspace = true } -pallet-balances = { workspace = true } +pallet-balances = { workspace = true, features = ["insecure_zero_ed"] } pallet-message-queue = { workspace = true } pallet-uniques = { workspace = true } sp-std = { workspace = true } From 34d93d7c77f3db45c96c554dd9c909917eec1468 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 11:31:01 +0200 Subject: [PATCH 49/69] clippy --- xcm-simulator/src/laosish/mod.rs | 2 +- xcm-simulator/src/lib.rs | 9 ++++----- xcm-simulator/src/parachain.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 34619e6c..8c98acf2 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -176,7 +176,7 @@ pub mod mock_msg_queue { iter: impl Iterator)>, limit: Weight, ) -> Weight { - for (_i, (_sent_at, data)) in iter.enumerate() { + for (_sent_at, data) in iter { let mut id = sp_io::hashing::blake2_256(&data[..]); let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); match maybe_versioned { diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index a88864ba..0e92cac0 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -19,7 +19,6 @@ mod parachain; mod relay_chain; use sp_runtime::BuildStorage; -use sp_tracing; use xcm::prelude::*; use xcm_executor::traits::ConvertLocation; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; @@ -269,7 +268,7 @@ mod tests { Unlimited, )); assert_eq!( - relay_chain::Balances::free_balance(&child_account_id(1)), + relay_chain::Balances::free_balance(child_account_id(1)), INITIAL_BALANCE + withdraw_amount ); }); @@ -300,7 +299,7 @@ mod tests { Relay::execute_with(|| { use pallet_balances::{BalanceLock, Reasons}; assert_eq!( - relay_chain::Balances::locks(&child_account_id(2)), + relay_chain::Balances::locks(child_account_id(2)), vec![BalanceLock { id: *b"py/xcmlk", amount: locked_amount, @@ -332,7 +331,7 @@ mod tests { use pallet_balances::{BalanceLock, Reasons}; // Lock is reduced assert_eq!( - relay_chain::Balances::locks(&child_account_id(2)), + relay_chain::Balances::locks(child_account_id(2)), vec![BalanceLock { id: *b"py/xcmlk", amount: locked_amount - 50, @@ -562,7 +561,7 @@ mod tests { assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); }); ParaA::execute_with(|| { - assert_eq!(parachain::Balances::reserved_balance(&parent_account_id()), 1000); + assert_eq!(parachain::Balances::reserved_balance(parent_account_id()), 1000); assert_eq!( parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), Some(parent_account_id()) diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index a681c1ce..29aaceee 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -381,7 +381,7 @@ pub mod mock_msg_queue { iter: impl Iterator)>, limit: Weight, ) -> Weight { - for (_i, (_sent_at, data)) in iter.enumerate() { + for (_sent_at, data) in iter { let mut id = sp_io::hashing::blake2_256(&data[..]); let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); match maybe_versioned { From 2414c26f88f7f57576ec91b773f378181a4d91c5 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 12:00:17 +0200 Subject: [PATCH 50/69] added cumulus_xcm --- Cargo.lock | 1 + xcm-simulator/Cargo.toml | 2 ++ xcm-simulator/src/laosish/configs/xcm_config.rs | 15 +++++++++++++-- xcm-simulator/src/laosish/mod.rs | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcf3961f..9ce5c444 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16313,6 +16313,7 @@ dependencies = [ name = "xcm-simulator-example" version = "7.0.0" dependencies = [ + "cumulus-pallet-xcm", "frame-support", "frame-system", "laos-primitives", diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index c99896b9..0708e07d 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -31,11 +31,13 @@ polkadot-runtime-parachains = { workspace = true } polkadot-parachain-primitives = { workspace = true } laos-primitives = { workspace = true } parachain-info = { workspace = true } +cumulus-pallet-xcm = { workspace = true } [features] default = ["std"] std = [ + "cumulus-pallet-xcm/std", "parachain-info/std", "laos-primitives/std", "frame-system/std", diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index b00de44b..8d62ad58 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -33,7 +33,7 @@ use xcm_builder::{ AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, - IsConcrete, NativeAsset, ParentIsPreset, SiblingParachainConvertsVia, + IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, WithComputedOrigin, }; @@ -42,7 +42,7 @@ use xcm_executor::XcmExecutor; parameter_types! { pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = None; - // pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); // For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain // and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`. pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into(); @@ -82,6 +82,12 @@ pub type XcmOriginToTransactDispatchOrigin = ( // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for // foreign chains who want to have a local sovereign account on this chain which they control. SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognized. + RelayChainAsNative, + // // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // // recognized. + // SiblingParachainAsNative, // Native signed account converter; this just converts an `AccountId20` origin into a normal // `RuntimeOrigin::Signed` origin of the same 20-byte value. SignedAccountKey20AsNative, @@ -185,6 +191,11 @@ impl pallet_xcm::Config for Runtime { type RemoteLockConsumerIdentifier = (); } +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + impl mock_msg_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 8c98acf2..37c825ba 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -242,5 +242,6 @@ construct_runtime!( Balances: pallet_balances, MsgQueue: mock_msg_queue, PolkadotXcm: pallet_xcm, + CumulusXcm: cumulus_pallet_xcm, } ); From 5bf8877f5cd65e980eb3a5e331dd71d633479c6c Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 12:00:57 +0200 Subject: [PATCH 51/69] active SiblingParachainAsNative --- xcm-simulator/src/laosish/configs/xcm_config.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 8d62ad58..52eecf79 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -33,9 +33,9 @@ use xcm_builder::{ AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, - IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainConvertsVia, - SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - WithComputedOrigin, + IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, TrailingSetTopicAsId, WithComputedOrigin, }; use xcm_executor::XcmExecutor; @@ -85,9 +85,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when // recognized. RelayChainAsNative, - // // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // // recognized. - // SiblingParachainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognized. + SiblingParachainAsNative, // Native signed account converter; this just converts an `AccountId20` origin into a normal // `RuntimeOrigin::Signed` origin of the same 20-byte value. SignedAccountKey20AsNative, From 8457354009c5f249ccf79233cc9e38124c789f0e Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 13:12:30 +0200 Subject: [PATCH 52/69] refactoring --- xcm-simulator/src/laosish/configs/xcm_config.rs | 8 ++++++-- xcm-simulator/src/laosish/mod.rs | 4 ---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 52eecf79..86bcb1dc 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -15,8 +15,8 @@ // along with LAOS. If not, see . use crate::laosish::{ - mock_msg_queue, AccountId, AllPalletsWithSystem, Balances, KsmPerSecondPerByte, MsgQueue, - ParachainInfo, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + mock_msg_queue, AccountId, AllPalletsWithSystem, Balances, MsgQueue, ParachainInfo, + PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, }; use core::marker::PhantomData; use frame_support::{ @@ -127,6 +127,10 @@ pub type Barrier = TrailingSetTopicAsId< >, >; +parameter_types! { + pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 37c825ba..88548932 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -47,10 +47,6 @@ parameter_types! { pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); } -parameter_types! { - pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); -} - #[frame_support::pallet] pub mod mock_msg_queue { use super::*; From 80b571ba5a882674fec07a8f8a3b655634406c0a Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 13:13:57 +0200 Subject: [PATCH 53/69] refactoring --- xcm-simulator/src/laosish/mod.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 88548932..58a81ea3 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -20,7 +20,7 @@ mod configs; use core::marker::PhantomData; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, traits::{ContainsPair, OriginTrait}, weights::Weight, }; @@ -41,12 +41,6 @@ pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; type Block = frame_system::mocking::MockBlock; -parameter_types! { - pub const KsmLocation: Location = Location::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Kusama; - pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); -} - #[frame_support::pallet] pub mod mock_msg_queue { use super::*; From 1edd0c7c08034e0ad8d961d3946d2a2b46da57ec Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 13:18:02 +0200 Subject: [PATCH 54/69] refactoring --- .../src/laosish/configs/xcm_config.rs | 4 +- xcm-simulator/src/laosish/mod.rs | 39 +------------------ 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 86bcb1dc..31b05ec8 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -128,7 +128,7 @@ pub type Barrier = TrailingSetTopicAsId< >; parameter_types! { - pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub ParentTojenPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); } pub struct XcmConfig; @@ -143,7 +143,7 @@ impl xcm_executor::Config for XcmConfig { type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; + type Trader = FixedRateOfFungible; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index 58a81ea3..d53d19ff 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -18,16 +18,9 @@ mod configs; -use core::marker::PhantomData; -use frame_support::{ - construct_runtime, - traits::{ContainsPair, OriginTrait}, - weights::Weight, -}; +use frame_support::{construct_runtime, weights::Weight}; use parity_scale_codec::{Decode, Encode}; -use sp_runtime::traits::TryConvert; -use frame_system::RawOrigin as SystemRawOrigin; use sp_runtime::traits::{Get, Hash}; use sp_std::prelude::*; @@ -194,36 +187,6 @@ pub mod mock_msg_queue { } } -pub struct SignedToAccountId20( - PhantomData<(RuntimeOrigin, AccountId, Network)>, -); -impl< - RuntimeOrigin: OriginTrait + Clone, - AccountId: Into<[u8; 20]>, - Network: frame_support::traits::Get>, - > TryConvert for SignedToAccountId20 -where - RuntimeOrigin::PalletsOrigin: From> - + TryInto, Error = RuntimeOrigin::PalletsOrigin>, -{ - fn try_convert(o: RuntimeOrigin) -> Result { - o.try_with_caller(|caller| match caller.try_into() { - Ok(SystemRawOrigin::Signed(who)) => - Ok(Junction::AccountKey20 { network: Network::get(), key: who.into() }.into()), - Ok(other) => Err(other.into()), - Err(other) => Err(other), - }) - } -} - -pub struct TrustedLockerCase(PhantomData); -impl> ContainsPair for TrustedLockerCase { - fn contains(origin: &Location, asset: &Asset) -> bool { - let (o, a) = T::get(); - a.matches(asset) && &o == origin - } -} - construct_runtime!( pub enum Runtime { From 44a23b5dc8e4ce5a4fbda286a25e66a7f308eafa Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 13:26:59 +0200 Subject: [PATCH 55/69] added laosish ump test --- xcm-simulator/src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 0e92cac0..67138932 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -146,6 +146,7 @@ pub fn relay_ext() -> sp_io::TestExternalities { pub type RelayChainPalletXcm = pallet_xcm::Pallet; pub type ParachainPalletXcm = pallet_xcm::Pallet; +pub type LaosishPalletXcm = pallet_xcm::Pallet; #[cfg(test)] mod tests { @@ -224,6 +225,34 @@ mod tests { }); } + #[test] + fn ump_laosish() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Laosish::execute_with(|| { + assert_ok!(LaosishPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); + } + #[test] fn xcmp() { MockNet::reset(); From 078349747be74d55bbe5436dd4a3662bd8c89014 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 14:44:00 +0200 Subject: [PATCH 56/69] refactoring --- xcm-simulator/src/laosish/configs/xcm_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcm-simulator/src/laosish/configs/xcm_config.rs b/xcm-simulator/src/laosish/configs/xcm_config.rs index 31b05ec8..ad988891 100644 --- a/xcm-simulator/src/laosish/configs/xcm_config.rs +++ b/xcm-simulator/src/laosish/configs/xcm_config.rs @@ -128,7 +128,7 @@ pub type Barrier = TrailingSetTopicAsId< >; parameter_types! { - pub ParentTojenPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub ParentTokenPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); } pub struct XcmConfig; @@ -143,7 +143,7 @@ impl xcm_executor::Config for XcmConfig { type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; - type Trader = FixedRateOfFungible; + type Trader = FixedRateOfFungible; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; From 586c442da01be997e1111e71166dac358b3e6ee1 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 14:50:09 +0200 Subject: [PATCH 57/69] rafactoring: mod tests extracted --- xcm-simulator/src/lib.rs | 541 +-------------------------------- xcm-simulator/src/tests/mod.rs | 526 ++++++++++++++++++++++++++++++++ 2 files changed, 527 insertions(+), 540 deletions(-) create mode 100644 xcm-simulator/src/tests/mod.rs diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 67138932..bef50953 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -149,543 +149,4 @@ pub type ParachainPalletXcm = pallet_xcm::Pallet; pub type LaosishPalletXcm = pallet_xcm::Pallet; #[cfg(test)] -mod tests { - use super::*; - - use frame_support::{assert_ok, weights::Weight}; - use parity_scale_codec::Encode; - use xcm::latest::QueryResponseInfo; - use xcm_simulator::TestExt; - - // Helper function for forming buy execution message - fn buy_execution(fees: impl Into) -> Instruction { - BuyExecution { fees: fees.into(), weight_limit: Unlimited } - } - - #[test] - fn remote_account_ids_work() { - child_account_account_id(1, ALICE); - sibling_account_account_id(1, ALICE); - parent_account_account_id(ALICE); - } - - #[test] - fn dmp() { - MockNet::reset(); - - let remark = parachain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::send_xcm( - Here, - Parachain(1), - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - ParaA::execute_with(|| { - use parachain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn ump() { - MockNet::reset(); - - let remark = relay_chain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Here, - Parent, - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - Relay::execute_with(|| { - use relay_chain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn ump_laosish() { - MockNet::reset(); - - let remark = relay_chain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - Laosish::execute_with(|| { - assert_ok!(LaosishPalletXcm::send_xcm( - Here, - Parent, - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - Relay::execute_with(|| { - use relay_chain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn xcmp() { - MockNet::reset(); - - let remark = parachain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Here, - (Parent, Parachain(2)), - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - ParaB::execute_with(|| { - use parachain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); - } - - #[test] - fn reserve_transfer() { - MockNet::reset(); - - let withdraw_amount = 123; - - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( - relay_chain::RuntimeOrigin::signed(ALICE), - Box::new(Parachain(1).into()), - Box::new(AccountId32 { network: None, id: ALICE.into() }.into()), - Box::new((Here, withdraw_amount).into()), - 0, - Unlimited, - )); - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(1)), - INITIAL_BALANCE + withdraw_amount - ); - }); - - ParaA::execute_with(|| { - // free execution, full amount received - assert_eq!( - pallet_balances::Pallet::::free_balance(&ALICE), - INITIAL_BALANCE + withdraw_amount - ); - }); - } - - #[test] - fn remote_locking_and_unlocking() { - MockNet::reset(); - - let locked_amount = 100; - - ParaB::execute_with(|| { - let message = Xcm(vec![LockAsset { - asset: (Here, locked_amount).into(), - unlocker: Parachain(1).into(), - }]); - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); - }); - - Relay::execute_with(|| { - use pallet_balances::{BalanceLock, Reasons}; - assert_eq!( - relay_chain::Balances::locks(child_account_id(2)), - vec![BalanceLock { - id: *b"py/xcmlk", - amount: locked_amount, - reasons: Reasons::All - }] - ); - }); - - ParaA::execute_with(|| { - assert_eq!( - parachain::MsgQueue::received_dmp(), - vec![Xcm(vec![NoteUnlockable { - owner: (Parent, Parachain(2)).into(), - asset: (Parent, locked_amount).into() - }])] - ); - }); - - ParaB::execute_with(|| { - // Request unlocking part of the funds on the relay chain - let message = Xcm(vec![RequestUnlock { - asset: (Parent, locked_amount - 50).into(), - locker: Parent.into(), - }]); - assert_ok!(ParachainPalletXcm::send_xcm(Here, (Parent, Parachain(1)), message)); - }); - - Relay::execute_with(|| { - use pallet_balances::{BalanceLock, Reasons}; - // Lock is reduced - assert_eq!( - relay_chain::Balances::locks(child_account_id(2)), - vec![BalanceLock { - id: *b"py/xcmlk", - amount: locked_amount - 50, - reasons: Reasons::All - }] - ); - }); - } - - /// Scenario: - /// A parachain transfers an NFT resident on the relay chain to another parachain account. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn withdraw_and_deposit_nft() { - MockNet::reset(); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(1))); - }); - - ParaA::execute_with(|| { - let message = Xcm(vec![TransferAsset { - assets: (GeneralIndex(1), 42u32).into(), - beneficiary: Parachain(2).into(), - }]); - // Send withdraw and deposit - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message)); - }); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(2))); - }); - } - - /// Scenario: - /// The relay-chain teleports an NFT to a parachain. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn teleport_nft() { - MockNet::reset(); - - Relay::execute_with(|| { - // Mint the NFT (1, 69) and give it to our "parachain#1 alias". - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 1, - 69, - child_account_account_id(1, ALICE), - )); - // The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be - // withdrawable by Alice on the parachain. - assert_eq!( - relay_chain::Uniques::owner(1, 69), - Some(child_account_account_id(1, ALICE)) - ); - }); - ParaA::execute_with(|| { - assert_ok!(parachain::ForeignUniques::force_create( - parachain::RuntimeOrigin::root(), - (Parent, GeneralIndex(1)).into(), - ALICE, - false, - )); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), - None, - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); - - // IRL Alice would probably just execute this locally on the Relay-chain, but we can't - // easily do that here since we only send between chains. - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(1), 69u32).into()), - InitiateTeleport { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - // Send teleport - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), - Some(ALICE), - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); - }); - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(1, 69), None); - }); - } - - /// Scenario: - /// The relay-chain transfers an NFT into a parachain's sovereign account, who then mints a - /// trustless-backed-derived locally. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn reserve_asset_transfer_nft() { - sp_tracing::init_for_tests(); - MockNet::reset(); - - Relay::execute_with(|| { - assert_ok!(relay_chain::Uniques::force_create( - relay_chain::RuntimeOrigin::root(), - 2, - ALICE, - false - )); - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 2, - 69, - child_account_account_id(1, ALICE) - )); - assert_eq!( - relay_chain::Uniques::owner(2, 69), - Some(child_account_account_id(1, ALICE)) - ); - }); - ParaA::execute_with(|| { - assert_ok!(parachain::ForeignUniques::force_create( - parachain::RuntimeOrigin::root(), - (Parent, GeneralIndex(2)).into(), - ALICE, - false, - )); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), - None, - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); - - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(2), 69u32).into()), - DepositReserveAsset { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - // Send transfer - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - log::debug!(target: "xcm-executor", "Hello"); - assert_eq!( - parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), - Some(ALICE), - ); - assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); - }); - - Relay::execute_with(|| { - assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_id(1))); - }); - } - - /// Scenario: - /// The relay-chain creates an asset class on a parachain and then Alice transfers her NFT into - /// that parachain's sovereign account, who then mints a trustless-backed-derivative locally. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn reserve_asset_class_create_and_reserve_transfer() { - MockNet::reset(); - - Relay::execute_with(|| { - assert_ok!(relay_chain::Uniques::force_create( - relay_chain::RuntimeOrigin::root(), - 2, - ALICE, - false - )); - assert_ok!(relay_chain::Uniques::mint( - relay_chain::RuntimeOrigin::signed(ALICE), - 2, - 69, - child_account_account_id(1, ALICE) - )); - assert_eq!( - relay_chain::Uniques::owner(2, 69), - Some(child_account_account_id(1, ALICE)) - ); - - let message = Xcm(vec![Transact { - origin_kind: OriginKind::Xcm, - require_weight_at_most: Weight::from_parts(1_000_000_000, 1024 * 1024), - call: parachain::RuntimeCall::from( - pallet_uniques::Call::::create { - collection: (Parent, 2u64).into(), - admin: parent_account_id(), - }, - ) - .encode() - .into(), - }]); - // Send creation. - assert_ok!(RelayChainPalletXcm::send_xcm(Here, Parachain(1), message)); - }); - ParaA::execute_with(|| { - // Then transfer - let message = Xcm(vec![ - WithdrawAsset((GeneralIndex(2), 69u32).into()), - DepositReserveAsset { - assets: AllCounted(1).into(), - dest: Parachain(1).into(), - xcm: Xcm(vec![DepositAsset { - assets: AllCounted(1).into(), - beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), - }]), - }, - ]); - let alice = AccountId32 { id: ALICE.into(), network: None }; - assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); - }); - ParaA::execute_with(|| { - assert_eq!(parachain::Balances::reserved_balance(parent_account_id()), 1000); - assert_eq!( - parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), - Some(parent_account_id()) - ); - }); - } - - /// Scenario: - /// A parachain transfers funds on the relay chain to another parachain account. - /// - /// Asserts that the parachain accounts are updated as expected. - #[test] - fn withdraw_and_deposit() { - MockNet::reset(); - - let send_amount = 10; - - ParaA::execute_with(|| { - let message = Xcm(vec![ - WithdrawAsset((Here, send_amount).into()), - buy_execution((Here, send_amount)), - DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, - ]); - // Send withdraw and deposit - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); - }); - - Relay::execute_with(|| { - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(1)), - INITIAL_BALANCE - send_amount - ); - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(2)), - INITIAL_BALANCE + send_amount - ); - }); - } - - /// Scenario: - /// A parachain wants to be notified that a transfer worked correctly. - /// It sends a `QueryHolding` after the deposit to get notified on success. - /// - /// Asserts that the balances are updated correctly and the expected XCM is sent. - #[test] - fn query_holding() { - MockNet::reset(); - - let send_amount = 10; - let query_id_set = 1234; - - // Send a message which fully succeeds on the relay chain - ParaA::execute_with(|| { - let message = Xcm(vec![ - WithdrawAsset((Here, send_amount).into()), - buy_execution((Here, send_amount)), - DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, - ReportHolding { - response_info: QueryResponseInfo { - destination: Parachain(1).into(), - query_id: query_id_set, - max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), - }, - assets: All.into(), - }, - ]); - // Send withdraw and deposit with query holding - assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); - }); - - // Check that transfer was executed - Relay::execute_with(|| { - // Withdraw executed - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(1)), - INITIAL_BALANCE - send_amount - ); - // Deposit executed - assert_eq!( - relay_chain::Balances::free_balance(child_account_id(2)), - INITIAL_BALANCE + send_amount - ); - }); - - // Check that QueryResponse message was received - ParaA::execute_with(|| { - assert_eq!( - parachain::MsgQueue::received_dmp(), - vec![Xcm(vec![QueryResponse { - query_id: query_id_set, - response: Response::Assets(Assets::new()), - max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), - querier: Some(Here.into()), - }])], - ); - }); - } -} +mod tests; diff --git a/xcm-simulator/src/tests/mod.rs b/xcm-simulator/src/tests/mod.rs new file mode 100644 index 00000000..016e2942 --- /dev/null +++ b/xcm-simulator/src/tests/mod.rs @@ -0,0 +1,526 @@ + +use super::*; + +use frame_support::{assert_ok, weights::Weight}; +use parity_scale_codec::Encode; +use xcm::latest::QueryResponseInfo; +use xcm_simulator::TestExt; + +// Helper function for forming buy execution message +fn buy_execution(fees: impl Into) -> Instruction { + BuyExecution { fees: fees.into(), weight_limit: Unlimited } +} + +#[test] +fn remote_account_ids_work() { + child_account_account_id(1, ALICE); + sibling_account_account_id(1, ALICE); + parent_account_account_id(ALICE); +} + +#[test] +fn dmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::send_xcm( + Here, + Parachain(1), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaA::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); +} + +#[test] +fn ump() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); +} + +#[test] +fn ump_laosish() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Laosish::execute_with(|| { + assert_ok!(LaosishPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); +} + +#[test] +fn xcmp() { + MockNet::reset(); + + let remark = parachain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Here, + (Parent, Parachain(2)), + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + ParaB::execute_with(|| { + use parachain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); +} + +#[test] +fn reserve_transfer() { + MockNet::reset(); + + let withdraw_amount = 123; + + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::limited_reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(ALICE), + Box::new(Parachain(1).into()), + Box::new(AccountId32 { network: None, id: ALICE.into() }.into()), + Box::new((Here, withdraw_amount).into()), + 0, + Unlimited, + )); + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE + withdraw_amount + ); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALICE), + INITIAL_BALANCE + withdraw_amount + ); + }); +} + +#[test] +fn remote_locking_and_unlocking() { + MockNet::reset(); + + let locked_amount = 100; + + ParaB::execute_with(|| { + let message = Xcm(vec![LockAsset { + asset: (Here, locked_amount).into(), + unlocker: Parachain(1).into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + assert_eq!( + relay_chain::Balances::locks(child_account_id(2)), + vec![BalanceLock { id: *b"py/xcmlk", amount: locked_amount, reasons: Reasons::All }] + ); + }); + + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![NoteUnlockable { + owner: (Parent, Parachain(2)).into(), + asset: (Parent, locked_amount).into() + }])] + ); + }); + + ParaB::execute_with(|| { + // Request unlocking part of the funds on the relay chain + let message = Xcm(vec![RequestUnlock { + asset: (Parent, locked_amount - 50).into(), + locker: Parent.into(), + }]); + assert_ok!(ParachainPalletXcm::send_xcm(Here, (Parent, Parachain(1)), message)); + }); + + Relay::execute_with(|| { + use pallet_balances::{BalanceLock, Reasons}; + // Lock is reduced + assert_eq!( + relay_chain::Balances::locks(child_account_id(2)), + vec![BalanceLock { + id: *b"py/xcmlk", + amount: locked_amount - 50, + reasons: Reasons::All + }] + ); + }); +} + +/// Scenario: +/// A parachain transfers an NFT resident on the relay chain to another parachain account. +/// +/// Asserts that the parachain accounts are updated as expected. +#[test] +fn withdraw_and_deposit_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(1))); + }); + + ParaA::execute_with(|| { + let message = Xcm(vec![TransferAsset { + assets: (GeneralIndex(1), 42u32).into(), + beneficiary: Parachain(2).into(), + }]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message)); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 42), Some(child_account_id(2))); + }); +} + +/// Scenario: +/// The relay-chain teleports an NFT to a parachain. +/// +/// Asserts that the parachain accounts are updated as expected. +#[test] +fn teleport_nft() { + MockNet::reset(); + + Relay::execute_with(|| { + // Mint the NFT (1, 69) and give it to our "parachain#1 alias". + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 1, + 69, + child_account_account_id(1, ALICE), + )); + // The parachain#1 alias of Alice is what must hold it on the Relay-chain for it to be + // withdrawable by Alice on the parachain. + assert_eq!(relay_chain::Uniques::owner(1, 69), Some(child_account_account_id(1, ALICE))); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(1)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + // IRL Alice would probably just execute this locally on the Relay-chain, but we can't + // easily do that here since we only send between chains. + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(1), 69u32).into()), + InitiateTeleport { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send teleport + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(1)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(1, 69), None); + }); +} + +/// Scenario: +/// The relay-chain transfers an NFT into a parachain's sovereign account, who then mints a +/// trustless-backed-derived locally. +/// +/// Asserts that the parachain accounts are updated as expected. +#[test] +fn reserve_asset_transfer_nft() { + sp_tracing::init_for_tests(); + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_account_id(1, ALICE))); + }); + ParaA::execute_with(|| { + assert_ok!(parachain::ForeignUniques::force_create( + parachain::RuntimeOrigin::root(), + (Parent, GeneralIndex(2)).into(), + ALICE, + false, + )); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + None, + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 0); + + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + // Send transfer + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + log::debug!(target: "xcm-executor", "Hello"); + assert_eq!( + parachain::ForeignUniques::owner((Parent, GeneralIndex(2)).into(), 69u32.into()), + Some(ALICE), + ); + assert_eq!(parachain::Balances::reserved_balance(&ALICE), 1000); + }); + + Relay::execute_with(|| { + assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_id(1))); + }); +} + +/// Scenario: +/// The relay-chain creates an asset class on a parachain and then Alice transfers her NFT into +/// that parachain's sovereign account, who then mints a trustless-backed-derivative locally. +/// +/// Asserts that the parachain accounts are updated as expected. +#[test] +fn reserve_asset_class_create_and_reserve_transfer() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(relay_chain::Uniques::force_create( + relay_chain::RuntimeOrigin::root(), + 2, + ALICE, + false + )); + assert_ok!(relay_chain::Uniques::mint( + relay_chain::RuntimeOrigin::signed(ALICE), + 2, + 69, + child_account_account_id(1, ALICE) + )); + assert_eq!(relay_chain::Uniques::owner(2, 69), Some(child_account_account_id(1, ALICE))); + + let message = Xcm(vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: Weight::from_parts(1_000_000_000, 1024 * 1024), + call: parachain::RuntimeCall::from( + pallet_uniques::Call::::create { + collection: (Parent, 2u64).into(), + admin: parent_account_id(), + }, + ) + .encode() + .into(), + }]); + // Send creation. + assert_ok!(RelayChainPalletXcm::send_xcm(Here, Parachain(1), message)); + }); + ParaA::execute_with(|| { + // Then transfer + let message = Xcm(vec![ + WithdrawAsset((GeneralIndex(2), 69u32).into()), + DepositReserveAsset { + assets: AllCounted(1).into(), + dest: Parachain(1).into(), + xcm: Xcm(vec![DepositAsset { + assets: AllCounted(1).into(), + beneficiary: (AccountId32 { id: ALICE.into(), network: None },).into(), + }]), + }, + ]); + let alice = AccountId32 { id: ALICE.into(), network: None }; + assert_ok!(ParachainPalletXcm::send_xcm(alice, Parent, message)); + }); + ParaA::execute_with(|| { + assert_eq!(parachain::Balances::reserved_balance(parent_account_id()), 1000); + assert_eq!( + parachain::ForeignUniques::collection_owner((Parent, 2u64).into()), + Some(parent_account_id()) + ); + }); +} + +/// Scenario: +/// A parachain transfers funds on the relay chain to another parachain account. +/// +/// Asserts that the parachain accounts are updated as expected. +#[test] +fn withdraw_and_deposit() { + MockNet::reset(); + + let send_amount = 10; + + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ]); + // Send withdraw and deposit + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone())); + }); + + Relay::execute_with(|| { + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); +} + +/// Scenario: +/// A parachain wants to be notified that a transfer worked correctly. +/// It sends a `QueryHolding` after the deposit to get notified on success. +/// +/// Asserts that the balances are updated correctly and the expected XCM is sent. +#[test] +fn query_holding() { + MockNet::reset(); + + let send_amount = 10; + let query_id_set = 1234; + + // Send a message which fully succeeds on the relay chain + ParaA::execute_with(|| { + let message = Xcm(vec![ + WithdrawAsset((Here, send_amount).into()), + buy_execution((Here, send_amount)), + DepositAsset { assets: AllCounted(1).into(), beneficiary: Parachain(2).into() }, + ReportHolding { + response_info: QueryResponseInfo { + destination: Parachain(1).into(), + query_id: query_id_set, + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + }, + assets: All.into(), + }, + ]); + // Send withdraw and deposit with query holding + assert_ok!(ParachainPalletXcm::send_xcm(Here, Parent, message.clone(),)); + }); + + // Check that transfer was executed + Relay::execute_with(|| { + // Withdraw executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(1)), + INITIAL_BALANCE - send_amount + ); + // Deposit executed + assert_eq!( + relay_chain::Balances::free_balance(child_account_id(2)), + INITIAL_BALANCE + send_amount + ); + }); + + // Check that QueryResponse message was received + ParaA::execute_with(|| { + assert_eq!( + parachain::MsgQueue::received_dmp(), + vec![Xcm(vec![QueryResponse { + query_id: query_id_set, + response: Response::Assets(Assets::new()), + max_weight: Weight::from_parts(1_000_000_000, 1024 * 1024), + querier: Some(Here.into()), + }])], + ); + }); +} From 871fec5d06d7afb231a3a650a4f31159d08e3320 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 14:51:54 +0200 Subject: [PATCH 58/69] created module test laoish --- xcm-simulator/src/tests/mod.rs | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/xcm-simulator/src/tests/mod.rs b/xcm-simulator/src/tests/mod.rs index 016e2942..bef654f6 100644 --- a/xcm-simulator/src/tests/mod.rs +++ b/xcm-simulator/src/tests/mod.rs @@ -1,4 +1,3 @@ - use super::*; use frame_support::{assert_ok, weights::Weight}; @@ -6,6 +5,8 @@ use parity_scale_codec::Encode; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; +mod laosish; + // Helper function for forming buy execution message fn buy_execution(fees: impl Into) -> Instruction { BuyExecution { fees: fees.into(), weight_limit: Unlimited } @@ -74,34 +75,6 @@ fn ump() { }); } -#[test] -fn ump_laosish() { - MockNet::reset(); - - let remark = relay_chain::RuntimeCall::System( - frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, - ); - Laosish::execute_with(|| { - assert_ok!(LaosishPalletXcm::send_xcm( - Here, - Parent, - Xcm(vec![Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), - call: remark.encode().into(), - }]), - )); - }); - - Relay::execute_with(|| { - use relay_chain::{RuntimeEvent, System}; - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::System(frame_system::Event::Remarked { .. }) - ))); - }); -} - #[test] fn xcmp() { MockNet::reset(); From 7db59cbfd600762ee4c3c1d8dc5d62e2786eeb92 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 15:08:47 +0200 Subject: [PATCH 59/69] initializing ethereum --- Cargo.lock | 1 + xcm-simulator/Cargo.toml | 1 + xcm-simulator/src/lib.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9ce5c444..d39b7370 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16316,6 +16316,7 @@ dependencies = [ "cumulus-pallet-xcm", "frame-support", "frame-system", + "hex-literal", "laos-primitives", "log", "pallet-balances", diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 0708e07d..12cc276f 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -9,6 +9,7 @@ version = "7.0.0" parity-scale-codec = { workspace = true } scale-info = { workspace = true } log = { workspace = true } +hex-literal = { workspace = true } frame-system = { workspace = true } frame-support = { workspace = true } diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index bef50953..14f1df75 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -18,12 +18,14 @@ mod laosish; mod parachain; mod relay_chain; +use hex_literal::hex; use sp_runtime::BuildStorage; use xcm::prelude::*; use xcm_executor::traits::ConvertLocation; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; pub const ALICE: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]); +pub const ALITH: [u8; 20] = hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"); pub const INITIAL_BALANCE: u128 = 1_000_000_000; decl_test_parachain! { @@ -49,7 +51,7 @@ decl_test_parachain! { Runtime = laosish::Runtime, XcmpMessageHandler = laosish::MsgQueue, DmpMessageHandler = laosish::MsgQueue, - new_ext = para_ext(3), + new_ext = para_ext_ethereum(3), } } @@ -71,6 +73,7 @@ decl_test_network! { parachains = vec![ (1, ParaA), (2, ParaB), + (3, Laosish), ], } } @@ -120,6 +123,28 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { ext } +pub fn para_ext_ethereum(para_id: u32) -> sp_io::TestExternalities { + use laosish::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (ALITH.into(), INITIAL_BALANCE), /* , (parent_account_id(), INITIAL_BALANCE) TODO */ + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + sp_tracing::try_init_simple(); + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + pub fn relay_ext() -> sp_io::TestExternalities { use relay_chain::{Runtime, RuntimeOrigin, System, Uniques}; @@ -130,6 +155,7 @@ pub fn relay_ext() -> sp_io::TestExternalities { (ALICE, INITIAL_BALANCE), (child_account_id(1), INITIAL_BALANCE), (child_account_id(2), INITIAL_BALANCE), + (child_account_id(3), INITIAL_BALANCE), ], } .assimilate_storage(&mut t) From 37bfbb9a5b4cd90daee7d636df4ef83ca6c54848 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 15:12:56 +0200 Subject: [PATCH 60/69] funding account --- xcm-simulator/src/tests/laosish_xcm.rs | 41 ++++++++++++++++++++++++++ xcm-simulator/src/tests/mod.rs | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 xcm-simulator/src/tests/laosish_xcm.rs diff --git a/xcm-simulator/src/tests/laosish_xcm.rs b/xcm-simulator/src/tests/laosish_xcm.rs new file mode 100644 index 00000000..f644f610 --- /dev/null +++ b/xcm-simulator/src/tests/laosish_xcm.rs @@ -0,0 +1,41 @@ +use super::*; + +#[test] +fn alish_has_tokens() { + MockNet::reset(); + + Laosish::execute_with(|| { + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALITH.into()), + INITIAL_BALANCE + ); + }); +} + +#[test] +fn ump_laosish() { + MockNet::reset(); + + let remark = relay_chain::RuntimeCall::System( + frame_system::Call::::remark_with_event { remark: vec![1, 2, 3] }, + ); + Laosish::execute_with(|| { + assert_ok!(LaosishPalletXcm::send_xcm( + Here, + Parent, + Xcm(vec![Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(INITIAL_BALANCE as u64, 1024 * 1024), + call: remark.encode().into(), + }]), + )); + }); + + Relay::execute_with(|| { + use relay_chain::{RuntimeEvent, System}; + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::System(frame_system::Event::Remarked { .. }) + ))); + }); +} diff --git a/xcm-simulator/src/tests/mod.rs b/xcm-simulator/src/tests/mod.rs index bef654f6..8b05422d 100644 --- a/xcm-simulator/src/tests/mod.rs +++ b/xcm-simulator/src/tests/mod.rs @@ -5,7 +5,7 @@ use parity_scale_codec::Encode; use xcm::latest::QueryResponseInfo; use xcm_simulator::TestExt; -mod laosish; +mod laosish_xcm; // Helper function for forming buy execution message fn buy_execution(fees: impl Into) -> Instruction { From 2119906f832d67a1779c693575d50080fed4bde3 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Fri, 4 Oct 2024 15:16:54 +0200 Subject: [PATCH 61/69] clippy --- xcm-simulator/src/tests/laosish_xcm.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xcm-simulator/src/tests/laosish_xcm.rs b/xcm-simulator/src/tests/laosish_xcm.rs index f644f610..799a022b 100644 --- a/xcm-simulator/src/tests/laosish_xcm.rs +++ b/xcm-simulator/src/tests/laosish_xcm.rs @@ -5,8 +5,9 @@ fn alish_has_tokens() { MockNet::reset(); Laosish::execute_with(|| { + let alith: laosish::AccountId = ALITH.into(); assert_eq!( - pallet_balances::Pallet::::free_balance(&ALITH.into()), + pallet_balances::Pallet::::free_balance(alith), INITIAL_BALANCE ); }); From 073600cde7bb3630747e2c4b28c9df6ecba7e475 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Mon, 7 Oct 2024 09:47:41 +0200 Subject: [PATCH 62/69] Update xcm-simulator/src/relay_chain.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomás Senovilla Polo <117524919+tsenovilla@users.noreply.github.com> --- xcm-simulator/src/relay_chain.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/xcm-simulator/src/relay_chain.rs b/xcm-simulator/src/relay_chain.rs index b41df3cf..618b4bf7 100644 --- a/xcm-simulator/src/relay_chain.rs +++ b/xcm-simulator/src/relay_chain.rs @@ -51,29 +51,12 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { From 9588bfeea1a26d56f8a4c5f65585c530228e08ee Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Mon, 7 Oct 2024 09:48:03 +0200 Subject: [PATCH 63/69] Update xcm-simulator/src/relay_chain.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomás Senovilla Polo <117524919+tsenovilla@users.noreply.github.com> --- xcm-simulator/src/relay_chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/src/relay_chain.rs b/xcm-simulator/src/relay_chain.rs index 618b4bf7..3728dd1d 100644 --- a/xcm-simulator/src/relay_chain.rs +++ b/xcm-simulator/src/relay_chain.rs @@ -23,7 +23,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; -use sp_core::{ConstU32, H256}; +use sp_core::ConstU32; use sp_runtime::{traits::IdentityLookup, AccountId32}; use polkadot_parachain_primitives::primitives::Id as ParaId; From 70e188cc52e4f7b8c6543607e46c4031bb18d7b0 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Mon, 7 Oct 2024 09:48:09 +0200 Subject: [PATCH 64/69] Update xcm-simulator/src/parachain.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomás Senovilla Polo <117524919+tsenovilla@users.noreply.github.com> --- xcm-simulator/src/parachain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index 29aaceee..4272d4d6 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -25,7 +25,7 @@ use frame_support::{ use parity_scale_codec::{Decode, Encode}; use frame_system::EnsureRoot; -use sp_core::{ConstU32, H256}; +use sp_core::ConstU32; use sp_runtime::{ traits::{Get, Hash, IdentityLookup}, AccountId32, From d698d72a785c120265e95c61aa494d29d9c7ab3b Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Mon, 7 Oct 2024 09:48:17 +0200 Subject: [PATCH 65/69] Update xcm-simulator/src/parachain.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomás Senovilla Polo <117524919+tsenovilla@users.noreply.github.com> --- xcm-simulator/src/parachain.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index 4272d4d6..566feddd 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -65,29 +65,12 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Runtime { - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; type Nonce = u64; - type Hash = H256; - type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type DbWeight = (); - type BaseCallFilter = Everything; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { From b1ea3c868e4e0f93139c2211dcbc3b70de57a3f3 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 8 Oct 2024 13:00:15 +0200 Subject: [PATCH 66/69] refactoring --- xcm-simulator/src/laosish/mod.rs | 154 +---------------------------- xcm-simulator/src/lib.rs | 160 +++++++++++++++++++++++++++++++ xcm-simulator/src/parachain.rs | 154 +---------------------------- 3 files changed, 162 insertions(+), 306 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index d53d19ff..b2bed7e5 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -24,6 +24,7 @@ use parity_scale_codec::{Decode, Encode}; use sp_runtime::traits::{Get, Hash}; use sp_std::prelude::*; +use crate::mock_msg_queue; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, @@ -34,159 +35,6 @@ pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; type Block = frame_system::mocking::MockBlock; -#[frame_support::pallet] -pub mod mock_msg_queue { - use super::*; - use frame_support::pallet_prelude::*; - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type XcmExecutor: ExecuteXcm; - } - - #[pallet::call] - impl Pallet {} - - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::storage] - #[pallet::getter(fn parachain_id)] - pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - - #[pallet::storage] - #[pallet::getter(fn received_dmp)] - /// A queue of received DMP messages - pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; - - impl Get for Pallet { - fn get() -> ParaId { - Self::parachain_id() - } - } - - pub type MessageId = [u8; 32]; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - // XCMP - /// Some XCM was executed OK. - Success(Option), - /// Some XCM failed. - Fail(Option, XcmError), - /// Bad XCM version used. - BadVersion(Option), - /// Bad XCM format used. - BadFormat(Option), - - // DMP - /// Downward message is invalid XCM. - InvalidFormat(MessageId), - /// Downward message is unsupported version of XCM. - UnsupportedVersion(MessageId), - /// Downward message executed with the given outcome. - ExecutedDownward(MessageId, Outcome), - } - - impl Pallet { - pub fn set_para_id(para_id: ParaId) { - ParachainId::::put(para_id); - } - - fn handle_xcmp_message( - sender: ParaId, - _sent_at: RelayBlockNumber, - xcm: VersionedXcm, - max_weight: Weight, - ) -> Result { - let hash = Encode::using_encoded(&xcm, T::Hashing::hash); - let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); - let (result, event) = match Xcm::::try_from(xcm) { - Ok(xcm) => { - let location = (Parent, Parachain(sender.into())); - match T::XcmExecutor::prepare_and_execute( - location, - xcm, - &mut message_hash, - max_weight, - Weight::zero(), - ) { - Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), - Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), - // As far as the caller is concerned, this was dispatched without error, so - // we just report the weight used. - Outcome::Incomplete { used, error } => - (Ok(used), Event::Fail(Some(hash), error)), - } - }, - Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), - }; - Self::deposit_event(event); - result - } - } - - impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - max_weight: Weight, - ) -> Weight { - for (sender, sent_at, data) in iter { - let mut data_ref = data; - let _ = XcmpMessageFormat::decode(&mut data_ref) - .expect("Simulator encodes with versioned xcm format; qed"); - - let mut remaining_fragments = data_ref; - while !remaining_fragments.is_empty() { - if let Ok(xcm) = - VersionedXcm::::decode(&mut remaining_fragments) - { - let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); - } else { - debug_assert!(false, "Invalid incoming XCMP message data"); - } - } - } - max_weight - } - } - - impl DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - for (_sent_at, data) in iter { - let mut id = sp_io::hashing::blake2_256(&data[..]); - let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); - match maybe_versioned { - Err(_) => { - Self::deposit_event(Event::InvalidFormat(id)); - }, - Ok(versioned) => match Xcm::try_from(versioned) { - Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), - Ok(x) => { - let outcome = T::XcmExecutor::prepare_and_execute( - Parent, - x.clone(), - &mut id, - limit, - Weight::zero(), - ); - >::append(x); - Self::deposit_event(Event::ExecutedDownward(id, outcome)); - }, - }, - } - } - limit - } - } -} - construct_runtime!( pub enum Runtime { diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index 14f1df75..e3618134 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -19,7 +19,9 @@ mod parachain; mod relay_chain; use hex_literal::hex; + use sp_runtime::BuildStorage; + use xcm::prelude::*; use xcm_executor::traits::ConvertLocation; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; @@ -174,5 +176,163 @@ pub type RelayChainPalletXcm = pallet_xcm::Pallet; pub type ParachainPalletXcm = pallet_xcm::Pallet; pub type LaosishPalletXcm = pallet_xcm::Pallet; +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + use polkadot_parachain_primitives::primitives::{ + DmpMessageHandler, XcmpMessageFormat, XcmpMessageHandler, + }; + use sp_runtime::traits::{Get, Hash}; + use xcm_simulator::{ParaId, RelayBlockNumber}; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => + (Ok(used), Event::Fail(Some(hash), error)), + } + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = data_ref; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_sent_at, data) in iter { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} + #[cfg(test)] mod tests; diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index 566feddd..50f85381 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -32,6 +32,7 @@ use sp_runtime::{ }; use sp_std::prelude::*; +use crate::mock_msg_queue; use pallet_xcm::XcmPassthrough; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; use polkadot_parachain_primitives::primitives::{ @@ -239,159 +240,6 @@ impl Config for XcmConfig { type HrmpChannelClosingHandler = (); } -#[frame_support::pallet] -pub mod mock_msg_queue { - use super::*; - use frame_support::pallet_prelude::*; - - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type XcmExecutor: ExecuteXcm; - } - - #[pallet::call] - impl Pallet {} - - #[pallet::pallet] - #[pallet::without_storage_info] - pub struct Pallet(_); - - #[pallet::storage] - #[pallet::getter(fn parachain_id)] - pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - - #[pallet::storage] - #[pallet::getter(fn received_dmp)] - /// A queue of received DMP messages - pub(super) type ReceivedDmp = StorageValue<_, Vec>, ValueQuery>; - - impl Get for Pallet { - fn get() -> ParaId { - Self::parachain_id() - } - } - - pub type MessageId = [u8; 32]; - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - // XCMP - /// Some XCM was executed OK. - Success(Option), - /// Some XCM failed. - Fail(Option, XcmError), - /// Bad XCM version used. - BadVersion(Option), - /// Bad XCM format used. - BadFormat(Option), - - // DMP - /// Downward message is invalid XCM. - InvalidFormat(MessageId), - /// Downward message is unsupported version of XCM. - UnsupportedVersion(MessageId), - /// Downward message executed with the given outcome. - ExecutedDownward(MessageId, Outcome), - } - - impl Pallet { - pub fn set_para_id(para_id: ParaId) { - ParachainId::::put(para_id); - } - - fn handle_xcmp_message( - sender: ParaId, - _sent_at: RelayBlockNumber, - xcm: VersionedXcm, - max_weight: Weight, - ) -> Result { - let hash = Encode::using_encoded(&xcm, T::Hashing::hash); - let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); - let (result, event) = match Xcm::::try_from(xcm) { - Ok(xcm) => { - let location = (Parent, Parachain(sender.into())); - match T::XcmExecutor::prepare_and_execute( - location, - xcm, - &mut message_hash, - max_weight, - Weight::zero(), - ) { - Outcome::Error { error } => (Err(error), Event::Fail(Some(hash), error)), - Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), - // As far as the caller is concerned, this was dispatched without error, so - // we just report the weight used. - Outcome::Incomplete { used, error } => - (Ok(used), Event::Fail(Some(hash), error)), - } - }, - Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), - }; - Self::deposit_event(event); - result - } - } - - impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - max_weight: Weight, - ) -> Weight { - for (sender, sent_at, data) in iter { - let mut data_ref = data; - let _ = XcmpMessageFormat::decode(&mut data_ref) - .expect("Simulator encodes with versioned xcm format; qed"); - - let mut remaining_fragments = data_ref; - while !remaining_fragments.is_empty() { - if let Ok(xcm) = - VersionedXcm::::decode(&mut remaining_fragments) - { - let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); - } else { - debug_assert!(false, "Invalid incoming XCMP message data"); - } - } - } - max_weight - } - } - - impl DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - for (_sent_at, data) in iter { - let mut id = sp_io::hashing::blake2_256(&data[..]); - let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); - match maybe_versioned { - Err(_) => { - Self::deposit_event(Event::InvalidFormat(id)); - }, - Ok(versioned) => match Xcm::try_from(versioned) { - Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), - Ok(x) => { - let outcome = T::XcmExecutor::prepare_and_execute( - Parent, - x.clone(), - &mut id, - limit, - Weight::zero(), - ); - >::append(x); - Self::deposit_event(Event::ExecutedDownward(id, outcome)); - }, - }, - } - } - limit - } - } -} - impl mock_msg_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type XcmExecutor = XcmExecutor; From ab507ffa2288222ba42c5343febb4fb17b76b0a1 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 8 Oct 2024 14:24:44 +0200 Subject: [PATCH 67/69] remove warnings --- xcm-simulator/src/laosish/mod.rs | 11 +---------- xcm-simulator/src/parachain.rs | 10 +++------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/xcm-simulator/src/laosish/mod.rs b/xcm-simulator/src/laosish/mod.rs index b2bed7e5..fe3f93bf 100644 --- a/xcm-simulator/src/laosish/mod.rs +++ b/xcm-simulator/src/laosish/mod.rs @@ -18,18 +18,9 @@ mod configs; -use frame_support::{construct_runtime, weights::Weight}; -use parity_scale_codec::{Decode, Encode}; - -use sp_runtime::traits::{Get, Hash}; -use sp_std::prelude::*; +use frame_support::construct_runtime; use crate::mock_msg_queue; -use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, -}; -use xcm::{latest::prelude::*, VersionedXcm}; pub type AccountId = laos_primitives::AccountId; pub type Balance = laos_primitives::Balance; diff --git a/xcm-simulator/src/parachain.rs b/xcm-simulator/src/parachain.rs index 50f85381..9b7a940c 100644 --- a/xcm-simulator/src/parachain.rs +++ b/xcm-simulator/src/parachain.rs @@ -22,23 +22,19 @@ use frame_support::{ traits::{ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, EverythingBut, Nothing}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; -use parity_scale_codec::{Decode, Encode}; use frame_system::EnsureRoot; use sp_core::ConstU32; use sp_runtime::{ - traits::{Get, Hash, IdentityLookup}, + traits::{Get, IdentityLookup}, AccountId32, }; use sp_std::prelude::*; use crate::mock_msg_queue; use pallet_xcm::XcmPassthrough; -use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -use polkadot_parachain_primitives::primitives::{ - DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, -}; -use xcm::{latest::prelude::*, VersionedXcm}; +use polkadot_parachain_primitives::primitives::Sibling; +use xcm::latest::prelude::*; use xcm_builder::{ Account32Hash, AccountId32Aliases, AllowUnpaidExecutionFrom, ConvertedConcreteId, EnsureDecodableXcm, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, From c1f4949e3524e9ab0532357795e6b40ca3aa30a9 Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 8 Oct 2024 14:26:12 +0200 Subject: [PATCH 68/69] removed unused code --- xcm-simulator/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/xcm-simulator/src/lib.rs b/xcm-simulator/src/lib.rs index e3618134..a20ea539 100644 --- a/xcm-simulator/src/lib.rs +++ b/xcm-simulator/src/lib.rs @@ -130,13 +130,9 @@ pub fn para_ext_ethereum(para_id: u32) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![ - (ALITH.into(), INITIAL_BALANCE), /* , (parent_account_id(), INITIAL_BALANCE) TODO */ - ], - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALITH.into(), INITIAL_BALANCE)] } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| { From ed124215c9df91060eb98ec29bdd56203caf049b Mon Sep 17 00:00:00 2001 From: Alessandro Siniscalchi Date: Tue, 8 Oct 2024 14:27:17 +0200 Subject: [PATCH 69/69] identation --- xcm-simulator/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcm-simulator/Cargo.toml b/xcm-simulator/Cargo.toml index 12cc276f..1166f679 100644 --- a/xcm-simulator/Cargo.toml +++ b/xcm-simulator/Cargo.toml @@ -39,8 +39,8 @@ cumulus-pallet-xcm = { workspace = true } default = ["std"] std = [ "cumulus-pallet-xcm/std", - "parachain-info/std", - "laos-primitives/std", + "parachain-info/std", + "laos-primitives/std", "frame-system/std", "frame-support/std", "pallet-balances/std",