From 662d025183edc9467aa470f537da7d4b3ac17e8c Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 16:50:22 +1200 Subject: [PATCH 1/9] Add xcm-simulator and xcm-simulator-example. --- Cargo.lock | 680 ++++++++++++++++--- Cargo.toml | 2 + xcm/xcm-simulator/Cargo.toml | 23 + xcm/xcm-simulator/example/Cargo.toml | 37 + xcm/xcm-simulator/example/src/lib.rs | 221 ++++++ xcm/xcm-simulator/example/src/parachain.rs | 212 ++++++ xcm/xcm-simulator/example/src/relay_chain.rs | 177 +++++ xcm/xcm-simulator/src/lib.rs | 226 ++++++ xcm/xcm-simulator/src/traits.rs | 36 + 9 files changed, 1513 insertions(+), 101 deletions(-) create mode 100644 xcm/xcm-simulator/Cargo.toml create mode 100644 xcm/xcm-simulator/example/Cargo.toml create mode 100644 xcm/xcm-simulator/example/src/lib.rs create mode 100644 xcm/xcm-simulator/example/src/parachain.rs create mode 100644 xcm/xcm-simulator/example/src/relay_chain.rs create mode 100644 xcm/xcm-simulator/src/lib.rs create mode 100644 xcm/xcm-simulator/src/traits.rs diff --git a/Cargo.lock b/Cargo.lock index f69325552b6d..67826669dbc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1461,6 +1461,150 @@ dependencies = [ "rand 0.7.3", ] +[[package]] +name = "cumulus-pallet-dmp-queue" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "rand 0.8.4", + "rand_chacha 0.3.1", + "sp-io", + "sp-runtime", + "sp-std", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "cumulus-pallet-parachain-system" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-pallet-parachain-system-proc-macro", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "environmental", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "serde", + "sp-core", + "sp-externalities", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "sp-version", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "cumulus-pallet-parachain-system-proc-macro" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "proc-macro-crate 1.0.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cumulus-pallet-xcm" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "parity-scale-codec", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "cumulus-pallet-xcmp-queue" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "rand 0.8.4", + "rand_chacha 0.3.1", + "sp-runtime", + "sp-std", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "cumulus-primitives-core" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "frame-support", + "impl-trait-for-tuples", + "parity-scale-codec", + "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "sp-api", + "sp-runtime", + "sp-std", + "sp-trie", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "cumulus-primitives-parachain-inherent" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "async-trait", + "cumulus-primitives-core", + "cumulus-test-relay-sproof-builder", + "parity-scale-codec", + "polkadot-client 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "sc-client-api", + "sp-api", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "tracing", +] + +[[package]] +name = "cumulus-test-relay-sproof-builder" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-primitives-core", + "parity-scale-codec", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "sp-runtime", + "sp-state-machine", + "sp-std", +] + [[package]] name = "curve25519-dalek" version = "2.1.0" @@ -3408,9 +3552,9 @@ dependencies = [ "pallet-vesting", "pallet-xcm", "parity-scale-codec", - "polkadot-primitives", - "polkadot-runtime-common", - "polkadot-runtime-parachains", + "polkadot-primitives 0.9.8", + "polkadot-runtime-common 0.9.8", + "polkadot-runtime-parachains 0.9.8", "rustc-hex", "separator", "serde", @@ -3438,9 +3582,9 @@ dependencies = [ "static_assertions", "substrate-wasm-builder", "tiny-keccak", - "xcm", + "xcm 0.9.8", "xcm-builder", - "xcm-executor", + "xcm-executor 0.9.8", ] [[package]] @@ -5452,8 +5596,20 @@ dependencies = [ "serde", "sp-runtime", "sp-std", - "xcm", - "xcm-executor", + "xcm 0.9.8", + "xcm-executor 0.9.8", +] + +[[package]] +name = "parachain-info" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "parity-scale-codec", + "serde", ] [[package]] @@ -5884,7 +6040,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand_core 0.5.1", "schnorrkel", "sp-core", @@ -5905,7 +6061,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-application-crypto", "sp-core", "sp-keystore", @@ -5929,7 +6085,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -5958,7 +6114,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -6000,8 +6156,8 @@ dependencies = [ "kusama-runtime", "pallet-mmr-primitives", "pallet-transaction-payment-rpc-runtime-api", - "polkadot-primitives", - "polkadot-runtime", + "polkadot-primitives 0.9.8", + "polkadot-runtime 0.9.8", "rococo-runtime", "sc-client-api", "sc-consensus", @@ -6022,6 +6178,36 @@ dependencies = [ "westend-runtime", ] +[[package]] +name = "polkadot-client" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "beefy-primitives", + "frame-benchmarking", + "frame-system-rpc-runtime-api", + "pallet-mmr-primitives", + "pallet-transaction-payment-rpc-runtime-api", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-runtime 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "sc-client-api", + "sc-consensus", + "sc-executor", + "sc-service", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-babe", + "sp-finality-grandpa", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-storage", + "sp-transaction-pool", +] + [[package]] name = "polkadot-collator-protocol" version = "0.1.0" @@ -6037,7 +6223,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-network", "sp-core", "sp-keyring", @@ -6058,6 +6244,18 @@ dependencies = [ "sp-std", ] +[[package]] +name = "polkadot-core-primitives" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "parity-scale-codec", + "parity-util-mem", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "polkadot-dispute-distribution" version = "0.1.0" @@ -6077,7 +6275,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "sc-keystore", "sc-network", @@ -6097,7 +6295,7 @@ version = "0.9.8" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "reed-solomon-novelpoly", "sp-core", "sp-trie", @@ -6114,7 +6312,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "rand_chacha 0.3.1", "sp-application-crypto", @@ -6140,7 +6338,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-network", "sp-consensus", "sp-core", @@ -6160,7 +6358,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-core", "sp-maybe-compressed-blob", "thiserror", @@ -6189,7 +6387,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "rand_core 0.5.1", "sc-client-api", @@ -6227,7 +6425,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-core", "sp-keyring", "thiserror", @@ -6246,7 +6444,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "polkadot-statement-table", "sc-keystore", "sp-application-crypto", @@ -6266,7 +6464,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-keystore", "thiserror", "tracing", @@ -6286,8 +6484,8 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-parachain", - "polkadot-primitives", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", "sp-core", "sp-keyring", "sp-maybe-compressed-blob", @@ -6305,7 +6503,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-client-api", "sc-consensus-babe", "sp-blockchain", @@ -6328,7 +6526,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-core", "thiserror", "tracing", @@ -6350,7 +6548,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-keystore", "sp-core", "sp-keyring", @@ -6369,7 +6567,7 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-core", "thiserror", "tracing", @@ -6383,7 +6581,7 @@ dependencies = [ "futures 0.3.15", "futures-timer 3.0.2", "polkadot-node-subsystem", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-blockchain", "sp-inherents", "sp-runtime", @@ -6401,7 +6599,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-application-crypto", "sp-keystore", "thiserror", @@ -6422,8 +6620,8 @@ dependencies = [ "libc", "parity-scale-codec", "pin-project 1.0.7", - "polkadot-core-primitives", - "polkadot-parachain", + "polkadot-core-primitives 0.9.8", + "polkadot-parachain 0.9.8", "rand 0.8.4", "sc-executor", "sc-executor-common", @@ -6452,7 +6650,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-api", "sp-authority-discovery", "sp-consensus-babe", @@ -6471,7 +6669,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.11.1", "polkadot-node-primitives", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-network", "sp-core", "thiserror", @@ -6501,7 +6699,7 @@ dependencies = [ "parity-scale-codec", "polkadot-node-jaeger", "polkadot-node-primitives", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-authority-discovery", "sc-network", "strum", @@ -6514,8 +6712,8 @@ version = "0.1.0" dependencies = [ "futures 0.3.15", "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", "polkadot-statement-table", "schnorrkel", "serde", @@ -6554,7 +6752,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "polkadot-statement-table", "sc-keystore", "sc-network", @@ -6587,7 +6785,7 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem-test-helpers", "polkadot-overseer-gen", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "polkadot-statement-table", "sc-network", "smallvec 1.6.1", @@ -6620,7 +6818,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-overseer", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -6650,7 +6848,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-overseer-all-subsystems-gen", "polkadot-overseer-gen", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-client-api", "sp-api", "sp-core", @@ -6703,7 +6901,22 @@ dependencies = [ "derive_more", "parity-scale-codec", "parity-util-mem", - "polkadot-core-primitives", + "polkadot-core-primitives 0.9.8", + "serde", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "polkadot-parachain" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "derive_more", + "parity-scale-codec", + "parity-util-mem", + "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", "serde", "sp-core", "sp-runtime", @@ -6719,8 +6932,8 @@ dependencies = [ "hex-literal", "parity-scale-codec", "parity-util-mem", - "polkadot-core-primitives", - "polkadot-parachain", + "polkadot-core-primitives 0.9.8", + "polkadot-parachain 0.9.8", "pretty_assertions 0.7.2", "serde", "sp-api", @@ -6741,6 +6954,36 @@ dependencies = [ "thiserror", ] +[[package]] +name = "polkadot-primitives" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "bitvec", + "frame-system", + "hex-literal", + "parity-scale-codec", + "parity-util-mem", + "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "serde", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-authority-discovery", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-trie", + "sp-version", + "thiserror", +] + [[package]] name = "polkadot-rpc" version = "0.9.8" @@ -6751,7 +6994,7 @@ dependencies = [ "pallet-mmr-rpc", "pallet-transaction-payment-rpc", "parity-scale-codec", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-chain-spec", "sc-client-api", "sc-consensus-babe", @@ -6822,8 +7065,8 @@ dependencies = [ "pallet-utility", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives", - "polkadot-runtime-common", + "polkadot-primitives 0.9.8", + "polkadot-runtime-common 0.9.8", "rustc-hex", "separator", "serde", @@ -6853,6 +7096,76 @@ dependencies = [ "trie-db", ] +[[package]] +name = "polkadot-runtime" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "beefy-primitives", + "bitvec", + "frame-election-provider-support", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "log", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-balances", + "pallet-bounties", + "pallet-collective", + "pallet-democracy", + "pallet-election-provider-multi-phase", + "pallet-elections-phragmen", + "pallet-grandpa", + "pallet-identity", + "pallet-im-online", + "pallet-indices", + "pallet-membership", + "pallet-mmr-primitives", + "pallet-multisig", + "pallet-nicks", + "pallet-offences", + "pallet-proxy", + "pallet-scheduler", + "pallet-session", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-timestamp", + "pallet-tips", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-vesting", + "parity-scale-codec", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-runtime-common 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "rustc-hex", + "serde", + "serde_derive", + "smallvec 1.6.1", + "sp-api", + "sp-authority-discovery", + "sp-block-builder", + "sp-consensus-babe", + "sp-core", + "sp-inherents", + "sp-io", + "sp-npos-elections", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "sp-transaction-pool", + "sp-version", + "static_assertions", + "substrate-wasm-builder", +] + [[package]] name = "polkadot-runtime-common" version = "0.9.8" @@ -6880,13 +7193,13 @@ dependencies = [ "pallet-treasury", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives", - "polkadot-runtime-parachains", + "polkadot-primitives 0.9.8", + "polkadot-runtime-parachains 0.9.8", "rustc-hex", "serde", "serde_derive", "serde_json", - "slot-range-helper", + "slot-range-helper 0.9.8", "sp-api", "sp-application-crypto", "sp-core", @@ -6901,7 +7214,48 @@ dependencies = [ "sp-trie", "static_assertions", "trie-db", - "xcm", + "xcm 0.9.8", +] + +[[package]] +name = "polkadot-runtime-common" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "bitvec", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "libsecp256k1 0.6.0", + "log", + "pallet-authorship", + "pallet-balances", + "pallet-beefy-mmr", + "pallet-election-provider-multi-phase", + "pallet-offences", + "pallet-session", + "pallet-staking", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-treasury", + "pallet-vesting", + "parity-scale-codec", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-runtime-parachains 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "rustc-hex", + "serde", + "serde_derive", + "slot-range-helper 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "sp-api", + "sp-core", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "static_assertions", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", ] [[package]] @@ -6930,7 +7284,7 @@ dependencies = [ "pallet-treasury", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "rand 0.8.4", "rand_chacha 0.3.1", "rustc-hex", @@ -6950,8 +7304,46 @@ dependencies = [ "sp-std", "sp-trie", "sp-version", - "xcm", - "xcm-executor", + "xcm 0.9.8", + "xcm-executor 0.9.8", +] + +[[package]] +name = "polkadot-runtime-parachains" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "bitflags", + "bitvec", + "derive_more", + "frame-support", + "frame-system", + "log", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-balances", + "pallet-offences", + "pallet-session", + "pallet-staking", + "pallet-timestamp", + "pallet-vesting", + "parity-scale-codec", + "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "rand 0.8.4", + "rand_chacha 0.3.1", + "rustc-hex", + "serde", + "sp-api", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", ] [[package]] @@ -6979,7 +7371,7 @@ dependencies = [ "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", - "polkadot-client", + "polkadot-client 0.9.8", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-gossip-support", @@ -7002,11 +7394,11 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-parachain", - "polkadot-primitives", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", "polkadot-rpc", - "polkadot-runtime", - "polkadot-runtime-parachains", + "polkadot-runtime 0.9.8", + "polkadot-runtime-parachains 0.9.8", "polkadot-statement-distribution", "polkadot-test-client", "rococo-runtime", @@ -7067,9 +7459,9 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "polkadot-cli", - "polkadot-primitives", - "polkadot-runtime", - "polkadot-runtime-common", + "polkadot-primitives 0.9.8", + "polkadot-runtime 0.9.8", + "polkadot-runtime-common 0.9.8", "polkadot-service", "sc-cli", "sc-consensus", @@ -7104,7 +7496,7 @@ version = "0.1.0" dependencies = [ "frame-system", "pallet-balances", - "polkadot-runtime", + "polkadot-runtime 0.9.8", "polkadot-simnet", "sc-client-api", "sp-blockchain", @@ -7127,7 +7519,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sc-keystore", "sc-network", "sp-application-crypto", @@ -7145,7 +7537,7 @@ name = "polkadot-statement-table" version = "0.9.8" dependencies = [ "parity-scale-codec", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "sp-core", ] @@ -7156,7 +7548,7 @@ dependencies = [ "futures 0.3.15", "parity-scale-codec", "polkadot-node-subsystem", - "polkadot-primitives", + "polkadot-primitives 0.9.8", "polkadot-test-runtime", "polkadot-test-service", "sc-block-builder", @@ -7221,10 +7613,10 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "pallet-vesting", "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime-common", - "polkadot-runtime-parachains", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", + "polkadot-runtime-common 0.9.8", + "polkadot-runtime-parachains 0.9.8", "rustc-hex", "serde", "serde_derive", @@ -7265,11 +7657,11 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-overseer", - "polkadot-parachain", - "polkadot-primitives", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", "polkadot-rpc", - "polkadot-runtime-common", - "polkadot-runtime-parachains", + "polkadot-runtime-common 0.9.8", + "polkadot-runtime-parachains 0.9.8", "polkadot-service", "polkadot-test-runtime", "rand 0.8.4", @@ -8040,10 +8432,10 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime-common", - "polkadot-runtime-parachains", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", + "polkadot-runtime-common 0.9.8", + "polkadot-runtime-parachains 0.9.8", "serde", "serde_derive", "smallvec 1.6.1", @@ -8062,9 +8454,9 @@ dependencies = [ "sp-transaction-pool", "sp-version", "substrate-wasm-builder", - "xcm", + "xcm 0.9.8", "xcm-builder", - "xcm-executor", + "xcm-executor 0.9.8", ] [[package]] @@ -9583,6 +9975,18 @@ dependencies = [ "sp-std", ] +[[package]] +name = "slot-range-helper" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "enumn", + "parity-scale-codec", + "paste", + "sp-runtime", + "sp-std", +] + [[package]] name = "slotmap" version = "1.0.5" @@ -10366,9 +10770,9 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "paste", - "polkadot-core-primitives", - "polkadot-runtime", - "polkadot-runtime-common", + "polkadot-core-primitives 0.9.8", + "polkadot-runtime 0.9.8", + "polkadot-runtime-common 0.9.8", "remote-externalities", "sc-transaction-pool-api", "serde", @@ -10660,9 +11064,9 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.67" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" dependencies = [ "proc-macro2", "quote", @@ -10739,7 +11143,7 @@ version = "0.9.8" dependencies = [ "dlmalloc", "parity-scale-codec", - "polkadot-parachain", + "polkadot-parachain 0.9.8", "sp-io", "sp-std", "substrate-wasm-builder", @@ -10758,8 +11162,8 @@ dependencies = [ "polkadot-node-core-pvf", "polkadot-node-primitives", "polkadot-node-subsystem", - "polkadot-parachain", - "polkadot-primitives", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", "polkadot-service", "polkadot-test-service", "sc-authority-discovery", @@ -10785,7 +11189,7 @@ name = "test-parachains" version = "0.9.8" dependencies = [ "parity-scale-codec", - "polkadot-parachain", + "polkadot-parachain 0.9.8", "sp-core", "test-parachain-adder", "test-parachain-halt", @@ -11477,7 +11881,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59" dependencies = [ "cfg-if 0.1.10", - "rand 0.7.3", + "rand 0.3.23", "static_assertions", ] @@ -12119,10 +12523,10 @@ dependencies = [ "pallet-vesting", "pallet-xcm", "parity-scale-codec", - "polkadot-parachain", - "polkadot-primitives", - "polkadot-runtime-common", - "polkadot-runtime-parachains", + "polkadot-parachain 0.9.8", + "polkadot-primitives 0.9.8", + "polkadot-runtime-common 0.9.8", + "polkadot-runtime-parachains 0.9.8", "rustc-hex", "serde", "serde_derive", @@ -12148,9 +12552,9 @@ dependencies = [ "static_assertions", "substrate-wasm-builder", "tiny-keccak", - "xcm", + "xcm 0.9.8", "xcm-builder", - "xcm-executor", + "xcm-executor 0.9.8", ] [[package]] @@ -12269,6 +12673,17 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "xcm" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "derivative", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", +] + [[package]] name = "xcm-builder" version = "0.9.8" @@ -12278,13 +12693,13 @@ dependencies = [ "impl-trait-for-tuples", "pallet-transaction-payment", "parity-scale-codec", - "polkadot-parachain", + "polkadot-parachain 0.9.8", "sp-arithmetic", "sp-io", "sp-runtime", "sp-std", - "xcm", - "xcm-executor", + "xcm 0.9.8", + "xcm-executor 0.9.8", ] [[package]] @@ -12300,7 +12715,70 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "xcm", + "xcm 0.9.8", +] + +[[package]] +name = "xcm-executor" +version = "0.9.8" +source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" +dependencies = [ + "frame-support", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", +] + +[[package]] +name = "xcm-simulator" +version = "0.9.8" +dependencies = [ + "cumulus-pallet-dmp-queue", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "frame-support", + "parity-scale-codec", + "paste", + "polkadot-parachain 0.9.8", + "polkadot-runtime-parachains 0.9.8", + "sp-io", + "sp-std", + "xcm 0.9.8", + "xcm-executor 0.9.8", +] + +[[package]] +name = "xcm-simulator-example" +version = "0.9.8" +dependencies = [ + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-xcm", + "parachain-info", + "parity-scale-codec", + "paste", + "polkadot-parachain 0.9.8", + "polkadot-runtime-parachains 0.9.8", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm 0.9.8", + "xcm-builder", + "xcm-executor 0.9.8", + "xcm-simulator", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 668b61db7ee0..03712f321752 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,8 @@ members = [ "xcm", "xcm/xcm-builder", "xcm/xcm-executor", + "xcm/xcm-simulator", + "xcm/xcm-simulator/example", "xcm/pallet-xcm", "node/client", "node/collation-generation", diff --git a/xcm/xcm-simulator/Cargo.toml b/xcm/xcm-simulator/Cargo.toml new file mode 100644 index 000000000000..2625b74baaf9 --- /dev/null +++ b/xcm/xcm-simulator/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "xcm-simulator" +version = "0.9.8" +authors = ["Parity Technologies x"] +description = "Test kit to simulate cross-chain message passing and XCM execution" +edition = "2018" + +[dependencies] +codec = { package = "parity-scale-codec", version = "2.0.0" } +paste = "1.0.5" + +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" } + +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } + +xcm = { path = "../" } +xcm-executor = { path = "../xcm-executor" } +polkadot-parachain = { path = "../../parachain" } +polkadot-runtime-parachains = { path = "../../runtime/parachains" } diff --git a/xcm/xcm-simulator/example/Cargo.toml b/xcm/xcm-simulator/example/Cargo.toml new file mode 100644 index 000000000000..9f09946c655a --- /dev/null +++ b/xcm/xcm-simulator/example/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "xcm-simulator-example" +version = "0.9.8" +authors = ["Parity Technologies x"] +description = "Examples of xcm-simulator usage." +edition = "2018" + +[dependencies] +codec = { package = "parity-scale-codec", version = "2.0.0" } +paste = "1.0.5" + +# substrate +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } + +# cumulus +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "master" } +parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "master" } + +# polkadot +xcm = { path = "../../" } +xcm-executor = { path = "../../xcm-executor" } +xcm-builder = { path = "../../xcm-builder" } +pallet-xcm = { path = "../../pallet-xcm" } +polkadot-runtime-parachains = { path = "../../../runtime/parachains" } +polkadot-parachain = { path = "../../../parachain" } + +xcm-simulator = { path = "../" } \ No newline at end of file diff --git a/xcm/xcm-simulator/example/src/lib.rs b/xcm/xcm-simulator/example/src/lib.rs new file mode 100644 index 000000000000..4f96dd35dd54 --- /dev/null +++ b/xcm/xcm-simulator/example/src/lib.rs @@ -0,0 +1,221 @@ +// Copyright 2021 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 frame_support::traits::GenesisBuild; +use sp_runtime::AccountId32; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; + +pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + new_ext = para_ext(2), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + XcmConfig = relay_chain::XcmConfig, + new_ext = relay_ext(), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + ], + } +} + +pub const INITIAL_BALANCE: u128 = 1_000_000_000; + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + let parachain_info_config = parachain_info::GenesisConfig { + parachain_id: para_id.into(), + }; + + >::assimilate_storage(¶chain_info_config, &mut t) + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} + +pub fn relay_ext() -> sp_io::TestExternalities { + use relay_chain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(ALICE, INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + 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; + use xcm::v0::{ + Junction::{self, Parachain, Parent}, + MultiAsset::*, + MultiLocation::*, + NetworkId, OriginKind, + Xcm::*, + }; + use xcm_simulator::TestExt; + + fn print_events(context: &str) { + println!("------ {:?} events ------", context); + frame_system::Pallet::::events().iter().for_each(|r| { + println!("{:?}", r.event); + }); + } + + #[test] + fn reserve_transfer() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::Origin::signed(ALICE), + X1(Parachain(1)), + X1(Junction::AccountId32 { + network: NetworkId::Any, + id: ALICE.into(), + }), + vec![ConcreteFungible { id: Null, amount: 123 }], + 123, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALICE), + INITIAL_BALANCE + 123 + ); + + print_events::("ParaA"); + }); + } + + #[test] + fn dmp() { + MockNet::reset(); + + let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::send_xcm( + Null, + X1(Parachain(1)), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + ParaA::execute_with(|| { + print_events::("ParaA"); + }); + } + + #[test] + fn ump() { + MockNet::reset(); + + let remark = relay_chain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Null, + X1(Parent), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + Relay::execute_with(|| { + print_events::("RelayChain"); + }); + } + + #[test] + fn xcmp() { + MockNet::reset(); + + let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Null, + X2(Parent, Parachain(2)), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + ParaB::execute_with(|| { + print_events::("ParaB"); + }); + } +} diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs new file mode 100644 index 000000000000..783d30271739 --- /dev/null +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -0,0 +1,212 @@ +// Copyright 2021 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 frame_support::{ + construct_runtime, parameter_types, + traits::{All, AllowAll}, + weights::{constants::WEIGHT_PER_SECOND, Weight}, +}; +use frame_system::EnsureRoot; +use sp_core::H256; +use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; + +use pallet_xcm::XcmPassthrough; +use polkadot_parachain::primitives::Sibling; +pub use xcm::v0::{ + Junction::{Parachain, Parent}, + MultiAsset, + MultiLocation::{self, X1, X2, X3}, + NetworkId, Xcm, +}; +pub use xcm_builder::{ + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, + CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, + LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, + TakeWeightCredit, +}; +use xcm_executor::{Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +impl frame_system::Config for Runtime { + type Origin = Origin; + type Call = Call; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + 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 = AllowAll; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; +} + +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 Event = Event; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = WEIGHT_PER_SECOND / 4; + pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND / 4; +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type Event = Event; + type OnValidationData = (); + type SelfParaId = ParachainInfo; + type DmpMessageHandler = DmpQueue; + type ReservedDmpWeight = ReservedDmpWeight; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = XcmpQueue; + type ReservedXcmpWeight = ReservedXcmpWeight; +} + +impl parachain_info::Config for Runtime {} + +parameter_types! { + pub const KsmLocation: MultiLocation = MultiLocation::X1(Parent); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); + pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); +} + +pub type LocationToAccountId = ( + ParentIsDefault, + SiblingParachainConvertsVia, + AccountId32Aliases, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + RelayChainAsNative, + SiblingParachainAsNative, + SignedAccountId32AsNative, + XcmPassthrough, +); + +parameter_types! { + pub const UnitWeightCost: Weight = 1; + pub KsmPerSecond: (MultiLocation, u128) = (X1(Parent), 1); +} + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, LocationToAccountId, AccountId, ()>; + +pub type XcmRouter = super::ParachainXcmRouter; +pub type Barrier = AllowUnpaidExecutionFrom>; + +pub struct XcmConfig; +impl Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfConcreteFungible; + type ResponseHandler = (); +} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type Event = Event; + type XcmExecutor = XcmExecutor; + type ChannelInfo = ParachainSystem; +} + +impl cumulus_pallet_dmp_queue::Config for Runtime { + type Event = Event; + type XcmExecutor = XcmExecutor; + type ExecuteOverweightOrigin = EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type Event = Event; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = All<(MultiLocation, Xcm)>; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = (); + type XcmReserveTransferFilter = All<(MultiLocation, Vec)>; + type Weigher = FixedWeightBounds; +} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Storage, Config, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event}, + ParachainInfo: parachain_info::{Pallet, Storage, Config}, + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event}, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event}, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin}, + + PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, + } +); diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs new file mode 100644 index 000000000000..4c0f896ec4c1 --- /dev/null +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -0,0 +1,177 @@ +// Copyright 2021 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, parameter_types, traits::{All, AllowAll}, weights::Weight}; +use sp_core::H256; +use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; + +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{configuration, origin, shared, ump}; +use xcm::v0::{MultiAsset, MultiLocation, NetworkId}; +use xcm_builder::{ + AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, + ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfConcreteFungible, + FixedWeightBounds, IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, +}; +use xcm_executor::{Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +impl frame_system::Config for Runtime { + type Origin = Origin; + type Call = Call; + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = Header; + type Event = Event; + 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 = AllowAll; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); +} + +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 Event = Event; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; +} + +impl shared::Config for Runtime {} + +impl configuration::Config for Runtime {} + +parameter_types! { + pub const KsmLocation: MultiLocation = MultiLocation::Null; + pub const KusamaNetwork: NetworkId = NetworkId::Kusama; + pub const AnyNetwork: NetworkId = NetworkId::Any; + pub Ancestry: MultiLocation = MultiLocation::Null; + pub UnitWeightCost: Weight = 1_000; +} + +pub type SovereignAccountOf = ( + ChildParachainConvertsVia, + AccountId32Aliases, +); + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = 1_000; + pub KsmPerSecond: (MultiLocation, u128) = (KsmLocation::get(), 1); +} + +pub type XcmRouter = super::RelayChainXcmRouter; +pub type Barrier = AllowUnpaidExecutionFrom>; + +pub struct XcmConfig; +impl Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = (); + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfConcreteFungible; + type ResponseHandler = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = (); + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = All<(MultiLocation, Vec)>; + type XcmReserveTransferFilter = All<(MultiLocation, Vec)>; + type Weigher = FixedWeightBounds; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +impl ump::Config for Runtime { + type Event = Event; + type UmpSink = ump::XcmSink, Runtime>; + type FirstMessageFactorPercent = FirstMessageFactorPercent; +} + +impl origin::Config for Runtime {} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Storage, Config, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + ParasOrigin: origin::{Pallet, Origin}, + ParasUmp: ump::{Pallet, Call, Storage, Event}, + XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event}, + } +); diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs new file mode 100644 index 000000000000..79c1cbfe2e85 --- /dev/null +++ b/xcm/xcm-simulator/src/lib.rs @@ -0,0 +1,226 @@ +// Copyright 2021 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 . + +//! Test kit to simulate cross-chain message passing and XCM execution + +pub use codec::Encode; +pub use paste; + +pub use frame_support::{traits::Get, weights::Weight}; +pub use sp_io::TestExternalities; +pub use sp_std::{cell::RefCell, marker::PhantomData}; + +pub use cumulus_pallet_dmp_queue; +pub use cumulus_pallet_xcmp_queue; +pub use cumulus_primitives_core; + +pub use polkadot_parachain::primitives::Id as ParaId; +pub use polkadot_runtime_parachains::{dmp, ump}; +pub use xcm::{v0::prelude::*, VersionedXcm}; +pub use xcm_executor::XcmExecutor; + +mod traits; +pub use traits::{HandleDmpMessage, HandleUmpMessage, HandleXcmpMessage, TestExt}; + +pub enum MessageKind { + Ump, + Dmp, + Xcmp, +} + +pub fn encode_xcm(message: Xcm<()>, message_kind: MessageKind) -> Vec { + match message_kind { + MessageKind::Ump | MessageKind::Dmp => VersionedXcm::<()>::from(message).encode(), + MessageKind::Xcmp => { + let fmt = cumulus_pallet_xcmp_queue::XcmpMessageFormat::ConcatenatedVersionedXcm; + let mut outbound = fmt.encode(); + + let encoded = VersionedXcm::<()>::from(message).encode(); + outbound.extend_from_slice(&encoded[..]); + outbound + } + } +} + +#[macro_export] +macro_rules! decl_test_relay_chain { + ( + pub struct $name:ident { + Runtime = $runtime:path, + XcmConfig = $xcm_config:path, + new_ext = $new_ext:expr, + } + ) => { + pub struct $name; + + $crate::__impl_ext!($name, $new_ext); + + impl $crate::HandleUmpMessage for $name { + fn handle_ump_message(from: $crate::ParaId, msg: &[u8], max_weight: $crate::Weight) { + use $crate::ump::UmpSink; + use $crate::TestExt; + + Self::execute_with(|| { + let _ = $crate::ump::XcmSink::<$crate::XcmExecutor<$xcm_config>, $runtime>::process_upward_message( + from, msg, max_weight, + ); + }); + } + } + }; +} + +#[macro_export] +macro_rules! decl_test_parachain { + ( + pub struct $name:ident { + Runtime = $runtime:path, + new_ext = $new_ext:expr, + } + ) => { + pub struct $name; + + $crate::__impl_ext!($name, $new_ext); + + impl $crate::HandleXcmpMessage for $name { + fn handle_xcmp_message(from: $crate::ParaId, at_relay_block: u32, msg: &[u8], max_weight: $crate::Weight) { + use $crate::cumulus_primitives_core::XcmpMessageHandler; + use $crate::TestExt; + + $name::execute_with(|| { + $crate::cumulus_pallet_xcmp_queue::Pallet::<$runtime>::handle_xcmp_messages( + vec![(from, at_relay_block, msg)].into_iter(), + max_weight, + ); + }); + } + } + + impl $crate::HandleDmpMessage for $name { + fn handle_dmp_message(at_relay_block: u32, msg: Vec, max_weight: $crate::Weight) { + use $crate::cumulus_primitives_core::DmpMessageHandler; + use $crate::TestExt; + + $name::execute_with(|| { + $crate::cumulus_pallet_dmp_queue::Pallet::<$runtime>::handle_dmp_messages( + vec![(at_relay_block, msg)].into_iter(), + max_weight, + ); + }); + } + } + }; +} + +#[macro_export] +macro_rules! __impl_ext { + // entry point: generate ext name + ($name:ident, $new_ext:expr) => { + $crate::paste::paste! { + $crate::__impl_ext!(@impl $name, $new_ext, []); + } + }; + // impl + (@impl $name:ident, $new_ext:expr, $ext_name:ident) => { + thread_local! { + pub static $ext_name: $crate::RefCell<$crate::TestExternalities> + = $crate::RefCell::new($new_ext); + } + + impl $crate::TestExt for $name { + fn new_ext() -> $crate::TestExternalities { + $new_ext + } + + fn reset_ext() { + $ext_name.with(|v| *v.borrow_mut() = $new_ext); + } + + fn execute_with(execute: impl FnOnce() -> R) -> R { + $ext_name.with(|v| v.borrow_mut().execute_with(execute)) + } + } + }; +} + +#[macro_export] +macro_rules! decl_test_network { + ( + pub struct $name:ident { + relay_chain = $relay_chain:ty, + parachains = vec![ $( ($para_id:expr, $parachain:ty), )* ], + } + ) => { + pub struct $name; + + impl $name { + pub fn reset() { + use $crate::TestExt; + + <$relay_chain>::reset_ext(); + $( <$parachain>::reset_ext(); )* + } + } + + /// XCM router for parachain. + pub struct ParachainXcmRouter($crate::PhantomData); + + impl> $crate::SendXcm for ParachainXcmRouter { + fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::XcmResult { + use $crate::{HandleUmpMessage, HandleXcmpMessage}; + + match destination { + $crate::X1($crate::Parent) => { + let encoded = $crate::encode_xcm(message, $crate::MessageKind::Ump); + <$relay_chain>::handle_ump_message(T::get(), &encoded[..], $crate::Weight::max_value()); + // TODO: update max weight + Ok(()) + }, + $( + $crate::X2($crate::Parent, $crate::Parachain(id)) if id == $para_id => { + let encoded = $crate::encode_xcm(message, $crate::MessageKind::Xcmp); + // TODO: update max weight; update `at_relay_block` + <$parachain>::handle_xcmp_message(T::get(), 1, &encoded[..], $crate::Weight::max_value()); + Ok(()) + }, + )* + _ => Err($crate::XcmError::CannotReachDestination(destination, message)), + } + } + } + + /// XCM router, only sends DMP messages. + pub struct RelayChainXcmRouter; + impl $crate::SendXcm for RelayChainXcmRouter { + fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::XcmResult { + use $crate::HandleDmpMessage; + + match destination { + $( + $crate::X1($crate::Parachain(id)) if id == $para_id => { + let encoded = $crate::encode_xcm(message, $crate::MessageKind::Dmp); + // TODO: update max weight; update `at_relay_block` + <$parachain>::handle_dmp_message(1, encoded, $crate::Weight::max_value()); + Ok(()) + }, + )* + _ => Err($crate::XcmError::SendFailed("Only sends to children parachain.")), + } + } + } + }; +} + diff --git a/xcm/xcm-simulator/src/traits.rs b/xcm/xcm-simulator/src/traits.rs new file mode 100644 index 000000000000..dbd151cce6c7 --- /dev/null +++ b/xcm/xcm-simulator/src/traits.rs @@ -0,0 +1,36 @@ +// Copyright 2021 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 . + +use polkadot_parachain::primitives::Id as ParaId; +use frame_support::weights::Weight; + +pub trait TestExt { + fn new_ext() -> sp_io::TestExternalities; + fn reset_ext(); + fn execute_with(execute: impl FnOnce() -> R) -> R; +} + +pub trait HandleUmpMessage { + fn handle_ump_message(from: ParaId, msg: &[u8], max_weight: Weight); +} + +pub trait HandleDmpMessage { + fn handle_dmp_message(at_relay_block: u32, msg: Vec, max_weight: Weight); +} + +pub trait HandleXcmpMessage { + fn handle_xcmp_message(from: ParaId, at_relay_block: u32, msg: &[u8], max_weight: Weight); +} From 41559015d75e4a17bb8e948f4405a851b6092ac8 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 17:37:58 +1200 Subject: [PATCH 2/9] Abstract xcmp and dmp handling. --- Cargo.lock | 5 +- parachain/Cargo.toml | 1 + parachain/src/primitives.rs | 54 +++++++++++++++++++ xcm/xcm-simulator/Cargo.toml | 5 +- xcm/xcm-simulator/src/lib.rs | 96 ++++++++++++++++++--------------- xcm/xcm-simulator/src/traits.rs | 19 ------- 6 files changed, 112 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67826669dbc7..f652bc7cca2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6899,6 +6899,7 @@ name = "polkadot-parachain" version = "0.9.8" dependencies = [ "derive_more", + "frame-support", "parity-scale-codec", "parity-util-mem", "polkadot-core-primitives 0.9.8", @@ -12739,12 +12740,10 @@ dependencies = [ name = "xcm-simulator" version = "0.9.8" dependencies = [ - "cumulus-pallet-dmp-queue", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", "frame-support", "parity-scale-codec", "paste", + "polkadot-core-primitives 0.9.8", "polkadot-parachain 0.9.8", "polkadot-runtime-parachains 0.9.8", "sp-io", diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml index 116d80e84188..819f1c8774d2 100644 --- a/parachain/Cargo.toml +++ b/parachain/Cargo.toml @@ -14,6 +14,7 @@ parity-util-mem = { version = "0.10.0", optional = true } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } polkadot-core-primitives = { path = "../core-primitives", default-features = false } derive_more = "0.99.11" diff --git a/parachain/src/primitives.rs b/parachain/src/primitives.rs index bf6d45ad01c8..5f7f58f9bb2d 100644 --- a/parachain/src/primitives.rs +++ b/parachain/src/primitives.rs @@ -22,6 +22,7 @@ use sp_std::vec::Vec; use parity_scale_codec::{Encode, Decode, CompactAs}; use sp_core::{RuntimeDebug, TypeId}; use sp_runtime::traits::Hash as _; +use frame_support::weights::Weight; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; @@ -318,6 +319,59 @@ pub struct HrmpChannelId { /// A message from a parachain to its Relay Chain. pub type UpwardMessage = Vec; +/// Something that should be called when a downward message is received. +pub trait DmpMessageHandler { + /// Handle some incoming DMP messages (note these are individual XCM messages). + /// + /// Also, process messages up to some `max_weight`. + fn handle_dmp_messages( + iter: impl Iterator)>, + max_weight: Weight, + ) -> Weight; +} +impl DmpMessageHandler for () { + fn handle_dmp_messages( + iter: impl Iterator)>, + _max_weight: Weight, + ) -> Weight { + iter.for_each(drop); + 0 + } +} + +/// The aggregate XCMP message format. +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode)] +pub enum XcmpMessageFormat { + /// Encoded `VersionedXcm` messages, all concatenated. + ConcatenatedVersionedXcm, + /// Encoded `Vec` messages, all concatenated. + ConcatenatedEncodedBlob, + /// One or more channel control signals; these should be interpreted immediately upon receipt + /// from the relay-chain. + Signals, +} + +/// Something that should be called for each batch of messages received over XCMP. +pub trait XcmpMessageHandler { + /// Handle some incoming XCMP messages (note these are the big one-per-block aggregate + /// messages). + /// + /// Also, process messages up to some `max_weight`. + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight; +} +impl XcmpMessageHandler for () { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + _max_weight: Weight, + ) -> Weight { + for _ in iter {} + 0 + } +} + /// Validation parameters for evaluating the parachain validity function. // TODO: balance downloads (https://github.com/paritytech/polkadot/issues/220) #[derive(PartialEq, Eq, Decode, Clone)] diff --git a/xcm/xcm-simulator/Cargo.toml b/xcm/xcm-simulator/Cargo.toml index 2625b74baaf9..b2abd4d75f9a 100644 --- a/xcm/xcm-simulator/Cargo.toml +++ b/xcm/xcm-simulator/Cargo.toml @@ -13,11 +13,8 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "mas sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } - xcm = { path = "../" } xcm-executor = { path = "../xcm-executor" } +polkadot-core-primitives = { path = "../../core-primitives"} polkadot-parachain = { path = "../../parachain" } polkadot-runtime-parachains = { path = "../../runtime/parachains" } diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs index 79c1cbfe2e85..d9daffb49939 100644 --- a/xcm/xcm-simulator/src/lib.rs +++ b/xcm/xcm-simulator/src/lib.rs @@ -23,17 +23,20 @@ pub use frame_support::{traits::Get, weights::Weight}; pub use sp_io::TestExternalities; pub use sp_std::{cell::RefCell, marker::PhantomData}; -pub use cumulus_pallet_dmp_queue; -pub use cumulus_pallet_xcmp_queue; -pub use cumulus_primitives_core; - -pub use polkadot_parachain::primitives::Id as ParaId; -pub use polkadot_runtime_parachains::{dmp, ump}; +pub use polkadot_parachain::primitives::{ + Id as ParaId, XcmpMessageHandler as XcmpMessageHandlerT, + DmpMessageHandler as DmpMessageHandlerT, XcmpMessageFormat, +}; +pub use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +pub use polkadot_runtime_parachains::{dmp, ump::{XcmSink, UmpSink, MessageId}}; pub use xcm::{v0::prelude::*, VersionedXcm}; pub use xcm_executor::XcmExecutor; -mod traits; -pub use traits::{HandleDmpMessage, HandleUmpMessage, HandleXcmpMessage, TestExt}; +pub trait TestExt { + fn new_ext() -> sp_io::TestExternalities; + fn reset_ext(); + fn execute_with(execute: impl FnOnce() -> R) -> R; +} pub enum MessageKind { Ump, @@ -45,7 +48,7 @@ pub fn encode_xcm(message: Xcm<()>, message_kind: MessageKind) -> Vec { match message_kind { MessageKind::Ump | MessageKind::Dmp => VersionedXcm::<()>::from(message).encode(), MessageKind::Xcmp => { - let fmt = cumulus_pallet_xcmp_queue::XcmpMessageFormat::ConcatenatedVersionedXcm; + let fmt = XcmpMessageFormat::ConcatenatedVersionedXcm; let mut outbound = fmt.encode(); let encoded = VersionedXcm::<()>::from(message).encode(); @@ -68,16 +71,20 @@ macro_rules! decl_test_relay_chain { $crate::__impl_ext!($name, $new_ext); - impl $crate::HandleUmpMessage for $name { - fn handle_ump_message(from: $crate::ParaId, msg: &[u8], max_weight: $crate::Weight) { + impl $crate::UmpSink for $name { + fn process_upward_message( + origin: $crate::ParaId, + msg: &[u8], + max_weight: $crate::Weight, + ) -> Result<$crate::Weight, ($crate::MessageId, $crate::Weight)> { use $crate::ump::UmpSink; use $crate::TestExt; Self::execute_with(|| { - let _ = $crate::ump::XcmSink::<$crate::XcmExecutor<$xcm_config>, $runtime>::process_upward_message( - from, msg, max_weight, - ); - }); + $crate::ump::XcmSink::<$crate::XcmExecutor<$xcm_config>, $runtime>::process_upward_message( + origin, msg, max_weight, + ) + }) } } }; @@ -88,6 +95,8 @@ macro_rules! decl_test_parachain { ( pub struct $name:ident { Runtime = $runtime:path, + XcmpMessageHandler = $xcmp_message_handler:path, + DmpMessageHandler = $dmp_message_handler:path, new_ext = $new_ext:expr, } ) => { @@ -95,31 +104,30 @@ macro_rules! decl_test_parachain { $crate::__impl_ext!($name, $new_ext); - impl $crate::HandleXcmpMessage for $name { - fn handle_xcmp_message(from: $crate::ParaId, at_relay_block: u32, msg: &[u8], max_weight: $crate::Weight) { - use $crate::cumulus_primitives_core::XcmpMessageHandler; - use $crate::TestExt; + impl $crate::XcmpMessageHandlerT for $name { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: $crate::Weight, + ) -> $crate::Weight { + use $crate::{XcmpMessageHandlerT, TestExt}; $name::execute_with(|| { - $crate::cumulus_pallet_xcmp_queue::Pallet::<$runtime>::handle_xcmp_messages( - vec![(from, at_relay_block, msg)].into_iter(), + XcmpMessageHandler::handle_xcmp_messages( + iter, max_weight, - ); - }); + ) + }) } } - impl $crate::HandleDmpMessage for $name { - fn handle_dmp_message(at_relay_block: u32, msg: Vec, max_weight: $crate::Weight) { - use $crate::cumulus_primitives_core::DmpMessageHandler; - use $crate::TestExt; - + impl $crate::DmpMessageHandlerT for $name { + fn handle_dmp_messages( + iter: impl Iterator)>, + max_weight: Weight, + ) -> Weight { $name::execute_with(|| { - $crate::cumulus_pallet_dmp_queue::Pallet::<$runtime>::handle_dmp_messages( - vec![(at_relay_block, msg)].into_iter(), - max_weight, - ); - }); + DmpMessageHandler::handle_dmp_messages(iter, max_weight) + }) } } }; @@ -180,20 +188,23 @@ macro_rules! decl_test_network { impl> $crate::SendXcm for ParachainXcmRouter { fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::XcmResult { - use $crate::{HandleUmpMessage, HandleXcmpMessage}; + use $crate::{UmpSink, XcmpMessageHandlerT}; match destination { $crate::X1($crate::Parent) => { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Ump); - <$relay_chain>::handle_ump_message(T::get(), &encoded[..], $crate::Weight::max_value()); - // TODO: update max weight + let _ = <$relay_chain>::process_upward_message( + T::get(), &encoded[..], + $crate::Weight::max_value(), + ); Ok(()) }, $( $crate::X2($crate::Parent, $crate::Parachain(id)) if id == $para_id => { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Xcmp); - // TODO: update max weight; update `at_relay_block` - <$parachain>::handle_xcmp_message(T::get(), 1, &encoded[..], $crate::Weight::max_value()); + // TODO: update relay block number + let messages = vec![(T::get(), 1, &encoded[..])]; + let _ = <$parachain>::handle_xcmp_messages(messages.into_iter(), $crate::Weight::max_value()); Ok(()) }, )* @@ -202,18 +213,19 @@ macro_rules! decl_test_network { } } - /// XCM router, only sends DMP messages. + /// XCM router for relay chain. pub struct RelayChainXcmRouter; impl $crate::SendXcm for RelayChainXcmRouter { fn send_xcm(destination: $crate::MultiLocation, message: $crate::Xcm<()>) -> $crate::XcmResult { - use $crate::HandleDmpMessage; + use $crate::DmpMessageHandlerT; match destination { $( $crate::X1($crate::Parachain(id)) if id == $para_id => { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Dmp); - // TODO: update max weight; update `at_relay_block` - <$parachain>::handle_dmp_message(1, encoded, $crate::Weight::max_value()); + // TODO: update relay block number + let messages = vec![(1, encoded)]; + let _ = <$parachain>::handle_dmp_messages(messages.into_iter(), $crate::Weight::max_value()); Ok(()) }, )* diff --git a/xcm/xcm-simulator/src/traits.rs b/xcm/xcm-simulator/src/traits.rs index dbd151cce6c7..7dcce37df34d 100644 --- a/xcm/xcm-simulator/src/traits.rs +++ b/xcm/xcm-simulator/src/traits.rs @@ -14,23 +14,4 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use polkadot_parachain::primitives::Id as ParaId; -use frame_support::weights::Weight; -pub trait TestExt { - fn new_ext() -> sp_io::TestExternalities; - fn reset_ext(); - fn execute_with(execute: impl FnOnce() -> R) -> R; -} - -pub trait HandleUmpMessage { - fn handle_ump_message(from: ParaId, msg: &[u8], max_weight: Weight); -} - -pub trait HandleDmpMessage { - fn handle_dmp_message(at_relay_block: u32, msg: Vec, max_weight: Weight); -} - -pub trait HandleXcmpMessage { - fn handle_xcmp_message(from: ParaId, at_relay_block: u32, msg: &[u8], max_weight: Weight); -} From cab3a7582bc42b747a5f702f773cbd73f9e1d8c4 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 19:38:25 +1200 Subject: [PATCH 3/9] Use mock message queue. --- Cargo.lock | 653 ++++----------------- xcm/xcm-simulator/example/Cargo.toml | 14 +- xcm/xcm-simulator/example/src/lib.rs | 248 ++++---- xcm/xcm-simulator/example/src/parachain.rs | 214 +++++-- xcm/xcm-simulator/src/lib.rs | 14 +- 5 files changed, 413 insertions(+), 730 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f652bc7cca2d..ceb753bffb4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1461,150 +1461,6 @@ dependencies = [ "rand 0.7.3", ] -[[package]] -name = "cumulus-pallet-dmp-queue" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-primitives-core", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "rand 0.8.4", - "rand_chacha 0.3.1", - "sp-io", - "sp-runtime", - "sp-std", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", -] - -[[package]] -name = "cumulus-pallet-parachain-system" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-pallet-parachain-system-proc-macro", - "cumulus-primitives-core", - "cumulus-primitives-parachain-inherent", - "environmental", - "frame-support", - "frame-system", - "log", - "pallet-balances", - "parity-scale-codec", - "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "serde", - "sp-core", - "sp-externalities", - "sp-inherents", - "sp-io", - "sp-runtime", - "sp-state-machine", - "sp-std", - "sp-trie", - "sp-version", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", -] - -[[package]] -name = "cumulus-pallet-parachain-system-proc-macro" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "proc-macro-crate 1.0.0", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cumulus-pallet-xcm" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-primitives-core", - "frame-support", - "frame-system", - "parity-scale-codec", - "serde", - "sp-io", - "sp-runtime", - "sp-std", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", -] - -[[package]] -name = "cumulus-pallet-xcmp-queue" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-primitives-core", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "rand 0.8.4", - "rand_chacha 0.3.1", - "sp-runtime", - "sp-std", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", -] - -[[package]] -name = "cumulus-primitives-core" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "frame-support", - "impl-trait-for-tuples", - "parity-scale-codec", - "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "sp-api", - "sp-runtime", - "sp-std", - "sp-trie", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", -] - -[[package]] -name = "cumulus-primitives-parachain-inherent" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "async-trait", - "cumulus-primitives-core", - "cumulus-test-relay-sproof-builder", - "parity-scale-codec", - "polkadot-client 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "sc-client-api", - "sp-api", - "sp-core", - "sp-inherents", - "sp-runtime", - "sp-state-machine", - "sp-std", - "sp-trie", - "tracing", -] - -[[package]] -name = "cumulus-test-relay-sproof-builder" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-primitives-core", - "parity-scale-codec", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "sp-runtime", - "sp-state-machine", - "sp-std", -] - [[package]] name = "curve25519-dalek" version = "2.1.0" @@ -3552,9 +3408,9 @@ dependencies = [ "pallet-vesting", "pallet-xcm", "parity-scale-codec", - "polkadot-primitives 0.9.8", - "polkadot-runtime-common 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", "rustc-hex", "separator", "serde", @@ -3582,9 +3438,9 @@ dependencies = [ "static_assertions", "substrate-wasm-builder", "tiny-keccak", - "xcm 0.9.8", + "xcm", "xcm-builder", - "xcm-executor 0.9.8", + "xcm-executor", ] [[package]] @@ -5596,20 +5452,8 @@ dependencies = [ "serde", "sp-runtime", "sp-std", - "xcm 0.9.8", - "xcm-executor 0.9.8", -] - -[[package]] -name = "parachain-info" -version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus?branch=master#2fd51bd915c9a5b63c67b61d32d54d00a7b8f529" -dependencies = [ - "cumulus-primitives-core", - "frame-support", - "frame-system", - "parity-scale-codec", - "serde", + "xcm", + "xcm-executor", ] [[package]] @@ -6040,7 +5884,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand_core 0.5.1", "schnorrkel", "sp-core", @@ -6061,7 +5905,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-application-crypto", "sp-core", "sp-keystore", @@ -6085,7 +5929,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -6114,7 +5958,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -6156,8 +6000,8 @@ dependencies = [ "kusama-runtime", "pallet-mmr-primitives", "pallet-transaction-payment-rpc-runtime-api", - "polkadot-primitives 0.9.8", - "polkadot-runtime 0.9.8", + "polkadot-primitives", + "polkadot-runtime", "rococo-runtime", "sc-client-api", "sc-consensus", @@ -6178,36 +6022,6 @@ dependencies = [ "westend-runtime", ] -[[package]] -name = "polkadot-client" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "beefy-primitives", - "frame-benchmarking", - "frame-system-rpc-runtime-api", - "pallet-mmr-primitives", - "pallet-transaction-payment-rpc-runtime-api", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-runtime 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "sc-client-api", - "sc-consensus", - "sc-executor", - "sc-service", - "sp-api", - "sp-authority-discovery", - "sp-block-builder", - "sp-blockchain", - "sp-consensus", - "sp-consensus-babe", - "sp-finality-grandpa", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-storage", - "sp-transaction-pool", -] - [[package]] name = "polkadot-collator-protocol" version = "0.1.0" @@ -6223,7 +6037,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-network", "sp-core", "sp-keyring", @@ -6244,18 +6058,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "polkadot-core-primitives" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "parity-scale-codec", - "parity-util-mem", - "sp-core", - "sp-runtime", - "sp-std", -] - [[package]] name = "polkadot-dispute-distribution" version = "0.1.0" @@ -6275,7 +6077,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "sc-keystore", "sc-network", @@ -6295,7 +6097,7 @@ version = "0.9.8" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "reed-solomon-novelpoly", "sp-core", "sp-trie", @@ -6312,7 +6114,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "rand_chacha 0.3.1", "sp-application-crypto", @@ -6338,7 +6140,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-network", "sp-consensus", "sp-core", @@ -6358,7 +6160,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-core", "sp-maybe-compressed-blob", "thiserror", @@ -6387,7 +6189,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "rand_core 0.5.1", "sc-client-api", @@ -6425,7 +6227,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-core", "sp-keyring", "thiserror", @@ -6444,7 +6246,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "polkadot-statement-table", "sc-keystore", "sp-application-crypto", @@ -6464,7 +6266,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-keystore", "thiserror", "tracing", @@ -6484,8 +6286,8 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", + "polkadot-parachain", + "polkadot-primitives", "sp-core", "sp-keyring", "sp-maybe-compressed-blob", @@ -6503,7 +6305,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-client-api", "sc-consensus-babe", "sp-blockchain", @@ -6526,7 +6328,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-core", "thiserror", "tracing", @@ -6548,7 +6350,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-keystore", "sp-core", "sp-keyring", @@ -6567,7 +6369,7 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-core", "thiserror", "tracing", @@ -6581,7 +6383,7 @@ dependencies = [ "futures 0.3.15", "futures-timer 3.0.2", "polkadot-node-subsystem", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-blockchain", "sp-inherents", "sp-runtime", @@ -6599,7 +6401,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-application-crypto", "sp-keystore", "thiserror", @@ -6620,8 +6422,8 @@ dependencies = [ "libc", "parity-scale-codec", "pin-project 1.0.7", - "polkadot-core-primitives 0.9.8", - "polkadot-parachain 0.9.8", + "polkadot-core-primitives", + "polkadot-parachain", "rand 0.8.4", "sc-executor", "sc-executor-common", @@ -6650,7 +6452,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-api", "sp-authority-discovery", "sp-consensus-babe", @@ -6669,7 +6471,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.11.1", "polkadot-node-primitives", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-network", "sp-core", "thiserror", @@ -6699,7 +6501,7 @@ dependencies = [ "parity-scale-codec", "polkadot-node-jaeger", "polkadot-node-primitives", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-authority-discovery", "sc-network", "strum", @@ -6712,8 +6514,8 @@ version = "0.1.0" dependencies = [ "futures 0.3.15", "parity-scale-codec", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", + "polkadot-parachain", + "polkadot-primitives", "polkadot-statement-table", "schnorrkel", "serde", @@ -6752,7 +6554,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "polkadot-statement-table", "sc-keystore", "sc-network", @@ -6785,7 +6587,7 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem-test-helpers", "polkadot-overseer-gen", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "polkadot-statement-table", "sc-network", "smallvec 1.6.1", @@ -6818,7 +6620,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-overseer", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "sc-network", "sp-application-crypto", @@ -6848,7 +6650,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-overseer-all-subsystems-gen", "polkadot-overseer-gen", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-client-api", "sp-api", "sp-core", @@ -6902,22 +6704,7 @@ dependencies = [ "frame-support", "parity-scale-codec", "parity-util-mem", - "polkadot-core-primitives 0.9.8", - "serde", - "sp-core", - "sp-runtime", - "sp-std", -] - -[[package]] -name = "polkadot-parachain" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "derive_more", - "parity-scale-codec", - "parity-util-mem", - "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "polkadot-core-primitives", "serde", "sp-core", "sp-runtime", @@ -6933,8 +6720,8 @@ dependencies = [ "hex-literal", "parity-scale-codec", "parity-util-mem", - "polkadot-core-primitives 0.9.8", - "polkadot-parachain 0.9.8", + "polkadot-core-primitives", + "polkadot-parachain", "pretty_assertions 0.7.2", "serde", "sp-api", @@ -6955,36 +6742,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "polkadot-primitives" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "bitvec", - "frame-system", - "hex-literal", - "parity-scale-codec", - "parity-util-mem", - "polkadot-core-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-parachain 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "serde", - "sp-api", - "sp-application-crypto", - "sp-arithmetic", - "sp-authority-discovery", - "sp-consensus-slots", - "sp-core", - "sp-inherents", - "sp-io", - "sp-keystore", - "sp-runtime", - "sp-staking", - "sp-std", - "sp-trie", - "sp-version", - "thiserror", -] - [[package]] name = "polkadot-rpc" version = "0.9.8" @@ -6995,7 +6752,7 @@ dependencies = [ "pallet-mmr-rpc", "pallet-transaction-payment-rpc", "parity-scale-codec", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-chain-spec", "sc-client-api", "sc-consensus-babe", @@ -7066,8 +6823,8 @@ dependencies = [ "pallet-utility", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives 0.9.8", - "polkadot-runtime-common 0.9.8", + "polkadot-primitives", + "polkadot-runtime-common", "rustc-hex", "separator", "serde", @@ -7097,76 +6854,6 @@ dependencies = [ "trie-db", ] -[[package]] -name = "polkadot-runtime" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "beefy-primitives", - "bitvec", - "frame-election-provider-support", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "log", - "pallet-authority-discovery", - "pallet-authorship", - "pallet-babe", - "pallet-balances", - "pallet-bounties", - "pallet-collective", - "pallet-democracy", - "pallet-election-provider-multi-phase", - "pallet-elections-phragmen", - "pallet-grandpa", - "pallet-identity", - "pallet-im-online", - "pallet-indices", - "pallet-membership", - "pallet-mmr-primitives", - "pallet-multisig", - "pallet-nicks", - "pallet-offences", - "pallet-proxy", - "pallet-scheduler", - "pallet-session", - "pallet-staking", - "pallet-staking-reward-curve", - "pallet-timestamp", - "pallet-tips", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-treasury", - "pallet-utility", - "pallet-vesting", - "parity-scale-codec", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-runtime-common 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "rustc-hex", - "serde", - "serde_derive", - "smallvec 1.6.1", - "sp-api", - "sp-authority-discovery", - "sp-block-builder", - "sp-consensus-babe", - "sp-core", - "sp-inherents", - "sp-io", - "sp-npos-elections", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-staking", - "sp-std", - "sp-transaction-pool", - "sp-version", - "static_assertions", - "substrate-wasm-builder", -] - [[package]] name = "polkadot-runtime-common" version = "0.9.8" @@ -7194,13 +6881,13 @@ dependencies = [ "pallet-treasury", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-primitives", + "polkadot-runtime-parachains", "rustc-hex", "serde", "serde_derive", "serde_json", - "slot-range-helper 0.9.8", + "slot-range-helper", "sp-api", "sp-application-crypto", "sp-core", @@ -7215,48 +6902,7 @@ dependencies = [ "sp-trie", "static_assertions", "trie-db", - "xcm 0.9.8", -] - -[[package]] -name = "polkadot-runtime-common" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "bitvec", - "frame-support", - "frame-system", - "impl-trait-for-tuples", - "libsecp256k1 0.6.0", - "log", - "pallet-authorship", - "pallet-balances", - "pallet-beefy-mmr", - "pallet-election-provider-multi-phase", - "pallet-offences", - "pallet-session", - "pallet-staking", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-treasury", - "pallet-vesting", - "parity-scale-codec", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "polkadot-runtime-parachains 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "rustc-hex", - "serde", - "serde_derive", - "slot-range-helper 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "sp-api", - "sp-core", - "sp-inherents", - "sp-io", - "sp-runtime", - "sp-session", - "sp-staking", - "sp-std", - "static_assertions", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm", ] [[package]] @@ -7285,7 +6931,7 @@ dependencies = [ "pallet-treasury", "pallet-vesting", "parity-scale-codec", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "rand 0.8.4", "rand_chacha 0.3.1", "rustc-hex", @@ -7305,46 +6951,8 @@ dependencies = [ "sp-std", "sp-trie", "sp-version", - "xcm 0.9.8", - "xcm-executor 0.9.8", -] - -[[package]] -name = "polkadot-runtime-parachains" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "bitflags", - "bitvec", - "derive_more", - "frame-support", - "frame-system", - "log", - "pallet-authority-discovery", - "pallet-authorship", - "pallet-balances", - "pallet-offences", - "pallet-session", - "pallet-staking", - "pallet-timestamp", - "pallet-vesting", - "parity-scale-codec", - "polkadot-primitives 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "rand 0.8.4", - "rand_chacha 0.3.1", - "rustc-hex", - "serde", - "sp-api", - "sp-core", - "sp-inherents", - "sp-io", - "sp-keystore", - "sp-runtime", - "sp-session", - "sp-staking", - "sp-std", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", - "xcm-executor 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm", + "xcm-executor", ] [[package]] @@ -7372,7 +6980,7 @@ dependencies = [ "polkadot-availability-bitfield-distribution", "polkadot-availability-distribution", "polkadot-availability-recovery", - "polkadot-client 0.9.8", + "polkadot-client", "polkadot-collator-protocol", "polkadot-dispute-distribution", "polkadot-gossip-support", @@ -7395,11 +7003,11 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-overseer", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", + "polkadot-parachain", + "polkadot-primitives", "polkadot-rpc", - "polkadot-runtime 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-runtime", + "polkadot-runtime-parachains", "polkadot-statement-distribution", "polkadot-test-client", "rococo-runtime", @@ -7460,9 +7068,9 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "polkadot-cli", - "polkadot-primitives 0.9.8", - "polkadot-runtime 0.9.8", - "polkadot-runtime-common 0.9.8", + "polkadot-primitives", + "polkadot-runtime", + "polkadot-runtime-common", "polkadot-service", "sc-cli", "sc-consensus", @@ -7497,7 +7105,7 @@ version = "0.1.0" dependencies = [ "frame-system", "pallet-balances", - "polkadot-runtime 0.9.8", + "polkadot-runtime", "polkadot-simnet", "sc-client-api", "sp-blockchain", @@ -7520,7 +7128,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sc-keystore", "sc-network", "sp-application-crypto", @@ -7538,7 +7146,7 @@ name = "polkadot-statement-table" version = "0.9.8" dependencies = [ "parity-scale-codec", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "sp-core", ] @@ -7549,7 +7157,7 @@ dependencies = [ "futures 0.3.15", "parity-scale-codec", "polkadot-node-subsystem", - "polkadot-primitives 0.9.8", + "polkadot-primitives", "polkadot-test-runtime", "polkadot-test-service", "sc-block-builder", @@ -7614,10 +7222,10 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "pallet-vesting", "parity-scale-codec", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", - "polkadot-runtime-common 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", "rustc-hex", "serde", "serde_derive", @@ -7658,11 +7266,11 @@ dependencies = [ "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-overseer", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", + "polkadot-parachain", + "polkadot-primitives", "polkadot-rpc", - "polkadot-runtime-common 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-runtime-common", + "polkadot-runtime-parachains", "polkadot-service", "polkadot-test-runtime", "rand 0.8.4", @@ -8433,10 +8041,10 @@ dependencies = [ "pallet-utility", "pallet-xcm", "parity-scale-codec", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", - "polkadot-runtime-common 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", "serde", "serde_derive", "smallvec 1.6.1", @@ -8455,9 +8063,9 @@ dependencies = [ "sp-transaction-pool", "sp-version", "substrate-wasm-builder", - "xcm 0.9.8", + "xcm", "xcm-builder", - "xcm-executor 0.9.8", + "xcm-executor", ] [[package]] @@ -9976,18 +9584,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "slot-range-helper" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "enumn", - "parity-scale-codec", - "paste", - "sp-runtime", - "sp-std", -] - [[package]] name = "slotmap" version = "1.0.5" @@ -10771,9 +10367,9 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "paste", - "polkadot-core-primitives 0.9.8", - "polkadot-runtime 0.9.8", - "polkadot-runtime-common 0.9.8", + "polkadot-core-primitives", + "polkadot-runtime", + "polkadot-runtime-common", "remote-externalities", "sc-transaction-pool-api", "serde", @@ -11144,7 +10740,7 @@ version = "0.9.8" dependencies = [ "dlmalloc", "parity-scale-codec", - "polkadot-parachain 0.9.8", + "polkadot-parachain", "sp-io", "sp-std", "substrate-wasm-builder", @@ -11163,8 +10759,8 @@ dependencies = [ "polkadot-node-core-pvf", "polkadot-node-primitives", "polkadot-node-subsystem", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", + "polkadot-parachain", + "polkadot-primitives", "polkadot-service", "polkadot-test-service", "sc-authority-discovery", @@ -11190,7 +10786,7 @@ name = "test-parachains" version = "0.9.8" dependencies = [ "parity-scale-codec", - "polkadot-parachain 0.9.8", + "polkadot-parachain", "sp-core", "test-parachain-adder", "test-parachain-halt", @@ -12524,10 +12120,10 @@ dependencies = [ "pallet-vesting", "pallet-xcm", "parity-scale-codec", - "polkadot-parachain 0.9.8", - "polkadot-primitives 0.9.8", - "polkadot-runtime-common 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-parachain", + "polkadot-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", "rustc-hex", "serde", "serde_derive", @@ -12553,9 +12149,9 @@ dependencies = [ "static_assertions", "substrate-wasm-builder", "tiny-keccak", - "xcm 0.9.8", + "xcm", "xcm-builder", - "xcm-executor 0.9.8", + "xcm-executor", ] [[package]] @@ -12674,17 +12270,6 @@ dependencies = [ "parity-scale-codec", ] -[[package]] -name = "xcm" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" -dependencies = [ - "derivative", - "impl-trait-for-tuples", - "log", - "parity-scale-codec", -] - [[package]] name = "xcm-builder" version = "0.9.8" @@ -12694,35 +12279,18 @@ dependencies = [ "impl-trait-for-tuples", "pallet-transaction-payment", "parity-scale-codec", - "polkadot-parachain 0.9.8", - "sp-arithmetic", - "sp-io", - "sp-runtime", - "sp-std", - "xcm 0.9.8", - "xcm-executor 0.9.8", -] - -[[package]] -name = "xcm-executor" -version = "0.9.8" -dependencies = [ - "frame-support", - "impl-trait-for-tuples", - "log", - "parity-scale-codec", + "polkadot-parachain", "sp-arithmetic", - "sp-core", "sp-io", "sp-runtime", "sp-std", - "xcm 0.9.8", + "xcm", + "xcm-executor", ] [[package]] name = "xcm-executor" version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot?branch=master#18de14db5ec7c86d83c7385c132a2513a3d449b4" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -12733,7 +12301,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "xcm 0.9.8 (git+https://github.com/paritytech/polkadot?branch=master)", + "xcm", ] [[package]] @@ -12743,40 +12311,35 @@ dependencies = [ "frame-support", "parity-scale-codec", "paste", - "polkadot-core-primitives 0.9.8", - "polkadot-parachain 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-runtime-parachains", "sp-io", "sp-std", - "xcm 0.9.8", - "xcm-executor 0.9.8", + "xcm", + "xcm-executor", ] [[package]] name = "xcm-simulator-example" version = "0.9.8" dependencies = [ - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", "frame-support", "frame-system", "pallet-balances", "pallet-xcm", - "parachain-info", "parity-scale-codec", "paste", - "polkadot-parachain 0.9.8", - "polkadot-runtime-parachains 0.9.8", + "polkadot-core-primitives", + "polkadot-parachain", + "polkadot-runtime-parachains", "sp-core", "sp-io", "sp-runtime", "sp-std", - "xcm 0.9.8", + "xcm", "xcm-builder", - "xcm-executor 0.9.8", + "xcm-executor", "xcm-simulator", ] diff --git a/xcm/xcm-simulator/example/Cargo.toml b/xcm/xcm-simulator/example/Cargo.toml index 9f09946c655a..1d85687b2ecb 100644 --- a/xcm/xcm-simulator/example/Cargo.toml +++ b/xcm/xcm-simulator/example/Cargo.toml @@ -18,20 +18,12 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } -# cumulus -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "master" } -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus", branch = "master" } -parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "master" } - # polkadot xcm = { path = "../../" } +xcm-simulator = { path = "../" } xcm-executor = { path = "../../xcm-executor" } xcm-builder = { path = "../../xcm-builder" } pallet-xcm = { path = "../../pallet-xcm" } +polkadot-core-primitives = { path = "../../../core-primitives"} polkadot-runtime-parachains = { path = "../../../runtime/parachains" } -polkadot-parachain = { path = "../../../parachain" } - -xcm-simulator = { path = "../" } \ No newline at end of file +polkadot-parachain = { path = "../../../parachain" } \ No newline at end of file diff --git a/xcm/xcm-simulator/example/src/lib.rs b/xcm/xcm-simulator/example/src/lib.rs index 4f96dd35dd54..9dc7ed4d9ced 100644 --- a/xcm/xcm-simulator/example/src/lib.rs +++ b/xcm/xcm-simulator/example/src/lib.rs @@ -14,18 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -mod parachain; mod relay_chain; +mod parachain; -use frame_support::traits::GenesisBuild; use sp_runtime::AccountId32; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; +use parachain::mock_msg_queue; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); decl_test_parachain! { pub struct ParaA { Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, new_ext = para_ext(1), } } @@ -33,6 +35,8 @@ decl_test_parachain! { decl_test_parachain! { pub struct ParaB { Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, new_ext = para_ext(2), } } @@ -64,12 +68,12 @@ pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { .build_storage::() .unwrap(); - let parachain_info_config = parachain_info::GenesisConfig { + mock_msg_queue::GenesisConfig:: { parachain_id: para_id.into(), - }; + } + .assimilate_storage(&mut t) + .unwrap(); - >::assimilate_storage(¶chain_info_config, &mut t) - .unwrap(); pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)], @@ -103,119 +107,119 @@ pub fn relay_ext() -> sp_io::TestExternalities { 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; - use xcm::v0::{ - Junction::{self, Parachain, Parent}, - MultiAsset::*, - MultiLocation::*, - NetworkId, OriginKind, - Xcm::*, - }; - use xcm_simulator::TestExt; - - fn print_events(context: &str) { - println!("------ {:?} events ------", context); - frame_system::Pallet::::events().iter().for_each(|r| { - println!("{:?}", r.event); - }); - } - - #[test] - fn reserve_transfer() { - MockNet::reset(); - - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( - relay_chain::Origin::signed(ALICE), - X1(Parachain(1)), - X1(Junction::AccountId32 { - network: NetworkId::Any, - id: ALICE.into(), - }), - vec![ConcreteFungible { id: Null, amount: 123 }], - 123, - )); - }); - - ParaA::execute_with(|| { - // free execution, full amount received - assert_eq!( - pallet_balances::Pallet::::free_balance(&ALICE), - INITIAL_BALANCE + 123 - ); - - print_events::("ParaA"); - }); - } - - #[test] - fn dmp() { - MockNet::reset(); - - let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); - Relay::execute_with(|| { - assert_ok!(RelayChainPalletXcm::send_xcm( - Null, - X1(Parachain(1)), - Transact { - origin_type: OriginKind::SovereignAccount, - require_weight_at_most: INITIAL_BALANCE as u64, - call: remark.encode().into(), - }, - )); - }); - - ParaA::execute_with(|| { - print_events::("ParaA"); - }); - } - - #[test] - fn ump() { - MockNet::reset(); - - let remark = relay_chain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Null, - X1(Parent), - Transact { - origin_type: OriginKind::SovereignAccount, - require_weight_at_most: INITIAL_BALANCE as u64, - call: remark.encode().into(), - }, - )); - }); - - Relay::execute_with(|| { - print_events::("RelayChain"); - }); - } - - #[test] - fn xcmp() { - MockNet::reset(); - - let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); - ParaA::execute_with(|| { - assert_ok!(ParachainPalletXcm::send_xcm( - Null, - X2(Parent, Parachain(2)), - Transact { - origin_type: OriginKind::SovereignAccount, - require_weight_at_most: INITIAL_BALANCE as u64, - call: remark.encode().into(), - }, - )); - }); - - ParaB::execute_with(|| { - print_events::("ParaB"); - }); - } -} +// #[cfg(test)] +// mod tests { +// use super::*; + +// use codec::Encode; +// use frame_support::assert_ok; +// use xcm::v0::{ +// Junction::{self, Parachain, Parent}, +// MultiAsset::*, +// MultiLocation::*, +// NetworkId, OriginKind, +// Xcm::*, +// }; +// use xcm_simulator::TestExt; + +// fn print_events(context: &str) { +// println!("------ {:?} events ------", context); +// frame_system::Pallet::::events().iter().for_each(|r| { +// println!("{:?}", r.event); +// }); +// } + +// #[test] +// fn reserve_transfer() { +// MockNet::reset(); + +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( +// relay_chain::Origin::signed(ALICE), +// X1(Parachain(1)), +// X1(Junction::AccountId32 { +// network: NetworkId::Any, +// id: ALICE.into(), +// }), +// vec![ConcreteFungible { id: Null, amount: 123 }], +// 123, +// )); +// }); + +// ParaA::execute_with(|| { +// // free execution, full amount received +// assert_eq!( +// pallet_balances::Pallet::::free_balance(&ALICE), +// INITIAL_BALANCE + 123 +// ); + +// print_events::("ParaA"); +// }); +// } + +// #[test] +// fn dmp() { +// MockNet::reset(); + +// let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); +// Relay::execute_with(|| { +// assert_ok!(RelayChainPalletXcm::send_xcm( +// Null, +// X1(Parachain(1)), +// Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }, +// )); +// }); + +// ParaA::execute_with(|| { +// print_events::("ParaA"); +// }); +// } + +// #[test] +// fn ump() { +// MockNet::reset(); + +// let remark = relay_chain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Null, +// X1(Parent), +// Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }, +// )); +// }); + +// Relay::execute_with(|| { +// print_events::("RelayChain"); +// }); +// } + +// #[test] +// fn xcmp() { +// MockNet::reset(); + +// let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); +// ParaA::execute_with(|| { +// assert_ok!(ParachainPalletXcm::send_xcm( +// Null, +// X2(Parent, Parachain(2)), +// Transact { +// origin_type: OriginKind::SovereignAccount, +// require_weight_at_most: INITIAL_BALANCE as u64, +// call: remark.encode().into(), +// }, +// )); +// }); + +// ParaB::execute_with(|| { +// print_events::("ParaB"); +// }); +// } +// } diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 783d30271739..4ace2db2fb1b 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -16,29 +16,29 @@ //! Parachain runtime mock. +use codec::{Encode, Decode}; use frame_support::{ construct_runtime, parameter_types, traits::{All, AllowAll}, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; -use frame_system::EnsureRoot; use sp_core::H256; -use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; +use sp_runtime::{testing::Header, traits::{IdentityLookup, Hash}, AccountId32}; +use sp_std::{convert::TryFrom, prelude::*}; use pallet_xcm::XcmPassthrough; -use polkadot_parachain::primitives::Sibling; -pub use xcm::v0::{ - Junction::{Parachain, Parent}, - MultiAsset, - MultiLocation::{self, X1, X2, X3}, - NetworkId, Xcm, +use polkadot_parachain::primitives::{Sibling, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, DmpMessageHandler}; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use xcm::v0::{ + Junction::{Parachain, Parent}, MultiAsset, MultiLocation::{self, X1}, + NetworkId, Xcm, Outcome, Error as XcmError, ExecuteXcm }; -pub use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, +use xcm::VersionedXcm; +use xcm_builder::{ + AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, - LocationInverter, NativeAsset, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, + LocationInverter, NativeAsset, ParentIsDefault, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, }; use xcm_executor::{Config, XcmExecutor}; @@ -72,7 +72,7 @@ impl frame_system::Config for Runtime { type BaseCallFilter = AllowAll; type SystemWeightInfo = (); type SS58Prefix = (); - type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type OnSetCode = (); } parameter_types! { @@ -98,24 +98,10 @@ parameter_types! { pub const ReservedDmpWeight: Weight = WEIGHT_PER_SECOND / 4; } -impl cumulus_pallet_parachain_system::Config for Runtime { - type Event = Event; - type OnValidationData = (); - type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; - type ReservedDmpWeight = ReservedDmpWeight; - type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = XcmpQueue; - type ReservedXcmpWeight = ReservedXcmpWeight; -} - -impl parachain_info::Config for Runtime {} - parameter_types! { pub const KsmLocation: MultiLocation = MultiLocation::X1(Parent); pub const RelayNetwork: NetworkId = NetworkId::Kusama; - pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub Ancestry: MultiLocation = Parachain(MsgQueue::parachain_id().into()).into(); } pub type LocationToAccountId = ( @@ -126,8 +112,6 @@ pub type LocationToAccountId = ( pub type XcmOriginToCallOrigin = ( SovereignSignedViaLocation, - RelayChainAsNative, - SiblingParachainAsNative, SignedAccountId32AsNative, XcmPassthrough, ); @@ -140,7 +124,7 @@ parameter_types! { pub type LocalAssetTransactor = XcmCurrencyAdapter, LocationToAccountId, AccountId, ()>; -pub type XcmRouter = super::ParachainXcmRouter; +pub type XcmRouter = super::ParachainXcmRouter; pub type Barrier = AllowUnpaidExecutionFrom>; pub struct XcmConfig; @@ -158,19 +142,161 @@ impl Config for XcmConfig { type ResponseHandler = (); } -impl cumulus_pallet_xcmp_queue::Config for Runtime { - type Event = Event; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; -} +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; -impl cumulus_pallet_dmp_queue::Config for Runtime { - type Event = Event; - type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; + #[pallet::config] + pub trait Config: frame_system::Config { + type Event: From> + IsType<::Event>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::generate_store(pub(super) trait Store)] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub parachain_id: ParaId, + } + + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { + parachain_id: 0.into() + } + } + } + + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + >::put(&self.parachain_id); + } + } + + 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 { + 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 (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::execute_xcm(location.into(), xcm, max_weight) { + Outcome::Error(e) => (Err(e.clone()), Event::Fail(Some(hash), e)), + Outcome::Complete(w) => (Ok(w), 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(w, e) => (Ok(w), Event::Fail(Some(hash), e)), + } + } + 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 id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + }, + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x, limit); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } } -impl cumulus_pallet_xcm::Config for Runtime { +impl mock_msg_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; } @@ -201,11 +327,7 @@ construct_runtime!( System: frame_system::{Pallet, Call, Storage, Config, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event}, - ParachainInfo: parachain_info::{Pallet, Storage, Config}, - XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event}, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event}, - CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin}, + MsgQueue: mock_msg_queue::{Pallet, Storage, Event, Config}, PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, } diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs index d9daffb49939..110b1de3de32 100644 --- a/xcm/xcm-simulator/src/lib.rs +++ b/xcm/xcm-simulator/src/lib.rs @@ -28,7 +28,7 @@ pub use polkadot_parachain::primitives::{ DmpMessageHandler as DmpMessageHandlerT, XcmpMessageFormat, }; pub use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -pub use polkadot_runtime_parachains::{dmp, ump::{XcmSink, UmpSink, MessageId}}; +pub use polkadot_runtime_parachains::{dmp, ump::{self, XcmSink, UmpSink, MessageId}}; pub use xcm::{v0::prelude::*, VersionedXcm}; pub use xcm_executor::XcmExecutor; @@ -112,7 +112,7 @@ macro_rules! decl_test_parachain { use $crate::{XcmpMessageHandlerT, TestExt}; $name::execute_with(|| { - XcmpMessageHandler::handle_xcmp_messages( + <$xcmp_message_handler>::handle_xcmp_messages( iter, max_weight, ) @@ -122,11 +122,13 @@ macro_rules! decl_test_parachain { impl $crate::DmpMessageHandlerT for $name { fn handle_dmp_messages( - iter: impl Iterator)>, - max_weight: Weight, - ) -> Weight { + iter: impl Iterator)>, + max_weight: $crate::Weight, + ) -> $crate::Weight { + use $crate::{DmpMessageHandlerT, TestExt}; + $name::execute_with(|| { - DmpMessageHandler::handle_dmp_messages(iter, max_weight) + <$dmp_message_handler>::handle_dmp_messages(iter, max_weight) }) } } From 1c2cf0ae8c45cdd38aa26169244ecfcc307f05e3 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 20:30:40 +1200 Subject: [PATCH 4/9] Xcm simulator example unit tests. --- xcm/xcm-simulator/example/src/lib.rs | 276 +++++++++---------- xcm/xcm-simulator/example/src/parachain.rs | 77 +++--- xcm/xcm-simulator/example/src/relay_chain.rs | 19 +- xcm/xcm-simulator/src/lib.rs | 35 +-- 4 files changed, 195 insertions(+), 212 deletions(-) diff --git a/xcm/xcm-simulator/example/src/lib.rs b/xcm/xcm-simulator/example/src/lib.rs index 9dc7ed4d9ced..f318409bf187 100644 --- a/xcm/xcm-simulator/example/src/lib.rs +++ b/xcm/xcm-simulator/example/src/lib.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -mod relay_chain; mod parachain; +mod relay_chain; use sp_runtime::AccountId32; use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain}; -use parachain::mock_msg_queue; pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); @@ -62,42 +61,30 @@ decl_test_network! { pub const INITIAL_BALANCE: u128 = 1_000_000_000; pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { - use parachain::{Runtime, System}; - - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - - mock_msg_queue::GenesisConfig:: { - parachain_id: para_id.into(), - } - .assimilate_storage(&mut t) - .unwrap(); + use parachain::{MsgQueue, Runtime, System}; + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_BALANCE)], - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); ext } pub fn relay_ext() -> sp_io::TestExternalities { use relay_chain::{Runtime, System}; - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); + let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(ALICE, INITIAL_BALANCE)], - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, INITIAL_BALANCE)] } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); ext.execute_with(|| System::set_block_number(1)); @@ -107,119 +94,122 @@ pub fn relay_ext() -> sp_io::TestExternalities { 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; -// use xcm::v0::{ -// Junction::{self, Parachain, Parent}, -// MultiAsset::*, -// MultiLocation::*, -// NetworkId, OriginKind, -// Xcm::*, -// }; -// use xcm_simulator::TestExt; - -// fn print_events(context: &str) { -// println!("------ {:?} events ------", context); -// frame_system::Pallet::::events().iter().for_each(|r| { -// println!("{:?}", r.event); -// }); -// } - -// #[test] -// fn reserve_transfer() { -// MockNet::reset(); - -// Relay::execute_with(|| { -// assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( -// relay_chain::Origin::signed(ALICE), -// X1(Parachain(1)), -// X1(Junction::AccountId32 { -// network: NetworkId::Any, -// id: ALICE.into(), -// }), -// vec![ConcreteFungible { id: Null, amount: 123 }], -// 123, -// )); -// }); - -// ParaA::execute_with(|| { -// // free execution, full amount received -// assert_eq!( -// pallet_balances::Pallet::::free_balance(&ALICE), -// INITIAL_BALANCE + 123 -// ); - -// print_events::("ParaA"); -// }); -// } - -// #[test] -// fn dmp() { -// MockNet::reset(); - -// let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); -// Relay::execute_with(|| { -// assert_ok!(RelayChainPalletXcm::send_xcm( -// Null, -// X1(Parachain(1)), -// Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }, -// )); -// }); - -// ParaA::execute_with(|| { -// print_events::("ParaA"); -// }); -// } - -// #[test] -// fn ump() { -// MockNet::reset(); - -// let remark = relay_chain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); -// ParaA::execute_with(|| { -// assert_ok!(ParachainPalletXcm::send_xcm( -// Null, -// X1(Parent), -// Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }, -// )); -// }); - -// Relay::execute_with(|| { -// print_events::("RelayChain"); -// }); -// } - -// #[test] -// fn xcmp() { -// MockNet::reset(); - -// let remark = parachain::Call::System(frame_system::Call::::remark_with_event(vec![1, 2, 3])); -// ParaA::execute_with(|| { -// assert_ok!(ParachainPalletXcm::send_xcm( -// Null, -// X2(Parent, Parachain(2)), -// Transact { -// origin_type: OriginKind::SovereignAccount, -// require_weight_at_most: INITIAL_BALANCE as u64, -// call: remark.encode().into(), -// }, -// )); -// }); - -// ParaB::execute_with(|| { -// print_events::("ParaB"); -// }); -// } -// } +#[cfg(test)] +mod tests { + use super::*; + + use codec::Encode; + use frame_support::assert_ok; + use xcm::v0::{ + Junction::{self, Parachain, Parent}, + MultiAsset::*, + MultiLocation::*, + NetworkId, OriginKind, + Xcm::*, + }; + use xcm_simulator::TestExt; + + #[test] + fn dmp() { + MockNet::reset(); + + let remark = parachain::Call::System( + frame_system::Call::::remark_with_event(vec![1, 2, 3]), + ); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::send_xcm( + Null, + X1(Parachain(1)), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + ParaA::execute_with(|| { + use parachain::{Event, System}; + assert!(System::events() + .iter() + .any(|r| matches!(r.event, Event::System(frame_system::Event::Remarked(_, _))))); + }); + } + + #[test] + fn ump() { + MockNet::reset(); + + let remark = relay_chain::Call::System( + frame_system::Call::::remark_with_event(vec![1, 2, 3]), + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Null, + X1(Parent), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + Relay::execute_with(|| { + use relay_chain::{Event, System}; + assert!(System::events() + .iter() + .any(|r| matches!(r.event, Event::System(frame_system::Event::Remarked(_, _))))); + }); + } + + #[test] + fn xcmp() { + MockNet::reset(); + + let remark = parachain::Call::System( + frame_system::Call::::remark_with_event(vec![1, 2, 3]), + ); + ParaA::execute_with(|| { + assert_ok!(ParachainPalletXcm::send_xcm( + Null, + X2(Parent, Parachain(2)), + Transact { + origin_type: OriginKind::SovereignAccount, + require_weight_at_most: INITIAL_BALANCE as u64, + call: remark.encode().into(), + }, + )); + }); + + ParaB::execute_with(|| { + use parachain::{Event, System}; + assert!(System::events() + .iter() + .any(|r| matches!(r.event, Event::System(frame_system::Event::Remarked(_, _))))); + }); + } + + #[test] + fn reserve_transfer() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::Origin::signed(ALICE), + X1(Parachain(1)), + X1(Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into() }), + vec![ConcreteFungible { id: Null, amount: 123 }], + 123, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + pallet_balances::Pallet::::free_balance(&ALICE), + INITIAL_BALANCE + 123 + ); + }); + } +} diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 4ace2db2fb1b..15f7ed7779aa 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -16,29 +16,40 @@ //! Parachain runtime mock. -use codec::{Encode, Decode}; +use codec::{Decode, Encode}; use frame_support::{ construct_runtime, parameter_types, traits::{All, AllowAll}, weights::{constants::WEIGHT_PER_SECOND, Weight}, }; use sp_core::H256; -use sp_runtime::{testing::Header, traits::{IdentityLookup, Hash}, AccountId32}; +use sp_runtime::{ + testing::Header, + traits::{Hash, IdentityLookup}, + AccountId32, +}; use sp_std::{convert::TryFrom, prelude::*}; use pallet_xcm::XcmPassthrough; -use polkadot_parachain::primitives::{Sibling, Id as ParaId, XcmpMessageFormat, XcmpMessageHandler, DmpMessageHandler}; use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -use xcm::v0::{ - Junction::{Parachain, Parent}, MultiAsset, MultiLocation::{self, X1}, - NetworkId, Xcm, Outcome, Error as XcmError, ExecuteXcm +use polkadot_parachain::primitives::{ + DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler, +}; +use xcm::{ + v0::{ + Error as XcmError, ExecuteXcm, + Junction::{Parachain, Parent}, + MultiAsset, + MultiLocation::{self, X1}, + NetworkId, Outcome, Xcm, + }, + VersionedXcm, }; -use xcm::VersionedXcm; use xcm_builder::{ - AccountId32Aliases, AllowUnpaidExecutionFrom, - CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, - LocationInverter, NativeAsset, ParentIsDefault, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, + AccountId32Aliases, AllowUnpaidExecutionFrom, CurrencyAdapter as XcmCurrencyAdapter, + EnsureXcmOrigin, FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter, + NativeAsset, ParentIsDefault, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, }; use xcm_executor::{Config, XcmExecutor}; @@ -164,27 +175,6 @@ pub mod mock_msg_queue { #[pallet::getter(fn parachain_id)] pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; - #[pallet::genesis_config] - pub struct GenesisConfig { - pub parachain_id: ParaId, - } - - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - parachain_id: 0.into() - } - } - } - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - >::put(&self.parachain_id); - } - } - impl Get for Pallet { fn get() -> ParaId { Self::parachain_id() @@ -197,7 +187,6 @@ pub mod mock_msg_queue { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { // XCMP - /// Some XCM was executed ok. Success(Option), /// Some XCM failed. @@ -208,7 +197,6 @@ pub mod mock_msg_queue { BadFormat(Option), // DMP - /// Downward message is invalid XCM. InvalidFormat(MessageId), /// Downward message is unsupported version of XCM. @@ -218,6 +206,10 @@ pub mod mock_msg_queue { } impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + fn handle_xcmp_message( sender: ParaId, _sent_at: RelayBlockNumber, @@ -235,11 +227,8 @@ pub mod mock_msg_queue { // we just report the weight used. Outcome::Incomplete(w, e) => (Ok(w), Event::Fail(Some(hash), e)), } - } - Err(()) => ( - Err(XcmError::UnhandledXcmVersion), - Event::BadVersion(Some(hash)), - ), + }, + Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))), }; Self::deposit_event(event); result @@ -271,13 +260,13 @@ pub mod mock_msg_queue { impl DmpMessageHandler for Pallet { fn handle_dmp_messages( - iter: impl Iterator)>, + iter: impl Iterator)>, limit: Weight, ) -> Weight { for (_i, (_sent_at, data)) in iter.enumerate() { let id = sp_io::hashing::blake2_256(&data[..]); - let maybe_msg = VersionedXcm::::decode(&mut &data[..]) - .map(Xcm::::try_from); + let maybe_msg = + VersionedXcm::::decode(&mut &data[..]).map(Xcm::::try_from); match maybe_msg { Err(_) => { Self::deposit_event(Event::InvalidFormat(id)); @@ -288,7 +277,7 @@ pub mod mock_msg_queue { Ok(Ok(x)) => { let outcome = T::XcmExecutor::execute_xcm(Parent.into(), x, limit); Self::deposit_event(Event::ExecutedDownward(id, outcome)); - } + }, } } limit @@ -327,7 +316,7 @@ construct_runtime!( System: frame_system::{Pallet, Call, Storage, Config, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - MsgQueue: mock_msg_queue::{Pallet, Storage, Event, Config}, + MsgQueue: mock_msg_queue::{Pallet, Storage, Event}, PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, } diff --git a/xcm/xcm-simulator/example/src/relay_chain.rs b/xcm/xcm-simulator/example/src/relay_chain.rs index 4c0f896ec4c1..c69f20d05eaf 100644 --- a/xcm/xcm-simulator/example/src/relay_chain.rs +++ b/xcm/xcm-simulator/example/src/relay_chain.rs @@ -16,7 +16,11 @@ //! Relay chain runtime mock. -use frame_support::{construct_runtime, parameter_types, traits::{All, AllowAll}, weights::Weight}; +use frame_support::{ + construct_runtime, parameter_types, + traits::{All, AllowAll}, + weights::Weight, +}; use sp_core::H256; use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32}; @@ -24,9 +28,10 @@ use polkadot_parachain::primitives::Id as ParaId; use polkadot_runtime_parachains::{configuration, origin, shared, ump}; use xcm::v0::{MultiAsset, MultiLocation, NetworkId}; use xcm_builder::{ - AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, - ChildSystemParachainAsSuperuser, CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfConcreteFungible, - FixedWeightBounds, IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, + AccountId32Aliases, AllowUnpaidExecutionFrom, ChildParachainAsNative, + ChildParachainConvertsVia, ChildSystemParachainAsSuperuser, + CurrencyAdapter as XcmCurrencyAdapter, FixedRateOfConcreteFungible, FixedWeightBounds, + IsConcrete, LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, }; use xcm_executor::{Config, XcmExecutor}; @@ -94,10 +99,8 @@ parameter_types! { pub UnitWeightCost: Weight = 1_000; } -pub type SovereignAccountOf = ( - ChildParachainConvertsVia, - AccountId32Aliases, -); +pub type SovereignAccountOf = + (ChildParachainConvertsVia, AccountId32Aliases); pub type LocalAssetTransactor = XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs index 110b1de3de32..48bd99b922ba 100644 --- a/xcm/xcm-simulator/src/lib.rs +++ b/xcm/xcm-simulator/src/lib.rs @@ -23,12 +23,15 @@ pub use frame_support::{traits::Get, weights::Weight}; pub use sp_io::TestExternalities; pub use sp_std::{cell::RefCell, marker::PhantomData}; +pub use polkadot_core_primitives::BlockNumber as RelayBlockNumber; pub use polkadot_parachain::primitives::{ - Id as ParaId, XcmpMessageHandler as XcmpMessageHandlerT, - DmpMessageHandler as DmpMessageHandlerT, XcmpMessageFormat, + DmpMessageHandler as DmpMessageHandlerT, Id as ParaId, XcmpMessageFormat, + XcmpMessageHandler as XcmpMessageHandlerT, +}; +pub use polkadot_runtime_parachains::{ + dmp, + ump::{self, MessageId, UmpSink, XcmSink}, }; -pub use polkadot_core_primitives::BlockNumber as RelayBlockNumber; -pub use polkadot_runtime_parachains::{dmp, ump::{self, XcmSink, UmpSink, MessageId}}; pub use xcm::{v0::prelude::*, VersionedXcm}; pub use xcm_executor::XcmExecutor; @@ -54,7 +57,7 @@ pub fn encode_xcm(message: Xcm<()>, message_kind: MessageKind) -> Vec { let encoded = VersionedXcm::<()>::from(message).encode(); outbound.extend_from_slice(&encoded[..]); outbound - } + }, } } @@ -77,13 +80,12 @@ macro_rules! decl_test_relay_chain { msg: &[u8], max_weight: $crate::Weight, ) -> Result<$crate::Weight, ($crate::MessageId, $crate::Weight)> { - use $crate::ump::UmpSink; - use $crate::TestExt; + use $crate::{ump::UmpSink, TestExt}; Self::execute_with(|| { $crate::ump::XcmSink::<$crate::XcmExecutor<$xcm_config>, $runtime>::process_upward_message( - origin, msg, max_weight, - ) + origin, msg, max_weight, + ) }) } } @@ -105,24 +107,24 @@ macro_rules! decl_test_parachain { $crate::__impl_ext!($name, $new_ext); impl $crate::XcmpMessageHandlerT for $name { - fn handle_xcmp_messages<'a, I: Iterator>( + fn handle_xcmp_messages< + 'a, + I: Iterator, + >( iter: I, max_weight: $crate::Weight, ) -> $crate::Weight { - use $crate::{XcmpMessageHandlerT, TestExt}; + use $crate::{TestExt, XcmpMessageHandlerT}; $name::execute_with(|| { - <$xcmp_message_handler>::handle_xcmp_messages( - iter, - max_weight, - ) + <$xcmp_message_handler>::handle_xcmp_messages(iter, max_weight) }) } } impl $crate::DmpMessageHandlerT for $name { fn handle_dmp_messages( - iter: impl Iterator)>, + iter: impl Iterator)>, max_weight: $crate::Weight, ) -> $crate::Weight { use $crate::{DmpMessageHandlerT, TestExt}; @@ -237,4 +239,3 @@ macro_rules! decl_test_network { } }; } - From 16c00bb53208c4ecaf9ced264c062855586fcc8d Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 20:36:14 +1200 Subject: [PATCH 5/9] Use relay chain block number on sending msg. --- xcm/xcm-simulator/src/lib.rs | 9 +++++++-- xcm/xcm-simulator/src/traits.rs | 17 ----------------- 2 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 xcm/xcm-simulator/src/traits.rs diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs index 48bd99b922ba..6c8ca28ee1f5 100644 --- a/xcm/xcm-simulator/src/lib.rs +++ b/xcm/xcm-simulator/src/lib.rs @@ -208,7 +208,10 @@ macro_rules! decl_test_network { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Xcmp); // TODO: update relay block number let messages = vec![(T::get(), 1, &encoded[..])]; - let _ = <$parachain>::handle_xcmp_messages(messages.into_iter(), $crate::Weight::max_value()); + let _ = <$parachain>::handle_xcmp_messages( + messages.into_iter(), + $crate::Weight::max_value(), + ); Ok(()) }, )* @@ -229,7 +232,9 @@ macro_rules! decl_test_network { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Dmp); // TODO: update relay block number let messages = vec![(1, encoded)]; - let _ = <$parachain>::handle_dmp_messages(messages.into_iter(), $crate::Weight::max_value()); + let _ = <$parachain>::handle_dmp_messages( + messages.into_iter(), $crate::Weight::max_value(), + ); Ok(()) }, )* diff --git a/xcm/xcm-simulator/src/traits.rs b/xcm/xcm-simulator/src/traits.rs deleted file mode 100644 index 7dcce37df34d..000000000000 --- a/xcm/xcm-simulator/src/traits.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 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 . - - From d13a85ad0165d4e1ec42e138cec09343eacba386 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 20:40:30 +1200 Subject: [PATCH 6/9] Fix typo. --- xcm/Cargo.toml | 2 +- xcm/xcm-simulator/Cargo.toml | 2 +- xcm/xcm-simulator/example/Cargo.toml | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/xcm/Cargo.toml b/xcm/Cargo.toml index 66d565efde4e..adb604bad336 100644 --- a/xcm/Cargo.toml +++ b/xcm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xcm" version = "0.9.8" -authors = ["Parity Technologies x"] +authors = ["Parity Technologies "] description = "The basic XCM datastructures." edition = "2018" diff --git a/xcm/xcm-simulator/Cargo.toml b/xcm/xcm-simulator/Cargo.toml index b2abd4d75f9a..be5c80111c00 100644 --- a/xcm/xcm-simulator/Cargo.toml +++ b/xcm/xcm-simulator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xcm-simulator" version = "0.9.8" -authors = ["Parity Technologies x"] +authors = ["Parity Technologies "] description = "Test kit to simulate cross-chain message passing and XCM execution" edition = "2018" diff --git a/xcm/xcm-simulator/example/Cargo.toml b/xcm/xcm-simulator/example/Cargo.toml index 1d85687b2ecb..3d8ddbb77d64 100644 --- a/xcm/xcm-simulator/example/Cargo.toml +++ b/xcm/xcm-simulator/example/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xcm-simulator-example" version = "0.9.8" -authors = ["Parity Technologies x"] +authors = ["Parity Technologies "] description = "Examples of xcm-simulator usage." edition = "2018" @@ -9,7 +9,6 @@ edition = "2018" codec = { package = "parity-scale-codec", version = "2.0.0" } paste = "1.0.5" -# substrate frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -18,7 +17,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" } -# polkadot xcm = { path = "../../" } xcm-simulator = { path = "../" } xcm-executor = { path = "../../xcm-executor" } From c6ca3a09012319a8e99436e33fb04265413fadfa Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 20:47:32 +1200 Subject: [PATCH 7/9] fmt --- xcm/xcm-simulator/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xcm/xcm-simulator/src/lib.rs b/xcm/xcm-simulator/src/lib.rs index 6c8ca28ee1f5..096d62b61695 100644 --- a/xcm/xcm-simulator/src/lib.rs +++ b/xcm/xcm-simulator/src/lib.rs @@ -84,8 +84,8 @@ macro_rules! decl_test_relay_chain { Self::execute_with(|| { $crate::ump::XcmSink::<$crate::XcmExecutor<$xcm_config>, $runtime>::process_upward_message( - origin, msg, max_weight, - ) + origin, msg, max_weight, + ) }) } } @@ -206,7 +206,6 @@ macro_rules! decl_test_network { $( $crate::X2($crate::Parent, $crate::Parachain(id)) if id == $para_id => { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Xcmp); - // TODO: update relay block number let messages = vec![(T::get(), 1, &encoded[..])]; let _ = <$parachain>::handle_xcmp_messages( messages.into_iter(), @@ -230,7 +229,6 @@ macro_rules! decl_test_network { $( $crate::X1($crate::Parachain(id)) if id == $para_id => { let encoded = $crate::encode_xcm(message, $crate::MessageKind::Dmp); - // TODO: update relay block number let messages = vec![(1, encoded)]; let _ = <$parachain>::handle_dmp_messages( messages.into_iter(), $crate::Weight::max_value(), From 129a3a3be26e3af26b16b14640647ada1a19f248 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 20:48:53 +1200 Subject: [PATCH 8/9] more fmt --- xcm/xcm-simulator/example/src/parachain.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/xcm/xcm-simulator/example/src/parachain.rs b/xcm/xcm-simulator/example/src/parachain.rs index 15f7ed7779aa..f4ad471ff697 100644 --- a/xcm/xcm-simulator/example/src/parachain.rs +++ b/xcm/xcm-simulator/example/src/parachain.rs @@ -315,9 +315,7 @@ construct_runtime!( { System: frame_system::{Pallet, Call, Storage, Config, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - MsgQueue: mock_msg_queue::{Pallet, Storage, Event}, - PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, } ); From dd7d2f787c627e1d9c4ed16b9f49ea21d2f5ae4b Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 1 Aug 2021 21:12:00 +1200 Subject: [PATCH 9/9] Fix deps. --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ceb753bffb4b..3918fd8ae846 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11478,7 +11478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59" dependencies = [ "cfg-if 0.1.10", - "rand 0.3.23", + "rand 0.7.3", "static_assertions", ]