diff --git a/Cargo.lock b/Cargo.lock index 85627e65e292..498c9120c0f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,7 +435,7 @@ dependencies = [ [[package]] name = "beefy-gadget" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "async-trait", @@ -472,7 +472,7 @@ dependencies = [ [[package]] name = "beefy-gadget-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "beefy-gadget", "beefy-primitives", @@ -492,7 +492,7 @@ dependencies = [ [[package]] name = "beefy-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "beefy-primitives", "sp-api", @@ -501,7 +501,7 @@ dependencies = [ [[package]] name = "beefy-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -1998,7 +1998,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", ] @@ -2016,7 +2016,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -2039,7 +2039,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "Inflector", "array-bytes", @@ -2090,7 +2090,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2101,7 +2101,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -2117,7 +2117,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -2146,7 +2146,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "bitflags", "frame-metadata", @@ -2178,7 +2178,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "Inflector", "cfg-expr", @@ -2192,7 +2192,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -2204,7 +2204,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro2", "quote", @@ -2214,7 +2214,7 @@ dependencies = [ [[package]] name = "frame-support-test" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-support-test-pallet", @@ -2237,7 +2237,7 @@ dependencies = [ [[package]] name = "frame-support-test-pallet" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -2248,7 +2248,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "log", @@ -2266,7 +2266,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -2281,7 +2281,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "sp-api", @@ -2290,7 +2290,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "parity-scale-codec", @@ -2473,7 +2473,7 @@ dependencies = [ [[package]] name = "generate-bags" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "chrono", "frame-election-provider-support", @@ -3224,6 +3224,7 @@ dependencies = [ "pallet-bounties", "pallet-child-bounties", "pallet-collective", + "pallet-conviction-voting", "pallet-democracy", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", @@ -3243,7 +3244,9 @@ dependencies = [ "pallet-offences-benchmarking", "pallet-preimage", "pallet-proxy", + "pallet-ranked-collective", "pallet-recovery", + "pallet-referenda", "pallet-scheduler", "pallet-session", "pallet-session-benchmarking", @@ -3257,6 +3260,7 @@ dependencies = [ "pallet-treasury", "pallet-utility", "pallet-vesting", + "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", "parity-scale-codec", @@ -4758,7 +4762,9 @@ dependencies = [ [[package]] name = "orchestra" -version = "0.0.1" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aab54694ddaa8a9b703724c6ef04272b2d27bc32d2c855aae5cdd1857216b43" dependencies = [ "async-trait", "dyn-clonable", @@ -4767,27 +4773,23 @@ dependencies = [ "orchestra-proc-macro", "pin-project", "prioritized-metered-channel", - "rustversion", "thiserror", "tracing", - "trybuild", ] [[package]] name = "orchestra-proc-macro" -version = "0.0.1" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a702b2f6bf592b3eb06c00d80d05afaf7a8eff6b41bb361e397d799acc21b45a" dependencies = [ - "assert_matches", "expander 0.0.6", "itertools", - "orchestra", "petgraph", "proc-macro-crate", "proc-macro2", "quote", "syn", - "thiserror", - "tracing", ] [[package]] @@ -4832,7 +4834,7 @@ checksum = "20448fd678ec04e6ea15bbe0476874af65e98a01515d667aa49f1434dc44ebf4" [[package]] name = "pallet-assets" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -4846,7 +4848,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -4862,7 +4864,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -4877,7 +4879,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -4901,7 +4903,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -4921,7 +4923,7 @@ dependencies = [ [[package]] name = "pallet-bags-list-remote-tests" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-election-provider-support", "frame-support", @@ -4940,7 +4942,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -4955,7 +4957,7 @@ dependencies = [ [[package]] name = "pallet-beefy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "beefy-primitives", "frame-support", @@ -4971,7 +4973,7 @@ dependencies = [ [[package]] name = "pallet-beefy-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "beefy-merkle-tree", @@ -4994,7 +4996,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5012,7 +5014,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5031,7 +5033,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5045,10 +5047,27 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-conviction-voting" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=master#dbb72f3fd98253b72c0090375b738b9d00995090" +dependencies = [ + "assert_matches", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5064,7 +5083,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5088,7 +5107,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5101,7 +5120,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5119,7 +5138,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5140,7 +5159,7 @@ dependencies = [ [[package]] name = "pallet-gilt" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5155,7 +5174,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5178,7 +5197,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5194,7 +5213,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5214,7 +5233,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5231,7 +5250,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5248,7 +5267,7 @@ dependencies = [ [[package]] name = "pallet-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ckb-merkle-mountain-range", "frame-benchmarking", @@ -5266,7 +5285,7 @@ dependencies = [ [[package]] name = "pallet-mmr-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -5281,7 +5300,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5296,7 +5315,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5313,7 +5332,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "1.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5333,7 +5352,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "sp-api", @@ -5343,7 +5362,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5360,7 +5379,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5383,7 +5402,7 @@ dependencies = [ [[package]] name = "pallet-preimage" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5399,7 +5418,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5411,10 +5430,28 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-ranked-collective" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=master#dbb72f3fd98253b72c0090375b738b9d00995090" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5426,10 +5463,28 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-referenda" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=master#dbb72f3fd98253b72c0090375b738b9d00995090" +dependencies = [ + "assert_matches", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5445,7 +5500,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5466,7 +5521,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5482,7 +5537,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5496,7 +5551,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5519,7 +5574,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5530,7 +5585,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "sp-arithmetic", @@ -5539,7 +5594,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5553,7 +5608,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5571,7 +5626,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5590,7 +5645,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-support", "frame-system", @@ -5606,7 +5661,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -5621,7 +5676,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -5632,7 +5687,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5649,7 +5704,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5665,7 +5720,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-benchmarking", "frame-support", @@ -5677,6 +5732,21 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-whitelist" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=master#dbb72f3fd98253b72c0090375b738b9d00995090" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-xcm" version = "0.9.29" @@ -7668,15 +7738,14 @@ dependencies = [ [[package]] name = "prioritized-metered-channel" version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382698e48a268c832d0b181ed438374a6bb708a82a8ca273bb0f61c74cf209c4" dependencies = [ - "assert_matches", "coarsetime", "crossbeam-queue", "derive_more", - "env_logger 0.9.0", "futures", "futures-timer", - "log", "nanorand", "thiserror", "tracing", @@ -8197,7 +8266,7 @@ dependencies = [ [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "env_logger 0.9.0", "jsonrpsee", @@ -8545,7 +8614,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "sp-core", @@ -8556,7 +8625,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures", @@ -8583,7 +8652,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "futures-timer", @@ -8606,7 +8675,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "sc-client-api", @@ -8622,7 +8691,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "impl-trait-for-tuples", "memmap2 0.5.0", @@ -8639,7 +8708,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -8650,7 +8719,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "chrono", @@ -8690,7 +8759,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "fnv", "futures", @@ -8718,7 +8787,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "hash-db", "kvdb", @@ -8743,7 +8812,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures", @@ -8767,7 +8836,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "fork-tree", @@ -8809,7 +8878,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "jsonrpsee", @@ -8831,7 +8900,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "fork-tree", "parity-scale-codec", @@ -8844,7 +8913,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures", @@ -8868,7 +8937,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "lazy_static", "lru 0.7.8", @@ -8895,7 +8964,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "environmental", "parity-scale-codec", @@ -8911,7 +8980,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "parity-scale-codec", @@ -8926,7 +8995,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "cfg-if 1.0.0", "libc", @@ -8946,7 +9015,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ahash", "array-bytes", @@ -8987,7 +9056,7 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "finality-grandpa", "futures", @@ -9008,7 +9077,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ansi_term", "futures", @@ -9025,7 +9094,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "async-trait", @@ -9040,7 +9109,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "async-trait", @@ -9087,7 +9156,7 @@ dependencies = [ [[package]] name = "sc-network-bitswap" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "cid", "futures", @@ -9107,7 +9176,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "bitflags", @@ -9133,7 +9202,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ahash", "futures", @@ -9151,7 +9220,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "futures", @@ -9172,7 +9241,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "fork-tree", @@ -9200,7 +9269,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "futures", @@ -9219,7 +9288,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "bytes", @@ -9249,7 +9318,7 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "libp2p", @@ -9262,7 +9331,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -9271,7 +9340,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "hash-db", @@ -9301,7 +9370,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "jsonrpsee", @@ -9324,7 +9393,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "jsonrpsee", @@ -9337,7 +9406,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "directories", @@ -9407,7 +9476,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "parity-scale-codec", @@ -9421,7 +9490,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -9440,7 +9509,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "libc", @@ -9459,7 +9528,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "chrono", "futures", @@ -9477,7 +9546,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ansi_term", "atty", @@ -9508,7 +9577,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9519,7 +9588,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "futures-timer", @@ -9545,7 +9614,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "log", @@ -9558,7 +9627,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "futures-timer", @@ -10044,7 +10113,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "hash-db", "log", @@ -10062,7 +10131,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "blake2", "proc-macro-crate", @@ -10074,7 +10143,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10087,7 +10156,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "integer-sqrt", "num-traits", @@ -10102,7 +10171,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10115,7 +10184,7 @@ dependencies = [ [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "parity-scale-codec", @@ -10127,7 +10196,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "sp-api", @@ -10139,7 +10208,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "log", @@ -10157,7 +10226,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures", @@ -10176,7 +10245,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "merlin", @@ -10199,7 +10268,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10213,7 +10282,7 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10226,7 +10295,7 @@ dependencies = [ [[package]] name = "sp-core" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "base58", @@ -10272,7 +10341,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "blake2", "byteorder", @@ -10286,7 +10355,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro2", "quote", @@ -10297,7 +10366,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "kvdb", "parking_lot 0.12.1", @@ -10306,7 +10375,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro2", "quote", @@ -10316,7 +10385,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "environmental", "parity-scale-codec", @@ -10327,7 +10396,7 @@ dependencies = [ [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "finality-grandpa", "log", @@ -10345,7 +10414,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -10359,7 +10428,7 @@ dependencies = [ [[package]] name = "sp-io" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "bytes", "futures", @@ -10385,7 +10454,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "lazy_static", "sp-core", @@ -10396,7 +10465,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures", @@ -10413,7 +10482,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "thiserror", "zstd", @@ -10422,7 +10491,7 @@ dependencies = [ [[package]] name = "sp-mmr-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "parity-scale-codec", @@ -10437,7 +10506,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10451,7 +10520,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "sp-api", "sp-core", @@ -10461,7 +10530,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "backtrace", "lazy_static", @@ -10471,7 +10540,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "rustc-hash", "serde", @@ -10481,7 +10550,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "either", "hash256-std-hasher", @@ -10504,7 +10573,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -10522,7 +10591,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "Inflector", "proc-macro-crate", @@ -10534,7 +10603,7 @@ dependencies = [ [[package]] name = "sp-sandbox" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "parity-scale-codec", @@ -10548,7 +10617,7 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10562,7 +10631,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "scale-info", @@ -10573,7 +10642,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.12.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "hash-db", "log", @@ -10595,12 +10664,12 @@ dependencies = [ [[package]] name = "sp-std" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" [[package]] name = "sp-storage" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "impl-serde", "parity-scale-codec", @@ -10613,7 +10682,7 @@ dependencies = [ [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "log", "sp-core", @@ -10626,7 +10695,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "futures-timer", @@ -10642,7 +10711,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "sp-std", @@ -10654,7 +10723,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "sp-api", "sp-runtime", @@ -10663,7 +10732,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "async-trait", "log", @@ -10679,7 +10748,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ahash", "hash-db", @@ -10702,7 +10771,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "impl-serde", "parity-scale-codec", @@ -10719,7 +10788,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -10730,7 +10799,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "impl-trait-for-tuples", "log", @@ -10743,7 +10812,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -10958,7 +11027,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "platforms", ] @@ -10966,7 +11035,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "frame-system-rpc-runtime-api", "futures", @@ -10987,7 +11056,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures-util", "hyper", @@ -11000,7 +11069,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "jsonrpsee", "log", @@ -11021,7 +11090,7 @@ dependencies = [ [[package]] name = "substrate-test-client" version = "2.0.1" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "array-bytes", "async-trait", @@ -11047,7 +11116,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "futures", "substrate-test-utils-derive", @@ -11057,7 +11126,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -11068,7 +11137,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "ansi_term", "build-helper", @@ -11587,7 +11656,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ "cfg-if 1.0.0", - "log", "pin-project-lite 0.2.7", "tracing-attributes", "tracing-core", @@ -11782,7 +11850,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#2ee4cb47fa01ad6c7d6c94acf3370fd26470b388" +source = "git+https://github.com/paritytech/substrate?branch=master#25795506052363e8b5795eb3526e61ef2a27d89a" dependencies = [ "clap", "frame-try-runtime", diff --git a/Cargo.toml b/Cargo.toml index be2e04291370..ee886dafdc8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,8 +83,6 @@ members = [ "node/network/gossip-support", "node/network/dispute-distribution", "node/overseer", - "node/orchestra", - "node/orchestra/proc-macro", "node/malus", "node/primitives", "node/service", @@ -96,7 +94,6 @@ members = [ "node/gum", "node/gum/proc-macro", "node/metrics", - "node/metered-channel", "node/test/client", "node/test/performance-test", "node/test/service", diff --git a/README.md b/README.md index 7679ebec5984..55b66f6ea619 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ dnf install polkadot Make sure you have the support software installed from the **Build from Source** section below this section. -If you want to install Polkadot in your PATH, you can do so with with: +If you want to install Polkadot in your PATH, you can do so with: ```bash cargo install --git https://github.com/paritytech/polkadot --tag polkadot --locked diff --git a/node/core/backing/src/lib.rs b/node/core/backing/src/lib.rs index dbc6e3f81903..a9ae518e3103 100644 --- a/node/core/backing/src/lib.rs +++ b/node/core/backing/src/lib.rs @@ -621,6 +621,7 @@ async fn request_pov( sender: &mut impl overseer::CandidateBackingSenderTrait, relay_parent: Hash, from_validator: ValidatorIndex, + para_id: ParaId, candidate_hash: CandidateHash, pov_hash: Hash, ) -> Result, Error> { @@ -629,6 +630,7 @@ async fn request_pov( .send_message(AvailabilityDistributionMessage::FetchPoV { relay_parent, from_validator, + para_id, candidate_hash, pov_hash, tx, @@ -697,8 +699,15 @@ async fn validate_and_make_available( PoVData::Ready(pov) => pov, PoVData::FetchFromValidator { from_validator, candidate_hash, pov_hash } => { let _span = span.as_ref().map(|s| s.child("request-pov")); - match request_pov(&mut sender, relay_parent, from_validator, candidate_hash, pov_hash) - .await + match request_pov( + &mut sender, + relay_parent, + from_validator, + candidate.descriptor.para_id, + candidate_hash, + pov_hash, + ) + .await { Err(Error::FetchPoV) => { tx_command diff --git a/node/metered-channel/Cargo.toml b/node/metered-channel/Cargo.toml deleted file mode 100644 index da95d0db8d6c..000000000000 --- a/node/metered-channel/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "prioritized-metered-channel" -version = "0.2.0" -authors = ["Parity Technologies "] -edition = "2021" -description = "Channels with built-in observability and message priorizitazion (coming soon™)" -repository = "https://github.com/paritytech/polkadot.git" -license = "MIT OR Apache-2.0" - -[dependencies] -futures = "0.3.21" -futures-timer = "3.0.2" -derive_more = "0.99" -tracing = "0.1.35" -thiserror = "1.0.31" -crossbeam-queue = "0.3.5" -nanorand = { version = "0.7.0", default-features = false, features = ["wyrand"] } -coarsetime = "^0.1.22" - -[dev-dependencies] -futures = { version = "0.3.21", features = ["thread-pool"] } -assert_matches = "1.5" -env_logger = "0.9" -log = "0.4" -tracing = { version = "0.1.35", features = ["log"] } diff --git a/node/metered-channel/src/bounded.rs b/node/metered-channel/src/bounded.rs deleted file mode 100644 index 4d3abffe729e..000000000000 --- a/node/metered-channel/src/bounded.rs +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2017-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 . - -//! Metered variant of bounded mpsc channels to be able to extract metrics. - -use futures::{ - channel::mpsc, - sink::SinkExt, - stream::Stream, - task::{Context, Poll}, -}; - -use std::{pin::Pin, result}; - -use super::{measure_tof_check, CoarseInstant, MaybeTimeOfFlight, Meter}; - -/// Create a wrapped `mpsc::channel` pair of `MeteredSender` and `MeteredReceiver`. -pub fn channel(capacity: usize) -> (MeteredSender, MeteredReceiver) { - let (tx, rx) = mpsc::channel::>(capacity); - let shared_meter = Meter::default(); - let tx = MeteredSender { meter: shared_meter.clone(), inner: tx }; - let rx = MeteredReceiver { meter: shared_meter, inner: rx }; - (tx, rx) -} - -/// A receiver tracking the messages consumed by itself. -#[derive(Debug)] -pub struct MeteredReceiver { - // count currently contained messages - meter: Meter, - inner: mpsc::Receiver>, -} - -impl std::ops::Deref for MeteredReceiver { - type Target = mpsc::Receiver>; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for MeteredReceiver { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - -impl Stream for MeteredReceiver { - type Item = T; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - match mpsc::Receiver::poll_next(Pin::new(&mut self.inner), cx) { - Poll::Ready(maybe_value) => Poll::Ready(self.maybe_meter_tof(maybe_value)), - Poll::Pending => Poll::Pending, - } - } - - /// Don't rely on the unreliable size hint. - fn size_hint(&self) -> (usize, Option) { - self.inner.size_hint() - } -} - -impl MeteredReceiver { - fn maybe_meter_tof(&mut self, maybe_value: Option>) -> Option { - self.meter.note_received(); - maybe_value.map(|value| { - match value { - MaybeTimeOfFlight::::WithTimeOfFlight(value, tof_start) => { - // do not use `.elapsed()` of `std::time`, it may panic - // `coarsetime` does a saturating sub for all `CoarseInstant` substractions - let duration = tof_start.elapsed(); - self.meter.note_time_of_flight(duration); - value - }, - MaybeTimeOfFlight::::Bare(value) => value, - } - .into() - }) - } - - /// Get an updated accessor object for all metrics collected. - pub fn meter(&self) -> &Meter { - &self.meter - } - - /// Attempt to receive the next item. - pub fn try_next(&mut self) -> Result, mpsc::TryRecvError> { - match self.inner.try_next()? { - Some(value) => Ok(self.maybe_meter_tof(Some(value))), - None => Ok(None), - } - } -} - -impl futures::stream::FusedStream for MeteredReceiver { - fn is_terminated(&self) -> bool { - self.inner.is_terminated() - } -} - -/// The sender component, tracking the number of items -/// sent across it. -#[derive(Debug)] -pub struct MeteredSender { - meter: Meter, - inner: mpsc::Sender>, -} - -impl Clone for MeteredSender { - fn clone(&self) -> Self { - Self { meter: self.meter.clone(), inner: self.inner.clone() } - } -} - -impl std::ops::Deref for MeteredSender { - type Target = mpsc::Sender>; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for MeteredSender { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - -impl MeteredSender { - fn prepare_with_tof(&self, item: T) -> MaybeTimeOfFlight { - let previous = self.meter.note_sent(); - let item = if measure_tof_check(previous) { - MaybeTimeOfFlight::WithTimeOfFlight(item, CoarseInstant::now()) - } else { - MaybeTimeOfFlight::Bare(item) - }; - item - } - - /// Get an updated accessor object for all metrics collected. - pub fn meter(&self) -> &Meter { - &self.meter - } - - /// Send message, wait until capacity is available. - pub async fn send(&mut self, msg: T) -> result::Result<(), mpsc::SendError> - where - Self: Unpin, - { - match self.try_send(msg) { - Err(send_err) => { - if !send_err.is_full() { - return Err(send_err.into_send_error()) - } - - let msg = send_err.into_inner(); - self.meter.note_sent(); - let fut = self.inner.send(msg); - futures::pin_mut!(fut); - fut.await.map_err(|e| { - self.meter.retract_sent(); - e - }) - }, - _ => Ok(()), - } - } - - /// Attempt to send message or fail immediately. - pub fn try_send( - &mut self, - msg: T, - ) -> result::Result<(), mpsc::TrySendError>> { - let msg = self.prepare_with_tof(msg); - self.inner.try_send(msg).map_err(|e| { - if e.is_full() { - // Count bounded channel sends that block. - self.meter.note_blocked(); - } - self.meter.retract_sent(); - e - }) - } -} diff --git a/node/metered-channel/src/lib.rs b/node/metered-channel/src/lib.rs deleted file mode 100644 index 726d7163270c..000000000000 --- a/node/metered-channel/src/lib.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2017-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 . - -//! Metered variant of mpsc channels to be able to extract metrics. - -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, -}; - -use derive_more::Display; - -mod bounded; -pub mod oneshot; -mod unbounded; - -pub use self::{bounded::*, unbounded::*}; - -pub use coarsetime::Duration as CoarseDuration; -use coarsetime::Instant as CoarseInstant; - -#[cfg(test)] -mod tests; - -/// A peek into the inner state of a meter. -#[derive(Debug, Clone)] -pub struct Meter { - // Number of sends on this channel. - sent: Arc, - // Number of receives on this channel. - received: Arc, - // Number of times senders blocked while sending messages to a subsystem. - blocked: Arc, - // Atomic ringbuffer of the last 50 time of flight values - tof: Arc>, -} - -impl std::default::Default for Meter { - fn default() -> Self { - Self { - sent: Arc::new(AtomicUsize::new(0)), - received: Arc::new(AtomicUsize::new(0)), - blocked: Arc::new(AtomicUsize::new(0)), - tof: Arc::new(crossbeam_queue::ArrayQueue::new(100)), - } - } -} - -/// A readout of sizes from the meter. Note that it is possible, due to asynchrony, for received -/// to be slightly higher than sent. -#[derive(Debug, Display, Clone, Default, PartialEq)] -#[display(fmt = "(sent={} received={})", sent, received)] -pub struct Readout { - /// The amount of messages sent on the channel, in aggregate. - pub sent: usize, - /// The amount of messages received on the channel, in aggregate. - pub received: usize, - /// How many times the caller blocked when sending messages. - pub blocked: usize, - /// Time of flight in micro seconds (us) - pub tof: Vec, -} - -impl Meter { - /// Count the number of items queued up inside the channel. - pub fn read(&self) -> Readout { - // when obtaining we don't care much about off by one - // accuracy - Readout { - sent: self.sent.load(Ordering::Relaxed), - received: self.received.load(Ordering::Relaxed), - blocked: self.blocked.load(Ordering::Relaxed), - tof: { - let mut acc = Vec::with_capacity(self.tof.len()); - while let Some(value) = self.tof.pop() { - acc.push(value) - } - acc - }, - } - } - - fn note_sent(&self) -> usize { - self.sent.fetch_add(1, Ordering::Relaxed) - } - - fn retract_sent(&self) { - self.sent.fetch_sub(1, Ordering::Relaxed); - } - - fn note_received(&self) { - self.received.fetch_add(1, Ordering::Relaxed); - } - - fn note_blocked(&self) { - self.blocked.fetch_add(1, Ordering::Relaxed); - } - - fn note_time_of_flight(&self, tof: CoarseDuration) { - let _ = self.tof.force_push(tof); - } -} - -/// Determine if this instance shall be measured -#[inline(always)] -fn measure_tof_check(nth: usize) -> bool { - if cfg!(test) { - // for tests, be deterministic and pick every second - nth & 0x01 == 0 - } else { - use nanorand::Rng; - let mut rng = nanorand::WyRand::new_seed(nth as u64); - let pick = rng.generate_range(1_usize..=1000); - // measure 5.3% - pick <= 53 - } -} - -/// Measure the time of flight between insertion and removal -/// of a single type `T` - -#[derive(Debug)] -pub enum MaybeTimeOfFlight { - Bare(T), - WithTimeOfFlight(T, CoarseInstant), -} - -impl From for MaybeTimeOfFlight { - fn from(value: T) -> Self { - Self::Bare(value) - } -} - -// Has some unexplicable conflict with a wildcard impl of std -impl MaybeTimeOfFlight { - /// Extract the inner `T` value. - pub fn into(self) -> T { - match self { - Self::Bare(value) => value, - Self::WithTimeOfFlight(value, _tof_start) => value, - } - } -} - -impl std::ops::Deref for MaybeTimeOfFlight { - type Target = T; - fn deref(&self) -> &Self::Target { - match self { - Self::Bare(ref value) => value, - Self::WithTimeOfFlight(ref value, _tof_start) => value, - } - } -} diff --git a/node/metered-channel/src/oneshot.rs b/node/metered-channel/src/oneshot.rs deleted file mode 100644 index 23cb548747b2..000000000000 --- a/node/metered-channel/src/oneshot.rs +++ /dev/null @@ -1,419 +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 . - -//! Metered variant of oneshot channels to be able to extract delays caused by delayed responses. - -use std::{ - ops::Deref, - pin::Pin, - task::{Context, Poll}, -}; - -use futures::{ - channel::oneshot::{self, Canceled, Cancellation}, - future::{Fuse, FusedFuture}, - prelude::*, -}; -use futures_timer::Delay; - -use crate::{CoarseDuration, CoarseInstant}; - -/// Provides the reason for termination. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u8)] -pub enum Reason { - Completion = 1, - Cancellation = 2, - HardTimeout = 3, -} - -/// Obtained measurements by the `Receiver` side of the `MeteredOneshot`. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Measurements { - /// Duration between first poll and polling termination. - first_poll_till_end: CoarseDuration, - /// Duration starting with creation until polling termination. - creation_till_end: CoarseDuration, - /// Reason for resolving the future. - reason: Reason, -} - -impl Measurements { - /// Obtain the duration of a finished or canceled - /// `oneshot` channel. - pub fn duration_since_first_poll(&self) -> &CoarseDuration { - &self.first_poll_till_end - } - - /// Obtain the duration of a finished or canceled - /// `oneshot` channel. - pub fn duration_since_creation(&self) -> &CoarseDuration { - &self.creation_till_end - } - - /// Obtain the reason to the channel termination. - pub fn reason(&self) -> &Reason { - &self.reason - } -} - -/// Create a new pair of `OneshotMetered{Sender,Receiver}`. -pub fn channel( - name: &'static str, - soft_timeout: CoarseDuration, - hard_timeout: CoarseDuration, -) -> (MeteredSender, MeteredReceiver) { - let (tx, rx) = oneshot::channel(); - - ( - MeteredSender { inner: tx }, - MeteredReceiver { - name, - inner: rx, - soft_timeout, - hard_timeout, - soft_timeout_fut: None, - hard_timeout_fut: None, - first_poll_timestamp: None, - creation_timestamp: CoarseInstant::now(), - }, - ) -} - -#[allow(missing_docs)] -#[derive(thiserror::Error, Debug)] -pub enum Error { - #[error("Oneshot was canceled.")] - Canceled(#[source] Canceled, Measurements), - #[error("Oneshot did not receive a response within {}", CoarseDuration::as_f64(.0))] - HardTimeout(CoarseDuration, Measurements), -} - -impl Measurable for Error { - fn measurements(&self) -> Measurements { - match self { - Self::Canceled(_, measurements) => measurements.clone(), - Self::HardTimeout(_, measurements) => measurements.clone(), - } - } -} - -/// Oneshot sender, created by [`channel`]. -#[derive(Debug)] -pub struct MeteredSender { - inner: oneshot::Sender<(CoarseInstant, T)>, -} - -impl MeteredSender { - /// Send a value. - pub fn send(self, t: T) -> Result<(), T> { - let Self { inner } = self; - inner.send((CoarseInstant::now(), t)).map_err(|(_, t)| t) - } - - /// Poll if the thing is already canceled. - pub fn poll_canceled(&mut self, ctx: &mut Context<'_>) -> Poll<()> { - self.inner.poll_canceled(ctx) - } - - /// Access the cancellation object. - pub fn cancellation(&mut self) -> Cancellation<'_, (CoarseInstant, T)> { - self.inner.cancellation() - } - - /// Check the cancellation state. - pub fn is_canceled(&self) -> bool { - self.inner.is_canceled() - } - - /// Verify if the `receiver` is connected to the `sender` [`Self`]. - pub fn is_connected_to(&self, receiver: &MeteredReceiver) -> bool { - self.inner.is_connected_to(&receiver.inner) - } -} - -/// Oneshot receiver, created by [`channel`]. -#[derive(Debug)] -pub struct MeteredReceiver { - name: &'static str, - inner: oneshot::Receiver<(CoarseInstant, T)>, - /// Soft timeout, on expire a warning is printed. - soft_timeout_fut: Option>, - soft_timeout: CoarseDuration, - /// Hard timeout, terminating the sender. - hard_timeout_fut: Option, - hard_timeout: CoarseDuration, - /// The first time the receiver was polled. - first_poll_timestamp: Option, - creation_timestamp: CoarseInstant, -} - -impl MeteredReceiver { - pub fn close(&mut self) { - self.inner.close() - } - - /// Attempts to receive a message outside of the context of a task. - /// - /// A return value of `None` must be considered immediately stale (out of - /// date) unless [`close`](MeteredReceiver::close) has been called first. - /// - /// Returns an error if the sender was dropped. - pub fn try_recv(&mut self) -> Result>, Error> { - match self.inner.try_recv() { - Ok(Some((when, value))) => { - let measurements = self.create_measurement(when, Reason::Completion); - Ok(Some(OutputWithMeasurements { value, measurements })) - }, - Err(e) => { - let measurements = self.create_measurement( - self.first_poll_timestamp.unwrap_or_else(|| CoarseInstant::now()), - Reason::Cancellation, - ); - Err(Error::Canceled(e, measurements)) - }, - Ok(None) => Ok(None), - } - } - - /// Helper to create a measurement. - /// - /// `start` determines the first possible time where poll can resolve with `Ready`. - fn create_measurement(&self, start: CoarseInstant, reason: Reason) -> Measurements { - let end = CoarseInstant::now(); - Measurements { - // negative values are ok, if `send` was called before we poll for the first time. - first_poll_till_end: end - start, - creation_till_end: end - self.creation_timestamp, - reason, - } - } -} - -impl FusedFuture for MeteredReceiver { - fn is_terminated(&self) -> bool { - self.inner.is_terminated() - } -} - -impl Future for MeteredReceiver { - type Output = Result, Error>; - - fn poll( - mut self: Pin<&mut Self>, - ctx: &mut Context<'_>, - ) -> Poll, Error>> { - let first_poll_timestamp = - self.first_poll_timestamp.get_or_insert_with(|| CoarseInstant::now()).clone(); - - let soft_timeout = self.soft_timeout.clone().into(); - let soft_timeout = self - .soft_timeout_fut - .get_or_insert_with(move || Delay::new(soft_timeout).fuse()); - - if Pin::new(soft_timeout).poll(ctx).is_ready() { - tracing::warn!(target: "oneshot", "Oneshot `{name}` exceeded the soft threshold", name = &self.name); - } - - let hard_timeout = self.hard_timeout.clone().into(); - let hard_timeout = - self.hard_timeout_fut.get_or_insert_with(move || Delay::new(hard_timeout)); - - if Pin::new(hard_timeout).poll(ctx).is_ready() { - let measurements = self.create_measurement(first_poll_timestamp, Reason::HardTimeout); - return Poll::Ready(Err(Error::HardTimeout(self.hard_timeout.clone(), measurements))) - } - - match Pin::new(&mut self.inner).poll(ctx) { - Poll::Pending => Poll::Pending, - Poll::Ready(Err(e)) => { - let measurements = - self.create_measurement(first_poll_timestamp, Reason::Cancellation); - Poll::Ready(Err(Error::Canceled(e, measurements))) - }, - Poll::Ready(Ok((ref sent_at_timestamp, value))) => { - let measurements = - self.create_measurement(sent_at_timestamp.clone(), Reason::Completion); - Poll::Ready(Ok(OutputWithMeasurements:: { value, measurements })) - }, - } - } -} - -/// A dummy trait that allows implementing `measurements` for `Result<_,_>`. -pub trait Measurable { - /// Obtain a set of measurements represented by the `Measurements` type. - fn measurements(&self) -> Measurements; -} - -impl Measurable for Result, Error> { - fn measurements(&self) -> Measurements { - match self { - Err(err) => err.measurements(), - Ok(val) => val.measurements(), - } - } -} - -/// A wrapping type for the actual type `T` that is sent with the -/// oneshot yet allow to attach `Measurements` to it. -/// -/// Implements `AsRef` besides others for easier access to the inner, -/// wrapped type. -#[derive(Clone, Debug)] -pub struct OutputWithMeasurements { - value: T, - measurements: Measurements, -} - -impl Measurable for OutputWithMeasurements { - fn measurements(&self) -> Measurements { - self.measurements.clone() - } -} - -impl OutputWithMeasurements { - /// Converts the wrapper type into it's inner value. - /// - /// `trait Into` cannot be implemented due to conflicts. - pub fn into(self) -> T { - self.value - } -} - -impl AsRef for OutputWithMeasurements { - fn as_ref(&self) -> &T { - &self.value - } -} - -impl Deref for OutputWithMeasurements { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.value - } -} - -#[cfg(test)] -mod tests { - use assert_matches::assert_matches; - use futures::{executor::ThreadPool, task::SpawnExt}; - use std::time::Duration; - - use super::*; - - #[derive(Clone, PartialEq, Eq, Debug)] - struct DummyItem { - vals: [u8; 256], - } - - impl Default for DummyItem { - fn default() -> Self { - Self { vals: [0u8; 256] } - } - } - - fn test_launch(name: &'static str, gen_sender_test: S, gen_receiver_test: R) - where - S: Fn(MeteredSender) -> FS, - R: Fn(MeteredReceiver) -> FR, - FS: Future + Send + 'static, - FR: Future + Send + 'static, - { - let _ = env_logger::builder().is_test(true).filter_level(LevelFilter::Trace).try_init(); - - let pool = ThreadPool::new().unwrap(); - let (tx, rx) = channel(name, CoarseDuration::from_secs(1), CoarseDuration::from_secs(3)); - futures::executor::block_on(async move { - let handle_receiver = pool.spawn_with_handle(gen_receiver_test(rx)).unwrap(); - let handle_sender = pool.spawn_with_handle(gen_sender_test(tx)).unwrap(); - futures::future::select( - futures::future::join(handle_sender, handle_receiver), - Delay::new(Duration::from_secs(5)), - ) - .await; - }); - } - - use log::LevelFilter; - - #[test] - fn easy() { - test_launch( - "easy", - |tx| async move { - tx.send(DummyItem::default()).unwrap(); - }, - |rx| async move { - let x = rx.await.unwrap(); - let measurements = x.measurements(); - assert_eq!(x.as_ref(), &DummyItem::default()); - dbg!(measurements); - }, - ); - } - - #[test] - fn cancel_by_drop() { - test_launch( - "cancel_by_drop", - |tx| async move { - Delay::new(Duration::from_secs(2)).await; - drop(tx); - }, - |rx| async move { - let result = rx.await; - assert_matches!(result, Err(Error::Canceled(_, _))); - dbg!(result.measurements()); - }, - ); - } - - #[test] - fn starve_till_hard_timeout() { - test_launch( - "starve_till_timeout", - |tx| async move { - Delay::new(Duration::from_secs(4)).await; - let _ = tx.send(DummyItem::default()); - }, - |rx| async move { - let result = rx.await; - assert_matches!(&result, e @ &Err(Error::HardTimeout(_, _)) => { - println!("{:?}", e); - }); - dbg!(result.measurements()); - }, - ); - } - - #[test] - fn starve_till_soft_timeout_then_food() { - test_launch( - "starve_till_soft_timeout_then_food", - |tx| async move { - Delay::new(Duration::from_secs(2)).await; - let _ = tx.send(DummyItem::default()); - }, - |rx| async move { - let result = rx.await; - assert_matches!(result, Ok(_)); - dbg!(result.measurements()); - }, - ); - } -} diff --git a/node/metered-channel/src/tests.rs b/node/metered-channel/src/tests.rs deleted file mode 100644 index 6ea947eaa5be..000000000000 --- a/node/metered-channel/src/tests.rs +++ /dev/null @@ -1,150 +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 . - -use super::*; -use assert_matches::assert_matches; -use futures::{executor::block_on, StreamExt}; - -#[derive(Clone, Copy, Debug, Default)] -struct Msg { - val: u8, -} - -#[test] -fn try_send_try_next() { - block_on(async move { - let (mut tx, mut rx) = channel::(5); - let msg = Msg::default(); - assert_matches!(rx.meter().read(), Readout { sent: 0, received: 0, .. }); - tx.try_send(msg).unwrap(); - assert_matches!(tx.meter().read(), Readout { sent: 1, received: 0, .. }); - tx.try_send(msg).unwrap(); - tx.try_send(msg).unwrap(); - tx.try_send(msg).unwrap(); - assert_matches!(tx.meter().read(), Readout { sent: 4, received: 0, .. }); - rx.try_next().unwrap(); - assert_matches!(rx.meter().read(), Readout { sent: 4, received: 1, .. }); - rx.try_next().unwrap(); - rx.try_next().unwrap(); - assert_matches!(tx.meter().read(), Readout { sent: 4, received: 3, blocked: 0, tof } => { - // every second in test, consumed before - assert_eq!(dbg!(tof).len(), 1); - }); - rx.try_next().unwrap(); - assert_matches!(rx.meter().read(), Readout { sent: 4, received: 4, blocked: 0, tof } => { - // every second in test, consumed before - assert_eq!(dbg!(tof).len(), 0); - }); - assert!(rx.try_next().is_err()); - }); -} - -#[test] -fn with_tasks() { - let (ready, go) = futures::channel::oneshot::channel(); - - let (mut tx, mut rx) = channel::(5); - block_on(async move { - futures::join!( - async move { - let msg = Msg::default(); - assert_matches!(tx.meter().read(), Readout { sent: 0, received: 0, .. }); - tx.try_send(msg).unwrap(); - assert_matches!(tx.meter().read(), Readout { sent: 1, received: 0, .. }); - tx.try_send(msg).unwrap(); - tx.try_send(msg).unwrap(); - tx.try_send(msg).unwrap(); - ready.send(()).expect("Helper oneshot channel must work. qed"); - }, - async move { - go.await.expect("Helper oneshot channel must work. qed"); - assert_matches!(rx.meter().read(), Readout { sent: 4, received: 0, .. }); - rx.try_next().unwrap(); - assert_matches!(rx.meter().read(), Readout { sent: 4, received: 1, .. }); - rx.try_next().unwrap(); - rx.try_next().unwrap(); - assert_matches!(rx.meter().read(), Readout { sent: 4, received: 3, .. }); - rx.try_next().unwrap(); - assert_matches!(dbg!(rx.meter().read()), Readout { sent: 4, received: 4, .. }); - } - ) - }); -} - -use futures_timer::Delay; -use std::time::Duration; - -#[test] -fn stream_and_sink() { - let (mut tx, mut rx) = channel::(5); - - block_on(async move { - futures::join!( - async move { - for i in 0..15 { - println!("Sent #{} with a backlog of {} items", i + 1, tx.meter().read()); - let msg = Msg { val: i as u8 + 1u8 }; - tx.send(msg).await.unwrap(); - assert!(tx.meter().read().sent > 0usize); - Delay::new(Duration::from_millis(20)).await; - } - () - }, - async move { - while let Some(msg) = rx.next().await { - println!("rx'd one {} with {} backlogged", msg.val, rx.meter().read()); - Delay::new(Duration::from_millis(29)).await; - } - } - ) - }); -} - -#[test] -fn failed_send_does_not_inc_sent() { - let (mut bounded, _) = channel::(5); - let (unbounded, _) = unbounded::(); - - block_on(async move { - assert!(bounded.send(Msg::default()).await.is_err()); - assert!(bounded.try_send(Msg::default()).is_err()); - assert_matches!(bounded.meter().read(), Readout { sent: 0, received: 0, .. }); - - assert!(unbounded.unbounded_send(Msg::default()).is_err()); - assert_matches!(unbounded.meter().read(), Readout { sent: 0, received: 0, .. }); - }); -} - -#[test] -fn blocked_send_is_metered() { - let (mut bounded_sender, mut bounded_receiver) = channel::(1); - - block_on(async move { - assert!(bounded_sender.send(Msg::default()).await.is_ok()); - assert!(bounded_sender.send(Msg::default()).await.is_ok()); - assert!(bounded_sender.try_send(Msg::default()).is_err()); - - assert_matches!( - bounded_sender.meter().read(), - Readout { sent: 2, received: 0, blocked: 1, .. } - ); - bounded_receiver.try_next().unwrap(); - assert_matches!( - bounded_receiver.meter().read(), - Readout { sent: 2, received: 1, blocked: 1, .. } - ); - }); -} diff --git a/node/metered-channel/src/unbounded.rs b/node/metered-channel/src/unbounded.rs deleted file mode 100644 index 8ade941d6831..000000000000 --- a/node/metered-channel/src/unbounded.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2017-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 . - -//! Metered variant of unbounded mpsc channels to be able to extract metrics. - -use futures::{ - channel::mpsc, - stream::Stream, - task::{Context, Poll}, -}; - -use std::{pin::Pin, result}; - -use super::{measure_tof_check, CoarseInstant, MaybeTimeOfFlight, Meter}; - -/// Create a wrapped `mpsc::channel` pair of `MeteredSender` and `MeteredReceiver`. -pub fn unbounded() -> (UnboundedMeteredSender, UnboundedMeteredReceiver) { - let (tx, rx) = mpsc::unbounded::>(); - let shared_meter = Meter::default(); - let tx = UnboundedMeteredSender { meter: shared_meter.clone(), inner: tx }; - let rx = UnboundedMeteredReceiver { meter: shared_meter, inner: rx }; - (tx, rx) -} - -/// A receiver tracking the messages consumed by itself. -#[derive(Debug)] -pub struct UnboundedMeteredReceiver { - // count currently contained messages - meter: Meter, - inner: mpsc::UnboundedReceiver>, -} - -impl std::ops::Deref for UnboundedMeteredReceiver { - type Target = mpsc::UnboundedReceiver>; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for UnboundedMeteredReceiver { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - -impl Stream for UnboundedMeteredReceiver { - type Item = T; - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - match mpsc::UnboundedReceiver::poll_next(Pin::new(&mut self.inner), cx) { - Poll::Ready(maybe_value) => Poll::Ready(self.maybe_meter_tof(maybe_value)), - Poll::Pending => Poll::Pending, - } - } - - /// Don't rely on the unreliable size hint. - fn size_hint(&self) -> (usize, Option) { - self.inner.size_hint() - } -} - -impl UnboundedMeteredReceiver { - fn maybe_meter_tof(&mut self, maybe_value: Option>) -> Option { - self.meter.note_received(); - maybe_value.map(|value| { - match value { - MaybeTimeOfFlight::::WithTimeOfFlight(value, tof_start) => { - // do not use `.elapsed()` of `std::time`, it may panic - // `coarsetime` does a saturating substractio for all `CoarseInstant`s - let duration = tof_start.elapsed(); - self.meter.note_time_of_flight(duration); - value - }, - MaybeTimeOfFlight::::Bare(value) => value, - } - .into() - }) - } - - /// Get an updated accessor object for all metrics collected. - pub fn meter(&self) -> &Meter { - &self.meter - } - - /// Attempt to receive the next item. - pub fn try_next(&mut self) -> Result, mpsc::TryRecvError> { - match self.inner.try_next()? { - Some(value) => Ok(self.maybe_meter_tof(Some(value))), - None => Ok(None), - } - } -} - -impl futures::stream::FusedStream for UnboundedMeteredReceiver { - fn is_terminated(&self) -> bool { - self.inner.is_terminated() - } -} - -/// The sender component, tracking the number of items -/// sent across it. -#[derive(Debug)] -pub struct UnboundedMeteredSender { - meter: Meter, - inner: mpsc::UnboundedSender>, -} - -impl Clone for UnboundedMeteredSender { - fn clone(&self) -> Self { - Self { meter: self.meter.clone(), inner: self.inner.clone() } - } -} - -impl std::ops::Deref for UnboundedMeteredSender { - type Target = mpsc::UnboundedSender>; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl std::ops::DerefMut for UnboundedMeteredSender { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.inner - } -} - -impl UnboundedMeteredSender { - fn prepare_with_tof(&self, item: T) -> MaybeTimeOfFlight { - let previous = self.meter.note_sent(); - let item = if measure_tof_check(previous) { - MaybeTimeOfFlight::WithTimeOfFlight(item, CoarseInstant::now()) - } else { - MaybeTimeOfFlight::Bare(item) - }; - item - } - - /// Get an updated accessor object for all metrics collected. - pub fn meter(&self) -> &Meter { - &self.meter - } - - /// Attempt to send message or fail immediately. - pub fn unbounded_send( - &self, - msg: T, - ) -> result::Result<(), mpsc::TrySendError>> { - let msg = self.prepare_with_tof(msg); - self.inner.unbounded_send(msg).map_err(|e| { - self.meter.retract_sent(); - e - }) - } -} diff --git a/node/metrics/Cargo.toml b/node/metrics/Cargo.toml index a5221a05dbd8..ba9843d24031 100644 --- a/node/metrics/Cargo.toml +++ b/node/metrics/Cargo.toml @@ -10,7 +10,7 @@ futures = "0.3.21" futures-timer = "3.0.2" gum = { package = "tracing-gum", path = "../gum" } -metered = { package = "prioritized-metered-channel", path = "../metered-channel" , "version" = "0.2.0" } +metered = { package = "prioritized-metered-channel", version = "0.2.0" } # Both `sc-service` and `sc-cli` are required by runtime metrics `logger_hook()`. sc-service = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/node/network/availability-distribution/src/lib.rs b/node/network/availability-distribution/src/lib.rs index 3faaa80ce835..7dceb5f80e6c 100644 --- a/node/network/availability-distribution/src/lib.rs +++ b/node/network/availability-distribution/src/lib.rs @@ -150,6 +150,7 @@ impl AvailabilityDistributionSubsystem { AvailabilityDistributionMessage::FetchPoV { relay_parent, from_validator, + para_id, candidate_hash, pov_hash, tx, @@ -161,6 +162,7 @@ impl AvailabilityDistributionSubsystem { &mut runtime, relay_parent, from_validator, + para_id, candidate_hash, pov_hash, tx, diff --git a/node/network/availability-distribution/src/pov_requester/mod.rs b/node/network/availability-distribution/src/pov_requester/mod.rs index 195c1748793c..f32a4bd4821d 100644 --- a/node/network/availability-distribution/src/pov_requester/mod.rs +++ b/node/network/availability-distribution/src/pov_requester/mod.rs @@ -30,7 +30,9 @@ use polkadot_node_subsystem::{ overseer, }; use polkadot_node_subsystem_util::runtime::RuntimeInfo; -use polkadot_primitives::v2::{AuthorityDiscoveryId, CandidateHash, Hash, ValidatorIndex}; +use polkadot_primitives::v2::{ + AuthorityDiscoveryId, CandidateHash, Hash, Id as ParaId, ValidatorIndex, +}; use crate::{ error::{Error, FatalError, JfyiError, Result}, @@ -45,6 +47,7 @@ pub async fn fetch_pov( runtime: &mut RuntimeInfo, parent: Hash, from_validator: ValidatorIndex, + para_id: ParaId, candidate_hash: CandidateHash, pov_hash: Hash, tx: oneshot::Sender, @@ -70,10 +73,12 @@ pub async fn fetch_pov( let span = jaeger::Span::new(candidate_hash, "fetch-pov") .with_validator_index(from_validator) - .with_relay_parent(parent); + .with_relay_parent(parent) + .with_para_id(para_id); ctx.spawn( "pov-fetcher", - fetch_pov_job(pov_hash, authority_id, pending_response.boxed(), span, tx, metrics).boxed(), + fetch_pov_job(para_id, pov_hash, authority_id, pending_response.boxed(), span, tx, metrics) + .boxed(), ) .map_err(|e| FatalError::SpawnTask(e))?; Ok(()) @@ -81,6 +86,7 @@ pub async fn fetch_pov( /// Future to be spawned for taking care of handling reception and sending of PoV. async fn fetch_pov_job( + para_id: ParaId, pov_hash: Hash, authority_id: AuthorityDiscoveryId, pending_response: BoxFuture<'static, std::result::Result>, @@ -89,7 +95,7 @@ async fn fetch_pov_job( metrics: Metrics, ) { if let Err(err) = do_fetch_pov(pov_hash, pending_response, span, tx, metrics).await { - gum::warn!(target: LOG_TARGET, ?err, ?pov_hash, ?authority_id, "fetch_pov_job"); + gum::warn!(target: LOG_TARGET, ?err, ?para_id, ?pov_hash, ?authority_id, "fetch_pov_job"); } } @@ -171,6 +177,7 @@ mod tests { &mut runtime, Hash::default(), ValidatorIndex(0), + ParaId::default(), CandidateHash::default(), pov_hash, tx, diff --git a/node/orchestra/Cargo.toml b/node/orchestra/Cargo.toml deleted file mode 100644 index 8686003f475b..000000000000 --- a/node/orchestra/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "orchestra" -version = "0.0.1" -authors = ["Parity Technologies "] -edition = "2021" -description = "Generate an orchestra of subsystems from a single struct." -repository = "https://github.com/paritytech/polkadot" -license = "MIT OR Apache-2.0" -autoexamples = false - -[dependencies] -tracing = "0.1.35" -futures = "0.3" -async-trait = "0.1" -thiserror = "1" -metered = { package = "prioritized-metered-channel", version = "0.2.0", path = "../metered-channel" } -orchestra-proc-macro = { version = "0.0.1", path = "./proc-macro" } -futures-timer = "3.0.2" -pin-project = "1.0" -dyn-clonable = "0.9" - -[dev-dependencies] -trybuild = "1.0.61" -rustversion = "1.0.6" - - -[[example]] -name = "duo" -crate-type = ["bin"] - -[[example]] -name = "solo" -crate-type = ["bin"] - -[features] -default = [] -expand = ["orchestra-proc-macro/expand"] diff --git a/node/orchestra/README.md b/node/orchestra/README.md deleted file mode 100644 index 2cfe4bb0a884..000000000000 --- a/node/orchestra/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# orchestra - -The orchestra pattern is a partial actor pattern, with a global orchestrator regarding -relevant work items. - -## proc-macro - -The proc macro provides a convenience generator with a builder pattern, -where at it's core it creates and spawns a set of subsystems, which are purely -declarative. - -```rust - #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] - pub struct Opera { - #[subsystem(MsgA, sends: [MsgB])] - sub_a: AwesomeSubSysA, - - #[subsystem(MsgB, sends: [MsgA])] - sub_b: AwesomeSubSysB, - } -``` - -* Each subsystem is annotated with `#[subsystem(_)]` where `MsgA` respectively `MsgB` are the messages -being consumed by that particular subsystem. Each of those subsystems is required to implement the subsystem -trait with the correct trait bounds. Commonly this is achieved -by using `#[subsystem]` and `#[contextbounds]` macro. - * `#[contextbounds(Foo, error=Yikes, prefix=wherethetraitsat)]` can applied to `impl`-blocks and `fn`-blocks. It will add additional trait bounds for the generic `Context` with `Context: FooContextTrait` for `::Sender: FooSenderTrait` besides a few more. Note that `Foo` here references the name of the subsystem as declared in `#[orchestra(..)]` macro. - * `#[subsystem(Foo, error=Yikes, prefix=wherethetraitsat)]` is a extension to the above, implementing `trait Subsystem`. -* `error=` tells the orchestra to use the user provided -error type, if not provided a builtin one is used. Note that this is the one error type used throughout all calls, so make sure it does impl `From` for all other error types `E` that are relevant to your application. -* `event=` declares an external event type, that injects certain events -into the orchestra, without participating in the subsystem pattern. -* `signal=` defines a signal type to be used for the orchestra. This is a shared "tick" or "clock" for all subsystems. -* `gen=` defines a wrapping `enum` type that is used to wrap all messages that can be consumed by _any_ subsystem. - -```rust - /// Execution context, always required. - pub struct DummyCtx; - - /// Task spawner, always required - /// and must implement `trait orchestra::Spawner`. - pub struct DummySpawner; - - fn main() { - let _orchestra = Opera::builder() - .sub_a(AwesomeSubSysA::default()) - .sub_b(AwesomeSubSysB::default()) - .spawner(DummySpawner) - .build(); - } -``` - -In the shown `main`, the orchestra is created by means of a generated, compile time erroring -builder pattern. - -The builder requires all subsystems, baggage fields (additional struct data) and spawner to be -set via the according setter method before `build` method could even be called. Failure to do -such an initialization will lead to a compile error. This is implemented by encoding each -builder field in a set of so called `state generics`, meaning that each field can be either -`Init` or `Missing`, so each setter translates a state from `Missing` to `Init` state -for the specific struct field. Therefore, if you see a compile time error that blames about -`Missing` where `Init` is expected it usually means that some subsystems or baggage fields were -not set prior to the `build` call. - -To exclude subsystems from such a check, one can set `wip` attribute on some subsystem that -is not ready to be included in the Orchestra: - -```rust - #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] - pub struct Opera { - #[subsystem(MsgA, sends: MsgB)] - sub_a: AwesomeSubSysA, - - #[subsystem(MsgB, sends: MsgA), wip] - sub_b: AwesomeSubSysB, // This subsystem will not be required nor allowed to be set - } -``` - -Baggage fields can be initialized more than one time, however, it is not true for subsystems: -subsystems must be initialized only once (another compile time check) or be _replaced_ by -a special setter like method `replace_`. - -A task spawner and subsystem context are required to be defined with `Spawner` and respectively `SubsystemContext` implemented. - -## Debugging - -As always, debugging is notoriously annoying with bugged proc-macros. - -Therefore [`expander`](https://github.com/drahnr/expander) is employed to yield better -error messages. Enable with `--feature=orchestra/expand`. - -## License - -Licensed under either of - -* Apache License, Version 2.0, (LICENSE-APACHE or ) -* MIT license (LICENSE-MIT or ) - -at your option. diff --git a/node/orchestra/adr/01-adr.md b/node/orchestra/adr/01-adr.md deleted file mode 100644 index 3b1cb57eb322..000000000000 --- a/node/orchestra/adr/01-adr.md +++ /dev/null @@ -1,21 +0,0 @@ -# Limit outgoing messages - -## Status - -Accepted + implemented. - -## Context - -Previously, there was no way to limit and hence reason about a subset of subsystems, and if they form a cycle. Limiting the outgoing message types is a first step to create respective graphs and use classic graph algorithms to detect those and leave it to the user to resolve these. - -## Decision - -Annotate the `#[orchestra]` inner `#[subsystem(..)]` annotation -with an aditional set of outgoing messages and enforce this via more fine grained trait bounds on the `Sender` and `::Sender` bounds. - -## Consequences - -* A graph will be spawn for every compilation under the `OUT_DIR` of the crate where `#[orchestra]` is specified. -* Each subsystem has a consuming message which is often referred to as generic `M` (no change on that, is as before), but now we have trait `AssociateOutgoing { type OutgoingMessages = ..; }` which defines an outgoing helper `enum` that is generated with an ident constructed as `${Subsystem}OutgoingMessages` where `${Subsystem}` is the subsystem identifier as used in the orchestra declaration. `${Subsystem}OutgoingMessages` is used throughout everywhere to constrain the outgoing messages (commonly referred to as `OutgoingMessage` generic bounded by `${Subsystem}OutgoingMessages: From` or `::OutgoingMessages: From`. It's what allows the construction of the graph and compile time verification. -* `${Subsystem}SenderTrait` and `${Subsystem}ContextTrait` are accumulation traits or wrapper traits, that combine over all annotated M or `OutgoingMessages` from the orchestra declaration or their respective outgoing types. It is usage convenience and assures consistency within a subsystem while also maintaining a single source of truth for which messages can be sent by a particular subsystem. Note that this is sidestepped for the test subsystem, which may consume `gen=AllMessages`, the global message wrapper type. -* `Job`-based subsystems, being on their way out, are patched, but they now are generic over the `Sender` type, leaking that type. diff --git a/node/orchestra/examples/duo.rs b/node/orchestra/examples/duo.rs deleted file mode 100644 index 7fd465981273..000000000000 --- a/node/orchestra/examples/duo.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#![allow(dead_code)] // orchestra events are not used - -//! A dummy to be used with cargo expand - -use orchestra::{self as orchestra, Spawner, *}; -use std::{collections::HashMap, sync::Arc}; -mod misc; - -pub use self::misc::*; - -/// Concrete subsystem implementation for `MsgStrukt` msg type. -#[derive(Default)] -pub struct AwesomeSubSys; - -#[orchestra::subsystem(Awesome, error=Yikes)] -impl AwesomeSubSys { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { - let mut sender = ctx.sender().clone(); - ctx.spawn( - "AwesomeSubsys", - Box::pin(async move { - sender.send_message(Plinko).await; - }), - ) - .unwrap(); - unimplemented!("starting yay!") - } -} - -#[derive(Default)] -pub struct Fortified; - -#[orchestra::subsystem(GoblinTower, error=Yikes)] -impl Fortified { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { - let mut sender = ctx.sender().clone(); - ctx.spawn( - "GoblinTower", - Box::pin(async move { - sender.send_message(MsgStrukt(8u8)).await; - }), - ) - .unwrap(); - unimplemented!("welcum") - } -} - -#[orchestra(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)] -struct Duo { - #[subsystem(consumes: MsgStrukt, sends: [Plinko])] - sub0: Awesome, - - #[subsystem(blocking, consumes: Plinko, sends: [MsgStrukt])] - plinkos: GoblinTower, - - i_like_pi: f64, - i_like_tuple: (f64, f64), - i_like_generic: Arc, - i_like_hash: HashMap<(U, V), Arc>, -} - -fn main() { - use futures::{executor, pin_mut}; - - executor::block_on(async move { - let (orchestra, _handle): (Duo<_, f64, u32, f32, f64>, _) = Duo::builder() - .sub0(AwesomeSubSys::default()) - .plinkos(Fortified::default()) - .i_like_pi(::std::f64::consts::PI) - .i_like_tuple((::std::f64::consts::PI, ::std::f64::consts::PI)) - .i_like_generic(Arc::new(42.0)) - .i_like_hash(HashMap::new()) - .spawner(DummySpawner) - .build() - .unwrap(); - - assert_eq!(orchestra.i_like_pi.floor() as i8, 3); - assert_eq!(orchestra.i_like_generic.floor() as i8, 42); - assert_eq!(orchestra.i_like_hash.len() as i8, 0); - - let orchestra_fut = orchestra - .running_subsystems - .into_future() - .timeout(std::time::Duration::from_millis(300)) - .fuse(); - - pin_mut!(orchestra_fut); - - orchestra_fut.await - }); -} diff --git a/node/orchestra/examples/misc.rs b/node/orchestra/examples/misc.rs deleted file mode 100644 index ffd5001d07bd..000000000000 --- a/node/orchestra/examples/misc.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use orchestra::{Spawner, *}; - -#[derive(Debug, Clone, Copy)] -pub enum SigSigSig { - Conclude, - Foo, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -/// The external event. -#[derive(Debug, Clone)] -pub struct EvX; - -impl EvX { - pub fn focus<'a, T>(&'a self) -> Result { - unimplemented!("focus") - } -} - -#[derive(Debug, Clone, Copy)] -pub struct Yikes; - -impl std::fmt::Display for Yikes { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "yikes!") - } -} - -impl std::error::Error for Yikes {} - -impl From for Yikes { - fn from(_: orchestra::OrchestraError) -> Yikes { - Yikes - } -} - -impl From for Yikes { - fn from(_: orchestra::mpsc::SendError) -> Yikes { - Yikes - } -} - -#[derive(Debug, Clone)] -pub struct MsgStrukt(pub u8); - -#[derive(Debug, Clone, Copy)] -pub struct Plinko; diff --git a/node/orchestra/examples/solo.rs b/node/orchestra/examples/solo.rs deleted file mode 100644 index cc82656759cd..000000000000 --- a/node/orchestra/examples/solo.rs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#![allow(dead_code)] // orchestra events are not used - -//! A minimal demo to be used with cargo expand. - -use orchestra::{self as orchestra, Spawner, *}; -mod misc; - -pub use self::misc::*; - -#[orchestra(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)] -struct Solo { - #[subsystem(consumes: Plinko, sends: [MsgStrukt])] - goblin_tower: GoblinTower, -} - -#[derive(Default)] -pub struct Fortified; - -#[orchestra::subsystem(GoblinTower, error=Yikes)] -impl Fortified { - fn start(self, mut ctx: Context) -> SpawnedSubsystem { - let mut sender = ctx.sender().clone(); - ctx.spawn( - "GoblinTower", - Box::pin(async move { - sender.send_message(MsgStrukt(8u8)).await; - }), - ) - .unwrap(); - unimplemented!("welcum") - } -} - -async fn setup() { - let builder = Solo::builder(); - - let builder = builder.goblin_tower(Fortified::default()); - - let builder = builder.spawner(DummySpawner); - let (orchestra, _handle): (Solo<_>, _) = builder.build().unwrap(); - - let orchestra_fut = orchestra - .running_subsystems - .into_future() - .timeout(std::time::Duration::from_millis(300)) - .fuse(); - - futures::pin_mut!(orchestra_fut); - - orchestra_fut.await; -} - -fn assert_t_impl_trait_send(_: &T) {} - -fn main() { - let x = setup(); - assert_t_impl_trait_send(&x); - futures::executor::block_on(x); -} diff --git a/node/orchestra/proc-macro/Cargo.toml b/node/orchestra/proc-macro/Cargo.toml deleted file mode 100644 index bd0551e2e005..000000000000 --- a/node/orchestra/proc-macro/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[package] -name = "orchestra-proc-macro" -version = "0.0.1" -authors = ["Parity Technologies "] -edition = "2021" -description = "Generate an orchestra of subsystems from a single annotated struct definition." -repository = "https://github.com/paritytech/polkadot" -license = "MIT OR Apache-2.0" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[lib] -proc-macro = true - -[dependencies] -syn = { version = "1.0.95", features = ["full", "extra-traits"] } -quote = "1.0.20" -proc-macro2 = "1.0.43" -proc-macro-crate = "1.1.3" -expander = { version = "0.0.6", default-features = false } -petgraph = "0.6.0" -itertools = { version = "0.10.3" } - -[dev-dependencies] -assert_matches = "1.5" -orchestra = { path = "../" } -thiserror = "1" -tracing = "0.1" - -[features] -default = [] # enable "graph" by default, blocked by -# write the expanded version to a `orchestra-expansion.[a-f0-9]{10}.rs` -# in the `OUT_DIR` as defined by `cargo` for the `expander` crate. -expand = [] -# Create directional message consuming / outgoing graph. -# Generates: `${OUT_DIR}/${orchestra|lowercase}-subsystem-messaging.dot` -graph = [] diff --git a/node/orchestra/proc-macro/build.rs b/node/orchestra/proc-macro/build.rs deleted file mode 100644 index 24bd09048397..000000000000 --- a/node/orchestra/proc-macro/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - // populate OUT_DIR -} diff --git a/node/orchestra/proc-macro/src/graph.rs b/node/orchestra/proc-macro/src/graph.rs deleted file mode 100644 index 13406efaf06a..000000000000 --- a/node/orchestra/proc-macro/src/graph.rs +++ /dev/null @@ -1,432 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use quote::ToTokens; -use syn::{Ident, Path}; - -use petgraph::{graph::NodeIndex, Graph}; -use std::collections::{hash_map::RandomState, HashMap, HashSet}; - -use super::*; - -/// Representation of all subsystem connections -pub(crate) struct ConnectionGraph<'a> { - /// Graph of connected subsystems - /// - /// The graph represents a subsystem as a node or `NodeIndex` - /// and edges are messages sent, directed from the sender to - /// the receiver of the message. - pub(crate) graph: Graph, - /// Cycles within the graph - #[cfg_attr(not(feature = "graph"), allow(dead_code))] - pub(crate) sccs: Vec>, - /// Messages that are never being sent (and by which subsystem), but are consumed - /// Maps the message `Path` to the subsystem `Ident` represented by `NodeIndex`. - #[cfg_attr(not(feature = "graph"), allow(dead_code))] - pub(crate) unsent_messages: HashMap<&'a Path, (&'a Ident, NodeIndex)>, - /// Messages being sent (and by which subsystem), but not consumed by any subsystem - /// Maps the message `Path` to the subsystem `Ident` represented by `NodeIndex`. - #[cfg_attr(not(feature = "graph"), allow(dead_code))] - pub(crate) unconsumed_messages: HashMap<&'a Path, Vec<(&'a Ident, NodeIndex)>>, -} - -impl<'a> ConnectionGraph<'a> { - /// Generates all subsystem types and related accumulation traits. - pub(crate) fn construct(ssfs: &'a [SubSysField]) -> Self { - // create a directed graph with all the subsystems as nodes and the messages as edges - // key is always the message path, values are node indices in the graph and the subsystem generic identifier - // store the message path and the source sender, both in the graph as well as identifier - let mut outgoing_lut = HashMap::<&Path, Vec<(&Ident, NodeIndex)>>::with_capacity(128); - // same for consuming the incoming messages - let mut consuming_lut = HashMap::<&Path, (&Ident, NodeIndex)>::with_capacity(128); - - let mut graph = Graph::::new(); - - // prepare the full index of outgoing and source subsystems - for ssf in ssfs { - let node_index = graph.add_node(ssf.generic.clone()); - for outgoing in ssf.messages_to_send.iter() { - outgoing_lut.entry(outgoing).or_default().push((&ssf.generic, node_index)); - } - if let Some(_first_consument) = - consuming_lut.insert(&ssf.message_to_consume, (&ssf.generic, node_index)) - { - // bail, two subsystems consuming the same message - } - } - - for (message_ty, (_consuming_subsystem_ident, consuming_node_index)) in consuming_lut.iter() - { - // match the outgoing ones that were registered above with the consumed message - if let Some(origin_subsystems) = outgoing_lut.get(message_ty) { - for (_origin_subsystem_ident, sending_node_index) in origin_subsystems.iter() { - graph.add_edge( - *sending_node_index, - *consuming_node_index, - (*message_ty).clone(), - ); - } - } - } - - // extract unsent and unreceived messages - let outgoing_set = HashSet::<_, RandomState>::from_iter(outgoing_lut.keys().cloned()); - let consuming_set = HashSet::<_, RandomState>::from_iter(consuming_lut.keys().cloned()); - - let mut unsent_messages = consuming_lut; - unsent_messages.retain(|k, _v| !outgoing_set.contains(k)); - - let mut unconsumed_messages = outgoing_lut; - unconsumed_messages.retain(|k, _v| !consuming_set.contains(k)); - - let scc = Self::extract_scc(&graph); - - Self { graph, sccs: scc, unsent_messages, unconsumed_messages } - } - - /// Extract the strongly connected components (`scc`) which each - /// includes at least one cycle each. - fn extract_scc(graph: &Graph) -> Vec> { - use petgraph::visit::EdgeRef; - - // there is no guarantee regarding the node indices in the individual sccs - let sccs = petgraph::algo::kosaraju_scc(&graph); - let sccs = Vec::from_iter(sccs.into_iter().filter(|scc| { - match scc.len() { - 1 => { - // contains sccs of length one, - // which do not exists, might be an upstream bug? - let node_idx = scc[0]; - graph - .edges_directed(node_idx, petgraph::Direction::Outgoing) - .find(|edge| edge.target() == node_idx) - .is_some() - }, - 0 => false, - _n => true, - } - })); - match sccs.len() { - 0 => eprintln!("✅ Found no strongly connected components, hence no cycles exist"), - 1 => eprintln!( - "⚡ Found 1 strongly connected component which includes at least one cycle" - ), - n => eprintln!( - "⚡ Found {n} strongly connected components which includes at least one cycle each" - ), - } - - let greek_alphabet = greek_alphabet(); - - for (scc_idx, scc) in sccs.iter().enumerate() { - let scc_tag = greek_alphabet.get(scc_idx).copied().unwrap_or('_'); - let mut acc = Vec::with_capacity(scc.len()); - assert!(scc.len() > 0); - let mut node_idx = scc[0].clone(); - let print_idx = scc_idx + 1; - // track which ones were visited and which step - // the step is required to truncate the output - // which is required to greedily find a cycle in the strongly connected component - let mut visited = HashMap::new(); - for step in 0..scc.len() { - if let Some(edge) = - graph.edges_directed(node_idx, petgraph::Direction::Outgoing).find(|edge| { - scc.iter().find(|&scc_node_idx| *scc_node_idx == edge.target()).is_some() - }) { - let next = edge.target(); - visited.insert(node_idx, step); - - let subsystem_name = &graph[node_idx].to_string(); - let message_name = &graph[edge.id()].to_token_stream().to_string(); - acc.push(format!("{subsystem_name} ~~{{{message_name:?}}}~~> ")); - node_idx = next; - - if let Some(step) = visited.get(&next) { - // we've been there, so there is a cycle - // cut off the extra tail - assert!(acc.len() >= *step); - acc.drain(..step); - // there might be more cycles in this cluster, - // but for they are ignored, the graph shows - // the entire strongly connected component. - break - } - } else { - eprintln!("cycle({print_idx:03}) ∈ {scc_tag}: Missing connection in hypothesized cycle after {step} steps, this is a bug 🐛"); - break - } - } - let acc = String::from_iter(acc); - eprintln!("cycle({print_idx:03}) ∈ {scc_tag}: {acc} *"); - } - - sccs - } - - /// Render a graphviz (aka dot graph) to a file. - /// - /// Cycles are annotated with the lower - #[cfg(feature = "graph")] - pub(crate) fn graphviz(self, dest: &mut impl std::io::Write) -> std::io::Result<()> { - use self::graph_helpers::*; - use petgraph::{ - dot::{self, Dot}, - visit::{EdgeRef, IntoEdgeReferences, IntoNodeReferences}, - }; - - // only write the grap content, we want a custom color scheme - let config = &[ - dot::Config::GraphContentOnly, - dot::Config::EdgeNoLabel, - dot::Config::NodeNoLabel, - ][..]; - - let Self { mut graph, unsent_messages, unconsumed_messages, sccs } = self; - - // the greek alphabet, lowercase - let greek_alphabet = greek_alphabet(); - - const COLOR_SCHEME_N: usize = 10; // rdylgn10 - - // Adding more than 10, is _definitely_ too much visual clutter in the graph. - const UPPER_BOUND: usize = 10; - - assert!(UPPER_BOUND <= GREEK_ALPHABET_SIZE); - assert!(UPPER_BOUND <= COLOR_SCHEME_N); - - let n = sccs.len(); - let n = if n > UPPER_BOUND { - eprintln!("Too many ({n}) strongly connected components, only annotating the first {UPPER_BOUND}"); - UPPER_BOUND - } else { - n - }; - - // restructure for lookups - let mut scc_lut = HashMap::>::with_capacity(n); - // lookup the color index (which is equiv to the index in the cycle set vector _plus one_) - // based on the cycle_tag (the greek char) - let mut color_lut = HashMap::::with_capacity(COLOR_SCHEME_N); - for (scc_idx, scc) in sccs.into_iter().take(UPPER_BOUND).enumerate() { - for node_idx in scc { - let _ = scc_lut.entry(node_idx).or_default().insert(greek_alphabet[scc_idx]); - } - color_lut.insert(greek_alphabet[scc_idx], scc_idx + 1); - } - let color_lut = &color_lut; - - // Adding nodes is ok, the `NodeIndex` is append only as long - // there are no removals. - - // Depict sink for unconsumed messages - let unconsumed_idx = graph.add_node(quote::format_ident!("SENT_TO_NONONE")); - for (message_name, subsystems) in unconsumed_messages { - // iterate over all subsystems that send such a message - for (_sub_name, sub_node_idx) in subsystems { - graph.add_edge(sub_node_idx, unconsumed_idx, message_name.clone()); - } - } - - // depict source of unsent message, this is legit when - // integrated with an external source, and sending messages based - // on that - let unsent_idx = graph.add_node(quote::format_ident!("NEVER_SENT_ANYWHERE")); - for (message_name, (_sub_name, sub_node_idx)) in unsent_messages { - graph.add_edge(unsent_idx, sub_node_idx, message_name.clone()); - } - let unsent_node_label = r#"label="✨",fillcolor=black,shape=doublecircle,style=filled,fontname="NotoColorEmoji""#; - let unconsumed_node_label = r#"label="💀",fillcolor=black,shape=doublecircle,style=filled,fontname="NotoColorEmoji""#; - let edge_attr = |_graph: &Graph, - edge: <&Graph as IntoEdgeReferences>::EdgeRef| - -> String { - let source = edge.source(); - let sink = edge.target(); - - let message_name = - edge.weight().get_ident().expect("Must have a trailing identifier. qed"); - - // use the intersection only, that's the set of cycles the edge is part of - if let Some(edge_intersecting_scc_tags) = scc_lut.get(&source).and_then(|source_set| { - scc_lut.get(&sink).and_then(move |sink_set| { - let intersection = - HashSet::<_, RandomState>::from_iter(source_set.intersection(sink_set)); - if intersection.is_empty() { - None - } else { - Some(intersection) - } - }) - }) { - if edge_intersecting_scc_tags.len() != 1 { - unreachable!("Strongly connected components are disjunct by definition. qed"); - } - let scc_tag = edge_intersecting_scc_tags.iter().next().unwrap(); - let color = get_color_by_tag(scc_tag, color_lut); - let scc_tag_str = cycle_tags_to_annotation(edge_intersecting_scc_tags, color_lut); - format!( - r#"color="{color}",fontcolor="{color}",xlabel=<{scc_tag_str}>,label="{message_name}""#, - ) - } else { - format!(r#"label="{message_name}""#,) - } - }; - let node_attr = - |_graph: &Graph, - (node_index, subsystem_name): <&Graph as IntoNodeReferences>::NodeRef| - -> String { - if node_index == unsent_idx { - unsent_node_label.to_owned().clone() - } else if node_index == unconsumed_idx { - unconsumed_node_label.to_owned().clone() - } else if let Some(edge_intersecting_scc_tags) = scc_lut.get(&node_index) { - if edge_intersecting_scc_tags.len() != 1 { - unreachable!( - "Strongly connected components are disjunct by definition. qed" - ); - }; - let scc_tag = edge_intersecting_scc_tags.iter().next().unwrap(); - let color = get_color_by_tag(scc_tag, color_lut); - - let scc_tag_str = - cycle_tags_to_annotation(edge_intersecting_scc_tags, color_lut); - format!( - r#"color="{color}",fontcolor="{color}",xlabel=<{scc_tag_str}>,label="{subsystem_name}""#, - ) - } else { - format!(r#"label="{subsystem_name}""#) - } - }; - let dot = Dot::with_attr_getters( - &graph, config, &edge_attr, // with state, the reference is a trouble maker - &node_attr, - ); - dest.write_all( - format!( - r#"digraph {{ - node [colorscheme={}] - {:?} -}}"#, - color_scheme(), - &dot - ) - .as_bytes(), - )?; - Ok(()) - } -} - -const GREEK_ALPHABET_SIZE: usize = 24; - -fn greek_alphabet() -> [char; GREEK_ALPHABET_SIZE] { - let mut alphabet = ['\u{03B1}'; 24]; - alphabet - .iter_mut() - .enumerate() - // closure should never return `None`, - // but rather safe than sorry - .for_each(|(i, c)| { - *c = char::from_u32(*c as u32 + i as u32).unwrap(); - }); - alphabet -} - -#[cfg(feature = "graph")] -mod graph_helpers { - use super::HashMap; - - pub(crate) const fn color_scheme() -> &'static str { - "rdylgn10" - } - - pub(crate) fn get_color_by_idx(color_idx: usize) -> String { - let scheme = color_scheme(); - format!("/{scheme}/{color_idx}") - } - - pub(crate) fn get_color_by_tag(scc_tag: &char, color_lut: &HashMap) -> String { - get_color_by_idx(color_lut.get(scc_tag).copied().unwrap_or_default()) - } - - /// A node can be member of multiple cycles, - /// but only of one strongly connected component. - pub(crate) fn cycle_tags_to_annotation<'a>( - cycle_tags: impl IntoIterator, - color_lut: &HashMap, - ) -> String { - // Must use fully qualified syntax: - // - let cycle_annotation = String::from_iter(itertools::Itertools::intersperse( - cycle_tags.into_iter().map(|scc_tag| { - let color = get_color_by_tag(scc_tag, color_lut); - format!(r#"{scc_tag}"#) - }), - ",".to_owned(), - )); - cycle_annotation - } -} - -#[cfg(test)] -mod tests { - // whenever this starts working, we should consider - // replacing the all caps idents with something like - // the below. - // - // - // For now the rendering is modified, the ident is a placeholder. - #[test] - #[should_panic] - fn check_ident() { - let _ident = quote::format_ident!("x💀x"); - } - - #[test] - fn kosaraju_scc_check_nodes_cannot_be_part_of_two_clusters() { - let mut graph = petgraph::graph::DiGraph::::new(); - - let a_idx = graph.add_node('A'); - let b_idx = graph.add_node('B'); - let c_idx = graph.add_node('C'); - let d_idx = graph.add_node('D'); - let e_idx = graph.add_node('E'); - let f_idx = graph.add_node('F'); - - graph.add_edge(a_idx, b_idx, "10"); - graph.add_edge(b_idx, c_idx, "11"); - graph.add_edge(c_idx, a_idx, "12"); - - graph.add_edge(a_idx, d_idx, "20"); - graph.add_edge(d_idx, c_idx, "21"); - - graph.add_edge(b_idx, e_idx, "30"); - graph.add_edge(e_idx, c_idx, "31"); - - graph.add_edge(c_idx, f_idx, "40"); - - let mut sccs = dbg!(petgraph::algo::kosaraju_scc(&graph)); - - dbg!(graph); - - sccs.sort_by(|a, b| { - if a.len() < b.len() { - std::cmp::Ordering::Greater - } else { - std::cmp::Ordering::Less - } - }); - assert_eq!(sccs.len(), 2); // `f` and everything else - assert_eq!(sccs[0].len(), 5); // every node but `f` - } -} diff --git a/node/orchestra/proc-macro/src/impl_builder.rs b/node/orchestra/proc-macro/src/impl_builder.rs deleted file mode 100644 index 1a88dc926120..000000000000 --- a/node/orchestra/proc-macro/src/impl_builder.rs +++ /dev/null @@ -1,759 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use quote::{format_ident, quote}; -use syn::{parse_quote, Path, PathSegment, TypePath}; - -use super::*; - -fn recollect_without_idx(x: &[T], idx: usize) -> Vec { - let mut v = Vec::::with_capacity(x.len().saturating_sub(1)); - v.extend(x.iter().take(idx).cloned()); - v.extend(x.iter().skip(idx + 1).cloned()); - v -} - -/// Implement a builder pattern for the `Orchestra`-type, -/// which acts as the gateway to constructing the orchestra. -/// -/// Elements tagged with `wip` are not covered here. -pub(crate) fn impl_builder(info: &OrchestraInfo) -> proc_macro2::TokenStream { - let orchestra_name = info.orchestra_name.clone(); - let builder = format_ident!("{}Builder", orchestra_name); - let handle = format_ident!("{}Handle", orchestra_name); - let connector = format_ident!("{}Connector", orchestra_name); - let subsystem_ctx_name = format_ident!("{}SubsystemContext", orchestra_name); - - let subsystem_name = &info.subsystem_names_without_wip(); - let subsystem_generics = &info.subsystem_generic_types(); - - let consumes = &info.consumes_without_wip(); - let channel_name = &info.channel_names_without_wip(""); - let channel_name_unbounded = &info.channel_names_without_wip("_unbounded"); - - let channel_name_tx = &info.channel_names_without_wip("_tx"); - let channel_name_unbounded_tx = &info.channel_names_without_wip("_unbounded_tx"); - - let channel_name_rx = &info.channel_names_without_wip("_rx"); - let channel_name_unbounded_rx = &info.channel_names_without_wip("_unbounded_rx"); - - let baggage_name = &info.baggage_names(); - let baggage_generic_ty = &info.baggage_generic_types(); - - // State generics that are used to encode each field's status (Init/Missing) - let baggage_passthrough_state_generics = baggage_name - .iter() - .enumerate() - .map(|(idx, _)| format_ident!("InitStateBaggage{}", idx)) - .collect::>(); - let subsystem_passthrough_state_generics = subsystem_name - .iter() - .enumerate() - .map(|(idx, _)| format_ident!("InitStateSubsystem{}", idx)) - .collect::>(); - - let error_ty = &info.extern_error_ty; - - let support_crate = info.support_crate_name(); - - let blocking = &info - .subsystems() - .iter() - .map(|x| { - if x.blocking { - quote! { Blocking } - } else { - quote! { Regular } - } - }) - .collect::>(); - - // Helpers to use within quote! macros - let spawner_where_clause: syn::TypeParam = parse_quote! { - S: #support_crate ::Spawner - }; - - // Field names and real types - let field_name = subsystem_name.iter().chain(baggage_name.iter()).collect::>(); - let field_type = subsystem_generics - .iter() - .map(|ident| { - syn::Type::Path(TypePath { - qself: None, - path: Path::from(PathSegment::from(ident.clone())), - }) - }) - .chain(info.baggage().iter().map(|bag| bag.field_ty.clone())) - .collect::>(); - - // Setters logic - - // For each setter we need to leave the remaining fields untouched and - // remove the field that we are fixing in this setter - // For subsystems `*_with` and `replace_*` setters are needed. - let subsystem_specific_setters = - info.subsystems().iter().filter(|ssf| !ssf.wip).enumerate().map(|(idx, ssf)| { - let field_name = &ssf.name; - let field_type = &ssf.generic; - let subsystem_consumes = &ssf.message_to_consume; - // Remove state generic for the item to be replaced. It sufficient to know `field_type` for - // that since we always move from `Init<#field_type>` to `Init`. - let impl_subsystem_state_generics = recollect_without_idx(&subsystem_passthrough_state_generics[..], idx); - - let field_name_with = format_ident!("{}_with", field_name); - let field_name_replace = format_ident!("replace_{}", field_name); - - // In a setter we replace `Uninit` with `Init` leaving all other - // types as they are, as such they will be free generics. - let mut current_state_generics = subsystem_passthrough_state_generics - .iter() - .map(|subsystem_state_generic_ty| parse_quote!(#subsystem_state_generic_ty)) - .collect::>(); - current_state_generics[idx] = parse_quote! { Missing<#field_type> }; - - // Generics that will be present after initializing a specific `Missing<_>` field. - let mut post_setter_state_generics = current_state_generics.clone(); - post_setter_state_generics[idx] = parse_quote! { Init<#field_type> }; - - let mut post_replace_state_generics = current_state_generics.clone(); - post_replace_state_generics[idx] = parse_quote! { Init }; - - // All fields except the one we update with the new argument - // see the loop below. - let to_keep_subsystem_name = recollect_without_idx(&subsystem_name[..], idx); - - let subsystem_sender_trait = format_ident!("{}SenderTrait", field_type); - let _subsystem_ctx_trait = format_ident!("{}ContextTrait", field_type); - - let builder_where_clause = quote!{ - #field_type : #support_crate::Subsystem< #subsystem_ctx_name< #subsystem_consumes >, #error_ty>, - < #subsystem_ctx_name < #subsystem_consumes > as #support_crate :: SubsystemContext>::Sender: - #subsystem_sender_trait, - }; - - // Create the field init `fn` - quote! { - impl - #builder - where - #builder_where_clause - { - /// Specify the subsystem in the builder directly - pub fn #field_name (self, var: #field_type ) -> - #builder - { - #builder { - #field_name: Init::< #field_type >::Value(var), - #( - #to_keep_subsystem_name: self. #to_keep_subsystem_name, - )* - #( - #baggage_name: self. #baggage_name, - )* - spawner: self.spawner, - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - /// Specify the the initialization function for a subsystem - pub fn #field_name_with<'a, F>(self, subsystem_init_fn: F ) -> - #builder - where - F: 'static + Send + FnOnce(#handle) -> - ::std::result::Result<#field_type, #error_ty>, - { - let boxed_func = Init::<#field_type>::Fn( - Box::new(subsystem_init_fn) as SubsystemInitFn<#field_type> - ); - #builder { - #field_name: boxed_func, - #( - #to_keep_subsystem_name: self. #to_keep_subsystem_name, - )* - #( - #baggage_name: self. #baggage_name, - )* - spawner: self.spawner, - - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - } - - impl - #builder - where - #builder_where_clause - { - /// Replace a subsystem by another implementation for the - /// consumable message type. - pub fn #field_name_replace(self, gen_replacement_fn: F) - -> #builder - where - #field_type: 'static, - F: 'static + Send + FnOnce(#field_type) -> NEW, - NEW: #support_crate ::Subsystem<#subsystem_ctx_name< #subsystem_consumes >, #error_ty>, - { - let replacement: Init = match self.#field_name { - Init::Fn(fx) => - Init::::Fn(Box::new(move |handle: #handle| { - let orig = fx(handle)?; - Ok(gen_replacement_fn(orig)) - })), - Init::Value(val) => - Init::Value(gen_replacement_fn(val)), - }; - #builder { - #field_name: replacement, - #( - #to_keep_subsystem_name: self. #to_keep_subsystem_name, - )* - #( - #baggage_name: self. #baggage_name, - )* - spawner: self.spawner, - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - } - } - }); - - // Produce setters for all baggage fields as well - let baggage_specific_setters = info.baggage().iter().enumerate().map(|(idx, bag_field)| { - // Baggage fields follow subsystems - let fname = &bag_field.field_name; - let field_type = &bag_field.field_ty; - let impl_baggage_state_generics = recollect_without_idx(&baggage_passthrough_state_generics[..], idx); - let to_keep_baggage_name = recollect_without_idx(&baggage_name[..], idx); - - let mut pre_setter_generics = baggage_passthrough_state_generics - .iter() - .map(|gen_ty| parse_quote!(#gen_ty)) - .collect::>(); - pre_setter_generics[idx] = parse_quote! { Missing<#field_type> }; - - let mut post_setter_generics = pre_setter_generics.clone(); - post_setter_generics[idx] = parse_quote! { Init<#field_type> }; - - // Baggage can also be generic, so we need to include that to a signature - let preserved_baggage_generics = &bag_field.generic_types; - quote! { - impl - #builder - { - /// Specify the baggage in the builder when it was not initialized before - pub fn #fname (self, var: #field_type ) -> - #builder - { - #builder { - #fname: Init::<#field_type>::Value(var), - #( - #subsystem_name: self. #subsystem_name, - )* - #( - #to_keep_baggage_name: self. #to_keep_baggage_name, - )* - spawner: self.spawner, - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - } - impl - #builder { - /// Specify the baggage in the builder when it has been previously initialized - pub fn #fname (self, var: #field_type ) -> - #builder - { - #builder { - #fname: Init::<#field_type>::Value(var), - #( - #subsystem_name: self. #subsystem_name, - )* - #( - #to_keep_baggage_name: self. #to_keep_baggage_name, - )* - spawner: self.spawner, - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - } - } - }); - - let event = &info.extern_event_ty; - let initialized_builder = format_ident!("Initialized{}", builder); - // The direct generics as expected by the `Orchestra<_,_,..>`, without states - let initialized_builder_generics = quote! { - S, #( #baggage_generic_ty, )* #( #subsystem_generics, )* - }; - - let builder_where_clause = info - .subsystems() - .iter() - .map(|ssf| { - let field_type = &ssf.generic; - let consumes = &ssf.message_to_consume; - let subsystem_sender_trait = format_ident!("{}SenderTrait", ssf.generic); - let subsystem_ctx_trait = format_ident!("{}ContextTrait", ssf.generic); - quote! { - #field_type: - #support_crate::Subsystem< #subsystem_ctx_name < #consumes>, #error_ty>, - <#subsystem_ctx_name< #consumes > as #subsystem_ctx_trait>::Sender: - #subsystem_sender_trait, - #subsystem_ctx_name< #consumes >: - #subsystem_ctx_trait, - } - }) - .fold(TokenStream::new(), |mut ts, addendum| { - ts.extend(addendum); - ts - }); - - let mut ts = quote! { - /// Convenience alias. - type SubsystemInitFn = Box ::std::result::Result + Send + 'static>; - - /// Type for the initialized field of the orchestra builder - pub enum Init { - /// Defer initialization to a point where the `handle` is available. - Fn(SubsystemInitFn), - /// Directly initialize the subsystem with the given subsystem type `T`. - /// Also used for baggage fields - Value(T), - } - /// Type marker for the uninitialized field of the orchestra builder. - /// `PhantomData` is used for type hinting when creating uninitialized - /// builder, e.g. to avoid specifying the generics when instantiating - /// the `FooBuilder` when calling `Foo::builder()` - #[derive(Debug)] - pub struct Missing(::core::marker::PhantomData); - - /// Trait used to mark fields status in a builder - trait OrchestraFieldState {} - - impl OrchestraFieldState for Init {} - impl OrchestraFieldState for Missing {} - - impl ::std::default::Default for Missing { - fn default() -> Self { - Missing::(::core::marker::PhantomData::::default()) - } - } - - impl #orchestra_name - where - #spawner_where_clause, - { - /// Create a new orchestra utilizing the builder. - pub fn builder< #( #subsystem_generics),* >() -> - #builder #(, Missing< #field_type > )* > - where - #builder_where_clause - { - #builder :: new() - } - } - }; - - ts.extend(quote! { - /// Handle for an orchestra. - pub type #handle = #support_crate ::metered::MeteredSender< #event >; - - /// External connector. - pub struct #connector { - /// Publicly accessible handle, to be used for setting up - /// components that are _not_ subsystems but access is needed - /// due to other limitations. - /// - /// For subsystems, use the `_with` variants of the builder. - handle: #handle, - /// The side consumed by the `spawned` side of the orchestra pattern. - consumer: #support_crate ::metered::MeteredReceiver < #event >, - } - - impl #connector { - /// Obtain access to the orchestra handle. - pub fn as_handle_mut(&mut self) -> &mut #handle { - &mut self.handle - } - /// Obtain access to the orchestra handle. - pub fn as_handle(&self) -> &#handle { - &self.handle - } - /// Obtain a clone of the handle. - pub fn handle(&self) -> #handle { - self.handle.clone() - } - - /// Create a new connector with non-default event channel capacity. - pub fn with_event_capacity(event_channel_capacity: usize) -> Self { - let (events_tx, events_rx) = #support_crate ::metered::channel::< - #event - >(event_channel_capacity); - - Self { - handle: events_tx, - consumer: events_rx, - } - } - } - - impl ::std::default::Default for #connector { - fn default() -> Self { - Self::with_event_capacity(SIGNAL_CHANNEL_CAPACITY) - } - } - }); - - ts.extend(quote!{ - /// Builder pattern to create compile time safe construction path. - pub struct #builder - { - #( - #subsystem_name: #subsystem_passthrough_state_generics, - )* - #( - #baggage_name: #baggage_passthrough_state_generics, - )* - spawner: InitStateSpawner, - // user provided runtime overrides, - // if `None`, the `orchestra(message_capacity=123,..)` is used - // or the default value. - channel_capacity: Option, - signal_capacity: Option, - } - }); - - ts.extend(quote! { - impl<#initialized_builder_generics> #builder, #( Missing<#field_type>, )*> - { - /// Create a new builder pattern, with all fields being uninitialized. - fn new() -> Self { - // explicitly assure the required traits are implemented - fn trait_from_must_be_implemented() - where - E: ::std::error::Error + Send + Sync + 'static + From<#support_crate ::OrchestraError> - {} - - trait_from_must_be_implemented::< #error_ty >(); - - Self { - #( - #field_name: Missing::<#field_type>::default(), - )* - spawner: Missing::::default(), - - channel_capacity: None, - signal_capacity: None, - } - } - } - }); - - // Spawner setter - ts.extend(quote!{ - impl - #builder, #( #subsystem_passthrough_state_generics, )* #( #baggage_passthrough_state_generics, )*> - where - #spawner_where_clause, - { - /// The `spawner` to use for spawning tasks. - pub fn spawner(self, spawner: S) -> #builder< - Init, - #( #subsystem_passthrough_state_generics, )* - #( #baggage_passthrough_state_generics, )* - > - { - #builder { - #( - #field_name: self. #field_name, - )* - spawner: Init::::Value(spawner), - - channel_capacity: self.channel_capacity, - signal_capacity: self.signal_capacity, - } - } - } - }); - - // message and signal channel capacity - ts.extend(quote! { - impl - #builder, #( #subsystem_passthrough_state_generics, )* #( #baggage_passthrough_state_generics, )*> - where - #spawner_where_clause, - { - /// Set the interconnecting signal channel capacity. - pub fn signal_channel_capacity(mut self, capacity: usize) -> Self - { - self.signal_capacity = Some(capacity); - self - } - - /// Set the interconnecting message channel capacities. - pub fn message_channel_capacity(mut self, capacity: usize) -> Self - { - self.channel_capacity = Some(capacity); - self - } - } - }); - - // Create the string literals for spawn. - let subsystem_name_str_literal = subsystem_name - .iter() - .map(|ident| proc_macro2::Literal::string(ident.to_string().replace("_", "-").as_str())) - .collect::>(); - - ts.extend(quote! { - /// Type used to represent a builder where all fields are initialized and the orchestra could be constructed. - pub type #initialized_builder<#initialized_builder_generics> = #builder, #( Init<#field_type>, )*>; - - // A builder specialization where all fields are set - impl<#initialized_builder_generics> #initialized_builder<#initialized_builder_generics> - where - #spawner_where_clause, - #builder_where_clause - { - /// Complete the construction and create the orchestra type. - pub fn build(self) - -> ::std::result::Result<(#orchestra_name, #handle), #error_ty> { - let connector = #connector ::with_event_capacity( - self.signal_capacity.unwrap_or(SIGNAL_CHANNEL_CAPACITY) - ); - self.build_with_connector(connector) - } - - /// Complete the construction and create the orchestra type based on an existing `connector`. - pub fn build_with_connector(self, connector: #connector) - -> ::std::result::Result<(#orchestra_name, #handle), #error_ty> - { - let #connector { - handle: events_tx, - consumer: events_rx, - } = connector; - - let handle = events_tx.clone(); - - let (to_orchestra_tx, to_orchestra_rx) = #support_crate ::metered::unbounded::< - ToOrchestra - >(); - - #( - let (#channel_name_tx, #channel_name_rx) - = - #support_crate ::metered::channel::< - MessagePacket< #consumes > - >( - self.channel_capacity.unwrap_or(CHANNEL_CAPACITY) - ); - )* - - #( - let (#channel_name_unbounded_tx, #channel_name_unbounded_rx) = - #support_crate ::metered::unbounded::< - MessagePacket< #consumes > - >(); - )* - - let channels_out = - ChannelsOut { - #( - #channel_name: #channel_name_tx .clone(), - )* - #( - #channel_name_unbounded: #channel_name_unbounded_tx, - )* - }; - - let mut spawner = match self.spawner { - Init::Value(value) => value, - _ => unreachable!("Only ever init spawner as value. qed"), - }; - - let mut running_subsystems = #support_crate ::FuturesUnordered::< - BoxFuture<'static, ::std::result::Result<(), #error_ty > > - >::new(); - - #( - let #subsystem_name = match self. #subsystem_name { - Init::Fn(func) => func(handle.clone())?, - Init::Value(val) => val, - }; - - let unbounded_meter = #channel_name_unbounded_rx.meter().clone(); - // Prefer unbounded channel when selecting - let message_rx: SubsystemIncomingMessages< #consumes > = #support_crate ::select_with_strategy( - #channel_name_rx, #channel_name_unbounded_rx, - #support_crate ::select_message_channel_strategy - ); - let (signal_tx, signal_rx) = #support_crate ::metered::channel( - self.signal_capacity.unwrap_or(SIGNAL_CHANNEL_CAPACITY) - ); - - let ctx = #subsystem_ctx_name::< #consumes >::new( - signal_rx, - message_rx, - channels_out.clone(), - to_orchestra_tx.clone(), - #subsystem_name_str_literal - ); - - let #subsystem_name: OrchestratedSubsystem< #consumes > = - spawn::<_,_, #blocking, _, _, _>( - &mut spawner, - #channel_name_tx, - signal_tx, - unbounded_meter, - ctx, - #subsystem_name, - #subsystem_name_str_literal, - &mut running_subsystems, - )?; - )* - - use #support_crate ::StreamExt; - - let to_orchestra_rx = to_orchestra_rx.fuse(); - let orchestra = #orchestra_name { - #( - #subsystem_name, - )* - - #( - #baggage_name: match self. #baggage_name { - Init::Value(val) => val, - _ => panic!("unexpected baggage initialization, must be value"), - }, - )* - - spawner, - running_subsystems, - events_rx, - to_orchestra_rx, - }; - - Ok((orchestra, handle)) - } - } - }); - - ts.extend(baggage_specific_setters); - ts.extend(subsystem_specific_setters); - ts.extend(impl_task_kind(info)); - ts -} - -pub(crate) fn impl_task_kind(info: &OrchestraInfo) -> proc_macro2::TokenStream { - let signal = &info.extern_signal_ty; - let error_ty = &info.extern_error_ty; - let support_crate = info.support_crate_name(); - - let ts = quote! { - /// Task kind to launch. - pub trait TaskKind { - /// Spawn a task, it depends on the implementer if this is blocking or not. - fn launch_task(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>); - } - - #[allow(missing_docs)] - struct Regular; - impl TaskKind for Regular { - fn launch_task(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) { - spawner.spawn(task_name, Some(subsystem_name), future) - } - } - - #[allow(missing_docs)] - struct Blocking; - impl TaskKind for Blocking { - fn launch_task(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) { - spawner.spawn_blocking(task_name, Some(subsystem_name), future) - } - } - - /// Spawn task of kind `self` using spawner `S`. - pub fn spawn( - spawner: &mut S, - message_tx: #support_crate ::metered::MeteredSender>, - signal_tx: #support_crate ::metered::MeteredSender< #signal >, - // meter for the unbounded channel - unbounded_meter: #support_crate ::metered::Meter, - ctx: Ctx, - s: SubSys, - subsystem_name: &'static str, - futures: &mut #support_crate ::FuturesUnordered >>, - ) -> ::std::result::Result, #error_ty > - where - S: #support_crate ::Spawner, - M: std::fmt::Debug + Send + 'static, - TK: TaskKind, - Ctx: #support_crate ::SubsystemContext, - E: ::std::error::Error + Send + Sync + 'static + ::std::convert::From<#support_crate ::OrchestraError>, - SubSys: #support_crate ::Subsystem, - { - let #support_crate ::SpawnedSubsystem:: { future, name } = s.start(ctx); - - let (tx, rx) = #support_crate ::oneshot::channel(); - - let fut = Box::pin(async move { - if let Err(e) = future.await { - #support_crate ::tracing::error!(subsystem=name, err = ?e, "subsystem exited with error"); - } else { - #support_crate ::tracing::debug!(subsystem=name, "subsystem exited without an error"); - } - let _ = tx.send(()); - }); - - ::launch_task(spawner, name, subsystem_name, fut); - - futures.push(Box::pin( - rx.map(|e| { - #support_crate ::tracing::warn!(err = ?e, "dropping error"); - Ok(()) - }) - )); - - let instance = Some(SubsystemInstance { - meters: #support_crate ::SubsystemMeters { - unbounded: unbounded_meter, - bounded: message_tx.meter().clone(), - signals: signal_tx.meter().clone(), - }, - tx_signal: signal_tx, - tx_bounded: message_tx, - signals_received: 0, - name, - }); - - Ok(OrchestratedSubsystem { - instance, - }) - } - }; - - ts -} diff --git a/node/orchestra/proc-macro/src/impl_channels_out.rs b/node/orchestra/proc-macro/src/impl_channels_out.rs deleted file mode 100644 index 5b694d15229d..000000000000 --- a/node/orchestra/proc-macro/src/impl_channels_out.rs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use quote::quote; -use syn::Result; - -use super::*; - -/// Implement the helper type `ChannelsOut` and `MessagePacket`. -pub(crate) fn impl_channels_out_struct(info: &OrchestraInfo) -> Result { - let message_wrapper = info.message_wrapper.clone(); - - let channel_name = &info.channel_names_without_wip(""); - let channel_name_unbounded = &info.channel_names_without_wip("_unbounded"); - - let consumes = &info.consumes_without_wip(); - - let consumes_variant = &info.variant_names_without_wip(); - let unconsumes_variant = &info.variant_names_only_wip(); - - let support_crate = info.support_crate_name(); - - let ts = quote! { - /// Collection of channels to the individual subsystems. - /// - /// Naming is from the point of view of the orchestra. - #[derive(Debug, Clone)] - pub struct ChannelsOut { - #( - /// Bounded channel sender, connected to a subsystem. - pub #channel_name: - #support_crate ::metered::MeteredSender< - MessagePacket< #consumes > - >, - )* - - #( - /// Unbounded channel sender, connected to a subsystem. - pub #channel_name_unbounded: - #support_crate ::metered::UnboundedMeteredSender< - MessagePacket< #consumes > - >, - )* - } - - #[allow(unreachable_code)] - // when no defined messages in enum - impl ChannelsOut { - /// Send a message via a bounded channel. - pub async fn send_and_log_error( - &mut self, - signals_received: usize, - message: #message_wrapper, - ) { - - let res: ::std::result::Result<_, _> = match message { - #( - #message_wrapper :: #consumes_variant ( inner ) => { - self. #channel_name .send( - #support_crate ::make_packet(signals_received, inner) - ).await.map_err(|_| stringify!( #channel_name )) - } - )* - // subsystems that are wip - #( - #message_wrapper :: #unconsumes_variant ( _ ) => Ok(()), - )* - // dummy message type - #message_wrapper :: Empty => Ok(()), - - #[allow(unreachable_patterns)] - // And everything that's not WIP but no subsystem consumes it - unused_msg => { - #support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg); - Ok(()) - } - }; - - if let Err(subsystem_name) = res { - #support_crate ::tracing::debug!( - target: LOG_TARGET, - "Failed to send (bounded) a message to {} subsystem", - subsystem_name - ); - } - } - - /// Send a message to another subsystem via an unbounded channel. - pub fn send_unbounded_and_log_error( - &self, - signals_received: usize, - message: #message_wrapper, - ) { - let res: ::std::result::Result<_, _> = match message { - #( - #message_wrapper :: #consumes_variant (inner) => { - self. #channel_name_unbounded .unbounded_send( - #support_crate ::make_packet(signals_received, inner) - ) - .map_err(|_| stringify!( #channel_name )) - }, - )* - // subsystems that are wip - #( - #message_wrapper :: #unconsumes_variant ( _ ) => Ok(()), - )* - // dummy message type - #message_wrapper :: Empty => Ok(()), - - // And everything that's not WIP but no subsystem consumes it - #[allow(unreachable_patterns)] - unused_msg => { - #support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg); - Ok(()) - } - }; - - if let Err(subsystem_name) = res { - #support_crate ::tracing::debug!( - target: LOG_TARGET, - "Failed to send_unbounded a message to {} subsystem", - subsystem_name - ); - } - } - } - - }; - Ok(ts) -} diff --git a/node/orchestra/proc-macro/src/impl_message_wrapper.rs b/node/orchestra/proc-macro/src/impl_message_wrapper.rs deleted file mode 100644 index 3c2f99999208..000000000000 --- a/node/orchestra/proc-macro/src/impl_message_wrapper.rs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use quote::quote; -use syn::{spanned::Spanned, Result}; - -use super::*; - -/// Generates the wrapper type enum. -pub(crate) fn impl_message_wrapper_enum(info: &OrchestraInfo) -> Result { - let consumes = info.any_message(); - let consumes_variant = info.variant_names(); - - let outgoing = &info.outgoing_ty; - - let message_wrapper = &info.message_wrapper; - - let (outgoing_from_impl, outgoing_decl) = if let Some(outgoing) = outgoing { - let outgoing_variant = outgoing.get_ident().ok_or_else(|| { - syn::Error::new( - outgoing.span(), - "Missing identifier to use as enum variant for outgoing.", - ) - })?; - ( - quote! { - impl ::std::convert::From< #outgoing > for #message_wrapper { - fn from(message: #outgoing) -> Self { - #message_wrapper :: #outgoing_variant ( message ) - } - } - }, - quote! { - #outgoing_variant ( #outgoing ) , - }, - ) - } else { - (TokenStream::new(), TokenStream::new()) - }; - - let ts = quote! { - /// Generated message type wrapper over all possible messages - /// used by any subsystem. - #[allow(missing_docs)] - #[derive(Debug)] - pub enum #message_wrapper { - #( - #consumes_variant ( #consumes ), - )* - #outgoing_decl - // dummy message type - Empty, - } - - impl ::std::convert::From< () > for #message_wrapper { - fn from(_: ()) -> Self { - #message_wrapper :: Empty - } - } - - #( - impl ::std::convert::From< #consumes > for #message_wrapper { - fn from(message: #consumes) -> Self { - #message_wrapper :: #consumes_variant ( message ) - } - } - )* - - #outgoing_from_impl - }; - - Ok(ts) -} diff --git a/node/orchestra/proc-macro/src/impl_orchestra.rs b/node/orchestra/proc-macro/src/impl_orchestra.rs deleted file mode 100644 index 66ff6c60939b..000000000000 --- a/node/orchestra/proc-macro/src/impl_orchestra.rs +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use quote::quote; - -use super::*; - -pub(crate) fn impl_orchestra_struct(info: &OrchestraInfo) -> proc_macro2::TokenStream { - let message_wrapper = &info.message_wrapper.clone(); - let orchestra_name = info.orchestra_name.clone(); - let subsystem_name = &info.subsystem_names_without_wip(); - let support_crate = info.support_crate_name(); - - let baggage_decl = &info.baggage_decl(); - - let baggage_generic_ty = &info.baggage_generic_types(); - - let generics = quote! { - < S, #( #baggage_generic_ty, )* > - }; - - let where_clause = quote! { - where - S: #support_crate ::Spawner, - }; - // TODO add `where ..` clauses for baggage types - // TODO - - let consumes = &info.consumes_without_wip(); - let consumes_variant = &info.variant_names_without_wip(); - let unconsumes_variant = &info.variant_names_only_wip(); - - let signal_ty = &info.extern_signal_ty; - - let error_ty = &info.extern_error_ty; - - let event_ty = &info.extern_event_ty; - - let message_channel_capacity = info.message_channel_capacity; - let signal_channel_capacity = info.signal_channel_capacity; - - let log_target = - syn::LitStr::new(orchestra_name.to_string().to_lowercase().as_str(), orchestra_name.span()); - - let ts = quote! { - /// Capacity of a bounded message channel between orchestra and subsystem - /// but also for bounded channels between two subsystems. - const CHANNEL_CAPACITY: usize = #message_channel_capacity; - - /// Capacity of a signal channel between a subsystem and the orchestra. - const SIGNAL_CHANNEL_CAPACITY: usize = #signal_channel_capacity; - - /// The log target tag. - const LOG_TARGET: &'static str = #log_target; - - /// The orchestra. - pub struct #orchestra_name #generics { - - #( - /// A subsystem instance. - #subsystem_name: OrchestratedSubsystem< #consumes >, - )* - - #( - /// A user specified addendum field. - #baggage_decl , - )* - - /// Responsible for driving the subsystem futures. - spawner: S, - - /// The set of running subsystems. - running_subsystems: #support_crate ::FuturesUnordered< - BoxFuture<'static, ::std::result::Result<(), #error_ty>> - >, - - /// Gather running subsystems' outbound streams into one. - to_orchestra_rx: #support_crate ::stream::Fuse< - #support_crate ::metered::UnboundedMeteredReceiver< #support_crate ::ToOrchestra > - >, - - /// Events that are sent to the orchestra from the outside world. - events_rx: #support_crate ::metered::MeteredReceiver< #event_ty >, - } - - impl #generics #orchestra_name #generics #where_clause { - /// Send the given signal, a termination signal, to all subsystems - /// and wait for all subsystems to go down. - /// - /// The definition of a termination signal is up to the user and - /// implementation specific. - pub async fn wait_terminate(&mut self, signal: #signal_ty, timeout: ::std::time::Duration) -> ::std::result::Result<(), #error_ty > { - #( - ::std::mem::drop(self. #subsystem_name .send_signal(signal.clone()).await); - )* - let _ = signal; - - let mut timeout_fut = #support_crate ::Delay::new( - timeout - ).fuse(); - - loop { - #support_crate ::futures::select! { - _ = self.running_subsystems.next() => - if self.running_subsystems.is_empty() { - break; - }, - _ = timeout_fut => break, - complete => break, - } - } - - Ok(()) - } - - /// Broadcast a signal to all subsystems. - pub async fn broadcast_signal(&mut self, signal: #signal_ty) -> ::std::result::Result<(), #error_ty > { - #( - let _ = self. #subsystem_name .send_signal(signal.clone()).await; - )* - let _ = signal; - - Ok(()) - } - - /// Route a particular message to a subsystem that consumes the message. - pub async fn route_message(&mut self, message: #message_wrapper, origin: &'static str) -> ::std::result::Result<(), #error_ty > { - match message { - #( - #message_wrapper :: #consumes_variant ( inner ) => - OrchestratedSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?, - )* - // subsystems that are still work in progress - #( - #message_wrapper :: #unconsumes_variant ( _ ) => {} - )* - #message_wrapper :: Empty => {} - - // And everything that's not WIP but no subsystem consumes it - #[allow(unreachable_patterns)] - unused_msg => { - #support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg); - } - } - Ok(()) - } - - /// Extract information from each subsystem. - pub fn map_subsystems<'a, Mapper, Output>(&'a self, mapper: Mapper) - -> Vec - where - #( - Mapper: MapSubsystem<&'a OrchestratedSubsystem< #consumes >, Output=Output>, - )* - { - vec![ - #( - mapper.map_subsystem( & self. #subsystem_name ), - )* - ] - } - - /// Get access to internal task spawner. - pub fn spawner<'a> (&'a mut self) -> &'a mut S { - &mut self.spawner - } - } - - }; - - ts -} - -pub(crate) fn impl_orchestrated_subsystem(info: &OrchestraInfo) -> proc_macro2::TokenStream { - let signal = &info.extern_signal_ty; - let error_ty = &info.extern_error_ty; - let support_crate = info.support_crate_name(); - - let ts = quote::quote! { - /// A subsystem that the orchestrator orchestrates. - /// - /// Ties together the [`Subsystem`] itself and it's running instance - /// (which may be missing if the [`Subsystem`] is not running at the moment - /// for whatever reason). - /// - /// [`Subsystem`]: trait.Subsystem.html - pub struct OrchestratedSubsystem { - /// The instance. - pub instance: std::option::Option< - #support_crate ::SubsystemInstance - >, - } - - impl OrchestratedSubsystem { - /// Send a message to the wrapped subsystem. - /// - /// If the inner `instance` is `None`, nothing is happening. - pub async fn send_message2(&mut self, message: M, origin: &'static str) -> ::std::result::Result<(), #error_ty > { - const MESSAGE_TIMEOUT: Duration = Duration::from_secs(10); - - if let Some(ref mut instance) = self.instance { - match instance.tx_bounded.send(MessagePacket { - signals_received: instance.signals_received, - message: message.into(), - }).timeout(MESSAGE_TIMEOUT).await - { - None => { - #support_crate ::tracing::error!( - target: LOG_TARGET, - %origin, - "Subsystem {} appears unresponsive.", - instance.name, - ); - Err(#error_ty :: from( - #support_crate ::OrchestraError::SubsystemStalled(instance.name) - )) - } - Some(res) => res.map_err(Into::into), - } - } else { - Ok(()) - } - } - - /// Send a signal to the wrapped subsystem. - /// - /// If the inner `instance` is `None`, nothing is happening. - pub async fn send_signal(&mut self, signal: #signal) -> ::std::result::Result<(), #error_ty > { - const SIGNAL_TIMEOUT: ::std::time::Duration = ::std::time::Duration::from_secs(10); - - if let Some(ref mut instance) = self.instance { - match instance.tx_signal.send(signal).timeout(SIGNAL_TIMEOUT).await { - None => { - Err(#error_ty :: from( - #support_crate ::OrchestraError::SubsystemStalled(instance.name) - )) - } - Some(res) => { - let res = res.map_err(Into::into); - if res.is_ok() { - instance.signals_received += 1; - } - res - } - } - } else { - Ok(()) - } - } - } - }; - ts -} diff --git a/node/orchestra/proc-macro/src/impl_subsystem_ctx_sender.rs b/node/orchestra/proc-macro/src/impl_subsystem_ctx_sender.rs deleted file mode 100644 index 58e95ca72890..000000000000 --- a/node/orchestra/proc-macro/src/impl_subsystem_ctx_sender.rs +++ /dev/null @@ -1,654 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Ident, Path, Result, Type}; - -use petgraph::{visit::EdgeRef, Direction}; - -use super::*; - -/// Generates all subsystem types and related accumulation traits. -pub(crate) fn impl_subsystem_types_all(info: &OrchestraInfo) -> Result { - let mut ts = TokenStream::new(); - - let orchestra_name = &info.orchestra_name; - let span = orchestra_name.span(); - let all_messages_wrapper = &info.message_wrapper; - let support_crate = info.support_crate_name(); - let signal_ty = &info.extern_signal_ty; - let error_ty = &info.extern_error_ty; - - let cg = graph::ConnectionGraph::construct(info.subsystems()); - let graph = &cg.graph; - - // All outgoing edges are now usable to derive everything we need - for node_index in graph.node_indices() { - let subsystem_name = graph[node_index].to_string(); - let outgoing_wrapper = Ident::new(&(subsystem_name + "OutgoingMessages"), span); - - // cannot be a hashmap, duplicate keys and sorting required - // maps outgoing messages to the subsystem that consumes it - let outgoing_to_consumer = graph - .edges_directed(node_index, Direction::Outgoing) - .map(|edge| { - let message_ty = edge.weight(); - let subsystem_generic_consumer = graph[edge.target()].clone(); - Ok((to_variant(message_ty, span.clone())?, subsystem_generic_consumer)) - }) - .collect::>>()?; - - // Split it for usage with quote - let outgoing_variant = outgoing_to_consumer.iter().map(|x| x.0.clone()).collect::>(); - let subsystem_generic = outgoing_to_consumer.into_iter().map(|x| x.1).collect::>(); - - ts.extend(quote! { - impl ::std::convert::From< #outgoing_wrapper > for #all_messages_wrapper { - fn from(message: #outgoing_wrapper) -> Self { - match message { - #( - #outgoing_wrapper :: #outgoing_variant ( msg ) => #all_messages_wrapper :: #subsystem_generic ( msg ), - )* - #outgoing_wrapper :: Empty => #all_messages_wrapper :: Empty, - // And everything that's not WIP but no subsystem consumes it - #[allow(unreachable_patterns)] - unused_msg => { - #support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg); - #all_messages_wrapper :: Empty - } - } - } - } - }) - } - - // Dump the graph to file. - #[cfg(feature = "graph")] - { - let path = std::path::PathBuf::from(env!("OUT_DIR")) - .join(orchestra_name.to_string().to_lowercase() + "-subsystem-messaging.dot"); - if let Err(e) = std::fs::OpenOptions::new() - .truncate(true) - .create(true) - .write(true) - .open(&path) - .and_then(|mut f| cg.graphviz(&mut f)) - { - eprintln!("Failed to write dot graph to {}: {:?}", path.display(), e); - } else { - println!("Wrote dot graph to {}", path.display()); - } - } - - let subsystem_sender_name = &Ident::new(&(orchestra_name.to_string() + "Sender"), span); - let subsystem_ctx_name = &Ident::new(&(orchestra_name.to_string() + "SubsystemContext"), span); - ts.extend(impl_subsystem_context(info, &subsystem_sender_name, &subsystem_ctx_name)); - - ts.extend(impl_associate_outgoing_messages_trait(&all_messages_wrapper)); - - ts.extend(impl_subsystem_sender( - support_crate, - info.subsystems().iter().map(|ssf| { - let outgoing_wrapper = - Ident::new(&(ssf.generic.to_string() + "OutgoingMessages"), span); - outgoing_wrapper - }), - &all_messages_wrapper, - &subsystem_sender_name, - )); - - // Create all subsystem specific types, one by one - for ssf in info.subsystems() { - let subsystem_name = ssf.generic.to_string(); - let outgoing_wrapper = &Ident::new(&(subsystem_name.clone() + "OutgoingMessages"), span); - - let subsystem_ctx_trait = &Ident::new(&(subsystem_name.clone() + "ContextTrait"), span); - let subsystem_sender_trait = &Ident::new(&(subsystem_name.clone() + "SenderTrait"), span); - - ts.extend(impl_per_subsystem_helper_traits( - info, - subsystem_ctx_name, - subsystem_ctx_trait, - subsystem_sender_name, - subsystem_sender_trait, - &ssf.message_to_consume, - &ssf.messages_to_send, - outgoing_wrapper, - )); - - ts.extend(impl_associate_outgoing_messages(&ssf.message_to_consume, &outgoing_wrapper)); - - ts.extend(impl_wrapper_enum(&outgoing_wrapper, ssf.messages_to_send.as_slice())?); - } - - // impl the emtpy tuple handling for tests - let empty_tuple: Type = parse_quote! { () }; - ts.extend(impl_subsystem_context_trait_for( - empty_tuple.clone(), - &[], - empty_tuple, - all_messages_wrapper, - subsystem_ctx_name, - subsystem_sender_name, - support_crate, - signal_ty, - error_ty, - )); - - Ok(ts) -} - -/// Extract the final component of the message type path as used in the `#[subsystem(consumes: path::to::Foo)]` annotation. -fn to_variant(path: &Path, span: Span) -> Result { - let ident = path - .segments - .last() - .ok_or_else(|| syn::Error::new(span, "Path is empty, but it must end with an identifier")) - .map(|segment| segment.ident.clone())?; - Ok(ident) -} - -/// Converts the outgoing message types to variants. -/// -/// Note: Commonly this is `${X}Message` becomes `${X}OutgoingMessages::${X}Message` -/// where for `AllMessages` it would be `AllMessages::${X}`. -fn to_variants(message_types: &[Path], span: Span) -> Result> { - let variants: Vec<_> = - Result::from_iter(message_types.into_iter().map(|path| to_variant(path, span.clone())))?; - Ok(variants) -} - -/// Generates the wrapper type enum, no bells or whistles. -pub(crate) fn impl_wrapper_enum(wrapper: &Ident, message_types: &[Path]) -> Result { - // The message types are path based, each of them must finish with a type - // and as such we do this upfront. - let variants = to_variants(message_types, wrapper.span())?; - - let ts = quote! { - #[allow(missing_docs)] - #[derive(Debug)] - pub enum #wrapper { - #( - #variants ( #message_types ), - )* - Empty, - } - - #( - impl ::std::convert::From< #message_types > for #wrapper { - fn from(message: #message_types) -> Self { - #wrapper :: #variants ( message ) - } - } - )* - - // Useful for unit and integration tests: - impl ::std::convert::From< () > for #wrapper { - fn from(_message: ()) -> Self { - #wrapper :: Empty - } - } - }; - Ok(ts) -} - -/// Create the subsystem sender type and implements `trait SubsystemSender` -/// for the `#outgoing_wrappers: From` with the proper associated types. -pub(crate) fn impl_subsystem_sender( - support_crate: &Path, - outgoing_wrappers: impl IntoIterator, - all_messages_wrapper: &Ident, - subsystem_sender_name: &Ident, -) -> TokenStream { - let mut ts = quote! { - /// Connector to send messages towards all subsystems, - /// while tracking the which signals where already received. - #[derive(Debug)] - pub struct #subsystem_sender_name < OutgoingWrapper > { - /// Collection of channels to all subsystems. - channels: ChannelsOut, - /// Systemwide tick for which signals were received by all subsystems. - signals_received: SignalsReceived, - /// Keep that marker around. - _phantom: ::core::marker::PhantomData< OutgoingWrapper >, - } - - // can't derive due to `PhantomData` and `OutgoingWrapper` not being - // bounded by `Clone`. - impl std::clone::Clone for #subsystem_sender_name < OutgoingWrapper > { - fn clone(&self) -> Self { - Self { - channels: self.channels.clone(), - signals_received: self.signals_received.clone(), - _phantom: ::core::marker::PhantomData::default(), - } - } - } - }; - - // Create the same for a wrapping enum: - // - // 1. subsystem specific `*OutgoingMessages`-type - // 2. orchestra-global-`AllMessages`-type - let wrapped = |outgoing_wrapper: &TokenStream| { - quote! { - #[#support_crate ::async_trait] - impl SubsystemSender< OutgoingMessage > for #subsystem_sender_name < #outgoing_wrapper > - where - OutgoingMessage: Send + 'static, - #outgoing_wrapper: ::std::convert::From + Send, - #all_messages_wrapper: ::std::convert::From< #outgoing_wrapper > + Send, - { - async fn send_message(&mut self, msg: OutgoingMessage) - { - self.channels.send_and_log_error( - self.signals_received.load(), - <#all_messages_wrapper as ::std::convert::From<_>> ::from ( - <#outgoing_wrapper as ::std::convert::From<_>> :: from ( msg ) - ) - ).await; - } - - async fn send_messages(&mut self, msgs: I) - where - I: IntoIterator + Send, - I::IntoIter: Iterator + Send, - { - for msg in msgs { - self.send_message( msg ).await; - } - } - - fn send_unbounded_message(&mut self, msg: OutgoingMessage) - { - self.channels.send_unbounded_and_log_error( - self.signals_received.load(), - <#all_messages_wrapper as ::std::convert::From<_>> ::from ( - <#outgoing_wrapper as ::std::convert::From<_>> :: from ( msg ) - ) - ); - } - } - } - }; - - for outgoing_wrapper in outgoing_wrappers { - ts.extend(wrapped("e! { - #outgoing_wrapper - })); - } - - ts.extend(wrapped("e! { - () - })); - - ts -} - -/// Define the `trait AssociateOutgoing` and implement it for `#all_messages_wrapper` and `()`. -pub(crate) fn impl_associate_outgoing_messages_trait(all_messages_wrapper: &Ident) -> TokenStream { - quote! { - /// Binds a generated type covering all declared outgoing messages, - /// which implements `#generated_outgoing: From` for all annotated types - /// of a particular subsystem. - /// - /// Note: This works because there is a 1?:1 relation between consumed messages and subsystems. - pub trait AssociateOutgoing: ::std::fmt::Debug + Send { - /// The associated _outgoing_ messages for a subsystem that _consumes_ the message `Self`. - type OutgoingMessages: Into< #all_messages_wrapper > + ::std::fmt::Debug + Send; - } - - // Helper for tests, where nothing is ever sent. - impl AssociateOutgoing for () { - type OutgoingMessages = (); - } - - // Helper for tests, allows sending of arbitrary messages give - // an test context. - impl AssociateOutgoing for #all_messages_wrapper { - type OutgoingMessages = #all_messages_wrapper ; - } - } -} - -/// Implement `AssociateOutgoing` for `#consumes` being handled by a particular subsystem. -/// -/// Binds the outgoing messages to the inbound message. -/// -/// Note: Works, since there is a 1:1 relation between inbound message type and subsystem declarations. -/// Note: A workaround until default associated types work in `rustc`. -pub(crate) fn impl_associate_outgoing_messages( - consumes: &Path, - outgoing_wrapper: &Ident, -) -> TokenStream { - quote! { - impl AssociateOutgoing for #outgoing_wrapper { - type OutgoingMessages = #outgoing_wrapper; - } - - impl AssociateOutgoing for #consumes { - type OutgoingMessages = #outgoing_wrapper; - } - } -} - -/// Implement `trait SubsystemContext` for a particular subsystem context, -/// that is generated by the proc-macro too. -pub(crate) fn impl_subsystem_context_trait_for( - consumes: Type, - outgoing: &[Type], - outgoing_wrapper: Type, - all_messages_wrapper: &Ident, - subsystem_ctx_name: &Ident, - subsystem_sender_name: &Ident, - support_crate: &Path, - signal: &Path, - error_ty: &Path, -) -> TokenStream { - // impl the subsystem context trait - let where_clause = quote! { - #consumes: AssociateOutgoing + ::std::fmt::Debug + Send + 'static, - #all_messages_wrapper: From< #outgoing_wrapper >, - #all_messages_wrapper: From< #consumes >, - #outgoing_wrapper: #( From< #outgoing > )+*, - }; - - quote! { - #[#support_crate ::async_trait] - impl #support_crate ::SubsystemContext for #subsystem_ctx_name < #consumes > - where - #where_clause - { - type Message = #consumes; - type Signal = #signal; - type OutgoingMessages = #outgoing_wrapper; - type Sender = #subsystem_sender_name < #outgoing_wrapper >; - type Error = #error_ty; - - async fn try_recv(&mut self) -> ::std::result::Result>, ()> { - match #support_crate ::poll!(self.recv()) { - #support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)), - #support_crate ::Poll::Pending => Ok(None), - } - } - - async fn recv(&mut self) -> ::std::result::Result, #error_ty> { - loop { - // If we have a message pending an orchestra signal, we only poll for signals - // in the meantime. - if let Some((needs_signals_received, msg)) = self.pending_incoming.take() { - if needs_signals_received <= self.signals_received.load() { - return Ok( #support_crate ::FromOrchestra::Communication { msg }); - } else { - self.pending_incoming = Some((needs_signals_received, msg)); - - // wait for next signal. - let signal = self.signals.next().await - .ok_or(#support_crate ::OrchestraError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - self.signals_received.inc(); - return Ok( #support_crate ::FromOrchestra::Signal(signal)) - } - } - - let mut await_message = self.messages.next().fuse(); - let mut await_signal = self.signals.next().fuse(); - let signals_received = self.signals_received.load(); - let pending_incoming = &mut self.pending_incoming; - - // Otherwise, wait for the next signal or incoming message. - let from_orchestra = #support_crate ::futures::select_biased! { - signal = await_signal => { - let signal = signal - .ok_or( #support_crate ::OrchestraError::Context( - "Signal channel is terminated and empty." - .to_owned() - ))?; - - #support_crate ::FromOrchestra::Signal(signal) - } - msg = await_message => { - let packet = msg - .ok_or( #support_crate ::OrchestraError::Context( - "Message channel is terminated and empty." - .to_owned() - ))?; - - if packet.signals_received > signals_received { - // wait until we've received enough signals to return this message. - *pending_incoming = Some((packet.signals_received, packet.message)); - continue; - } else { - // we know enough to return this message. - #support_crate ::FromOrchestra::Communication { msg: packet.message} - } - } - }; - - if let #support_crate ::FromOrchestra::Signal(_) = from_orchestra { - self.signals_received.inc(); - } - - return Ok(from_orchestra); - } - } - - fn sender(&mut self) -> &mut Self::Sender { - &mut self.to_subsystems - } - - fn spawn(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_orchestra.unbounded_send(#support_crate ::ToOrchestra::SpawnJob { - name, - subsystem: Some(self.name()), - s, - }).map_err(|_| #support_crate ::OrchestraError::TaskSpawn(name))?; - Ok(()) - } - - fn spawn_blocking(&mut self, name: &'static str, s: Pin + Send>>) - -> ::std::result::Result<(), #error_ty> - { - self.to_orchestra.unbounded_send(#support_crate ::ToOrchestra::SpawnBlockingJob { - name, - subsystem: Some(self.name()), - s, - }).map_err(|_| #support_crate ::OrchestraError::TaskSpawn(name))?; - Ok(()) - } - } - } -} - -/// Implement the additional subsystem accumulation traits, for simplified usage, -/// i.e. `${Subsystem}SenderTrait` and `${Subsystem}ContextTrait`. -pub(crate) fn impl_per_subsystem_helper_traits( - info: &OrchestraInfo, - subsystem_ctx_name: &Ident, - subsystem_ctx_trait: &Ident, - subsystem_sender_name: &Ident, - subsystem_sender_trait: &Ident, - consumes: &Path, - outgoing: &[Path], - outgoing_wrapper: &Ident, -) -> TokenStream { - let all_messages_wrapper = &info.message_wrapper; - let signal_ty = &info.extern_signal_ty; - let error_ty = &info.extern_error_ty; - let support_crate = info.support_crate_name(); - - let mut ts = TokenStream::new(); - - // Create a helper trait bound of all outgoing messages, and the generated wrapper type - // for ease of use within subsystems: - let acc_sender_trait_bounds = quote! { - #support_crate ::SubsystemSender< #outgoing_wrapper > - #( - + #support_crate ::SubsystemSender< #outgoing > - )* - + #support_crate ::SubsystemSender< () > - + Send - + 'static - }; - - ts.extend(quote! { - /// A abstracting trait for usage with subsystems. - pub trait #subsystem_sender_trait : #acc_sender_trait_bounds - {} - - impl #subsystem_sender_trait for T - where - T: #acc_sender_trait_bounds - {} - }); - - // Create a helper accumulated per subsystem trait bound: - let where_clause = quote! { - #consumes: AssociateOutgoing + ::std::fmt::Debug + Send + 'static, - #all_messages_wrapper: From< #outgoing_wrapper >, - #all_messages_wrapper: From< #consumes >, - #all_messages_wrapper: From< () >, - #outgoing_wrapper: #( From< #outgoing > )+*, - #outgoing_wrapper: From< () >, - }; - - ts.extend(quote! { - /// Accumulative trait for a particular subsystem wrapper. - pub trait #subsystem_ctx_trait : SubsystemContext < - Message = #consumes, - Signal = #signal_ty, - OutgoingMessages = #outgoing_wrapper, - // Sender, - Error = #error_ty, - > - where - #where_clause - ::Sender: - #subsystem_sender_trait - + #acc_sender_trait_bounds, - { - /// Sender. - type Sender: #subsystem_sender_trait; - } - - impl #subsystem_ctx_trait for T - where - T: SubsystemContext < - Message = #consumes, - Signal = #signal_ty, - OutgoingMessages = #outgoing_wrapper, - // Sender - Error = #error_ty, - >, - #where_clause - ::Sender: - #subsystem_sender_trait - + #acc_sender_trait_bounds, - { - type Sender = ::Sender; - } - }); - - ts.extend(impl_subsystem_context_trait_for( - parse_quote! { #consumes }, - &Vec::from_iter(outgoing.iter().map(|path| { - parse_quote! { #path } - })), - parse_quote! { #outgoing_wrapper }, - all_messages_wrapper, - subsystem_ctx_name, - subsystem_sender_name, - support_crate, - signal_ty, - error_ty, - )); - ts -} - -/// Generate the subsystem context type and provide `fn new` on it. -/// -/// Note: The generated `fn new` is used by the [builder pattern](../impl_builder.rs). -pub(crate) fn impl_subsystem_context( - info: &OrchestraInfo, - subsystem_sender_name: &Ident, - subsystem_ctx_name: &Ident, -) -> TokenStream { - let signal_ty = &info.extern_signal_ty; - let support_crate = info.support_crate_name(); - - let ts = quote! { - /// A context type that is given to the [`Subsystem`] upon spawning. - /// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s - /// or to spawn it's [`SubsystemJob`]s. - /// - /// [`Orchestra`]: struct.Orchestra.html - /// [`Subsystem`]: trait.Subsystem.html - /// [`SubsystemJob`]: trait.SubsystemJob.html - #[derive(Debug)] - #[allow(missing_docs)] - pub struct #subsystem_ctx_name { - signals: #support_crate ::metered::MeteredReceiver< #signal_ty >, - messages: SubsystemIncomingMessages< M >, - to_subsystems: #subsystem_sender_name < ::OutgoingMessages >, - to_orchestra: #support_crate ::metered::UnboundedMeteredSender< - #support_crate ::ToOrchestra - >, - signals_received: SignalsReceived, - pending_incoming: Option<(usize, M)>, - name: &'static str - } - - impl #subsystem_ctx_name - where - M: AssociateOutgoing + Send + 'static, - { - /// Create a new context. - fn new( - signals: #support_crate ::metered::MeteredReceiver< #signal_ty >, - messages: SubsystemIncomingMessages< M >, - to_subsystems: ChannelsOut, - to_orchestra: #support_crate ::metered::UnboundedMeteredSender<#support_crate:: ToOrchestra>, - name: &'static str - ) -> Self { - let signals_received = SignalsReceived::default(); - #subsystem_ctx_name :: { - signals, - messages, - to_subsystems: #subsystem_sender_name :: < ::OutgoingMessages > { - channels: to_subsystems, - signals_received: signals_received.clone(), - _phantom: ::core::marker::PhantomData::default(), - }, - to_orchestra, - signals_received, - pending_incoming: None, - name - } - } - - fn name(&self) -> &'static str { - self.name - } - } - }; - - ts -} diff --git a/node/orchestra/proc-macro/src/lib.rs b/node/orchestra/proc-macro/src/lib.rs deleted file mode 100644 index df3f216afdf6..000000000000 --- a/node/orchestra/proc-macro/src/lib.rs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::{Ident, Span, TokenStream}; -use syn::{parse_quote, spanned::Spanned, Path}; - -mod graph; -mod impl_builder; -mod impl_channels_out; -mod impl_message_wrapper; -mod impl_orchestra; -mod impl_subsystem_ctx_sender; -mod orchestra; -mod parse; -mod subsystem; - -#[cfg(test)] -mod tests; - -use impl_builder::*; -use impl_channels_out::*; -use impl_message_wrapper::*; -use impl_orchestra::*; -use impl_subsystem_ctx_sender::*; -use parse::*; - -use self::{orchestra::*, subsystem::*}; - -/// Obtain the support crate `Path` as `TokenStream`. -pub(crate) fn support_crate() -> Result { - Ok(if cfg!(test) { - parse_quote! {crate} - } else { - use proc_macro_crate::{crate_name, FoundCrate}; - let crate_name = crate_name("orchestra")?; - match crate_name { - FoundCrate::Itself => parse_quote! {crate}, - FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).into(), - } - }) -} - -#[proc_macro_attribute] -pub fn orchestra( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let attr: TokenStream = attr.into(); - let item: TokenStream = item.into(); - impl_orchestra_gen(attr, item) - .unwrap_or_else(|err| err.to_compile_error()) - .into() -} - -#[proc_macro_attribute] -pub fn subsystem( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let attr: TokenStream = attr.into(); - let item: TokenStream = item.into(); - impl_subsystem_context_trait_bounds(attr, item, MakeSubsystem::ImplSubsystemTrait) - .unwrap_or_else(|err| err.to_compile_error()) - .into() -} - -#[proc_macro_attribute] -pub fn contextbounds( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let attr: TokenStream = attr.into(); - let item: TokenStream = item.into(); - impl_subsystem_context_trait_bounds(attr, item, MakeSubsystem::AddContextTraitBounds) - .unwrap_or_else(|err| err.to_compile_error()) - .into() -} diff --git a/node/orchestra/proc-macro/src/orchestra.rs b/node/orchestra/proc-macro/src/orchestra.rs deleted file mode 100644 index ab1f9af3082f..000000000000 --- a/node/orchestra/proc-macro/src/orchestra.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::TokenStream; -use syn::{parse2, Result}; - -use super::{parse::*, *}; - -pub(crate) fn impl_orchestra_gen( - attr: TokenStream, - orig: TokenStream, -) -> Result { - let args: OrchestraAttrArgs = parse2(attr)?; - let message_wrapper = args.message_wrapper; - - let of: OrchestraGuts = parse2(orig)?; - - let support_crate = support_crate().expect("The crate this macro is run for, includes the proc-macro support as dependency, otherwise it could not be run in the first place. qed"); - let info = OrchestraInfo { - support_crate, - subsystems: of.subsystems, - baggage: of.baggage, - orchestra_name: of.name, - message_wrapper, - message_channel_capacity: args.message_channel_capacity, - signal_channel_capacity: args.signal_channel_capacity, - extern_event_ty: args.extern_event_ty, - extern_signal_ty: args.extern_signal_ty, - extern_error_ty: args.extern_error_ty, - outgoing_ty: args.outgoing_ty, - }; - - let mut additive = impl_orchestra_struct(&info); - additive.extend(impl_builder(&info)); - - additive.extend(impl_orchestrated_subsystem(&info)); - additive.extend(impl_channels_out_struct(&info)); - additive.extend(impl_subsystem_types_all(&info)?); - - additive.extend(impl_message_wrapper_enum(&info)?); - - let ts = expander::Expander::new("orchestra-expansion") - .add_comment("Generated orchestra code by `#[orchestra(..)]`".to_owned()) - .dry(!cfg!(feature = "expand")) - .verbose(true) - // once all our needed format options are available on stable - // we should enabled this again, until then too many warnings - // are generated - // .fmt(expander::Edition::_2021) - .write_to_out_dir(additive) - .expect("Expander does not fail due to IO in OUT_DIR. qed"); - - Ok(ts) -} diff --git a/node/orchestra/proc-macro/src/parse/mod.rs b/node/orchestra/proc-macro/src/parse/mod.rs deleted file mode 100644 index 05d6cc2efcd7..000000000000 --- a/node/orchestra/proc-macro/src/parse/mod.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -mod kw { - syn::custom_keyword!(event); - syn::custom_keyword!(signal); - syn::custom_keyword!(error); - syn::custom_keyword!(outgoing); - syn::custom_keyword!(gen); - syn::custom_keyword!(signal_capacity); - syn::custom_keyword!(message_capacity); - syn::custom_keyword!(subsystem); - syn::custom_keyword!(prefix); -} - -mod parse_orchestra_attr; -mod parse_orchestra_struct; - -mod parse_subsystem_attr; - -#[cfg(test)] -mod tests; - -pub(crate) use self::{parse_orchestra_attr::*, parse_orchestra_struct::*}; - -pub(crate) use self::parse_subsystem_attr::*; diff --git a/node/orchestra/proc-macro/src/parse/parse_orchestra_attr.rs b/node/orchestra/proc-macro/src/parse/parse_orchestra_attr.rs deleted file mode 100644 index 27486b5697a2..000000000000 --- a/node/orchestra/proc-macro/src/parse/parse_orchestra_attr.rs +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::kw; -use proc_macro2::Span; -use quote::{quote, ToTokens}; -use std::collections::{hash_map::RandomState, HashMap}; -use syn::{ - parse::{Parse, ParseBuffer}, - punctuated::Punctuated, - spanned::Spanned, - Error, Ident, LitInt, Path, Result, Token, -}; - -#[derive(Clone, Debug)] -enum OrchestraAttrItem { - ExternEventType { tag: kw::event, eq_token: Token![=], value: Path }, - ExternOrchestraSignalType { tag: kw::signal, eq_token: Token![=], value: Path }, - ExternErrorType { tag: kw::error, eq_token: Token![=], value: Path }, - OutgoingType { tag: kw::outgoing, eq_token: Token![=], value: Path }, - MessageWrapperName { tag: kw::gen, eq_token: Token![=], value: Ident }, - SignalChannelCapacity { tag: kw::signal_capacity, eq_token: Token![=], value: usize }, - MessageChannelCapacity { tag: kw::message_capacity, eq_token: Token![=], value: usize }, -} - -impl ToTokens for OrchestraAttrItem { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let ts = match self { - Self::ExternEventType { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::ExternOrchestraSignalType { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::ExternErrorType { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::OutgoingType { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::MessageWrapperName { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::SignalChannelCapacity { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::MessageChannelCapacity { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - }; - tokens.extend(ts.into_iter()); - } -} - -impl Parse for OrchestraAttrItem { - fn parse(input: &ParseBuffer) -> Result { - let lookahead = input.lookahead1(); - if lookahead.peek(kw::event) { - Ok(OrchestraAttrItem::ExternEventType { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::signal) { - Ok(OrchestraAttrItem::ExternOrchestraSignalType { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::error) { - Ok(OrchestraAttrItem::ExternErrorType { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::outgoing) { - Ok(OrchestraAttrItem::OutgoingType { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::gen) { - Ok(OrchestraAttrItem::MessageWrapperName { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::signal_capacity) { - Ok(OrchestraAttrItem::SignalChannelCapacity { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse::()?.base10_parse::()?, - }) - } else if lookahead.peek(kw::message_capacity) { - Ok(OrchestraAttrItem::MessageChannelCapacity { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse::()?.base10_parse::()?, - }) - } else { - Err(lookahead.error()) - } - } -} - -/// Attribute arguments -#[derive(Clone, Debug)] -pub(crate) struct OrchestraAttrArgs { - pub(crate) message_wrapper: Ident, - pub(crate) extern_event_ty: Path, - pub(crate) extern_signal_ty: Path, - pub(crate) extern_error_ty: Path, - pub(crate) outgoing_ty: Option, - pub(crate) signal_channel_capacity: usize, - pub(crate) message_channel_capacity: usize, -} - -macro_rules! extract_variant { - ($unique:expr, $variant:ident ; default = $fallback:expr) => { - extract_variant!($unique, $variant).unwrap_or_else(|| $fallback) - }; - ($unique:expr, $variant:ident ; err = $err:expr) => { - extract_variant!($unique, $variant).ok_or_else(|| Error::new(Span::call_site(), $err)) - }; - ($unique:expr, $variant:ident) => { - $unique.values().find_map(|item| { - if let OrchestraAttrItem::$variant { value, .. } = item { - Some(value.clone()) - } else { - None - } - }) - }; -} - -impl Parse for OrchestraAttrArgs { - fn parse(input: &ParseBuffer) -> Result { - let items: Punctuated = - input.parse_terminated(OrchestraAttrItem::parse)?; - - let mut unique = HashMap::< - std::mem::Discriminant, - OrchestraAttrItem, - RandomState, - >::default(); - for item in items { - if let Some(first) = unique.insert(std::mem::discriminant(&item), item.clone()) { - let mut e = Error::new( - item.span(), - format!("Duplicate definition of orchestra generation type found"), - ); - e.combine(Error::new(first.span(), "previously defined here.")); - return Err(e) - } - } - - let signal_channel_capacity = - extract_variant!(unique, SignalChannelCapacity; default = 64_usize); - let message_channel_capacity = - extract_variant!(unique, MessageChannelCapacity; default = 1024_usize); - - let error = extract_variant!(unique, ExternErrorType; err = "Must declare the orchestra error type via `error=..`.")?; - let event = extract_variant!(unique, ExternEventType; err = "Must declare the orchestra event type via `event=..`.")?; - let signal = extract_variant!(unique, ExternOrchestraSignalType; err = "Must declare the orchestra signal type via `signal=..`.")?; - let message_wrapper = extract_variant!(unique, MessageWrapperName; err = "Must declare the orchestra generated wrapping message type via `gen=..`.")?; - let outgoing = extract_variant!(unique, OutgoingType); - - Ok(OrchestraAttrArgs { - signal_channel_capacity, - message_channel_capacity, - extern_event_ty: event, - extern_signal_ty: signal, - extern_error_ty: error, - outgoing_ty: outgoing, - message_wrapper, - }) - } -} diff --git a/node/orchestra/proc-macro/src/parse/parse_orchestra_struct.rs b/node/orchestra/proc-macro/src/parse/parse_orchestra_struct.rs deleted file mode 100644 index e8ab449af632..000000000000 --- a/node/orchestra/proc-macro/src/parse/parse_orchestra_struct.rs +++ /dev/null @@ -1,601 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use itertools::Itertools; -use proc_macro2::{Span, TokenStream}; -use std::collections::{hash_map::RandomState, HashMap, HashSet}; -use syn::{ - parenthesized, - parse::{Parse, ParseStream}, - punctuated::Punctuated, - spanned::Spanned, - token::Bracket, - AttrStyle, Error, Field, FieldsNamed, GenericParam, Ident, ItemStruct, Path, PathSegment, - Result, Token, Type, Visibility, -}; - -use quote::{quote, ToTokens}; - -mod kw { - syn::custom_keyword!(wip); - syn::custom_keyword!(blocking); - syn::custom_keyword!(consumes); - syn::custom_keyword!(sends); -} - -#[derive(Clone, Debug)] -pub(crate) enum SubSysAttrItem { - /// The subsystem is still a work in progress - /// and should not be communicated with. - Wip(kw::wip), - /// The subsystem is blocking and requires to be - /// spawned on an exclusive thread. - Blocking(kw::blocking), - /// Message to be sent by this subsystem. - Sends(Sends), - /// Message to be consumed by this subsystem. - Consumes(Consumes), -} - -impl Parse for SubSysAttrItem { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - Ok(if lookahead.peek(kw::wip) { - Self::Wip(input.parse::()?) - } else if lookahead.peek(kw::blocking) { - Self::Blocking(input.parse::()?) - } else if lookahead.peek(kw::sends) { - Self::Sends(input.parse::()?) - } else { - Self::Consumes(input.parse::()?) - }) - } -} - -impl ToTokens for SubSysAttrItem { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let ts = match self { - Self::Wip(wip) => { - quote! { #wip } - }, - Self::Blocking(blocking) => { - quote! { #blocking } - }, - Self::Sends(_) => { - quote! {} - }, - Self::Consumes(_) => { - quote! {} - }, - }; - tokens.extend(ts.into_iter()); - } -} - -/// A field of the struct annotated with -/// `#[subsystem(A, B, C)]` -#[derive(Clone, Debug)] -pub(crate) struct SubSysField { - /// Name of the field. - pub(crate) name: Ident, - /// Generate generic type name for the `AllSubsystems` type - /// which is also used `#wrapper_message :: #variant` variant - /// part. - pub(crate) generic: Ident, - /// Type of message to be consumed by the subsystem. - pub(crate) message_to_consume: Path, - /// Types of messages to be sent by the subsystem. - pub(crate) messages_to_send: Vec, - /// If the subsystem implementation is blocking execution and hence - /// has to be spawned on a separate thread or thread pool. - pub(crate) blocking: bool, - /// The subsystem is a work in progress. - /// Avoids dispatching `Wrapper` type messages, but generates the variants. - /// Does not require the subsystem to be instantiated with the builder pattern. - pub(crate) wip: bool, -} - -// Converts a type enum to a path if this type is a TypePath -fn try_type_to_path(ty: &Type, span: Span) -> Result { - match ty { - Type::Path(path) => Ok(path.path.clone()), - _ => Err(Error::new(span, "Type must be a path expression.")), - } -} - -// Converts a Rust type to a list of idents recursively checking the possible values -fn flatten_type(ty: &Type, span: Span) -> Result> { - match ty { - syn::Type::Array(ar) => flatten_type(&ar.elem, span), - syn::Type::Paren(par) => flatten_type(&par.elem, span), - syn::Type::Path(type_path) => type_path - .path - .segments - .iter() - .map(|seg| flatten_path_segments(seg, span.clone())) - .flatten_ok() - .collect::>>(), - syn::Type::Tuple(tup) => tup - .elems - .iter() - .map(|element| flatten_type(element, span.clone())) - .flatten_ok() - .collect::>>(), - _ => Err(Error::new(span, format!("Unsupported type: {:?}", ty))), - } -} - -// Flatten segments of some path to a list of idents used in these segments -fn flatten_path_segments(path_segment: &PathSegment, span: Span) -> Result> { - let mut result = vec![path_segment.ident.clone()]; - - match &path_segment.arguments { - syn::PathArguments::AngleBracketed(args) => { - let mut recursive_idents = args - .args - .iter() - .map(|generic_argument| match generic_argument { - syn::GenericArgument::Type(ty) => flatten_type(ty, span.clone()), - _ => Err(Error::new( - span, - format!( - "Field has a generic with an unsupported parameter {:?}", - generic_argument - ), - )), - }) - .flatten_ok() - .collect::>>()?; - result.append(&mut recursive_idents); - }, - syn::PathArguments::None => {}, - _ => - return Err(Error::new( - span, - format!( - "Field has a generic with an unsupported path {:?}", - path_segment.arguments - ), - )), - } - - Ok(result) -} - -macro_rules! extract_variant { - ($unique:expr, $variant:ident ; default = $fallback:expr) => { - extract_variant!($unique, $variant).unwrap_or_else(|| $fallback) - }; - ($unique:expr, $variant:ident ; err = $err:expr) => { - extract_variant!($unique, $variant).ok_or_else(|| Error::new(Span::call_site(), $err)) - }; - ($unique:expr, $variant:ident take) => { - $unique.values().find_map(|item| { - if let SubSysAttrItem::$variant(value) = item { - Some(value.clone()) - } else { - None - } - }) - }; - ($unique:expr, $variant:ident) => { - $unique.values().find_map(|item| { - if let SubSysAttrItem::$variant(_) = item { - Some(true) - } else { - None - } - }) - }; -} - -#[derive(Debug, Clone)] -pub(crate) struct Sends { - #[allow(dead_code)] - pub(crate) keyword_sends: kw::sends, - #[allow(dead_code)] - pub(crate) colon: Token![:], - #[allow(dead_code)] - pub(crate) bracket: Option, - pub(crate) sends: Punctuated, -} - -impl Parse for Sends { - fn parse(input: syn::parse::ParseStream) -> Result { - let content; - let keyword_sends = input.parse()?; - let colon = input.parse()?; - let (bracket, sends) = if !input.peek(syn::token::Bracket) { - let mut sends = Punctuated::new(); - sends.push_value(input.parse::()?); - (None, sends) - } else { - let bracket = Some(syn::bracketed!(content in input)); - let sends = Punctuated::parse_terminated(&content)?; - (bracket, sends) - }; - Ok(Self { keyword_sends, colon, bracket, sends }) - } -} - -#[derive(Debug, Clone)] -pub(crate) struct Consumes { - #[allow(dead_code)] - pub(crate) keyword_consumes: Option, - #[allow(dead_code)] - pub(crate) colon: Option, - pub(crate) consumes: Path, -} - -impl Parse for Consumes { - fn parse(input: syn::parse::ParseStream) -> Result { - let lookahead = input.lookahead1(); - Ok(if lookahead.peek(kw::consumes) { - Self { - keyword_consumes: Some(input.parse()?), - colon: input.parse()?, - consumes: input.parse()?, - } - } else { - Self { keyword_consumes: None, colon: None, consumes: input.parse()? } - }) - } -} - -/// Parses `(Foo, sends = [Bar, Baz])` -/// including the `(` and `)`. -#[derive(Debug, Clone)] -pub(crate) struct SubSystemAttrItems { - /// The subsystem is in progress, only generate the `Wrapper` variant, but do not forward messages - /// and also not include the subsystem in the list of subsystems. - pub(crate) wip: bool, - /// If there are blocking components in the subsystem and hence it should be - /// spawned on a dedicated thread pool for such subssytems. - pub(crate) blocking: bool, - /// The message type being consumed by the subsystem. - pub(crate) consumes: Option, - pub(crate) sends: Option, -} - -impl Parse for SubSystemAttrItems { - fn parse(input: syn::parse::ParseStream) -> Result { - let span = input.span(); - - let content; - let _paren_token = parenthesized!(content in input); - - let items = content.call(Punctuated::::parse_terminated)?; - - let mut unique = HashMap::< - std::mem::Discriminant, - SubSysAttrItem, - RandomState, - >::default(); - - for item in items { - if let Some(first) = unique.insert(std::mem::discriminant(&item), item.clone()) { - let mut e = - Error::new(item.span(), "Duplicate definition of subsystem attribute found"); - e.combine(Error::new(first.span(), "previously defined here.")); - return Err(e) - } - } - - // A subsystem makes no sense if not one of them is provided - let sends = extract_variant!(unique, Sends take); - let consumes = extract_variant!(unique, Consumes take); - if sends.as_ref().map(|sends| sends.sends.is_empty()).unwrap_or(true) && consumes.is_none() - { - return Err(Error::new( - span, - "Must have at least one of `consumes: [..]` and `sends: [..]`.", - )) - } - - let blocking = extract_variant!(unique, Blocking; default = false); - let wip = extract_variant!(unique, Wip; default = false); - - Ok(Self { blocking, wip, sends, consumes }) - } -} - -/// Fields that are _not_ subsystems. -#[derive(Debug, Clone)] -pub(crate) struct BaggageField { - pub(crate) field_name: Ident, - pub(crate) field_ty: Type, - pub(crate) generic_types: Vec, - pub(crate) vis: Visibility, -} - -#[derive(Clone, Debug)] -pub(crate) struct OrchestraInfo { - /// Where the support crate `::orchestra` lives. - pub(crate) support_crate: Path, - - /// Fields annotated with `#[subsystem(..)]`. - pub(crate) subsystems: Vec, - /// Fields that do not define a subsystem, - /// but are mere baggage. - pub(crate) baggage: Vec, - /// Name of the wrapping enum for all messages, defaults to `AllMessages`. - pub(crate) message_wrapper: Ident, - /// Name of the orchestra struct, used as a prefix for - /// almost all generated types. - pub(crate) orchestra_name: Ident, - - /// Size of the bounded channel. - pub(crate) message_channel_capacity: usize, - /// Size of the bounded signal channel. - pub(crate) signal_channel_capacity: usize, - - /// Signals to be sent, sparse information that is used intermittently. - pub(crate) extern_signal_ty: Path, - - /// Incoming event type from the outer world, usually an external framework of some sort. - pub(crate) extern_event_ty: Path, - - /// Type of messages that are sent to an external subsystem. - /// Merely here to be included during generation of `#message_wrapper` type. - pub(crate) outgoing_ty: Option, - - /// Incoming event type from the outer world, commonly from the network. - pub(crate) extern_error_ty: Path, -} - -impl OrchestraInfo { - pub(crate) fn support_crate_name(&self) -> &Path { - &self.support_crate - } - - pub(crate) fn variant_names(&self) -> Vec { - self.subsystems.iter().map(|ssf| ssf.generic.clone()).collect::>() - } - - pub(crate) fn variant_names_without_wip(&self) -> Vec { - self.subsystems - .iter() - .filter(|ssf| !ssf.wip) - .map(|ssf| ssf.generic.clone()) - .collect::>() - } - - pub(crate) fn variant_names_only_wip(&self) -> Vec { - self.subsystems - .iter() - .filter(|ssf| ssf.wip) - .map(|ssf| ssf.generic.clone()) - .collect::>() - } - - pub(crate) fn subsystems(&self) -> &[SubSysField] { - self.subsystems.as_slice() - } - - pub(crate) fn subsystem_names_without_wip(&self) -> Vec { - self.subsystems - .iter() - .filter(|ssf| !ssf.wip) - .map(|ssf| ssf.name.clone()) - .collect::>() - } - - pub(crate) fn subsystem_generic_types(&self) -> Vec { - self.subsystems - .iter() - .filter(|ssf| !ssf.wip) - .map(|sff| sff.generic.clone()) - .collect::>() - } - - pub(crate) fn baggage(&self) -> &[BaggageField] { - self.baggage.as_slice() - } - - pub(crate) fn baggage_names(&self) -> Vec { - self.baggage.iter().map(|bag| bag.field_name.clone()).collect::>() - } - pub(crate) fn baggage_decl(&self) -> Vec { - self.baggage - .iter() - .map(|bag| { - let BaggageField { vis, field_ty, field_name, .. } = bag; - quote! { #vis #field_name: #field_ty } - }) - .collect::>() - } - - pub(crate) fn baggage_generic_types(&self) -> Vec { - self.baggage - .iter() - .flat_map(|bag| bag.generic_types.clone()) - .collect::>() - } - - pub(crate) fn any_message(&self) -> Vec { - self.subsystems - .iter() - .map(|ssf| ssf.message_to_consume.clone()) - .collect::>() - } - - pub(crate) fn channel_names_without_wip(&self, suffix: &'static str) -> Vec { - self.subsystems - .iter() - .filter(|ssf| !ssf.wip) - .map(|ssf| Ident::new(&(ssf.name.to_string() + suffix), ssf.name.span())) - .collect::>() - } - - pub(crate) fn consumes_without_wip(&self) -> Vec { - self.subsystems - .iter() - .filter(|ssf| !ssf.wip) - .map(|ssf| ssf.message_to_consume.clone()) - .collect::>() - } -} - -/// Internals of the orchestra. -#[derive(Debug, Clone)] -pub(crate) struct OrchestraGuts { - pub(crate) name: Ident, - pub(crate) subsystems: Vec, - pub(crate) baggage: Vec, -} - -impl OrchestraGuts { - pub(crate) fn parse_fields( - name: Ident, - baggage_generics: HashSet, - fields: FieldsNamed, - ) -> Result { - let n = fields.named.len(); - let mut subsystems = Vec::with_capacity(n); - let mut baggage = Vec::with_capacity(n); - - // The types of `#[subsystem(..)]` annotated fields - // have to be unique, since they are used as generics - // for the builder pattern besides other places. - let mut unique_subsystem_idents = HashSet::::new(); - for Field { attrs, vis, ident, ty, .. } in fields.named.into_iter() { - // collect all subsystem annotations per field - let mut subsystem_attr = - attrs.iter().filter(|attr| attr.style == AttrStyle::Outer).filter_map(|attr| { - let span = attr.path.span(); - attr.path.get_ident().filter(|ident| *ident == "subsystem").map(move |_ident| { - let attr_tokens = attr.tokens.clone(); - (attr_tokens, span) - }) - }); - let ident = ident.ok_or_else(|| { - Error::new( - ty.span(), - "Missing identifier for field, only named fields are expected.", - ) - })?; - - // a `#[subsystem(..)]` annotation exists - if let Some((attr_tokens, span)) = subsystem_attr.next() { - if let Some((_attr_tokens2, span2)) = subsystem_attr.next() { - return Err({ - let mut err = Error::new(span, "The first subsystem annotation is at"); - err.combine(Error::new(span2, "but another here for the same field.")); - err - }) - } - - let span = attr_tokens.span(); - - let attr_tokens = attr_tokens.clone(); - let subsystem_attrs: SubSystemAttrItems = syn::parse2(attr_tokens.clone())?; - - let field_ty = try_type_to_path(&ty, span)?; - let generic = field_ty - .get_ident() - .ok_or_else(|| { - Error::new( - field_ty.span(), - "Must be an identifier, not a path. It will be used as a generic.", - ) - })? - .clone(); - // check for unique subsystem name, otherwise we'd create invalid code: - if let Some(previous) = unique_subsystem_idents.get(&generic) { - let mut e = Error::new(generic.span(), "Duplicate subsystem names"); - e.combine(Error::new(previous.span(), "previously defined here.")); - return Err(e) - } - unique_subsystem_idents.insert(generic.clone()); - - let SubSystemAttrItems { wip, blocking, consumes, sends, .. } = subsystem_attrs; - - // messages to be sent - let sends = if let Some(sends) = sends { - Vec::from_iter(sends.sends.iter().cloned()) - } else { - vec![] - }; - // messages deemed for consumption - let consumes = if let Some(consumes) = consumes { - consumes.consumes - } else { - return Err(Error::new(span, "Must provide exactly one consuming message type")) - }; - - subsystems.push(SubSysField { - name: ident, - generic, - message_to_consume: consumes, - messages_to_send: sends, - wip, - blocking, - }); - } else { - let flattened = flatten_type(&ty, ident.span())?; - let generic_types = flattened - .iter() - .filter(|flat_ident| baggage_generics.contains(flat_ident)) - .cloned() - .collect::>(); - baggage.push(BaggageField { field_name: ident, generic_types, field_ty: ty, vis }); - } - } - Ok(Self { name, subsystems, baggage }) - } -} - -impl Parse for OrchestraGuts { - fn parse(input: ParseStream) -> Result { - let ds: ItemStruct = input.parse()?; - match ds.fields { - syn::Fields::Named(named) => { - let name = ds.ident.clone(); - - // collect the independent subsystem generics - // which need to be carried along, there are the non-generated ones - let mut orig_generics = ds.generics; - - // remove defaults from types - let mut baggage_generic_idents = HashSet::with_capacity(orig_generics.params.len()); - orig_generics.params = orig_generics - .params - .into_iter() - .map(|mut generic| { - match generic { - GenericParam::Type(ref mut param) => { - baggage_generic_idents.insert(param.ident.clone()); - param.eq_token = None; - param.default = None; - }, - _ => {}, - } - generic - }) - .collect(); - - Self::parse_fields(name, baggage_generic_idents, named) - }, - syn::Fields::Unit => Err(Error::new( - ds.fields.span(), - "Must be a struct with named fields. Not an unit struct.", - )), - syn::Fields::Unnamed(unnamed) => Err(Error::new( - unnamed.span(), - "Must be a struct with named fields. Not an unnamed fields struct.", - )), - } - } -} diff --git a/node/orchestra/proc-macro/src/parse/parse_subsystem_attr.rs b/node/orchestra/proc-macro/src/parse/parse_subsystem_attr.rs deleted file mode 100644 index 6df4a4c8e292..000000000000 --- a/node/orchestra/proc-macro/src/parse/parse_subsystem_attr.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::kw; -use proc_macro2::Span; -use quote::{quote, ToTokens}; -use std::collections::{hash_map::RandomState, HashMap}; -use syn::{ - parse::{Parse, ParseBuffer}, - punctuated::Punctuated, - spanned::Spanned, - Error, Ident, Path, Result, Token, -}; - -#[derive(Clone, Debug)] -enum SubsystemAttrItem { - /// Error type provided by the user. - Error { tag: kw::error, eq_token: Token![=], value: Path }, - /// For which slot in the orchestra this should be plugged. - /// - /// The subsystem implementation can and should have a different name - /// from the declared parameter type in the orchestra. - Subsystem { tag: Option, eq_token: Option, value: Ident }, - /// The prefix to apply when a subsystem is implemented in a different file/crate - /// than the orchestra itself. - /// - /// Important for `#[subsystem(..)]` to reference the traits correctly. - TraitPrefix { tag: kw::prefix, eq_token: Token![=], value: Path }, -} - -impl ToTokens for SubsystemAttrItem { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - let ts = match self { - Self::TraitPrefix { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::Error { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - Self::Subsystem { tag, eq_token, value } => { - quote! { #tag #eq_token, #value } - }, - }; - tokens.extend(ts.into_iter()); - } -} - -impl Parse for SubsystemAttrItem { - fn parse(input: &ParseBuffer) -> Result { - let lookahead = input.lookahead1(); - if lookahead.peek(kw::error) { - Ok(SubsystemAttrItem::Error { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::prefix) { - Ok(SubsystemAttrItem::TraitPrefix { - tag: input.parse::()?, - eq_token: input.parse()?, - value: input.parse()?, - }) - } else if lookahead.peek(kw::subsystem) { - Ok(SubsystemAttrItem::Subsystem { - tag: Some(input.parse::()?), - eq_token: Some(input.parse()?), - value: input.parse()?, - }) - } else { - Ok(SubsystemAttrItem::Subsystem { tag: None, eq_token: None, value: input.parse()? }) - } - } -} - -/// Attribute arguments `$args` in `#[subsystem( $args )]`. -#[derive(Clone, Debug)] -pub(crate) struct SubsystemAttrArgs { - span: Span, - pub(crate) error_path: Option, - pub(crate) subsystem_ident: Ident, - pub(crate) trait_prefix_path: Option, -} - -impl Spanned for SubsystemAttrArgs { - fn span(&self) -> Span { - self.span.clone() - } -} - -macro_rules! extract_variant { - ($unique:expr, $variant:ident ; default = $fallback:expr) => { - extract_variant!($unique, $variant).unwrap_or_else(|| $fallback) - }; - ($unique:expr, $variant:ident ; err = $err:expr) => { - extract_variant!($unique, $variant).ok_or_else(|| Error::new(Span::call_site(), $err)) - }; - ($unique:expr, $variant:ident) => { - $unique.values().find_map(|item| match item { - SubsystemAttrItem::$variant { value, .. } => Some(value.clone()), - _ => None, - }) - }; -} - -impl Parse for SubsystemAttrArgs { - fn parse(input: &ParseBuffer) -> Result { - let span = input.span(); - let items: Punctuated = - input.parse_terminated(SubsystemAttrItem::parse)?; - - let mut unique = HashMap::< - std::mem::Discriminant, - SubsystemAttrItem, - RandomState, - >::default(); - for item in items { - if let Some(first) = unique.insert(std::mem::discriminant(&item), item.clone()) { - let mut e = Error::new( - item.span(), - format!("Duplicate definition of subsystem generation type found"), - ); - e.combine(Error::new(first.span(), "previously defined here.")); - return Err(e) - } - } - let error_path = extract_variant!(unique, Error); - let subsystem_ident = extract_variant!(unique, Subsystem; err = "Must annotate the identical orchestra error type via `subsystem=..` or plainly as `Subsystem` as specified in the orchestra declaration.")?; - let trait_prefix_path = extract_variant!(unique, TraitPrefix); - Ok(SubsystemAttrArgs { span, error_path, subsystem_ident, trait_prefix_path }) - } -} diff --git a/node/orchestra/proc-macro/src/parse/tests.rs b/node/orchestra/proc-macro/src/parse/tests.rs deleted file mode 100644 index 3bcfda45db80..000000000000 --- a/node/orchestra/proc-macro/src/parse/tests.rs +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::*; -use crate::{SubSysAttrItem, SubSystemAttrItems}; -use assert_matches::assert_matches; -use quote::quote; -use syn::parse_quote; - -mod attr { - use super::*; - - #[test] - fn attr_full_works() { - let attr: OrchestraAttrArgs = parse_quote! { - gen=AllMessage, event=::some::why::ExternEvent, signal=SigSigSig, signal_capacity=111, message_capacity=222, - error=OrchestraError, - }; - assert_matches!(attr, OrchestraAttrArgs { - message_channel_capacity, - signal_channel_capacity, - .. - } => { - assert_eq!(message_channel_capacity, 222); - assert_eq!(signal_channel_capacity, 111); - }); - } - - #[test] - fn attr_partial_works() { - let attr: OrchestraAttrArgs = parse_quote! { - gen=AllMessage, event=::some::why::ExternEvent, signal=::foo::SigSigSig, - error=OrchestraError, - }; - assert_matches!(attr, OrchestraAttrArgs { - message_channel_capacity: _, - signal_channel_capacity: _, - .. - } => { - }); - } -} - -mod strukt { - - use super::*; - - #[test] - fn parse_subsystem_attr_item_works_00_wip() { - assert_matches!( - syn::parse2::(quote! { - wip - }), Ok(SubSysAttrItem::Wip(_)) => { - }); - } - - #[test] - fn parse_subsystem_attr_item_works_02_sends() { - assert_matches!( - syn::parse2::(quote! { - sends: [A, B, C] - }), Ok(SubSysAttrItem::Sends(sends)) => { - assert_eq!(sends.sends.len(), 3); - }); - } - - #[test] - fn parse_subsystem_attr_item_works_03_sends() { - assert_matches!( - syn::parse2::(quote! { - sends: [A] - }), Ok(SubSysAttrItem::Sends(sends)) => { - assert_eq!(sends.sends.len(), 1); - }); - } - - #[test] - fn parse_subsystem_attr_item_works_04_sends() { - assert_matches!( - syn::parse2::(quote! { - sends: [A,] - }), Ok(SubSysAttrItem::Sends(sends)) => { - assert_eq!(sends.sends.len(), 1); - }); - } - - #[test] - fn parse_subsystem_attr_item_works_05_sends() { - assert_matches!( - syn::parse2::(quote! { - sends: [] - }), Ok(SubSysAttrItem::Sends(sends)) => { - assert_eq!(sends.sends.len(), 0); - }); - } - - #[test] - fn parse_subsystem_attr_item_works_06_consumes() { - assert_matches!( - syn::parse2::(quote! { - consumes: Foo - }), Ok(SubSysAttrItem::Consumes(_consumes)) => { - }); - } - - #[test] - fn parse_subsystem_attr_item_works_07_consumes() { - assert_matches!( - syn::parse2::(quote! { - Foo - }), Ok(SubSysAttrItem::Consumes(_consumes)) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_00() { - syn::parse2::(quote! { - (wip, blocking, consumes: Foo, sends: []) - }) - .unwrap(); - } - - #[test] - fn parse_subsystem_attributes_works_01() { - assert_matches!( - syn::parse2::(quote! { - (blocking, Foo, sends: []) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_02() { - assert_matches!( - syn::parse2::(quote! { - (consumes: Foo, sends: [Bar]) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_03() { - assert_matches!( - syn::parse2::(quote! { - (blocking, consumes: Foo, sends: [Bar]) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_04() { - assert_matches!( - syn::parse2::(quote! { - (wip, consumes: Foo, sends: [Bar]) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_05() { - assert_matches!( - syn::parse2::(quote! { - (consumes: Foo) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_06() { - assert_matches!( - syn::parse2::(quote! { - (sends: [Foo], consumes: Bar) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_07_duplicate_send() { - assert_matches!( - syn::parse2::(quote! { - (sends: [Foo], Bar, Y) - }), Err(e) => { - dbg!(e) - }); - } - - #[test] - fn parse_subsystem_attributes_works_08() { - assert_matches!( - syn::parse2::(quote! { - (sends: [Foo], consumes: Bar) - }), Ok(_) => { - }); - } - - #[test] - fn parse_subsystem_attributes_works_09_neither_consumes_nor_sends() { - assert_matches!( - syn::parse2::(quote! { - (sends: []) - }), Err(e) => { - // must either consume smth or sends smth, neither is NOK - dbg!(e) - }); - } - - #[test] - fn parse_subsystem_attributes_works_10_empty_with_braces() { - assert_matches!( - syn::parse2::(quote! { - () - }), Err(e) => { - dbg!(e) - }); - } - - #[test] - fn parse_subsystem_attributes_works_11_empty() { - assert_matches!( - syn::parse2::(quote! { - - }), Err(e) => { - dbg!(e) - }); - } - - #[test] - fn parse_subsystem_attributes_works_12_duplicate_consumes_different_fmt() { - assert_matches!( - syn::parse2::(quote! { - (Foo, consumes = Foo) - }), Err(e) => { - dbg!(e) - }); - } - - #[test] - fn struct_parse_baggage() { - let item: OrchestraGuts = parse_quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(consumes: Foo, sends: [])] - sub0: FooSubsystem, - - metrics: Metrics, - } - }; - let _ = dbg!(item); - } - - #[test] - fn struct_parse_full() { - let item: OrchestraGuts = parse_quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(consumes: Foo, sends: [])] - sub0: FooSubsystem, - - #[subsystem(blocking, consumes: Bar, sends: [])] - yyy: BaersBuyBilliardBalls, - - #[subsystem(blocking, consumes: Twain, sends: [])] - fff: Beeeeep, - - #[subsystem(consumes: Rope)] - mc: MountainCave, - - metrics: Metrics, - } - }; - let _ = dbg!(item); - } - - #[test] - fn struct_parse_basic() { - let item: OrchestraGuts = parse_quote! { - pub struct Ooooh { - #[subsystem(consumes: Foo, sends: [])] - sub0: FooSubsystem, - } - }; - let _ = dbg!(item); - } -} diff --git a/node/orchestra/proc-macro/src/subsystem.rs b/node/orchestra/proc-macro/src/subsystem.rs deleted file mode 100644 index 27f50704bb94..000000000000 --- a/node/orchestra/proc-macro/src/subsystem.rs +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Generates the bounds for a particular subsystem `Context` and associate `type Sender`. -//! -//! -//! ## Implement `trait Subsystem` via `subsystem` -//! -//! ```ignore -//! # use orchestra_proc_macro::subsystem; -//! # mod somewhere { -//! # use orchestra_proc_macro::orchestra; -//! # pub use orchestra::*; -//! # -//! # #[derive(Debug, thiserror::Error)] -//! # #[error("Yikes!")] -//! # pub struct Yikes; -//! # impl From for Yikes { -//! # fn from(_: OrchestraError) -> Yikes { Yikes } -//! # } -//! # impl From for Yikes { -//! # fn from(_: mpsc::SendError) -> Yikes { Yikes } -//! # } -//! # -//! # #[derive(Debug)] -//! # pub struct Eve; -//! # -//! # #[derive(Debug, Clone)] -//! # pub struct Sig; -//! # -//! # #[derive(Debug, Clone, Copy)] -//! # pub struct A; -//! # #[derive(Debug, Clone, Copy)] -//! # pub struct B; -//! # -//! # #[orchestra(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)] -//! # pub struct Wonderland { -//! # #[subsystem(A, sends: [B])] -//! # foo: Foo, -//! # #[subsystem(B, sends: [A])] -//! # bar: Bar, -//! # } -//! # } -//! # use somewhere::{Yikes, SpawnedSubsystem}; -//! # -//! # struct FooSubsystem; -//! # -//! #[subsystem(Foo, error = Yikes, prefix = somewhere)] -//! impl FooSubsystem { -//! fn start(self, context: Context) -> SpawnedSubsystem { -//! // .. -//! # let _ = context; -//! # unimplemented!() -//! } -//! } -//! ``` -//! -//! expands to -//! -//! ```ignore -//! # use orchestra_proc_macro::subsystem; -//! # mod somewhere { -//! # use orchestra_proc_macro::orchestra; -//! # pub use orchestra::*; -//! # -//! # #[derive(Debug, thiserror::Error)] -//! # #[error("Yikes!")] -//! # pub struct Yikes; -//! # impl From for Yikes { -//! # fn from(_: OrchestraError) -> Yikes { Yikes } -//! # } -//! # impl From for Yikes { -//! # fn from(_: mpsc::SendError) -> Yikes { Yikes } -//! # } -//! # -//! # #[derive(Debug)] -//! # pub struct Eve; -//! # -//! # #[derive(Debug, Clone)] -//! # pub struct Sig; -//! # -//! # #[derive(Debug, Clone, Copy)] -//! # pub struct A; -//! # #[derive(Debug, Clone, Copy)] -//! # pub struct B; -//! # -//! # #[orchestra(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)] -//! # pub struct Wonderland { -//! # #[subsystem(A, sends: [B])] -//! # foo: Foo, -//! # #[subsystem(B, sends: [A])] -//! # bar: Bar, -//! # } -//! # } -//! # use somewhere::{Yikes, SpawnedSubsystem}; -//! # use orchestra as support_crate; -//! # -//! # struct FooSubsystem; -//! # -//! impl support_crate::Subsystem for FooSubsystem -//! where -//! Context: somewhere::FooContextTrait, -//! Context: support_crate::SubsystemContext, -//! ::Sender: somewhere::FooSenderTrait, -//! ::Sender: somewhere::FooSenderTrait, -//! { -//! fn start(self, context: Context) -> SpawnedSubsystem { -//! // .. -//! # let _ = context; -//! # unimplemented!() -//! } -//! } -//! ``` -//! -//! where `support_crate` is either equivalent to `somewhere` or derived from the cargo manifest. -//! -//! -//! ## Add additional trait bounds for a generic `Context` via `contextbounds` -//! -//! ### To an `ImplItem` -//! -//! ```ignore -//! #[contextbounds(Foo, prefix = somewhere)] -//! impl X { -//! .. -//! } -//! ``` -//! -//! expands to -//! -//! ```ignore -//! impl X -//! where -//! Context: somewhere::FooSubsystemTrait, -//! Context: support_crate::SubsystemContext, -//! ::Sender: somewhere::FooSenderTrait, -//! ::Sender: somewhere::FooSenderTrait, -//! { -//! } -//! ``` -//! -//! ### To a free standing `Fn` (not a method, that's covered by the above) -//! -//! ```ignore -//! #[contextbounds(Foo, prefix = somewhere)] -//! fn do_smth(context: &mut Context) { -//! .. -//! } -//! ``` -//! -//! expands to -//! -//! ```ignore -//! fn do_smth(context: &mut Context) -//! where -//! Context: somewhere::FooSubsystemTrait, -//! Context: support_crate::SubsystemContext, -//! ::Sender: somewhere::FooSenderTrait, -//! ::Sender: somewhere::FooSenderTrait, -//! { -//! } -//! ``` -use proc_macro2::TokenStream; -use quote::{format_ident, ToTokens}; -use syn::{parse2, parse_quote, punctuated::Punctuated, Result}; - -use super::{parse::*, *}; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum MakeSubsystem { - /// Implements `trait Subsystem` and apply the trait bounds to the `Context` generic. - /// - /// Relevant to `impl Item` only. - ImplSubsystemTrait, - /// Only apply the trait bounds to the context. - AddContextTraitBounds, -} - -pub(crate) fn impl_subsystem_context_trait_bounds( - attr: TokenStream, - orig: TokenStream, - make_subsystem: MakeSubsystem, -) -> Result { - let args = parse2::(attr.clone())?; - let span = args.span(); - let SubsystemAttrArgs { error_path, subsystem_ident, trait_prefix_path, .. } = args; - - let mut item = parse2::(orig)?; - - // always prefer the direct usage, if it's not there, let's see if there is - // a `prefix=*` provided. Either is ok. - - // Technically this is two different things: - // The place where the `#[orchestra]` is annotated is where all `trait *SenderTrait` and - // `trait *ContextTrait` types exist. - // The other usage is the true support crate `orchestra`, where the static ones - // are declared. - // Right now, if the `support_crate` is not included, it falls back silently to the `trait_prefix_path`. - let support_crate = support_crate() - .or_else(|_e| { - trait_prefix_path.clone().ok_or_else(|| { - syn::Error::new(attr.span(), "Couldn't find `orchestra` in manifest, but also missing a `prefix=` to help trait bound resolution") - }) - })?; - - let trait_prefix_path = trait_prefix_path.unwrap_or_else(|| parse_quote! { self }); - if trait_prefix_path.segments.trailing_punct() { - return Err(syn::Error::new(trait_prefix_path.span(), "Must not end with `::`")) - } - - let subsystem_ctx_trait = format_ident!("{}ContextTrait", subsystem_ident); - let subsystem_sender_trait = format_ident!("{}SenderTrait", subsystem_ident); - - let extra_where_predicates: Punctuated = parse_quote! { - Context: #trait_prefix_path::#subsystem_ctx_trait, - Context: #support_crate::SubsystemContext, - ::Sender: #trait_prefix_path::#subsystem_sender_trait, - ::Sender: #trait_prefix_path::#subsystem_sender_trait, - }; - - let apply_ctx_bound_if_present = move |generics: &mut syn::Generics| -> bool { - if generics - .params - .iter() - .find(|generic| match generic { - syn::GenericParam::Type(ty) if ty.ident == "Context" => true, - _ => false, - }) - .is_some() - { - let where_clause = generics.make_where_clause(); - where_clause.predicates.extend(extra_where_predicates.clone()); - true - } else { - false - } - }; - - match item { - syn::Item::Impl(ref mut struktured_impl) => { - if make_subsystem == MakeSubsystem::ImplSubsystemTrait { - let error_path = error_path.ok_or_else(|| { - syn::Error::new( - span, - "Must annotate the identical orchestra error type via `error=..`.", - ) - })?; - // Only replace the subsystem trait if it's desired. - struktured_impl.trait_.replace(( - None, - parse_quote! { - #support_crate::Subsystem - }, - syn::token::For::default(), - )); - } - - apply_ctx_bound_if_present(&mut struktured_impl.generics); - for item in struktured_impl.items.iter_mut() { - match item { - syn::ImplItem::Method(method) => { - apply_ctx_bound_if_present(&mut method.sig.generics); - }, - _others => { - // don't error, just nop - }, - } - } - }, - syn::Item::Fn(ref mut struktured_fn) => { - if make_subsystem == MakeSubsystem::ImplSubsystemTrait { - return Err(syn::Error::new(struktured_fn.span(), "Cannot make a free function a subsystem, did you mean to apply `contextbound` instead?")) - } - apply_ctx_bound_if_present(&mut struktured_fn.sig.generics); - }, - other => - return Err(syn::Error::new( - other.span(), - "Macro can only be annotated on functions or struct implementations", - )), - }; - - Ok(item.to_token_stream()) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn is_path() { - let _p: Path = parse_quote! { self }; - let _p: Path = parse_quote! { crate }; - let _p: Path = parse_quote! { ::foo }; - let _p: Path = parse_quote! { bar }; - } -} diff --git a/node/orchestra/proc-macro/src/tests.rs b/node/orchestra/proc-macro/src/tests.rs deleted file mode 100644 index 2b19b5f29a56..000000000000 --- a/node/orchestra/proc-macro/src/tests.rs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::*; -use assert_matches::assert_matches; -use quote::quote; -use syn::parse_quote; - -#[test] -fn print() { - let attr = quote! { - gen=AllMessage, - event=::some::why::ExternEvent, - signal=SigSigSig, - signal_capacity=111, - message_capacity=222, - error=OrchestraError, - }; - - let item = quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(Foo)] - sub0: FooSubsystem, - - #[subsystem(blocking, Bar)] - yyy: BaersBuyBilliardBalls, - - #[subsystem(blocking, Twain)] - fff: Beeeeep, - - #[subsystem(Rope)] - mc: MountainCave, - - metrics: Metrics, - } - }; - - let output = impl_orchestra_gen(attr, item).expect("Simple example always works. qed"); - println!("//generated:"); - println!("{}", output); -} - -#[test] -fn struct_parse_full() { - let item: OrchestraGuts = parse_quote! { - pub struct Ooooh where X: Secrit { - #[subsystem(Foo)] - sub0: FooSubsystem, - - #[subsystem(blocking, Bar)] - yyy: BaersBuyBilliardBalls, - - #[subsystem(blocking, Twain)] - fff: Beeeeep, - - #[subsystem(Rope)] - mc: MountainCave, - - metrics: Metrics, - } - }; - let _ = dbg!(item); -} - -#[test] -fn struct_parse_basic() { - let item: OrchestraGuts = parse_quote! { - pub struct Ooooh { - #[subsystem(Foo)] - sub0: FooSubsystem, - } - }; - let _ = dbg!(item); -} - -#[test] -fn attr_full() { - let attr: OrchestraAttrArgs = parse_quote! { - gen=AllMessage, event=::some::why::ExternEvent, signal=SigSigSig, signal_capacity=111, message_capacity=222, - error=OrchestraError, - }; - assert_matches!(attr, OrchestraAttrArgs { - message_channel_capacity, - signal_channel_capacity, - .. - } => { - assert_eq!(message_channel_capacity, 222); - assert_eq!(signal_channel_capacity, 111); - }); -} - -#[test] -fn attr_partial() { - let attr: OrchestraAttrArgs = parse_quote! { - gen=AllMessage, event=::some::why::ExternEvent, signal=::foo::SigSigSig, - error=OrchestraError, - }; - assert_matches!(attr, OrchestraAttrArgs { - message_channel_capacity: _, - signal_channel_capacity: _, - .. - } => { - }); -} diff --git a/node/orchestra/src/lib.rs b/node/orchestra/src/lib.rs deleted file mode 100644 index 15bd661e7200..000000000000 --- a/node/orchestra/src/lib.rs +++ /dev/null @@ -1,549 +0,0 @@ -// Copyright (C) 2021 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! # Orchestra -//! -//! `orchestra` provides a global information flow of what a token of information. -//! The token is arbitrary, but is used to notify all `Subsystem`s of what is relevant -//! and what is not. -//! -//! For the motivations behind implementing the orchestra itself you should -//! check out that guide, documentation in this crate will focus and be of -//! technical nature. -//! -//! An `Orchestra` is something that allows spawning/stopping and orchestrating -//! asynchronous tasks as well as establishing a well-defined and easy to use -//! protocol that the tasks can use to communicate with each other. It is desired -//! that this protocol is the only way tasks communicate with each other, however -//! at this moment there are no foolproof guards against other ways of communication. -//! -//! The `Orchestra` is instantiated with a pre-defined set of `Subsystems` that -//! share the same behavior from `Orchestra`'s point of view. -//! -//! ```text -//! +-----------------------------+ -//! | Orchesta | -//! +-----------------------------+ -//! -//! ................| Orchestra "holds" these and uses |............. -//! . them to (re)start things . -//! . . -//! . +-------------------+ +---------------------+ . -//! . | Subsystem1 | | Subsystem2 | . -//! . +-------------------+ +---------------------+ . -//! . | | . -//! .................................................................. -//! | | -//! start() start() -//! V V -//! ..................| Orchestra "runs" these |....................... -//! . +--------------------+ +---------------------+ . -//! . | SubsystemInstance1 | <-- bidir --> | SubsystemInstance2 | . -//! . +--------------------+ +---------------------+ . -//! .................................................................. -//! ``` - -// #![deny(unused_results)] -// unused dependencies can not work for test and examples at the same time -// yielding false positives -#![deny(missing_docs)] -#![deny(unused_crate_dependencies)] - -pub use orchestra_proc_macro::{contextbounds, orchestra, subsystem}; - -#[doc(hidden)] -pub use metered; -#[doc(hidden)] -pub use tracing; - -#[doc(hidden)] -pub use async_trait::async_trait; -#[doc(hidden)] -pub use futures::{ - self, - channel::{mpsc, oneshot}, - future::{BoxFuture, Fuse, Future}, - poll, select, - stream::{self, select, select_with_strategy, FuturesUnordered, PollNext}, - task::{Context, Poll}, - FutureExt, StreamExt, -}; -#[doc(hidden)] -pub use std::pin::Pin; - -use std::sync::{ - atomic::{self, AtomicUsize}, - Arc, -}; -#[doc(hidden)] -pub use std::time::Duration; - -#[doc(hidden)] -pub use futures_timer::Delay; - -use std::fmt; - -#[cfg(test)] -mod tests; - -/// A spawner -#[dyn_clonable::clonable] -pub trait Spawner: Clone + Send + Sync { - /// Spawn the given blocking future. - /// - /// The given `group` and `name` is used to identify the future in tracing. - fn spawn_blocking( - &self, - name: &'static str, - group: Option<&'static str>, - future: futures::future::BoxFuture<'static, ()>, - ); - /// Spawn the given non-blocking future. - /// - /// The given `group` and `name` is used to identify the future in tracing. - fn spawn( - &self, - name: &'static str, - group: Option<&'static str>, - future: futures::future::BoxFuture<'static, ()>, - ); -} - -/// A type of messages that are sent from a [`Subsystem`] to the declared orchestra. -/// -/// Used to launch jobs. -pub enum ToOrchestra { - /// A message that wraps something the `Subsystem` is desiring to - /// spawn on the orchestra and a `oneshot::Sender` to signal the result - /// of the spawn. - SpawnJob { - /// Name of the task to spawn which be shown in jaeger and tracing logs. - name: &'static str, - /// Subsystem of the task to spawn which be shown in jaeger and tracing logs. - subsystem: Option<&'static str>, - /// The future to execute. - s: BoxFuture<'static, ()>, - }, - - /// Same as `SpawnJob` but for blocking tasks to be executed on a - /// dedicated thread pool. - SpawnBlockingJob { - /// Name of the task to spawn which be shown in jaeger and tracing logs. - name: &'static str, - /// Subsystem of the task to spawn which be shown in jaeger and tracing logs. - subsystem: Option<&'static str>, - /// The future to execute. - s: BoxFuture<'static, ()>, - }, -} - -impl fmt::Debug for ToOrchestra { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::SpawnJob { name, subsystem, .. } => { - writeln!(f, "SpawnJob{{ {}, {} ..}}", name, subsystem.unwrap_or("default")) - }, - Self::SpawnBlockingJob { name, subsystem, .. } => { - writeln!(f, "SpawnBlockingJob{{ {}, {} ..}}", name, subsystem.unwrap_or("default")) - }, - } - } -} - -/// A helper trait to map a subsystem to smth. else. -pub trait MapSubsystem { - /// The output type of the mapping. - type Output; - - /// Consumes a `T` per subsystem, and maps it to `Self::Output`. - fn map_subsystem(&self, sub: T) -> Self::Output; -} - -impl MapSubsystem for F -where - F: Fn(T) -> U, -{ - type Output = U; - - fn map_subsystem(&self, sub: T) -> U { - (self)(sub) - } -} - -/// A wrapping type for messages. -/// -/// Includes a counter to synchronize signals with messages, -/// such that no inconsistent message sequences are prevented. -#[derive(Debug)] -pub struct MessagePacket { - /// Signal level at the point of reception. - /// - /// Required to assure signals were consumed _before_ - /// consuming messages that are based on the assumption - /// that a certain signal was assumed. - pub signals_received: usize, - /// The message to be sent/consumed. - pub message: T, -} - -/// Create a packet from its parts. -pub fn make_packet(signals_received: usize, message: T) -> MessagePacket { - MessagePacket { signals_received, message } -} - -/// A functor to specify strategy of the channels selection in the `SubsystemIncomingMessages` -pub fn select_message_channel_strategy(_: &mut ()) -> PollNext { - PollNext::Right -} - -/// Incoming messages from both the bounded and unbounded channel. -pub type SubsystemIncomingMessages = self::stream::SelectWithStrategy< - self::metered::MeteredReceiver>, - self::metered::UnboundedMeteredReceiver>, - fn(&mut ()) -> self::stream::PollNext, - (), ->; - -/// Watermark to track the received signals. -#[derive(Debug, Default, Clone)] -pub struct SignalsReceived(Arc); - -impl SignalsReceived { - /// Load the current value of received signals. - pub fn load(&self) -> usize { - // It's imperative that we prevent reading a stale value from memory because of reordering. - // Memory barrier to ensure that no reads or writes in the current thread before this load are reordered. - // All writes in other threads using release semantics become visible to the current thread. - self.0.load(atomic::Ordering::Acquire) - } - - /// Increase the number of signals by one. - pub fn inc(&self) { - self.0.fetch_add(1, atomic::Ordering::AcqRel); - } -} - -/// A trait to support the origin annotation -/// such that errors across subsystems can be easier tracked. -pub trait AnnotateErrorOrigin: 'static + Send + Sync + std::error::Error { - /// Annotate the error with a origin `str`. - /// - /// Commonly this is used to create nested enum variants. - /// - /// ```rust,ignore - /// E::WithOrigin("I am originally from Cowtown.", E::Variant) - /// ``` - fn with_origin(self, origin: &'static str) -> Self; -} - -/// An asynchronous subsystem task.. -/// -/// In essence it's just a new type wrapping a `BoxFuture`. -pub struct SpawnedSubsystem -where - E: std::error::Error + Send + Sync + 'static + From, -{ - /// Name of the subsystem being spawned. - pub name: &'static str, - /// The task of the subsystem being spawned. - pub future: BoxFuture<'static, Result<(), E>>, -} - -/// An error type that describes faults that may happen -/// -/// These are: -/// * Channels being closed -/// * Subsystems dying when they are not expected to -/// * Subsystems not dying when they are told to die -/// * etc. -#[derive(thiserror::Error, Debug)] -#[allow(missing_docs)] -pub enum OrchestraError { - #[error(transparent)] - NotifyCancellation(#[from] oneshot::Canceled), - - #[error(transparent)] - QueueError(#[from] mpsc::SendError), - - #[error("Failed to spawn task {0}")] - TaskSpawn(&'static str), - - #[error(transparent)] - Infallible(#[from] std::convert::Infallible), - - #[error("Failed to {0}")] - Context(String), - - #[error("Subsystem stalled: {0}")] - SubsystemStalled(&'static str), - - /// Per origin (or subsystem) annotations to wrap an error. - #[error("Error originated in {origin}")] - FromOrigin { - /// An additional annotation tag for the origin of `source`. - origin: &'static str, - /// The wrapped error. Marked as source for tracking the error chain. - #[source] - source: Box, - }, -} - -/// Alias for a result with error type `OrchestraError`. -pub type OrchestraResult = std::result::Result; - -/// Collection of meters related to a subsystem. -#[derive(Clone)] -pub struct SubsystemMeters { - #[allow(missing_docs)] - pub bounded: metered::Meter, - #[allow(missing_docs)] - pub unbounded: metered::Meter, - #[allow(missing_docs)] - pub signals: metered::Meter, -} - -impl SubsystemMeters { - /// Read the values of all subsystem `Meter`s. - pub fn read(&self) -> SubsystemMeterReadouts { - SubsystemMeterReadouts { - bounded: self.bounded.read(), - unbounded: self.unbounded.read(), - signals: self.signals.read(), - } - } -} - -/// Set of readouts of the `Meter`s of a subsystem. -pub struct SubsystemMeterReadouts { - #[allow(missing_docs)] - pub bounded: metered::Readout, - #[allow(missing_docs)] - pub unbounded: metered::Readout, - #[allow(missing_docs)] - pub signals: metered::Readout, -} - -/// A running instance of some [`Subsystem`]. -/// -/// [`Subsystem`]: trait.Subsystem.html -/// -/// `M` here is the inner message type, and _not_ the generated `enum AllMessages` or `#message_wrapper` type. -pub struct SubsystemInstance { - /// Send sink for `Signal`s to be sent to a subsystem. - pub tx_signal: crate::metered::MeteredSender, - /// Send sink for `Message`s to be sent to a subsystem. - pub tx_bounded: crate::metered::MeteredSender>, - /// All meters of the particular subsystem instance. - pub meters: SubsystemMeters, - /// The number of signals already received. - /// Required to assure messages and signals - /// are processed correctly. - pub signals_received: usize, - /// Name of the subsystem instance. - pub name: &'static str, -} - -/// A message type that a subsystem receives from an orchestra. -/// It wraps signals from an orchestra and messages that are circulating -/// between subsystems. -/// -/// It is generic over over the message type `M` that a particular `Subsystem` may use. -#[derive(Debug)] -pub enum FromOrchestra { - /// Signal from the `Orchestra`. - Signal(Signal), - - /// Some other `Subsystem`'s message. - Communication { - /// Contained message - msg: Message, - }, -} - -impl From for FromOrchestra { - fn from(signal: Signal) -> Self { - Self::Signal(signal) - } -} - -/// A context type that is given to the [`Subsystem`] upon spawning. -/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s -/// or spawn jobs. -/// -/// [`Orchestra`]: struct.Orchestra.html -/// [`SubsystemJob`]: trait.SubsystemJob.html -#[async_trait::async_trait] -pub trait SubsystemContext: Send + 'static { - /// The message type of this context. Subsystems launched with this context will expect - /// to receive messages of this type. Commonly uses the wrapping `enum` commonly called - /// `AllMessages`. - type Message: ::std::fmt::Debug + Send + 'static; - /// And the same for signals. - type Signal: ::std::fmt::Debug + Send + 'static; - /// The overarching messages `enum` for this particular subsystem. - type OutgoingMessages: ::std::fmt::Debug + Send + 'static; - - // The overarching messages `enum` for this particular subsystem. - // type AllMessages: From + From + std::fmt::Debug + Send + 'static; - - /// The sender type as provided by `sender()` and underlying. - type Sender: Clone + Send + 'static + SubsystemSender; - /// The error type. - type Error: ::std::error::Error + ::std::convert::From + Sync + Send + 'static; - - /// Try to asynchronously receive a message. - /// - /// Has to be used with caution, if you loop over this without - /// using `pending!()` macro you will end up with a busy loop! - async fn try_recv(&mut self) -> Result>, ()>; - - /// Receive a message. - async fn recv(&mut self) -> Result, Self::Error>; - - /// Spawn a child task on the executor. - fn spawn( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>>, - ) -> Result<(), Self::Error>; - - /// Spawn a blocking child task on the executor's dedicated thread pool. - fn spawn_blocking( - &mut self, - name: &'static str, - s: ::std::pin::Pin + Send>>, - ) -> Result<(), Self::Error>; - - /// Send a direct message to some other `Subsystem`, routed based on message type. - // #[deprecated(note = "Use `self.sender().send_message(msg) instead, avoid passing around the full context.")] - async fn send_message(&mut self, msg: T) - where - Self::OutgoingMessages: From + Send, - T: Send, - { - self.sender().send_message(::from(msg)).await - } - - /// Send multiple direct messages to other `Subsystem`s, routed based on message type. - // #[deprecated(note = "Use `self.sender().send_message(msg) instead, avoid passing around the full context.")] - async fn send_messages(&mut self, msgs: I) - where - Self::OutgoingMessages: From + Send, - I: IntoIterator + Send, - I::IntoIter: Send, - T: Send, - { - self.sender() - .send_messages(msgs.into_iter().map(::from)) - .await - } - - /// Send a message using the unbounded connection. - // #[deprecated(note = "Use `self.sender().send_unbounded_message(msg) instead, avoid passing around the full context.")] - fn send_unbounded_message(&mut self, msg: X) - where - Self::OutgoingMessages: From + Send, - X: Send, - { - self.sender().send_unbounded_message(::from(msg)) - } - - /// Obtain the sender. - fn sender(&mut self) -> &mut Self::Sender; -} - -/// A trait that describes the [`Subsystem`]s that can run on the [`Orchestra`]. -/// -/// It is generic over the message type circulating in the system. -/// The idea that we want some type containing persistent state that -/// can spawn actually running subsystems when asked. -/// -/// [`Orchestra`]: struct.Orchestra.html -/// [`Subsystem`]: trait.Subsystem.html -pub trait Subsystem -where - Ctx: SubsystemContext, - E: std::error::Error + Send + Sync + 'static + From, -{ - /// Start this `Subsystem` and return `SpawnedSubsystem`. - fn start(self, ctx: Ctx) -> SpawnedSubsystem; -} - -/// Sender end of a channel to interface with a subsystem. -#[async_trait::async_trait] -pub trait SubsystemSender: Clone + Send + 'static -where - OutgoingMessage: Send, -{ - /// Send a direct message to some other `Subsystem`, routed based on message type. - async fn send_message(&mut self, msg: OutgoingMessage); - - /// Send multiple direct messages to other `Subsystem`s, routed based on message type. - async fn send_messages(&mut self, msgs: I) - where - I: IntoIterator + Send, - I::IntoIter: Send; - - /// Send a message onto the unbounded queue of some other `Subsystem`, routed based on message - /// type. - /// - /// This function should be used only when there is some other bounding factor on the messages - /// sent with it. Otherwise, it risks a memory leak. - fn send_unbounded_message(&mut self, msg: OutgoingMessage); -} - -/// A future that wraps another future with a `Delay` allowing for time-limited futures. -#[pin_project::pin_project] -pub struct Timeout { - #[pin] - future: F, - #[pin] - delay: Delay, -} - -/// Extends `Future` to allow time-limited futures. -pub trait TimeoutExt: Future { - /// Adds a timeout of `duration` to the given `Future`. - /// Returns a new `Future`. - fn timeout(self, duration: Duration) -> Timeout - where - Self: Sized, - { - Timeout { future: self, delay: Delay::new(duration) } - } -} - -impl TimeoutExt for F where F: Future {} - -impl Future for Timeout -where - F: Future, -{ - type Output = Option; - - fn poll(self: Pin<&mut Self>, ctx: &mut Context) -> Poll { - let this = self.project(); - - if this.delay.poll(ctx).is_ready() { - return Poll::Ready(None) - } - - if let Poll::Ready(output) = this.future.poll(ctx) { - return Poll::Ready(Some(output)) - } - - Poll::Pending - } -} diff --git a/node/orchestra/src/tests.rs b/node/orchestra/src/tests.rs deleted file mode 100644 index 4b622faf889f..000000000000 --- a/node/orchestra/src/tests.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#[test] -#[rustversion::attr(not(stable), ignore)] -fn ui_compile_fail() { - // Only run the ui tests when `RUN_UI_TESTS` is set. - if std::env::var("RUN_UI_TESTS").is_err() { - return - } - - let t = trybuild::TestCases::new(); - t.compile_fail("tests/ui/err-*.rs"); -} - -#[test] -#[rustversion::attr(not(stable), ignore)] -fn ui_pass() { - // Only run the ui tests when `RUN_UI_TESTS` is set. - if std::env::var("RUN_UI_TESTS").is_err() { - return - } - - let t = trybuild::TestCases::new(); - t.pass("tests/ui/ok-*.rs"); -} diff --git a/node/orchestra/tests/ui/err-01-duplicate-consumer.rs b/node/orchestra/tests/ui/err-01-duplicate-consumer.rs deleted file mode 100644 index 589bcede9963..000000000000 --- a/node/orchestra/tests/ui/err-01-duplicate-consumer.rs +++ /dev/null @@ -1,38 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -#[derive(Default)] -struct AwesomeSubSys2; - -#[derive(Clone, Debug)] -struct SigSigSig; - -struct Event; - -#[derive(Clone)] -struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - - #[subsystem(MsgStrukt)] - sub1: AwesomeSubSys2, -} - -#[derive(Debug, Clone)] -struct DummySpawner; - -struct DummyCtx; - -fn main() { - let orchestra = Orchestra::<_,_>::builder() - .sub0(AwesomeSubSys::default()) - .spawner(DummySpawner) - .build(|| -> DummyCtx { DummyCtx } ); -} diff --git a/node/orchestra/tests/ui/err-01-duplicate-consumer.stderr b/node/orchestra/tests/ui/err-01-duplicate-consumer.stderr deleted file mode 100644 index af27b95a2ea0..000000000000 --- a/node/orchestra/tests/ui/err-01-duplicate-consumer.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0119]: conflicting implementations of trait `std::convert::From` for type `AllMessages` - --> tests/ui/err-01-duplicate-consumer.rs:19:1 - | -19 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | first implementation here - | conflicting implementation for `AllMessages` - | - = note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0119]: conflicting implementations of trait `AssociateOutgoing` for type `MsgStrukt` - --> tests/ui/err-01-duplicate-consumer.rs:19:1 - | -19 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | first implementation here - | conflicting implementation for `MsgStrukt` - | - = note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/node/orchestra/tests/ui/err-02-enum.rs b/node/orchestra/tests/ui/err-02-enum.rs deleted file mode 100644 index 8d1ddeac6dda..000000000000 --- a/node/orchestra/tests/ui/err-02-enum.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -struct SigSigSig; - -struct Event; - -#[derive(Clone, Debug)] -struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] -enum Orchestra { - #[subsystem(MsgStrukt)] - Sub0(AwesomeSubSys), -} - -#[derive(Debug, Clone)] -struct DummySpawner; - -struct DummyCtx; - -fn main() { - let orchestra = Orchestra::<_,_>::builder() - .sub0(AwesomeSubSys::default()) - .i_like_pie(std::f64::consts::PI) - .spawner(DummySpawner) - .build(|| -> DummyCtx { DummyCtx } ); -} diff --git a/node/orchestra/tests/ui/err-02-enum.stderr b/node/orchestra/tests/ui/err-02-enum.stderr deleted file mode 100644 index 4694f5db9730..000000000000 --- a/node/orchestra/tests/ui/err-02-enum.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: expected `struct` - --> tests/ui/err-02-enum.rs:16:1 - | -16 | enum Orchestra { - | ^^^^ - -error[E0433]: failed to resolve: use of undeclared type `Orchestra` - --> tests/ui/err-02-enum.rs:27:18 - | -27 | let orchestra = Orchestra::<_,_>::builder() - | ^^^^^^^^^ use of undeclared type `Orchestra` diff --git a/node/orchestra/tests/ui/err-03-subsys-twice.rs b/node/orchestra/tests/ui/err-03-subsys-twice.rs deleted file mode 100644 index 187d9e1e7a5b..000000000000 --- a/node/orchestra/tests/ui/err-03-subsys-twice.rs +++ /dev/null @@ -1,39 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -#[derive(Clone, Debug)] -struct SigSigSig; - -struct Event; - -#[derive(Clone, Debug)] -struct MsgStrukt(u8); - -#[derive(Clone, Debug)] -struct MsgStrukt2(f64); - -#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - - #[subsystem(MsgStrukt2)] - sub1: AwesomeSubSys, -} - -#[derive(Debug, Clone)] -struct DummySpawner; - -struct DummyCtx; - -fn main() { - let orchestra = Orchestra::<_,_>::builder() - .sub0(AwesomeSubSys::default()) - .i_like_pie(std::f64::consts::PI) - .spawner(DummySpawner) - .build(|| -> DummyCtx { DummyCtx } ); -} diff --git a/node/orchestra/tests/ui/err-03-subsys-twice.stderr b/node/orchestra/tests/ui/err-03-subsys-twice.stderr deleted file mode 100644 index de69031b248b..000000000000 --- a/node/orchestra/tests/ui/err-03-subsys-twice.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error: Duplicate subsystem names - --> tests/ui/err-03-subsys-twice.rs:25:8 - | -25 | sub1: AwesomeSubSys, - | ^^^^^^^^^^^^^ - -error: previously defined here. - --> tests/ui/err-03-subsys-twice.rs:22:8 - | -22 | sub0: AwesomeSubSys, - | ^^^^^^^^^^^^^ - -error[E0433]: failed to resolve: use of undeclared type `Orchestra` - --> tests/ui/err-03-subsys-twice.rs:34:18 - | -34 | let orchestra = Orchestra::<_,_>::builder() - | ^^^^^^^^^ use of undeclared type `Orchestra` diff --git a/node/orchestra/tests/ui/err-04-missing-error.rs b/node/orchestra/tests/ui/err-04-missing-error.rs deleted file mode 100644 index 74672a4549a4..000000000000 --- a/node/orchestra/tests/ui/err-04-missing-error.rs +++ /dev/null @@ -1,36 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -#[derive(Clone, Debug)] -struct SigSigSig; - -struct Event; - -#[derive(Clone)] -struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - - i_like_pie: f64, -} - -#[derive(Debug, Clone)] -struct DummySpawner; - -struct DummyCtx; - -fn main() { - let _ = Orchestra::builder() - .sub0(AwesomeSubSys::default()) - .i_like_pie(std::f64::consts::PI) - .spawner(DummySpawner) - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-04-missing-error.stderr b/node/orchestra/tests/ui/err-04-missing-error.stderr deleted file mode 100644 index 70c3e790eafc..000000000000 --- a/node/orchestra/tests/ui/err-04-missing-error.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: Must declare the orchestra error type via `error=..`. - --> tests/ui/err-04-missing-error.rs:16:1 - | -16 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0433]: failed to resolve: use of undeclared type `Orchestra` - --> tests/ui/err-04-missing-error.rs:30:10 - | -30 | let _ = Orchestra::builder() - | ^^^^^^^^^ use of undeclared type `Orchestra` diff --git a/node/orchestra/tests/ui/err-05-missing-field.rs b/node/orchestra/tests/ui/err-05-missing-field.rs deleted file mode 100644 index f351724072b6..000000000000 --- a/node/orchestra/tests/ui/err-05-missing-field.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSys { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - unimplemented!("starting yay!") - } -} - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - i_like_pie: f64, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -struct DummyCtx; - -fn main() { - let _ = Orchestra::builder() - .sub0(AwesomeSubSys::default()) - //.i_like_pie(std::f64::consts::PI) // The filed is not initialised - .spawner(DummySpawner) - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-05-missing-field.stderr b/node/orchestra/tests/ui/err-05-missing-field.stderr deleted file mode 100644 index 84778a427552..000000000000 --- a/node/orchestra/tests/ui/err-05-missing-field.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0599]: no method named `build` found for struct `OrchestraBuilder, Init, Missing>` in the current scope - --> tests/ui/err-05-missing-field.rs:59:4 - | -22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] - | ---------------------------------------------------------------------------------- method `build` not found for this struct -... -59 | .build() - | ^^^^^ method not found in `OrchestraBuilder, Init, Missing>` - | - = note: the method was found for - - `OrchestraBuilder, Init, Init>` diff --git a/node/orchestra/tests/ui/err-06-missing-subsystem.rs b/node/orchestra/tests/ui/err-06-missing-subsystem.rs deleted file mode 100644 index 85b1b2f618fe..000000000000 --- a/node/orchestra/tests/ui/err-06-missing-subsystem.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSys { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - unimplemented!("starting yay!") - } -} - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - i_like_pie: f64, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -struct DummyCtx; - -fn main() { - let _ = Orchestra::builder() - //.sub0(AwesomeSubSys::default()) // Subsystem is uninitialized - .i_like_pie(std::f64::consts::PI) - .spawner(DummySpawner) - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-06-missing-subsystem.stderr b/node/orchestra/tests/ui/err-06-missing-subsystem.stderr deleted file mode 100644 index 767d7feae398..000000000000 --- a/node/orchestra/tests/ui/err-06-missing-subsystem.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0599]: no method named `build` found for struct `OrchestraBuilder, Missing<_>, Init>` in the current scope - --> tests/ui/err-06-missing-subsystem.rs:59:4 - | -22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] - | ---------------------------------------------------------------------------------- method `build` not found for this struct -... -59 | .build() - | ^^^^^ method not found in `OrchestraBuilder, Missing<_>, Init>` - | - = note: the method was found for - - `OrchestraBuilder, Init, Init>` diff --git a/node/orchestra/tests/ui/err-07-missing-spawner.rs b/node/orchestra/tests/ui/err-07-missing-spawner.rs deleted file mode 100644 index 45f0af1c6e50..000000000000 --- a/node/orchestra/tests/ui/err-07-missing-spawner.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSys { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - unimplemented!("starting yay!") - } -} - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - i_like_pie: f64, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -struct DummyCtx; - -fn main() { - let _ = Orchestra::builder() - .sub0(AwesomeSubSys::default()) - .i_like_pie(std::f64::consts::PI) - //.spawner(DummySpawner) // Spawner is missing - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-07-missing-spawner.stderr b/node/orchestra/tests/ui/err-07-missing-spawner.stderr deleted file mode 100644 index 1b5fb5413ced..000000000000 --- a/node/orchestra/tests/ui/err-07-missing-spawner.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0599]: no method named `build` found for struct `OrchestraBuilder, Init, Init>` in the current scope - --> tests/ui/err-07-missing-spawner.rs:59:4 - | -22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] - | ---------------------------------------------------------------------------------- method `build` not found for this struct -... -59 | .build() - | ^^^^^ method not found in `OrchestraBuilder, Init, Init>` - | - = note: the method was found for - - `OrchestraBuilder, Init, Init>` diff --git a/node/orchestra/tests/ui/err-08-duplicate-subsystem.rs b/node/orchestra/tests/ui/err-08-duplicate-subsystem.rs deleted file mode 100644 index 8a3eab1ee726..000000000000 --- a/node/orchestra/tests/ui/err-08-duplicate-subsystem.rs +++ /dev/null @@ -1,62 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSys { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - unimplemented!("starting yay!") - } -} - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - i_like_pie: f64, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -struct DummyCtx; - -fn main() { - let _ = Orchestra::builder() - .sub0(AwesomeSubSys::default()) - .sub0(AwesomeSubSys::default()) // Duplicate subsystem - .i_like_pie(std::f64::consts::PI) - .spawner(DummySpawner) - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-08-duplicate-subsystem.stderr b/node/orchestra/tests/ui/err-08-duplicate-subsystem.stderr deleted file mode 100644 index b95c0d0a7daf..000000000000 --- a/node/orchestra/tests/ui/err-08-duplicate-subsystem.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error[E0599]: no method named `sub0` found for struct `OrchestraBuilder, Init, Missing>` in the current scope - --> tests/ui/err-08-duplicate-subsystem.rs:57:4 - | -22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] - | ---------------------------------------------------------------------------------- method `sub0` not found for this struct -... -57 | .sub0(AwesomeSubSys::default()) // Duplicate subsystem - | ^^^^-------------------------- help: remove the arguments - | | - | field, not a method diff --git a/node/orchestra/tests/ui/err-09-uninit_generic_baggage.rs b/node/orchestra/tests/ui/err-09-uninit_generic_baggage.rs deleted file mode 100644 index c90979c4e4e8..000000000000 --- a/node/orchestra/tests/ui/err-09-uninit_generic_baggage.rs +++ /dev/null @@ -1,61 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSys; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSys { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - unimplemented!("starting yay!") - } -} - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgStrukt(u8); - -#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] -struct Orchestra { - #[subsystem(MsgStrukt)] - sub0: AwesomeSubSys, - i_like_pie: T, -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - unimplemented!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -struct DummyCtx; - -fn main() { - let (_, _): (Orchestra<_, f64>, _) = Orchestra::builder() - .sub0(AwesomeSubSys::default()) - //.i_like_pie(std::f64::consts::PI) // The filed is not initialised - .spawner(DummySpawner) - .build() - .unwrap(); -} diff --git a/node/orchestra/tests/ui/err-09-uninit_generic_baggage.stderr b/node/orchestra/tests/ui/err-09-uninit_generic_baggage.stderr deleted file mode 100644 index ef9743fcdf22..000000000000 --- a/node/orchestra/tests/ui/err-09-uninit_generic_baggage.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0599]: no method named `build` found for struct `OrchestraBuilder, Init, Missing<_>>` in the current scope - --> tests/ui/err-09-uninit_generic_baggage.rs:59:4 - | -22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)] - | ---------------------------------------------------------------------------------- method `build` not found for this struct -... -59 | .build() - | ^^^^^ method not found in `OrchestraBuilder, Init, Missing<_>>` - | - = note: the method was found for - - `OrchestraBuilder, Init, Init>` diff --git a/node/orchestra/tests/ui/ok-01-wip.rs b/node/orchestra/tests/ui/ok-01-wip.rs deleted file mode 100644 index 5a2fad40540e..000000000000 --- a/node/orchestra/tests/ui/ok-01-wip.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![allow(dead_code)] - -use orchestra::*; - -#[derive(Default)] -struct AwesomeSubSysA; - -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSysA { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - SpawnedSubsystem { name: "sub A", future: Box::pin(async move { Ok(()) }) } - } -} -impl ::orchestra::Subsystem, OrchestraError> for AwesomeSubSysB { - fn start(self, _ctx: OrchestraSubsystemContext) -> SpawnedSubsystem { - SpawnedSubsystem { name: "sub B", future: Box::pin(async move { Ok(()) }) } - } -} - -#[derive(Debug, Clone)] -pub struct DummySpawner; - -impl Spawner for DummySpawner { - fn spawn_blocking( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - println!("spawn blocking {} {}", task_name, subsystem_name.unwrap_or("default")) - } - - fn spawn( - &self, - task_name: &'static str, - subsystem_name: Option<&'static str>, - _future: futures::future::BoxFuture<'static, ()>, - ) { - println!("spawn {} {}", task_name, subsystem_name.unwrap_or("default")) - } -} - -#[derive(Default)] -pub struct AwesomeSubSysB; - -#[derive(Clone, Debug)] -pub struct SigSigSig; - -pub struct Event; - -#[derive(Clone, Debug)] -pub struct MsgA(u8); - -#[derive(Clone, Debug)] -pub struct MsgB(u8); - -#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)] -pub struct Orchestra { - #[subsystem(MsgA)] - sub_a: AwesomeSubSysA, - - #[subsystem(wip, MsgB)] - sub_b: AwesomeSubSysB, -} - -pub struct DummyCtx; - -fn main() { - let _orchestra_builder = Orchestra::builder() - .sub_a(AwesomeSubSysA::default()) - // b is tagged as `wip` - // .sub_b(AwesomeSubSysB::default()) - .spawner(DummySpawner) - .build(); -} diff --git a/node/overseer/Cargo.toml b/node/overseer/Cargo.toml index d25639084eb5..0db382e4e783 100644 --- a/node/overseer/Cargo.toml +++ b/node/overseer/Cargo.toml @@ -15,7 +15,7 @@ polkadot-node-primitives = { path = "../primitives" } polkadot-node-subsystem-types = { path = "../subsystem-types" } polkadot-node-metrics = { path = "../metrics" } polkadot-primitives = { path = "../../primitives" } -orchestra = { path = "../orchestra" } +orchestra = "0.0.2" gum = { package = "tracing-gum", path = "../gum" } lru = "0.7" parity-util-mem = { version = "0.11.0", default-features = false } @@ -23,7 +23,8 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } async-trait = "0.1.57" [dev-dependencies] -metered = { package = "prioritized-metered-channel", path = "../metered-channel" } +metered = { package = "prioritized-metered-channel", version = "0.2.0" } + sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } futures = { version = "0.3.21", features = ["thread-pool"] } femme = "2.2.1" diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 9f16feeff8ea..e2c0a7bfdf94 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -190,7 +190,8 @@ fn default_parachains_host_configuration( max_upward_queue_count: 8, max_upward_queue_size: 1024 * 1024, max_downward_message_size: 1024 * 1024, - ump_service_total_weight: Weight::from_ref_time(100_000_000_000), + ump_service_total_weight: Weight::from_ref_time(100_000_000_000) + .set_proof_size(MAX_POV_SIZE as u64), max_upward_message_size: 50 * 1024, max_upward_message_num_per_candidate: 5, hrmp_sender_deposit: 0, diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 3ae207be8e13..6425ee7a7536 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -849,13 +849,24 @@ where .extra_sets .push(grandpa::grandpa_peers_set_config(grandpa_protocol_name.clone())); - let beefy_protocol_name = - beefy_gadget::protocol_standard_name(&genesis_hash, &config.chain_spec); + let beefy_gossip_proto_name = + beefy_gadget::gossip_protocol_name(&genesis_hash, config.chain_spec.fork_id()); + // `beefy_on_demand_justifications_handler` is given to `beefy-gadget` task to be run, + // while `beefy_req_resp_cfg` is added to `config.network.request_response_protocols`. + let (beefy_on_demand_justifications_handler, beefy_req_resp_cfg) = + beefy_gadget::communication::request_response::BeefyJustifsRequestHandler::new( + &genesis_hash, + config.chain_spec.fork_id(), + client.clone(), + ); if enable_beefy { config .network .extra_sets - .push(beefy_gadget::beefy_peers_set_config(beefy_protocol_name.clone())); + .push(beefy_gadget::communication::beefy_peers_set_config( + beefy_gossip_proto_name.clone(), + )); + config.network.request_response_protocols.push(beefy_req_resp_cfg); } let peerset_protocol_names = @@ -1174,16 +1185,23 @@ where if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None }; if enable_beefy { + let justifications_protocol_name = beefy_on_demand_justifications_handler.protocol_name(); + let network_params = beefy_gadget::BeefyNetworkParams { + network: network.clone(), + gossip_protocol_name: beefy_gossip_proto_name, + justifications_protocol_name, + _phantom: core::marker::PhantomData::, + }; let beefy_params = beefy_gadget::BeefyParams { client: client.clone(), backend: backend.clone(), runtime: client.clone(), key_store: keystore_opt.clone(), - network: network.clone(), + network_params, min_block_delta: if chain_spec.is_wococo() { 4 } else { 8 }, prometheus_registry: prometheus_registry.clone(), - protocol_name: beefy_protocol_name, links: beefy_links, + on_demand_justifications_handler: beefy_on_demand_justifications_handler, }; let gadget = beefy_gadget::start_beefy_gadget::<_, _, _, _, _>(beefy_params); diff --git a/node/subsystem-types/Cargo.toml b/node/subsystem-types/Cargo.toml index 24274dd22608..2b997128b8e2 100644 --- a/node/subsystem-types/Cargo.toml +++ b/node/subsystem-types/Cargo.toml @@ -13,7 +13,7 @@ polkadot-node-primitives = { path = "../primitives" } polkadot-node-network-protocol = { path = "../network/protocol" } polkadot-statement-table = { path = "../../statement-table" } polkadot-node-jaeger = { path = "../jaeger" } -orchestra = { path = "../orchestra" } +orchestra = "0.0.2" sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/node/subsystem-types/src/messages.rs b/node/subsystem-types/src/messages.rs index 17b47e507c27..a1520a9aeba8 100644 --- a/node/subsystem-types/src/messages.rs +++ b/node/subsystem-types/src/messages.rs @@ -430,6 +430,10 @@ pub enum AvailabilityDistributionMessage { relay_parent: Hash, /// Validator to fetch the PoV from. from_validator: ValidatorIndex, + /// The id of the parachain that produced this PoV. + /// This field is only used to provide more context when logging errors + /// from the `AvailabilityDistribution` subsystem. + para_id: ParaId, /// Candidate hash to fetch the PoV for. candidate_hash: CandidateHash, /// Expected hash of the PoV, a PoV not matching this hash will be rejected. diff --git a/node/subsystem-util/Cargo.toml b/node/subsystem-util/Cargo.toml index d515be37fe3e..a3985a898849 100644 --- a/node/subsystem-util/Cargo.toml +++ b/node/subsystem-util/Cargo.toml @@ -26,7 +26,7 @@ polkadot-node-network-protocol = { path = "../network/protocol" } polkadot-primitives = { path = "../../primitives" } polkadot-node-primitives = { path = "../primitives" } polkadot-overseer = { path = "../overseer" } -metered = { package = "prioritized-metered-channel", path = "../metered-channel" , "version" = "0.2.0" } +metered = { package = "prioritized-metered-channel", version = "0.2.0" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index d05388ea5441..fa2c61f17c25 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -61,7 +61,9 @@ pub struct GrandpaDeps { pub finality_provider: Arc>, } -use beefy_gadget::notification::{BeefyBestBlockStream, BeefyVersionedFinalityProofStream}; +use beefy_gadget::communication::notification::{ + BeefyBestBlockStream, BeefyVersionedFinalityProofStream, +}; /// Dependencies for BEEFY pub struct BeefyDeps { /// Receives notifications about finality proof events from BEEFY. diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index 4c09397e0451..939b753092f5 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -97,7 +97,7 @@ mod tests { weight.base_extrinsic = Weight::from_ref_time(100); }) .for_class(DispatchClass::non_mandatory(), |weight| { - weight.max_total = Some(Weight::from_ref_time(1024)); + weight.max_total = Some(Weight::from_ref_time(1024).set_proof_size(u64::MAX)); }) .build_or_panic(); pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024); diff --git a/runtime/common/src/integration_tests.rs b/runtime/common/src/integration_tests.rs index 15a39ff5a2f4..eb9c4496e59a 100644 --- a/runtime/common/src/integration_tests.rs +++ b/runtime/common/src/integration_tests.rs @@ -104,7 +104,9 @@ use crate::{auctions::Error as AuctionsError, crowdloan::Error as CrowdloanError parameter_types! { pub const BlockHashCount: u32 = 250; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(4 * 1024 * 1024)); + frame_system::limits::BlockWeights::simple_max( + Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX), + ); } impl frame_system::Config for Test { diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 06f76fbfbff1..936feedde1c3 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -43,7 +43,7 @@ use frame_support::{ weights::{constants::WEIGHT_PER_SECOND, Weight}, }; use frame_system::limits; -use primitives::v2::{AssignmentId, Balance, BlockNumber, ValidatorId}; +use primitives::v2::{AssignmentId, Balance, BlockNumber, ValidatorId, MAX_POV_SIZE}; use sp_runtime::{FixedPointNumber, Perbill, Perquintill}; use static_assertions::const_assert; @@ -68,8 +68,9 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1); /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used /// by Operational extrinsics. pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); -/// We allow for 2 seconds of compute with a 6 second average block time. -pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2); +/// The storage proof size is not limited so far. +pub const MAXIMUM_BLOCK_WEIGHT: Weight = + WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(MAX_POV_SIZE as u64); const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct()); diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 90493c9077b9..d5bc59599715 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -642,7 +642,9 @@ mod tests { parameter_types! { pub const BlockHashCount: u32 = 250; pub BlockWeights: limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); + frame_system::limits::BlockWeights::simple_max( + Weight::from_ref_time(1024).set_proof_size(u64::MAX), + ); pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO); } diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index 9eddf926cde0..ee9d859b84b3 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -47,6 +47,7 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-nomination-pools-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -63,7 +64,9 @@ pallet-nomination-pools = { git = "https://github.com/paritytech/substrate", bra pallet-offences = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-proxy = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-ranked-collective = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-recovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-referenda = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -77,6 +80,7 @@ pallet-tips = { git = "https://github.com/paritytech/substrate", branch = "maste pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-whitelist = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false } pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true } frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -142,6 +146,7 @@ std = [ "pallet-transaction-payment/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-collective/std", + "pallet-conviction-voting/std", "pallet-elections-phragmen/std", "pallet-election-provider-multi-phase/std", "pallet-fast-unstake/std", @@ -158,7 +163,9 @@ std = [ "pallet-offences/std", "pallet-preimage/std", "pallet-proxy/std", + "pallet-ranked-collective/std", "pallet-recovery/std", + "pallet-referenda/std", "pallet-scheduler/std", "pallet-session/std", "pallet-society/std", @@ -169,6 +176,7 @@ std = [ "pallet-treasury/std", "pallet-utility/std", "pallet-vesting/std", + "pallet-whitelist/std", "pallet-babe/std", "pallet-xcm/std", "sp-mmr-primitives/std", @@ -204,6 +212,7 @@ runtime-benchmarks = [ "pallet-bounties/runtime-benchmarks", "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", "pallet-democracy/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", "pallet-election-provider-multi-phase/runtime-benchmarks", @@ -220,6 +229,8 @@ runtime-benchmarks = [ "pallet-nomination-pools-benchmarking/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-ranked-collective/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-society/runtime-benchmarks", "pallet-recovery/runtime-benchmarks", @@ -231,6 +242,7 @@ runtime-benchmarks = [ "pallet-vesting/runtime-benchmarks", "pallet-offences-benchmarking/runtime-benchmarks", "pallet-session-benchmarking/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "hex-literal", @@ -252,6 +264,7 @@ try-runtime = [ "pallet-child-bounties/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-collective/try-runtime", + "pallet-conviction-voting/try-runtime", "pallet-elections-phragmen/try-runtime", "pallet-election-provider-multi-phase/try-runtime", "pallet-fast-unstake/try-runtime", @@ -267,7 +280,9 @@ try-runtime = [ "pallet-offences/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", + "pallet-ranked-collective/try-runtime", "pallet-recovery/try-runtime", + "pallet-referenda/try-runtime", "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-society/try-runtime", @@ -277,6 +292,7 @@ try-runtime = [ "pallet-treasury/try-runtime", "pallet-utility/try-runtime", "pallet-vesting/try-runtime", + "pallet-whitelist/try-runtime", "pallet-babe/try-runtime", "pallet-xcm/try-runtime", "runtime-common/try-runtime", diff --git a/runtime/kusama/constants/src/lib.rs b/runtime/kusama/constants/src/lib.rs index 719f42c235c2..a8d047241b24 100644 --- a/runtime/kusama/constants/src/lib.rs +++ b/runtime/kusama/constants/src/lib.rs @@ -27,7 +27,8 @@ pub mod currency { pub const UNITS: Balance = 1_000_000_000_000; pub const CENTS: Balance = UNITS / 30_000; - pub const GRAND: Balance = CENTS * 100_000; + pub const QUID: Balance = CENTS * 100; + pub const GRAND: Balance = QUID * 1_000; pub const MILLICENTS: Balance = CENTS / 1_000; pub const fn deposit(items: u32, bytes: u32) -> Balance { diff --git a/runtime/kusama/src/governance/fellowship.rs b/runtime/kusama/src/governance/fellowship.rs new file mode 100644 index 000000000000..66e2f6ee6d58 --- /dev/null +++ b/runtime/kusama/src/governance/fellowship.rs @@ -0,0 +1,368 @@ +// Copyright 2022 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 . + +//! Elements of governance concerning the Polkadot Fellowship. This is only a temporary arrangement +//! since the Polkadot Fellowship belongs under the Polkadot Relay. However, that is not yet in +//! place, so until then it will need to live here. Once it is in place and there exists a bridge +//! between Polkadot/Kusama then this code can be removed. + +use frame_support::traits::{MapSuccess, TryMapSuccess}; +use sp_arithmetic::traits::CheckedSub; +use sp_runtime::{ + morph_types, + traits::{ConstU16, Replace, TypedGet}, +}; + +use super::*; +use crate::{DAYS, QUID}; + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 0; + pub const UndecidingTimeout: BlockNumber = 7 * DAYS; +} + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + static DATA: [(u16, pallet_referenda::TrackInfo); 10] = [ + ( + 0u16, + pallet_referenda::TrackInfo { + name: "candidates", + max_deciding: 10, + decision_deposit: 100 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 1u16, + pallet_referenda::TrackInfo { + name: "members", + max_deciding: 10, + decision_deposit: 10 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 2u16, + pallet_referenda::TrackInfo { + name: "proficients", + max_deciding: 10, + decision_deposit: 10 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 3u16, + pallet_referenda::TrackInfo { + name: "fellows", + max_deciding: 10, + decision_deposit: 10 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 4u16, + pallet_referenda::TrackInfo { + name: "senior fellows", + max_deciding: 10, + decision_deposit: 10 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 5u16, + pallet_referenda::TrackInfo { + name: "experts", + max_deciding: 10, + decision_deposit: 1 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 6u16, + pallet_referenda::TrackInfo { + name: "senior experts", + max_deciding: 10, + decision_deposit: 1 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 7u16, + pallet_referenda::TrackInfo { + name: "masters", + max_deciding: 10, + decision_deposit: 1 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 8u16, + pallet_referenda::TrackInfo { + name: "senior masters", + max_deciding: 10, + decision_deposit: 1 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ( + 9u16, + pallet_referenda::TrackInfo { + name: "grand masters", + max_deciding: 10, + decision_deposit: 1 * QUID, + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 4, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(50), + }, + }, + ), + ]; + &DATA[..] + } + fn track_for(id: &Self::RuntimeOrigin) -> Result { + use super::origins::Origin; + + #[cfg(feature = "runtime-benchmarks")] + { + // For benchmarks, we enable a root origin. + // It is important that this is not available in production! + let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into(); + if &root == id { + return Ok(9) + } + } + + match Origin::try_from(id.clone()) { + Ok(Origin::FellowshipInitiates) => Ok(0), + Ok(Origin::Fellowship1Dan) => Ok(1), + Ok(Origin::Fellowship2Dan) => Ok(2), + Ok(Origin::Fellowship3Dan) | Ok(Origin::Fellows) => Ok(3), + Ok(Origin::Fellowship4Dan) => Ok(4), + Ok(Origin::Fellowship5Dan) | Ok(Origin::FellowshipExperts) => Ok(5), + Ok(Origin::Fellowship6Dan) => Ok(6), + Ok(Origin::Fellowship7Dan | Origin::FellowshipMasters) => Ok(7), + Ok(Origin::Fellowship8Dan) => Ok(8), + Ok(Origin::Fellowship9Dan) => Ok(9), + _ => Err(()), + } + } +} +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); + +pub type FellowshipReferendaInstance = pallet_referenda::Instance2; + +impl pallet_referenda::Config for Runtime { + type WeightInfo = weights::pallet_referenda_fellowship_referenda::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = + pallet_ranked_collective::EnsureMember; + type CancelOrigin = FellowshipExperts; + type KillOrigin = FellowshipMasters; + type Slash = Treasury; + type Votes = pallet_ranked_collective::Votes; + type Tally = pallet_ranked_collective::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = TracksInfo; +} + +pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1; + +morph_types! { + /// A `TryMorph` implementation to reduce a scalar by a particular amount, checking for + /// underflow. + pub type CheckedReduceBy: TryMorph = |r: N::Type| -> Result { + r.checked_sub(&N::get()).ok_or(()) + } where N::Type: CheckedSub; +} + +impl pallet_ranked_collective::Config for Runtime { + type WeightInfo = weights::pallet_ranked_collective::WeightInfo; + type RuntimeEvent = RuntimeEvent; + // Promotion is by any of: + // - Root can demote arbitrarily. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank *above* the new rank. + type PromoteOrigin = EitherOf< + EitherOf< + frame_system::EnsureRootWithSuccess>, + MapSuccess< + pallet_collective::EnsureProportionAtLeast< + Self::AccountId, + super::old::TechnicalCollective, + 2, + 3, + >, + Replace>, + >, + >, + EitherOf< + MapSuccess>>, + TryMapSuccess>>, + >, + >; + // Demotion is by any of: + // - Root can demote arbitrarily. + // - the FellowshipAdmin origin (i.e. token holder referendum); + // - a vote by the rank two above the current rank. + type DemoteOrigin = EitherOf< + frame_system::EnsureRootWithSuccess>, + EitherOf< + MapSuccess>>, + TryMapSuccess>>, + >, + >; + type Polls = FellowshipReferenda; + type MinRankOfClass = sp_runtime::traits::Identity; + type VoteWeight = pallet_ranked_collective::Geometric; +} diff --git a/runtime/kusama/src/governance/mod.rs b/runtime/kusama/src/governance/mod.rs index 27aa07a4795b..4dbf375f67f0 100644 --- a/runtime/kusama/src/governance/mod.rs +++ b/runtime/kusama/src/governance/mod.rs @@ -14,7 +14,81 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Governance configurations for the Kusama runtime. +//! New governance configurations for the Kusama runtime. + +use super::*; +use frame_support::{ + parameter_types, + traits::{ConstU16, EitherOf}, +}; +use frame_system::EnsureRootWithSuccess; // Old governance configurations. pub mod old; + +mod origins; +pub use origins::{ + pallet_custom_origins, AuctionAdmin, Fellows, FellowshipAdmin, FellowshipExperts, + FellowshipInitiates, FellowshipMasters, GeneralAdmin, LeaseAdmin, ReferendumCanceller, + ReferendumKiller, Spender, StakingAdmin, WhitelistedCaller, +}; +mod tracks; +pub use tracks::TracksInfo; +mod fellowship; +pub use fellowship::{FellowshipCollectiveInstance, FellowshipReferendaInstance}; + +parameter_types! { + pub const VoteLockingPeriod: BlockNumber = 7 * DAYS; +} + +impl pallet_conviction_voting::Config for Runtime { + type WeightInfo = weights::pallet_conviction_voting::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type VoteLockingPeriod = VoteLockingPeriod; + type MaxVotes = ConstU32<512>; + type MaxTurnout = frame_support::traits::TotalIssuanceOf; + type Polls = Referenda; +} + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 100 * UNITS; + pub const UndecidingTimeout: BlockNumber = 28 * DAYS; +} + +parameter_types! { + pub const MaxBalance: Balance = Balance::max_value(); +} +pub type TreasurySpender = EitherOf, Spender>; + +impl origins::pallet_custom_origins::Config for Runtime {} + +impl pallet_whitelist::Config for Runtime { + type WeightInfo = weights::pallet_whitelist::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WhitelistOrigin = + EitherOf>, Fellows>; + type DispatchWhitelistedOrigin = EitherOf, WhitelistedCaller>; + type PreimageProvider = Preimage; +} + +impl pallet_referenda::Config for Runtime { + type WeightInfo = weights::pallet_referenda_referenda::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = frame_system::EnsureSigned; + type CancelOrigin = ReferendumCanceller; + type KillOrigin = ReferendumKiller; + type Slash = Treasury; + type Votes = pallet_conviction_voting::VotesOf; + type Tally = pallet_conviction_voting::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = TracksInfo; +} diff --git a/runtime/kusama/src/governance/old.rs b/runtime/kusama/src/governance/old.rs index 371b88dcd443..c16ca5eddd7a 100644 --- a/runtime/kusama/src/governance/old.rs +++ b/runtime/kusama/src/governance/old.rs @@ -160,11 +160,11 @@ impl pallet_collective::Config for Runtime { impl pallet_membership::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type AddOrigin = MoreThanHalfCouncil; - type RemoveOrigin = MoreThanHalfCouncil; - type SwapOrigin = MoreThanHalfCouncil; - type ResetOrigin = MoreThanHalfCouncil; - type PrimeOrigin = MoreThanHalfCouncil; + type AddOrigin = EnsureRoot; + type RemoveOrigin = EnsureRoot; + type SwapOrigin = EnsureRoot; + type ResetOrigin = EnsureRoot; + type PrimeOrigin = EnsureRoot; type MembershipInitialized = TechnicalCommittee; type MembershipChanged = TechnicalCommittee; type MaxMembers = TechnicalMaxMembers; diff --git a/runtime/kusama/src/governance/origins.rs b/runtime/kusama/src/governance/origins.rs new file mode 100644 index 000000000000..be8c44430f46 --- /dev/null +++ b/runtime/kusama/src/governance/origins.rs @@ -0,0 +1,192 @@ +// Copyright 2022 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 . + +//! Custom origins for governance interventions. + +pub use pallet_custom_origins::*; + +#[frame_support::pallet] +pub mod pallet_custom_origins { + use crate::{Balance, GRAND, QUID}; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)] + #[pallet::origin] + pub enum Origin { + /// Origin for cancelling slashes. + StakingAdmin, + /// Origin for spending (any amount of) funds. + Treasurer, + /// Origin for managing the composition of the fellowship. + FellowshipAdmin, + /// Origin for managing the registrar. + GeneralAdmin, + /// Origin for starting auctions. + AuctionAdmin, + /// Origin able to force slot leases. + LeaseAdmin, + /// Origin able to cancel referenda. + ReferendumCanceller, + /// Origin able to kill referenda. + ReferendumKiller, + /// Origin able to spend up to 1 KSM from the treasury at once. + SmallTipper, + /// Origin able to spend up to 5 KSM from the treasury at once. + BigTipper, + /// Origin able to spend up to 50 KSM from the treasury at once. + SmallSpender, + /// Origin able to spend up to 500 KSM from the treasury at once. + MediumSpender, + /// Origin able to spend up to 5,000 KSM from the treasury at once. + BigSpender, + /// Origin able to dispatch a whitelisted call. + WhitelistedCaller, + /// Origin commanded by any members of the Polkadot Fellowship (no Dan grade needed). + FellowshipInitiates, + /// Origin commanded by Polkadot Fellows (3rd Dan fellows or greater). + Fellows, + /// Origin commanded by Polkadot Experts (5th Dan fellows or greater). + FellowshipExperts, + /// Origin commanded by Polkadot Masters (7th Dan fellows of greater). + FellowshipMasters, + /// Origin commanded by rank 1 of the Polkadot Fellowship and with a success of 1. + Fellowship1Dan, + /// Origin commanded by rank 2 of the Polkadot Fellowship and with a success of 2. + Fellowship2Dan, + /// Origin commanded by rank 3 of the Polkadot Fellowship and with a success of 3. + Fellowship3Dan, + /// Origin commanded by rank 4 of the Polkadot Fellowship and with a success of 4. + Fellowship4Dan, + /// Origin commanded by rank 5 of the Polkadot Fellowship and with a success of 5. + Fellowship5Dan, + /// Origin commanded by rank 6 of the Polkadot Fellowship and with a success of 6. + Fellowship6Dan, + /// Origin commanded by rank 7 of the Polkadot Fellowship and with a success of 7. + Fellowship7Dan, + /// Origin commanded by rank 8 of the Polkadot Fellowship and with a success of 8. + Fellowship8Dan, + /// Origin commanded by rank 9 of the Polkadot Fellowship and with a success of 9. + Fellowship9Dan, + } + + macro_rules! decl_unit_ensures { + ( $name:ident: $success_type:ty = $success:expr ) => { + pub struct $name; + impl> + From> + EnsureOrigin for $name + { + type Success = $success_type; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::$name => Ok($success), + r => Err(O::from(r)), + }) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::$name)) + } + } + }; + ( $name:ident ) => { decl_unit_ensures! { $name : () = () } }; + ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => { + decl_unit_ensures! { $name: $success_type = $success } + decl_unit_ensures! { $( $rest )* } + }; + ( $name:ident, $( $rest:tt )* ) => { + decl_unit_ensures! { $name } + decl_unit_ensures! { $( $rest )* } + }; + () => {} + } + decl_unit_ensures!( + StakingAdmin, + FellowshipAdmin, + GeneralAdmin, + AuctionAdmin, + LeaseAdmin, + ReferendumCanceller, + ReferendumKiller, + WhitelistedCaller, + FellowshipInitiates: u16 = 0, + Fellows: u16 = 3, + FellowshipExperts: u16 = 5, + FellowshipMasters: u16 = 7, + ); + + macro_rules! decl_ensure { + ( + $vis:vis type $name:ident: EnsureOrigin { + $( $item:ident = $success:expr, )* + } + ) => { + $vis struct $name; + impl> + From> + EnsureOrigin for $name + { + type Success = $success_type; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + $( + Origin::$item => Ok($success), + )* + r => Err(O::from(r)), + }) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + // By convention the more privileged origins go later, so for greatest chance + // of success, we want the last one. + let _result: Result = Err(()); + $( + let _result: Result = Ok(O::from(Origin::$item)); + )* + _result + } + } + } + } + + decl_ensure! { + pub type Spender: EnsureOrigin { + SmallTipper = 250 * QUID, + BigTipper = 1 * GRAND, + SmallSpender = 10 * GRAND, + MediumSpender = 100 * GRAND, + BigSpender = 1_000 * GRAND, + } + } + + decl_ensure! { + pub type EnsureFellowship: EnsureOrigin { + Fellowship1Dan = 1, + Fellowship2Dan = 2, + Fellowship3Dan = 3, + Fellowship4Dan = 4, + Fellowship5Dan = 5, + Fellowship6Dan = 6, + Fellowship7Dan = 7, + Fellowship8Dan = 8, + Fellowship9Dan = 9, + } + } +} diff --git a/runtime/kusama/src/governance/tracks.rs b/runtime/kusama/src/governance/tracks.rs new file mode 100644 index 000000000000..fd1c94118507 --- /dev/null +++ b/runtime/kusama/src/governance/tracks.rs @@ -0,0 +1,320 @@ +// Copyright 2022 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 . + +//! Track configurations for governance. + +use super::*; + +const fn percent(x: i32) -> sp_arithmetic::FixedI64 { + sp_arithmetic::FixedI64::from_rational(x as u128, 100) +} +use pallet_referenda::Curve; +const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100)); +const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50)); +const APP_STAKING_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_STAKING_ADMIN: Curve = + Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_TREASURER: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100)); +const SUP_TREASURER: Curve = Curve::make_linear(28, 28, percent(0), percent(50)); +const APP_FELLOWSHIP_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_FELLOWSHIP_ADMIN: Curve = + Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_GENERAL_ADMIN: Curve = + Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100)); +const SUP_GENERAL_ADMIN: Curve = + Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50)); +const APP_AUCTION_ADMIN: Curve = + Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100)); +const SUP_AUCTION_ADMIN: Curve = + Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50)); +const APP_LEASE_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_LEASE_ADMIN: Curve = Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_REFERENDUM_CANCELLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_REFERENDUM_CANCELLER: Curve = + Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_REFERENDUM_KILLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_REFERENDUM_KILLER: Curve = + Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_SMALL_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100)); +const SUP_SMALL_TIPPER: Curve = Curve::make_reciprocal(1, 28, percent(4), percent(0), percent(50)); +const APP_BIG_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100)); +const SUP_BIG_TIPPER: Curve = Curve::make_reciprocal(8, 28, percent(1), percent(0), percent(50)); +const APP_SMALL_SPENDER: Curve = Curve::make_linear(17, 28, percent(50), percent(100)); +const SUP_SMALL_SPENDER: Curve = + Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50)); +const APP_MEDIUM_SPENDER: Curve = Curve::make_linear(23, 28, percent(50), percent(100)); +const SUP_MEDIUM_SPENDER: Curve = + Curve::make_reciprocal(16, 28, percent(1), percent(0), percent(50)); +const APP_BIG_SPENDER: Curve = Curve::make_linear(28, 28, percent(50), percent(100)); +const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percent(0), percent(50)); +const APP_WHITELISTED_CALLER: Curve = + Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100)); +const SUP_WHITELISTED_CALLER: Curve = + Curve::make_reciprocal(1, 28, percent(20), percent(10), percent(50)); + +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 15] = [ + ( + 0, + pallet_referenda::TrackInfo { + name: "root", + max_deciding: 1, + decision_deposit: 1_000 * GRAND, + prepare_period: 3 * HOURS, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 3 * HOURS, + min_approval: APP_ROOT, + min_support: SUP_ROOT, + }, + ), + ( + 1, + pallet_referenda::TrackInfo { + name: "whitelisted_caller", + max_deciding: 10, + decision_deposit: 10_000 * GRAND, + prepare_period: 3 * HOURS, + decision_period: 28 * DAYS, + confirm_period: 10 * MINUTES, + min_enactment_period: 30 * MINUTES, + min_approval: APP_WHITELISTED_CALLER, + min_support: SUP_WHITELISTED_CALLER, + }, + ), + ( + 10, + pallet_referenda::TrackInfo { + name: "staking_admin", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_STAKING_ADMIN, + min_support: SUP_STAKING_ADMIN, + }, + ), + ( + 11, + pallet_referenda::TrackInfo { + name: "treasurer", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_TREASURER, + min_support: SUP_TREASURER, + }, + ), + ( + 12, + pallet_referenda::TrackInfo { + name: "lease_admin", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_LEASE_ADMIN, + min_support: SUP_LEASE_ADMIN, + }, + ), + ( + 13, + pallet_referenda::TrackInfo { + name: "fellowship_admin", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_FELLOWSHIP_ADMIN, + min_support: SUP_FELLOWSHIP_ADMIN, + }, + ), + ( + 14, + pallet_referenda::TrackInfo { + name: "general_admin", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_GENERAL_ADMIN, + min_support: SUP_GENERAL_ADMIN, + }, + ), + ( + 15, + pallet_referenda::TrackInfo { + name: "auction_admin", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 2 * DAYS, + min_approval: APP_AUCTION_ADMIN, + min_support: SUP_AUCTION_ADMIN, + }, + ), + ( + 20, + pallet_referenda::TrackInfo { + name: "referendum_canceller", + max_deciding: 1_000, + decision_deposit: 50 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: APP_REFERENDUM_CANCELLER, + min_support: SUP_REFERENDUM_CANCELLER, + }, + ), + ( + 21, + pallet_referenda::TrackInfo { + name: "referendum_killer", + max_deciding: 1_000, + decision_deposit: 50 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: APP_REFERENDUM_KILLER, + min_support: SUP_REFERENDUM_KILLER, + }, + ), + ( + 30, + pallet_referenda::TrackInfo { + name: "small_tipper", + max_deciding: 200, + decision_deposit: 5 * QUID, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 28 * DAYS, + min_approval: APP_SMALL_TIPPER, + min_support: SUP_SMALL_TIPPER, + }, + ), + ( + 31, + pallet_referenda::TrackInfo { + name: "big_tipper", + max_deciding: 100, + decision_deposit: 50 * QUID, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 6 * HOURS, + min_enactment_period: 28 * DAYS, + min_approval: APP_BIG_TIPPER, + min_support: SUP_BIG_TIPPER, + }, + ), + ( + 32, + pallet_referenda::TrackInfo { + name: "small_spender", + max_deciding: 50, + decision_deposit: 500 * QUID, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 12 * HOURS, + min_enactment_period: 28 * DAYS, + min_approval: APP_SMALL_SPENDER, + min_support: SUP_SMALL_SPENDER, + }, + ), + ( + 33, + pallet_referenda::TrackInfo { + name: "medium_spender", + max_deciding: 20, + decision_deposit: 1_500 * QUID, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 24 * HOURS, + min_enactment_period: 28 * DAYS, + min_approval: APP_MEDIUM_SPENDER, + min_support: SUP_MEDIUM_SPENDER, + }, + ), + ( + 34, + pallet_referenda::TrackInfo { + name: "big_spender", + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 4, + decision_period: 28 * DAYS, + confirm_period: 48 * HOURS, + min_enactment_period: 28 * DAYS, + min_approval: APP_BIG_SPENDER, + min_support: SUP_BIG_SPENDER, + }, + ), +]; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + &TRACKS_DATA[..] + } + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => Ok(0), + _ => Err(()), + } + } else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) { + match custom_origin { + origins::Origin::WhitelistedCaller => Ok(1), + // General admin + origins::Origin::StakingAdmin => Ok(10), + origins::Origin::Treasurer => Ok(11), + origins::Origin::LeaseAdmin => Ok(12), + origins::Origin::FellowshipAdmin => Ok(13), + origins::Origin::GeneralAdmin => Ok(14), + origins::Origin::AuctionAdmin => Ok(15), + // Referendum admins + origins::Origin::ReferendumCanceller => Ok(20), + origins::Origin::ReferendumKiller => Ok(21), + // Limited treasury spenders + origins::Origin::SmallTipper => Ok(30), + origins::Origin::BigTipper => Ok(31), + origins::Origin::SmallSpender => Ok(32), + origins::Origin::MediumSpender => Ok(33), + origins::Origin::BigSpender => Ok(34), + _ => Err(()), + } + } else { + Err(()) + } + } +} +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index bbd221749c75..48762d5e67ec 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -51,8 +51,8 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU32, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, - PrivilegeCmp, + ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, + LockIdentifier, PrivilegeCmp, }, weights::ConstantMultiplier, PalletId, RuntimeDebug, @@ -103,7 +103,10 @@ pub mod xcm_config; // Governance configurations. pub mod governance; -use governance::old::CouncilCollective; +use governance::{ + old::CouncilCollective, pallet_custom_origins, AuctionAdmin, GeneralAdmin, LeaseAdmin, + StakingAdmin, TreasurySpender, +}; #[cfg(test)] mod tests; @@ -143,10 +146,13 @@ pub fn native_version() -> NativeVersion { NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } } -type MoreThanHalfCouncil = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionMoreThan, ->; +/// We currently allow all calls. +pub struct BaseFilter; +impl Contains for BaseFilter { + fn contains(_c: &RuntimeCall) -> bool { + true + } +} parameter_types! { pub const Version: RuntimeVersion = VERSION; @@ -181,17 +187,11 @@ impl frame_system::Config for Runtime { } parameter_types! { - pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * - BlockWeights::get().max_block; + pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; pub const MaxScheduledPerBlock: u32 = 50; pub const NoPreimagePostponement: Option = Some(10); } -type ScheduleOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - /// Used the compare the privilege of an origin inside the scheduler. pub struct OriginPrivilegeCmp; @@ -221,7 +221,7 @@ impl pallet_scheduler::Config for Runtime { type PalletsOrigin = OriginCaller; type RuntimeCall = RuntimeCall; type MaximumWeight = MaximumSchedulerWeight; - type ScheduleOrigin = ScheduleOrigin; + type ScheduleOrigin = EnsureRoot; type MaxScheduledPerBlock = MaxScheduledPerBlock; type WeightInfo = weights::pallet_scheduler::WeightInfo; type OriginPrivilegeCmp = OriginPrivilegeCmp; @@ -239,7 +239,7 @@ impl pallet_preimage::Config for Runtime { type WeightInfo = weights::pallet_preimage::WeightInfo; type RuntimeEvent = RuntimeEvent; type Currency = Balances; - type ManagerOrigin = EnsureRoot; + type ManagerOrigin = EnsureRoot; // This might be too strong a requirenent? type MaxSize = PreimageMaxSize; type BaseDeposit = PreimageBaseDeposit; type ByteDeposit = PreimageByteDeposit; @@ -488,10 +488,7 @@ impl pallet_election_provider_multi_phase::Config for Runtime { (), >; type BenchmarkingConfig = runtime_common::elections::BenchmarkConfig; - type ForceOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, - >; + type ForceOrigin = StakingAdmin; type WeightInfo = weights::pallet_election_provider_multi_phase::WeightInfo; type MaxElectingVoters = MaxElectingVoters; type MaxElectableTargets = MaxElectableTargets; @@ -585,11 +582,6 @@ parameter_types! { pub const MaxNominations: u32 = ::LIMIT as u32; } -type SlashCancelOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - impl pallet_staking::Config for Runtime { type MaxNominations = MaxNominations; type Currency = Balances; @@ -605,8 +597,8 @@ impl pallet_staking::Config for Runtime { type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; - // A majority of the council or root can cancel the slash. - type SlashCancelOrigin = SlashCancelOrigin; + // The staking admin or root can cancel the slash. + type SlashCancelOrigin = EitherOf, StakingAdmin>; type SessionInterface = Self; type EraPayout = EraPayout; type NextNewSession = Session; @@ -651,16 +643,11 @@ parameter_types! { pub const MaxPeerDataEncodingSize: u32 = 1_000; } -type ApproveOrigin = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - impl pallet_treasury::Config for Runtime { type PalletId = TreasuryPalletId; type Currency = Balances; - type ApproveOrigin = ApproveOrigin; - type RejectOrigin = MoreThanHalfCouncil; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; type RuntimeEvent = RuntimeEvent; type OnSlash = Treasury; type ProposalBond = ProposalBond; @@ -672,7 +659,7 @@ impl pallet_treasury::Config for Runtime { type MaxApprovals = MaxApprovals; type WeightInfo = weights::pallet_treasury::WeightInfo; type SpendFunds = Bounties; - type SpendOrigin = frame_support::traits::NeverEnsureOrigin; + type SpendOrigin = TreasurySpender; } parameter_types! { @@ -843,8 +830,7 @@ impl claims::Config for Runtime { type RuntimeEvent = RuntimeEvent; type VestingSchedule = Vesting; type Prefix = Prefix; - type MoveClaimOrigin = - pallet_collective::EnsureProportionMoreThan; + type MoveClaimOrigin = EnsureRoot; type WeightInfo = weights::runtime_common_claims::WeightInfo; } @@ -868,8 +854,8 @@ impl pallet_identity::Config for Runtime { type MaxAdditionalFields = MaxAdditionalFields; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; - type ForceOrigin = MoreThanHalfCouncil; - type RegistrarOrigin = MoreThanHalfCouncil; + type ForceOrigin = GeneralAdmin; + type RegistrarOrigin = GeneralAdmin; type WeightInfo = weights::pallet_identity::WeightInfo; } @@ -917,11 +903,11 @@ impl pallet_recovery::Config for Runtime { } parameter_types! { - pub const CandidateDeposit: Balance = 1000 * CENTS; - pub const WrongSideDeduction: Balance = 200 * CENTS; + pub const CandidateDeposit: Balance = 10 * QUID; + pub const WrongSideDeduction: Balance = 2 * QUID; pub const MaxStrikes: u32 = 10; pub const RotationPeriod: BlockNumber = 7 * DAYS; - pub const PeriodSpend: Balance = 50000 * CENTS; + pub const PeriodSpend: Balance = 500 * QUID; pub const MaxLockDuration: BlockNumber = 36 * 30 * DAYS; pub const ChallengePeriod: BlockNumber = 7 * DAYS; pub const MaxCandidateIntake: u32 = 1; @@ -939,8 +925,7 @@ impl pallet_society::Config for Runtime { type MembershipChanged = (); type RotationPeriod = RotationPeriod; type MaxLockDuration = MaxLockDuration; - type FounderSetOrigin = - pallet_collective::EnsureProportionMoreThan; + type FounderSetOrigin = EnsureRoot; type SuspensionJudgementOrigin = pallet_society::EnsureFounder; type ChallengePeriod = ChallengePeriod; type MaxCandidateIntake = MaxCandidateIntake; @@ -1217,13 +1202,13 @@ impl slots::Config for Runtime { type Registrar = Registrar; type LeasePeriod = LeasePeriod; type LeaseOffset = (); - type ForceOrigin = MoreThanHalfCouncil; + type ForceOrigin = LeaseAdmin; type WeightInfo = weights::runtime_common_slots::WeightInfo; } parameter_types! { pub const CrowdloanId: PalletId = PalletId(*b"py/cfund"); - pub const SubmissionDeposit: Balance = 3 * GRAND; // ~ 10 KSM + pub const OldSubmissionDeposit: Balance = 3 * GRAND; // ~ 10 KSM pub const MinContribution: Balance = 3_000 * CENTS; // ~ .1 KSM pub const RemoveKeysLimit: u32 = 1000; // Allow 32 bytes for an additional memo to a crowdloan. @@ -1233,7 +1218,7 @@ parameter_types! { impl crowdloan::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletId = CrowdloanId; - type SubmissionDeposit = SubmissionDeposit; + type SubmissionDeposit = OldSubmissionDeposit; type MinContribution = MinContribution; type RemoveKeysLimit = RemoveKeysLimit; type Registrar = Registrar; @@ -1250,11 +1235,6 @@ parameter_types! { pub const SampleLength: BlockNumber = 2 * MINUTES; } -type AuctionInitiate = EitherOfDiverse< - EnsureRoot, - pallet_collective::EnsureProportionAtLeast, ->; - impl auctions::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Leaser = Slots; @@ -1262,7 +1242,7 @@ impl auctions::Config for Runtime { type EndingPeriod = EndingPeriod; type SampleLength = SampleLength; type Randomness = pallet_babe::RandomnessFromOneEpochAgo; - type InitiateOrigin = AuctionInitiate; + type InitiateOrigin = AuctionAdmin; type WeightInfo = weights::runtime_common_auctions::WeightInfo; } @@ -1281,7 +1261,7 @@ impl pallet_gilt::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type CurrencyBalance = Balance; - type AdminOrigin = MoreThanHalfCouncil; + type AdminOrigin = EnsureRoot; type Deficit = (); // Mint type Surplus = (); // Burn type IgnoredIssuance = IgnoredIssuance; @@ -1346,7 +1326,7 @@ construct_runtime! { ImOnline: pallet_im_online::{Pallet, Call, Storage, Event, ValidateUnsigned, Config} = 11, AuthorityDiscovery: pallet_authority_discovery::{Pallet, Config} = 12, - // Governance stuff; uncallable initially. + // Governance stuff. Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event} = 13, Council: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config} = 14, TechnicalCommittee: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config} = 15, @@ -1354,6 +1334,19 @@ construct_runtime! { TechnicalMembership: pallet_membership::::{Pallet, Call, Storage, Event, Config} = 17, Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event} = 18, + ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event} = 20, + Referenda: pallet_referenda::{Pallet, Call, Storage, Event} = 21, +// pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1; + FellowshipCollective: pallet_ranked_collective::::{ + Pallet, Call, Storage, Event + } = 22, +// pub type FellowshipReferendaInstance = pallet_referenda::Instance2; + FellowshipReferenda: pallet_referenda::::{ + Pallet, Call, Storage, Event + } = 23, + Origins: pallet_custom_origins::{Origin} = 43, + Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event} = 44, + // Claims. Usable initially. Claims: claims::{Pallet, Call, Storage, Event, Config, ValidateUnsigned} = 19, @@ -1513,6 +1506,7 @@ mod benches { [pallet_child_bounties, ChildBounties] [pallet_collective, Council] [pallet_collective, TechnicalCommittee] + [pallet_conviction_voting, ConvictionVoting] [pallet_democracy, Democracy] [pallet_elections_phragmen, PhragmenElection] [pallet_election_provider_multi_phase, ElectionProviderMultiPhase] @@ -1528,7 +1522,10 @@ mod benches { [pallet_offences, OffencesBench::] [pallet_preimage, Preimage] [pallet_proxy, Proxy] + [pallet_ranked_collective, FellowshipCollective] [pallet_recovery, Recovery] + [pallet_referenda, Referenda] + [pallet_referenda, FellowshipReferenda] [pallet_scheduler, Scheduler] [pallet_session, SessionBench::] [pallet_staking, Staking] @@ -1538,6 +1535,7 @@ mod benches { [pallet_treasury, Treasury] [pallet_utility, Utility] [pallet_vesting, Vesting] + [pallet_whitelist, Whitelist] // XCM [pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::] [pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::] @@ -1740,6 +1738,13 @@ sp_api::impl_runtime_apis! { Err(mmr::Error::PalletNotIncluded) } + fn generate_historical_batch_proof( + _leaf_indices: Vec, + _leaves_count: u64, + ) -> Result<(Vec, mmr::BatchProof), mmr::Error> { + Err(mmr::Error::PalletNotIncluded) + } + fn verify_batch_proof(_leaves: Vec, _proof: mmr::BatchProof) -> Result<(), mmr::Error> { @@ -2101,7 +2106,7 @@ mod multiplier_tests { BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); // if the min is too small, then this will not change, and we are doomed forever. // the weight is 1/100th bigger than target. - run_with_system_weight(target * 101 / 100, || { + run_with_system_weight(target.saturating_mul(101) / 100, || { let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); }) diff --git a/runtime/kusama/src/weights/mod.rs b/runtime/kusama/src/weights/mod.rs index 4f8eb7d453d2..2f9e2d35c211 100644 --- a/runtime/kusama/src/weights/mod.rs +++ b/runtime/kusama/src/weights/mod.rs @@ -23,6 +23,7 @@ pub mod pallet_bounties; pub mod pallet_child_bounties; pub mod pallet_collective_council; pub mod pallet_collective_technical_committee; +pub mod pallet_conviction_voting; pub mod pallet_democracy; pub mod pallet_election_provider_multi_phase; pub mod pallet_elections_phragmen; @@ -36,6 +37,9 @@ pub mod pallet_multisig; pub mod pallet_nomination_pools; pub mod pallet_preimage; pub mod pallet_proxy; +pub mod pallet_ranked_collective; +pub mod pallet_referenda_fellowship_referenda; +pub mod pallet_referenda_referenda; pub mod pallet_scheduler; pub mod pallet_session; pub mod pallet_staking; @@ -44,6 +48,7 @@ pub mod pallet_tips; pub mod pallet_treasury; pub mod pallet_utility; pub mod pallet_vesting; +pub mod pallet_whitelist; pub mod runtime_common_auctions; pub mod runtime_common_claims; pub mod runtime_common_crowdloan; diff --git a/runtime/kusama/src/weights/pallet_collective_council.rs b/runtime/kusama/src/weights/pallet_collective_council.rs index b59c6ff54ceb..8fe7d12e04b5 100644 --- a/runtime/kusama/src/weights/pallet_collective_council.rs +++ b/runtime/kusama/src/weights/pallet_collective_council.rs @@ -27,7 +27,6 @@ // --chain=kusama-dev // --steps=50 // --repeat=20 -// --pallet=pallet_collective // --extrinsic=* // --execution=wasm // --wasm-execution=compiled diff --git a/runtime/kusama/src/weights/pallet_collective_technical_committee.rs b/runtime/kusama/src/weights/pallet_collective_technical_committee.rs index 6ec788ec0fd5..149a26d54b0e 100644 --- a/runtime/kusama/src/weights/pallet_collective_technical_committee.rs +++ b/runtime/kusama/src/weights/pallet_collective_technical_committee.rs @@ -27,7 +27,6 @@ // --chain=kusama-dev // --steps=50 // --repeat=20 -// --pallet=pallet_collective // --extrinsic=* // --execution=wasm // --wasm-execution=compiled diff --git a/runtime/kusama/src/weights/pallet_conviction_voting.rs b/runtime/kusama/src/weights/pallet_conviction_voting.rs new file mode 100644 index 000000000000..fbbb0d6529b5 --- /dev/null +++ b/runtime/kusama/src/weights/pallet_conviction_voting.rs @@ -0,0 +1,119 @@ +// Copyright 2017-2022 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 . +//! Autogenerated weights for `pallet_conviction_voting` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-09-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_conviction_voting +// --chain=kusama-dev +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight}}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_conviction_voting`. +pub struct WeightInfo(PhantomData); +impl pallet_conviction_voting::WeightInfo for WeightInfo { + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: ConvictionVoting VotingFor (r:1 w:1) + // Storage: ConvictionVoting ClassLocksFor (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn vote_new() -> Weight { + Weight::from_ref_time(5_652_326_000 as u64) + .saturating_add(T::DbWeight::get().reads(6 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: ConvictionVoting VotingFor (r:1 w:1) + // Storage: ConvictionVoting ClassLocksFor (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn vote_existing() -> Weight { + Weight::from_ref_time(509_859_000 as u64) + .saturating_add(T::DbWeight::get().reads(6 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) + } + // Storage: ConvictionVoting VotingFor (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn remove_vote() -> Weight { + Weight::from_ref_time(486_638_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: ConvictionVoting VotingFor (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:1 w:0) + fn remove_other_vote() -> Weight { + Weight::from_ref_time(74_517_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: ConvictionVoting VotingFor (r:2 w:2) + // Storage: ConvictionVoting ClassLocksFor (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:10 w:10) + // Storage: Scheduler Agenda (r:2 w:2) + /// The range of component `r` is `[0, 512]`. + fn delegate(r: u32, ) -> Weight { + Weight::from_ref_time(78_376_000 as u64) + // Standard Error: 2_253_708 + .saturating_add(Weight::from_ref_time(221_428_037 as u64).saturating_mul(r as u64)) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64))) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(r as u64))) + } + // Storage: ConvictionVoting VotingFor (r:2 w:2) + // Storage: Referenda ReferendumInfoFor (r:10 w:10) + // Storage: Scheduler Agenda (r:2 w:2) + /// The range of component `r` is `[0, 512]`. + fn undelegate(r: u32, ) -> Weight { + Weight::from_ref_time(55_946_000 as u64) + // Standard Error: 2_268_396 + .saturating_add(Weight::from_ref_time(221_648_859 as u64).saturating_mul(r as u64)) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(r as u64))) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(r as u64))) + } + // Storage: ConvictionVoting VotingFor (r:1 w:1) + // Storage: ConvictionVoting ClassLocksFor (r:1 w:1) + // Storage: Balances Locks (r:1 w:1) + fn unlock() -> Weight { + Weight::from_ref_time(93_068_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } +} diff --git a/runtime/kusama/src/weights/pallet_ranked_collective.rs b/runtime/kusama/src/weights/pallet_ranked_collective.rs new file mode 100644 index 000000000000..33b62a7db764 --- /dev/null +++ b/runtime/kusama/src/weights/pallet_ranked_collective.rs @@ -0,0 +1,116 @@ +// Copyright 2017-2022 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 . +//! Autogenerated weights for `pallet_ranked_collective` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-09-16, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_ranked_collective +// --chain=kusama-dev +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight}}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_ranked_collective`. +pub struct WeightInfo(PhantomData); +impl pallet_ranked_collective::WeightInfo for WeightInfo { + // Storage: FellowshipCollective Members (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:1) + // Storage: FellowshipCollective IndexToId (r:0 w:1) + // Storage: FellowshipCollective IdToIndex (r:0 w:1) + fn add_member() -> Weight { + Weight::from_ref_time(20_797_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipCollective Members (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:1) + // Storage: FellowshipCollective IdToIndex (r:1 w:1) + // Storage: FellowshipCollective IndexToId (r:1 w:1) + /// The range of component `r` is `[0, 10]`. + fn remove_member(r: u32, ) -> Weight { + Weight::from_ref_time(30_196_000 as u64) + // Standard Error: 10_539 + .saturating_add(Weight::from_ref_time(9_633_382 as u64).saturating_mul(r as u64)) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().reads((3 as u64).saturating_mul(r as u64))) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(r as u64))) + } + // Storage: FellowshipCollective Members (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:1) + // Storage: FellowshipCollective IndexToId (r:0 w:1) + // Storage: FellowshipCollective IdToIndex (r:0 w:1) + /// The range of component `r` is `[0, 10]`. + fn promote_member(r: u32, ) -> Weight { + Weight::from_ref_time(21_958_000 as u64) + // Standard Error: 3_398 + .saturating_add(Weight::from_ref_time(527_087 as u64).saturating_mul(r as u64)) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipCollective Members (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:1) + // Storage: FellowshipCollective IdToIndex (r:1 w:1) + // Storage: FellowshipCollective IndexToId (r:1 w:1) + /// The range of component `r` is `[0, 10]`. + fn demote_member(r: u32, ) -> Weight { + Weight::from_ref_time(29_934_000 as u64) + // Standard Error: 11_453 + .saturating_add(Weight::from_ref_time(884_044 as u64).saturating_mul(r as u64)) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipCollective Members (r:1 w:0) + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective Voting (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn vote() -> Weight { + Weight::from_ref_time(45_989_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:0) + // Storage: FellowshipCollective VotingCleanup (r:1 w:0) + // Storage: FellowshipCollective Voting (r:0 w:1) + /// The range of component `n` is `[1, 100]`. + fn cleanup_poll(n: u32, ) -> Weight { + Weight::from_ref_time(17_842_000 as u64) + // Standard Error: 733 + .saturating_add(Weight::from_ref_time(892_322 as u64).saturating_mul(n as u64)) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(n as u64))) + } +} diff --git a/runtime/kusama/src/weights/pallet_referenda_fellowship_referenda.rs b/runtime/kusama/src/weights/pallet_referenda_fellowship_referenda.rs new file mode 100644 index 000000000000..ca52d8044bbf --- /dev/null +++ b/runtime/kusama/src/weights/pallet_referenda_fellowship_referenda.rs @@ -0,0 +1,264 @@ +// Copyright 2017-2022 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 . +//! Autogenerated weights for `pallet_referenda` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-09-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_referenda +// --chain=kusama-dev +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_referenda`. +pub struct WeightInfo(PhantomData); +impl pallet_referenda::WeightInfo for WeightInfo { + // Storage: FellowshipCollective Members (r:1 w:0) + // Storage: FellowshipReferenda ReferendumCount (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: FellowshipReferenda ReferendumInfoFor (r:0 w:1) + fn submit() -> Weight { + Weight::from_ref_time(32_438_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_preparing() -> Weight { + Weight::from_ref_time(48_476_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:0) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + fn place_decision_deposit_queued() -> Weight { + Weight::from_ref_time(94_751_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:0) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + fn place_decision_deposit_not_queued() -> Weight { + Weight::from_ref_time(94_975_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_passing() -> Weight { + Weight::from_ref_time(194_931_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + fn place_decision_deposit_failing() -> Weight { + Weight::from_ref_time(42_888_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + fn refund_decision_deposit() -> Weight { + Weight::from_ref_time(30_949_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn cancel() -> Weight { + Weight::from_ref_time(38_960_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn kill() -> Weight { + Weight::from_ref_time(67_836_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda TrackQueue (r:1 w:0) + // Storage: FellowshipReferenda DecidingCount (r:1 w:1) + fn one_fewer_deciding_queue_empty() -> Weight { + Weight::from_ref_time(11_204_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_failing() -> Weight { + Weight::from_ref_time(224_465_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_passing() -> Weight { + Weight::from_ref_time(224_764_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_insertion() -> Weight { + Weight::from_ref_time(91_727_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_slide() -> Weight { + Weight::from_ref_time(91_868_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:0) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_queued() -> Weight { + Weight::from_ref_time(94_520_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:0) + // Storage: FellowshipReferenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_not_queued() -> Weight { + Weight::from_ref_time(93_483_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_no_deposit() -> Weight { + Weight::from_ref_time(29_294_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_preparing() -> Weight { + Weight::from_ref_time(30_363_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + fn nudge_referendum_timed_out() -> Weight { + Weight::from_ref_time(22_703_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_failing() -> Weight { + Weight::from_ref_time(40_760_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipReferenda DecidingCount (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_passing() -> Weight { + Weight::from_ref_time(91_300_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_confirming() -> Weight { + Weight::from_ref_time(165_577_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_end_confirming() -> Weight { + Weight::from_ref_time(166_188_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_not_confirming() -> Weight { + Weight::from_ref_time(159_324_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_confirming() -> Weight { + Weight::from_ref_time(82_615_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn nudge_referendum_approved() -> Weight { + Weight::from_ref_time(185_354_000 as u64) + .saturating_add(T::DbWeight::get().reads(6 as u64)) + .saturating_add(T::DbWeight::get().writes(5 as u64)) + } + // Storage: FellowshipReferenda ReferendumInfoFor (r:1 w:1) + // Storage: FellowshipCollective MemberCount (r:1 w:0) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_rejected() -> Weight { + Weight::from_ref_time(165_963_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } +} diff --git a/runtime/kusama/src/weights/pallet_referenda_referenda.rs b/runtime/kusama/src/weights/pallet_referenda_referenda.rs new file mode 100644 index 000000000000..8d8fc6ecbd61 --- /dev/null +++ b/runtime/kusama/src/weights/pallet_referenda_referenda.rs @@ -0,0 +1,251 @@ +// Copyright 2017-2022 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 . +//! Autogenerated weights for `pallet_referenda` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-09-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_referenda +// --chain=kusama-dev +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_referenda`. +pub struct WeightInfo(PhantomData); +impl pallet_referenda::WeightInfo for WeightInfo { + // Storage: Referenda ReferendumCount (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:0 w:1) + fn submit() -> Weight { + Weight::from_ref_time(37_366_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_preparing() -> Weight { + Weight::from_ref_time(47_931_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:0) + // Storage: Referenda TrackQueue (r:1 w:1) + fn place_decision_deposit_queued() -> Weight { + Weight::from_ref_time(48_799_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:0) + // Storage: Referenda TrackQueue (r:1 w:1) + fn place_decision_deposit_not_queued() -> Weight { + Weight::from_ref_time(48_899_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn place_decision_deposit_passing() -> Weight { + Weight::from_ref_time(61_981_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:1) + fn place_decision_deposit_failing() -> Weight { + Weight::from_ref_time(42_318_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + fn refund_decision_deposit() -> Weight { + Weight::from_ref_time(30_391_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn cancel() -> Weight { + Weight::from_ref_time(38_601_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn kill() -> Weight { + Weight::from_ref_time(78_111_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda TrackQueue (r:1 w:0) + // Storage: Referenda DecidingCount (r:1 w:1) + fn one_fewer_deciding_queue_empty() -> Weight { + Weight::from_ref_time(11_132_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_failing() -> Weight { + Weight::from_ref_time(161_624_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + fn one_fewer_deciding_passing() -> Weight { + Weight::from_ref_time(167_193_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_insertion() -> Weight { + Weight::from_ref_time(44_257_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_requeued_slide() -> Weight { + Weight::from_ref_time(43_981_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:0) + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_queued() -> Weight { + Weight::from_ref_time(45_931_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:0) + // Storage: Referenda TrackQueue (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_not_queued() -> Weight { + Weight::from_ref_time(45_854_000 as u64) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_no_deposit() -> Weight { + Weight::from_ref_time(28_641_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_preparing() -> Weight { + Weight::from_ref_time(29_629_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + fn nudge_referendum_timed_out() -> Weight { + Weight::from_ref_time(21_852_000 as u64) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_failing() -> Weight { + Weight::from_ref_time(41_478_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Referenda DecidingCount (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_deciding_passing() -> Weight { + Weight::from_ref_time(44_198_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_begin_confirming() -> Weight { + Weight::from_ref_time(38_978_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_end_confirming() -> Weight { + Weight::from_ref_time(40_123_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_not_confirming() -> Weight { + Weight::from_ref_time(36_868_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_continue_confirming() -> Weight { + Weight::from_ref_time(36_835_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:2 w:2) + // Storage: Scheduler Lookup (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn nudge_referendum_approved() -> Weight { + Weight::from_ref_time(56_130_000 as u64) + .saturating_add(T::DbWeight::get().reads(5 as u64)) + .saturating_add(T::DbWeight::get().writes(5 as u64)) + } + // Storage: Referenda ReferendumInfoFor (r:1 w:1) + // Storage: Scheduler Agenda (r:1 w:1) + fn nudge_referendum_rejected() -> Weight { + Weight::from_ref_time(38_997_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } +} diff --git a/runtime/kusama/src/weights/pallet_whitelist.rs b/runtime/kusama/src/weights/pallet_whitelist.rs new file mode 100644 index 000000000000..5e7dcf8f75b3 --- /dev/null +++ b/runtime/kusama/src/weights/pallet_whitelist.rs @@ -0,0 +1,82 @@ +// Copyright 2017-2022 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 . +//! Autogenerated weights for `pallet_whitelist` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-09-18, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024 + +// Executed Command: +// /home/benchbot/cargo_target_dir/production/polkadot +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --pallet=pallet_whitelist +// --chain=kusama-dev +// --header=./file_header.txt +// --output=./runtime/kusama/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight}}; +use sp_std::marker::PhantomData; + +/// Weight functions for `pallet_whitelist`. +pub struct WeightInfo(PhantomData); +impl pallet_whitelist::WeightInfo for WeightInfo { + // Storage: Whitelist WhitelistedCall (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn whitelist_call() -> Weight { + Weight::from_ref_time(21_808_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(2 as u64)) + } + // Storage: Whitelist WhitelistedCall (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + fn remove_whitelisted_call() -> Weight { + Weight::from_ref_time(24_193_000 as u64) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Whitelist WhitelistedCall (r:1 w:1) + // Storage: Preimage PreimageFor (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + fn dispatch_whitelisted_call() -> Weight { + Weight::from_ref_time(7_327_364_000 as u64) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } + // Storage: Whitelist WhitelistedCall (r:1 w:1) + // Storage: Preimage StatusFor (r:1 w:1) + // Storage: Preimage PreimageFor (r:0 w:1) + /// The range of component `n` is `[1, 10000]`. + fn dispatch_whitelisted_call_with_preimage(n: u32, ) -> Weight { + Weight::from_ref_time(26_992_000 as u64) + // Standard Error: 4 + .saturating_add(Weight::from_ref_time(1_621 as u64).saturating_mul(n as u64)) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(3 as u64)) + } +} diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index 05c17b00150b..bc576fa9d4a6 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -82,7 +82,9 @@ where parameter_types! { pub const BlockHashCount: u32 = 250; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(4 * 1024 * 1024)); + frame_system::limits::BlockWeights::simple_max( + Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX), + ); } pub type AccountId = u64; diff --git a/runtime/parachains/src/ump.rs b/runtime/parachains/src/ump.rs index 92cce87f85a7..5aa7b17d923c 100644 --- a/runtime/parachains/src/ump.rs +++ b/runtime/parachains/src/ump.rs @@ -524,7 +524,10 @@ impl Pallet { let max_weight = if weight_used == Weight::zero() { // we increase the amount of weight that we're allowed to use on the first message to try to prevent // the possibility of blockage of the queue. - config.ump_service_total_weight * T::FirstMessageFactorPercent::get() / 100 + config + .ump_service_total_weight + .saturating_mul(T::FirstMessageFactorPercent::get()) / + 100 } else { config.ump_service_total_weight - weight_used }; diff --git a/runtime/parachains/src/ump/benchmarking.rs b/runtime/parachains/src/ump/benchmarking.rs index c415526da7c5..a257da79b373 100644 --- a/runtime/parachains/src/ump/benchmarking.rs +++ b/runtime/parachains/src/ump/benchmarking.rs @@ -117,7 +117,7 @@ frame_benchmarking::benchmarks! { let msg = create_message_overweight::(); // This just makes sure that 0 is not a valid index and we can use it later on. - let _ = Ump::::service_overweight(RawOrigin::Root.into(), 0, Weight::from_ref_time(1000)); + let _ = Ump::::service_overweight(RawOrigin::Root.into(), 0, Weight::from_ref_time(1000).set_proof_size(u64::MAX)); // Start with the block number 1. This is needed because should an event be // emitted during the genesis block they will be implicitly wiped. frame_system::Pallet::::set_block_number(1u32.into()); diff --git a/runtime/parachains/src/ump/tests.rs b/runtime/parachains/src/ump/tests.rs index c0ffbdc8256c..23c5159eab0f 100644 --- a/runtime/parachains/src/ump/tests.rs +++ b/runtime/parachains/src/ump/tests.rs @@ -38,8 +38,8 @@ impl Default for GenesisConfigBuilder { max_upward_message_num_per_candidate: 2, max_upward_queue_count: 4, max_upward_queue_size: 64, - ump_service_total_weight: Weight::from_ref_time(1000), - ump_max_individual_weight: Weight::from_ref_time(100), + ump_service_total_weight: Weight::from_ref_time(1000).set_proof_size(1000), + ump_max_individual_weight: Weight::from_ref_time(100).set_proof_size(100), } } } @@ -156,7 +156,7 @@ fn dispatch_resume_after_exceeding_dispatch_stage_weight() { new_test_ext( GenesisConfigBuilder { - ump_service_total_weight: Weight::from_ref_time(500), + ump_service_total_weight: Weight::from_ref_time(500).set_proof_size(500), ..Default::default() } .build(), @@ -203,8 +203,8 @@ fn dispatch_keeps_message_after_weight_exhausted() { new_test_ext( GenesisConfigBuilder { - ump_service_total_weight: Weight::from_ref_time(500), - ump_max_individual_weight: Weight::from_ref_time(300), + ump_service_total_weight: Weight::from_ref_time(500).set_proof_size(500), + ump_max_individual_weight: Weight::from_ref_time(300).set_proof_size(300), ..Default::default() } .build(), @@ -243,7 +243,7 @@ fn dispatch_correctly_handle_remove_of_latest() { new_test_ext( GenesisConfigBuilder { - ump_service_total_weight: Weight::from_ref_time(900), + ump_service_total_weight: Weight::from_ref_time(900).set_proof_size(900), ..Default::default() } .build(), @@ -312,8 +312,8 @@ fn overweight_queue_works() { new_test_ext( GenesisConfigBuilder { - ump_service_total_weight: Weight::from_ref_time(900), - ump_max_individual_weight: Weight::from_ref_time(300), + ump_service_total_weight: Weight::from_ref_time(900).set_proof_size(900), + ump_max_individual_weight: Weight::from_ref_time(300).set_proof_size(300), ..Default::default() } .build(), diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 6abf57de9edf..96a557712a76 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1827,6 +1827,13 @@ sp_api::impl_runtime_apis! { Err(mmr::Error::PalletNotIncluded) } + fn generate_historical_batch_proof( + _leaf_indices: Vec, + _leaves_count: u64, + ) -> Result<(Vec, mmr::BatchProof), mmr::Error> { + Err(mmr::Error::PalletNotIncluded) + } + fn verify_batch_proof(_leaves: Vec, _proof: mmr::BatchProof) -> Result<(), mmr::Error> { @@ -2284,7 +2291,7 @@ mod multiplier_tests { BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); // if the min is too small, then this will not change, and we are doomed forever. // the weight is 1/100th bigger than target. - run_with_system_weight(target * 101 / 100, || { + run_with_system_weight(target.saturating_mul(101) / 100, || { let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); }) diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index f27905b66e29..94677cc07290 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1723,6 +1723,23 @@ sp_api::impl_runtime_apis! { .map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof)) } + fn generate_historical_batch_proof( + leaf_indices: Vec, + leaves_count: mmr::LeafIndex, + ) -> Result<(Vec, mmr::BatchProof), mmr::Error> { + Mmr::generate_historical_batch_proof(leaf_indices, leaves_count).map( + |(leaves, proof)| { + ( + leaves + .into_iter() + .map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)) + .collect(), + proof, + ) + }, + ) + } + fn verify_batch_proof(leaves: Vec, proof: mmr::BatchProof) -> Result<(), mmr::Error> { diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 311ff132b54f..2eade55e3877 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -947,6 +947,13 @@ sp_api::impl_runtime_apis! { Err(mmr::Error::PalletNotIncluded) } + fn generate_historical_batch_proof( + _leaf_indices: Vec, + _leaves_count: u64, + ) -> Result<(Vec, mmr::BatchProof), mmr::Error> { + Err(mmr::Error::PalletNotIncluded) + } + fn verify_batch_proof(_leaves: Vec, _proof: mmr::BatchProof) -> Result<(), mmr::Error> { diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 62993cc24fd7..6aef1be3a267 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1473,7 +1473,13 @@ sp_api::impl_runtime_apis! { fn generate_batch_proof(_leaf_indices: Vec) -> Result<(Vec, mmr::BatchProof), mmr::Error> { + Err(mmr::Error::PalletNotIncluded) + } + fn generate_historical_batch_proof( + _leaf_indices: Vec, + _leaves_count: u64, + ) -> Result<(Vec, mmr::BatchProof), mmr::Error> { Err(mmr::Error::PalletNotIncluded) } diff --git a/scripts/ci/gitlab/pipeline/zombienet.yml b/scripts/ci/gitlab/pipeline/zombienet.yml index 5c6215aad2c4..8b8bc3abe0ae 100644 --- a/scripts/ci/gitlab/pipeline/zombienet.yml +++ b/scripts/ci/gitlab/pipeline/zombienet.yml @@ -88,7 +88,7 @@ zombienet-tests-parachains-disputes: - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh --github-remote-dir="${GH_DIR}" --test="0002-parachains-disputes.zndsl" - allow_failure: false + allow_failure: true retry: 2 tags: - zombienet-polkadot-integration-test diff --git a/xcm/pallet-xcm-benchmarks/Cargo.toml b/xcm/pallet-xcm-benchmarks/Cargo.toml index b14dd3301346..5c48219a6d1e 100644 --- a/xcm/pallet-xcm-benchmarks/Cargo.toml +++ b/xcm/pallet-xcm-benchmarks/Cargo.toml @@ -14,9 +14,9 @@ frame-support = { default-features = false, branch = "master", git = "https://gi frame-system = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" } sp-runtime = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" } sp-std = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" } -xcm-executor = { path = "../xcm-executor", default-features = false, features = ["runtime-benchmarks"] } +xcm-executor = { path = "../xcm-executor", default-features = false } frame-benchmarking = { default-features = false, branch = "master", git = "https://github.com/paritytech/substrate" } -xcm = { path = "..", default-features = false, features = ["runtime-benchmarks"] } +xcm = { path = "..", default-features = false } log = "0.4.17" [dev-dependencies] @@ -44,6 +44,8 @@ std = [ "sp-std/std" ] runtime-benchmarks = [ + "xcm/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs b/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs index 3cc67971e667..3722c7602a84 100644 --- a/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs +++ b/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs @@ -47,7 +47,9 @@ frame_support::construct_runtime!( parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); + frame_system::limits::BlockWeights::simple_max( + Weight::from_ref_time(1024).set_proof_size(u64::MAX), + ); } impl frame_system::Config for Test { type BaseCallFilter = Everything; diff --git a/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs b/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs index 1acf61cf0010..a7fd0e99fd8e 100644 --- a/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs +++ b/xcm/pallet-xcm-benchmarks/src/fungible/mod.rs @@ -18,6 +18,7 @@ pub use pallet::*; +#[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; #[cfg(test)] mod mock; diff --git a/xcm/pallet-xcm-benchmarks/src/generic/mock.rs b/xcm/pallet-xcm-benchmarks/src/generic/mock.rs index ea7899afceb9..1aeec6c317fe 100644 --- a/xcm/pallet-xcm-benchmarks/src/generic/mock.rs +++ b/xcm/pallet-xcm-benchmarks/src/generic/mock.rs @@ -52,7 +52,9 @@ frame_support::construct_runtime!( parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); + frame_system::limits::BlockWeights::simple_max( + Weight::from_ref_time(1024).set_proof_size(u64::MAX), + ); } impl frame_system::Config for Test { diff --git a/xcm/pallet-xcm-benchmarks/src/generic/mod.rs b/xcm/pallet-xcm-benchmarks/src/generic/mod.rs index adf31fb207f2..de347a537be2 100644 --- a/xcm/pallet-xcm-benchmarks/src/generic/mod.rs +++ b/xcm/pallet-xcm-benchmarks/src/generic/mod.rs @@ -1,5 +1,6 @@ pub use pallet::*; +#[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; #[cfg(test)] mod mock;