Revert "Abstracts elections-phragmen pallet to use NposSolver (#12588)" (#13451)

This reverts commit b793666ca5.
This commit is contained in:
Gonçalo Pestana
2023-02-23 18:15:08 +00:00
committed by GitHub
parent 4af011f418
commit c848d40775
28 changed files with 1018 additions and 1197 deletions
+140 -125
View File
@@ -27,7 +27,7 @@ version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
dependencies = [
"gimli 0.27.2",
"gimli 0.27.1",
]
[[package]]
@@ -246,7 +246,7 @@ dependencies = [
"num-traits",
"rusticata-macros",
"thiserror",
"time 0.3.19",
"time 0.3.17",
]
[[package]]
@@ -262,7 +262,7 @@ dependencies = [
"num-traits",
"rusticata-macros",
"thiserror",
"time 0.3.19",
"time 0.3.17",
]
[[package]]
@@ -358,20 +358,19 @@ dependencies = [
[[package]]
name = "async-stream"
version = "0.3.4"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad445822218ce64be7a341abfb0b1ea43b5c23aa83902542a4542e78309d8e5e"
checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e"
dependencies = [
"async-stream-impl",
"futures-core",
"pin-project-lite 0.2.9",
]
[[package]]
name = "async-stream-impl"
version = "0.3.4"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965"
checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27"
dependencies = [
"proc-macro2",
"quote",
@@ -580,9 +579,9 @@ dependencies = [
[[package]]
name = "bindgen"
version = "0.64.0"
version = "0.60.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4"
checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
dependencies = [
"bitflags",
"cexpr",
@@ -595,7 +594,6 @@ dependencies = [
"regex",
"rustc-hash",
"shlex",
"syn",
]
[[package]]
@@ -627,24 +625,24 @@ dependencies = [
[[package]]
name = "blake2b_simd"
version = "1.0.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc"
checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127"
dependencies = [
"arrayref",
"arrayvec 0.7.2",
"constant_time_eq",
"constant_time_eq 0.1.5",
]
[[package]]
name = "blake2s_simd"
version = "1.0.1"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f"
checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4"
dependencies = [
"arrayref",
"arrayvec 0.7.2",
"constant_time_eq",
"constant_time_eq 0.1.5",
]
[[package]]
@@ -657,7 +655,7 @@ dependencies = [
"arrayvec 0.7.2",
"cc",
"cfg-if",
"constant_time_eq",
"constant_time_eq 0.2.4",
]
[[package]]
@@ -717,9 +715,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae"
[[package]]
name = "bounded-collections"
version = "0.1.5"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a071c348a5ef6da1d3a87166b408170b46002382b1dda83992b5c2208cefb370"
checksum = "de2aff4807e40f478132150d80b031f2461d88f061851afcab537d7600c24120"
dependencies = [
"log",
"parity-scale-codec",
@@ -735,9 +733,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bstr"
version = "1.3.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffdb39cb703212f3c11973452c2861b972f757b021158f3516ba10f2fa8b2c1"
checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832"
dependencies = [
"memchr",
"once_cell",
@@ -919,7 +917,7 @@ name = "chain-spec-builder"
version = "2.0.0"
dependencies = [
"ansi_term",
"clap 4.1.6",
"clap 4.1.4",
"node-cli",
"rand 0.8.5",
"sc-chain-spec",
@@ -1012,9 +1010,9 @@ dependencies = [
[[package]]
name = "clang-sys"
version = "1.6.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a"
checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3"
dependencies = [
"glob",
"libc",
@@ -1035,9 +1033,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.1.6"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
@@ -1050,11 +1048,11 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.1.2"
version = "4.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd125be87bf4c255ebc50de0b7f4d2a6201e8ac3dc86e39c0ad081dc5e7236fe"
checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
]
[[package]]
@@ -1124,6 +1122,12 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b"
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "constant_time_eq"
version = "0.2.4"
@@ -1511,9 +1515,9 @@ dependencies = [
[[package]]
name = "cxx"
version = "1.0.91"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62"
checksum = "bc831ee6a32dd495436e317595e639a587aa9907bef96fe6e6abc290ab6204e9"
dependencies = [
"cc",
"cxxbridge-flags",
@@ -1523,9 +1527,9 @@ dependencies = [
[[package]]
name = "cxx-build"
version = "1.0.91"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690"
checksum = "94331d54f1b1a8895cd81049f7eaaaef9d05a7dcb4d1fd08bf3ff0806246789d"
dependencies = [
"cc",
"codespan-reporting",
@@ -1538,15 +1542,15 @@ dependencies = [
[[package]]
name = "cxxbridge-flags"
version = "1.0.91"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf"
checksum = "48dcd35ba14ca9b40d6e4b4b39961f23d835dbb8eed74565ded361d93e1feb8a"
[[package]]
name = "cxxbridge-macro"
version = "1.0.91"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892"
checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2"
dependencies = [
"proc-macro2",
"quote",
@@ -2047,9 +2051,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]]
name = "fastrand"
version = "1.9.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
"instant",
]
@@ -2091,14 +2095,14 @@ dependencies = [
[[package]]
name = "filetime"
version = "0.2.20"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412"
checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"windows-sys 0.45.0",
"windows-sys 0.42.0",
]
[[package]]
@@ -2218,7 +2222,7 @@ dependencies = [
"Inflector",
"array-bytes",
"chrono",
"clap 4.1.6",
"clap 4.1.4",
"comfy-table",
"frame-benchmarking",
"frame-support",
@@ -2291,7 +2295,6 @@ dependencies = [
name = "frame-election-provider-support"
version = "4.0.0-dev"
dependencies = [
"frame-benchmarking",
"frame-election-provider-solution-type",
"frame-support",
"frame-system",
@@ -2310,7 +2313,7 @@ dependencies = [
name = "frame-election-solution-type-fuzzer"
version = "2.0.0-alpha.5"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"frame-election-provider-solution-type",
"frame-election-provider-support",
"frame-support",
@@ -2363,7 +2366,7 @@ dependencies = [
"frame-support",
"futures",
"log",
"pallet-elections",
"pallet-elections-phragmen",
"parity-scale-codec",
"serde",
"sp-core",
@@ -2793,9 +2796,9 @@ dependencies = [
[[package]]
name = "gimli"
version = "0.27.2"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec"
[[package]]
name = "git2"
@@ -2938,9 +2941,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
version = "0.3.1"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
checksum = "856b5cb0902c2b6d65d5fd97dfa30f9b70c7538e770b98eab5ed52d8db923e01"
[[package]]
name = "hex"
@@ -3032,9 +3035,9 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.9"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
dependencies = [
"bytes",
"fnv",
@@ -3318,7 +3321,7 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22e18b0a45d56fe973d6db23972bf5bc46f988a4a2385deac9cc29572f09daef"
dependencies = [
"hermit-abi 0.3.1",
"hermit-abi 0.3.0",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
@@ -3544,7 +3547,8 @@ dependencies = [
"pallet-conviction-voting",
"pallet-democracy",
"pallet-election-provider-multi-phase",
"pallet-elections",
"pallet-election-provider-support-benchmarking",
"pallet-elections-phragmen",
"pallet-fast-unstake",
"pallet-glutton",
"pallet-grandpa",
@@ -4110,9 +4114,9 @@ dependencies = [
[[package]]
name = "librocksdb-sys"
version = "0.8.3+7.4.4"
version = "0.8.0+7.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "557b255ff04123fcc176162f56ed0c9cd42d8f357cf55b3fabeb60f7413741b3"
checksum = "611804e4666a25136fcc5f8cf425ab4d26c7f74ea245ffe92ea23b85b6420b5d"
dependencies = [
"bindgen",
"bzip2-sys",
@@ -4371,9 +4375,9 @@ dependencies = [
[[package]]
name = "memmap2"
version = "0.5.9"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af2c65375e552a67fe3829ca63e8a7c27a378a62824594f43b2851d682b5ec2"
checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc"
dependencies = [
"libc",
]
@@ -4441,14 +4445,14 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.6"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.45.0",
"windows-sys 0.42.0",
]
[[package]]
@@ -4730,7 +4734,7 @@ name = "node-bench"
version = "0.9.0-dev"
dependencies = [
"array-bytes",
"clap 4.1.6",
"clap 4.1.4",
"derive_more",
"fs_extra",
"futures",
@@ -4767,7 +4771,7 @@ version = "3.0.0-dev"
dependencies = [
"array-bytes",
"assert_cmd",
"clap 4.1.6",
"clap 4.1.4",
"clap_complete",
"criterion",
"frame-benchmarking-cli",
@@ -4887,7 +4891,7 @@ dependencies = [
name = "node-inspect"
version = "0.9.0-dev"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"parity-scale-codec",
"sc-cli",
"sc-client-api",
@@ -4946,7 +4950,7 @@ dependencies = [
name = "node-runtime-generate-bags"
version = "3.0.0"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"generate-bags",
"kitchensink-runtime",
]
@@ -4955,7 +4959,7 @@ dependencies = [
name = "node-template"
version = "4.0.0-dev"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"frame-benchmarking",
"frame-benchmarking-cli",
"frame-system",
@@ -5211,9 +5215,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.17.1"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
[[package]]
name = "oorandom"
@@ -5719,6 +5723,7 @@ dependencies = [
"frame-system",
"log",
"pallet-balances",
"pallet-election-provider-support-benchmarking",
"parity-scale-codec",
"parking_lot 0.12.1",
"rand 0.8.5",
@@ -5734,11 +5739,22 @@ dependencies = [
]
[[package]]
name = "pallet-elections"
version = "5.0.0-dev"
name = "pallet-election-provider-support-benchmarking"
version = "4.0.0-dev"
dependencies = [
"frame-benchmarking",
"frame-election-provider-support",
"frame-system",
"parity-scale-codec",
"sp-npos-elections",
"sp-runtime",
]
[[package]]
name = "pallet-elections-phragmen"
version = "5.0.0-dev"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"log",
@@ -6788,9 +6804,9 @@ dependencies = [
[[package]]
name = "parity-scale-codec"
version = "3.4.0"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac"
checksum = "c3840933452adf7b3b9145e27086a5a3376c619dca1a21b1e5a5af0d54979bed"
dependencies = [
"arrayvec 0.7.2",
"bitvec",
@@ -6935,9 +6951,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pest"
version = "2.5.5"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660"
checksum = "4ab62d2fa33726dbe6321cc97ef96d8cde531e3eeaf858a058de53a8a6d40d8f"
dependencies = [
"thiserror",
"ucd-trie",
@@ -6945,9 +6961,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.5.5"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69"
checksum = "8bf026e2d0581559db66d837fe5242320f525d85c76283c61f4d51a1238d65ea"
dependencies = [
"pest",
"pest_generator",
@@ -6955,9 +6971,9 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.5.5"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202"
checksum = "2b27bd18aa01d91c8ed2b61ea23406a676b42d82609c6e2581fba42f0c15f17f"
dependencies = [
"pest",
"pest_meta",
@@ -6968,9 +6984,9 @@ dependencies = [
[[package]]
name = "pest_meta"
version = "2.5.5"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616"
checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d"
dependencies = [
"once_cell",
"pest",
@@ -7542,7 +7558,7 @@ checksum = "6413f3de1edee53342e6138e75b56d32e7bc6e332b3bd62d497b1929d4cfbcdd"
dependencies = [
"pem",
"ring",
"time 0.3.19",
"time 0.3.17",
"x509-parser 0.13.2",
"yasna",
]
@@ -7555,7 +7571,7 @@ checksum = "ffbe84efe2f38dea12e9bfc1f65377fdf03e53a18cb3b995faedf7934c7e785b"
dependencies = [
"pem",
"ring",
"time 0.3.19",
"time 0.3.17",
"yasna",
]
@@ -8029,7 +8045,7 @@ version = "0.10.0-dev"
dependencies = [
"array-bytes",
"chrono",
"clap 4.1.6",
"clap 4.1.4",
"fdlimit",
"futures",
"futures-timer",
@@ -9064,7 +9080,7 @@ dependencies = [
name = "sc-storage-monitor"
version = "0.1.0"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"futures",
"log",
"nix 0.26.2",
@@ -9460,9 +9476,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.93"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a"
dependencies = [
"itoa",
"ryu",
@@ -9545,9 +9561,9 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
@@ -9577,9 +9593,9 @@ dependencies = [
[[package]]
name = "slab"
version = "0.4.8"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
dependencies = [
"autocfg",
]
@@ -10123,7 +10139,7 @@ dependencies = [
name = "sp-npos-elections-fuzzer"
version = "2.0.0-alpha.5"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"honggfuzz",
"parity-scale-codec",
"rand 0.8.5",
@@ -10480,9 +10496,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.5"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc"
checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09"
[[package]]
name = "spki"
@@ -10600,7 +10616,7 @@ dependencies = [
name = "subkey"
version = "3.0.0"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"sc-cli",
]
@@ -10628,7 +10644,7 @@ dependencies = [
name = "substrate-frame-cli"
version = "4.0.0-dev"
dependencies = [
"clap 4.1.6",
"clap 4.1.4",
"frame-support",
"frame-system",
"sc-cli",
@@ -10938,9 +10954,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "target-lexicon"
version = "0.12.6"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5"
checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d"
[[package]]
name = "tempfile"
@@ -11005,11 +11021,10 @@ checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
[[package]]
name = "thread_local"
version = "1.1.7"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
"cfg-if",
"once_cell",
]
@@ -11045,9 +11060,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.3.19"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa",
"serde",
@@ -11063,9 +11078,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.7"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
@@ -11167,9 +11182,9 @@ dependencies = [
[[package]]
name = "tokio-stream"
version = "0.1.12"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313"
checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce"
dependencies = [
"futures-core",
"pin-project-lite 0.2.9",
@@ -11192,9 +11207,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.7"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2"
checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
dependencies = [
"bytes",
"futures-core",
@@ -11466,7 +11481,7 @@ name = "try-runtime-cli"
version = "0.10.0-dev"
dependencies = [
"async-trait",
"clap 4.1.6",
"clap 4.1.4",
"frame-remote-externalities",
"frame-try-runtime",
"hex",
@@ -11811,9 +11826,9 @@ checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
[[package]]
name = "wasm-encoder"
version = "0.24.0"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704553b4d614a47080b4a457a976b3c16174b19ce95b931b847561b590dd09ba"
checksum = "9a584273ccc2d9311f1dd19dc3fb26054661fa3e373d53ede5d1144ba07a9acd"
dependencies = [
"leb128",
]
@@ -11909,7 +11924,7 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729"
dependencies = [
"spin 0.9.5",
"spin 0.9.4",
"wasmi_arena",
"wasmi_core 0.5.0",
"wasmparser-nostd",
@@ -12154,9 +12169,9 @@ dependencies = [
[[package]]
name = "wast"
version = "54.0.0"
version = "52.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d3df4a63b10958fe98ab9d7e9a57a7bc900209d2b4edd10535bfb0703e6516"
checksum = "15942180f265280eede7bc38b239e9770031d1821c02d905284216c645316430"
dependencies = [
"leb128",
"memchr",
@@ -12166,9 +12181,9 @@ dependencies = [
[[package]]
name = "wat"
version = "1.0.59"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e9a7c7d177696d0548178c36e377d49eba54170e885801d4270e2d44e82ac84"
checksum = "37212100d4cbe6f0f6ff6e707f1e5a5b5b675f0451231ed9e4235e234e127ed3"
dependencies = [
"wast",
]
@@ -12238,7 +12253,7 @@ dependencies = [
"sha2 0.10.6",
"stun",
"thiserror",
"time 0.3.19",
"time 0.3.17",
"tokio",
"turn",
"url",
@@ -12311,9 +12326,9 @@ dependencies = [
[[package]]
name = "webrtc-ice"
version = "0.9.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465a03cc11e9a7d7b4f9f99870558fe37a102b65b93f8045392fef7c67b39e80"
checksum = "494483fbb2f5492620871fdc78b084aed8807377f6e3fe88b2e49f0a9c9c41d7"
dependencies = [
"arc-swap",
"async-trait",
@@ -12671,7 +12686,7 @@ dependencies = [
"ring",
"rusticata-macros",
"thiserror",
"time 0.3.19",
"time 0.3.17",
]
[[package]]
@@ -12689,7 +12704,7 @@ dependencies = [
"oid-registry 0.6.1",
"rusticata-macros",
"thiserror",
"time 0.3.19",
"time 0.3.17",
]
[[package]]
@@ -12718,7 +12733,7 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aed2e7a52e3744ab4d0c05c20aa065258e84c49fd4226f5191b2ed29712710b4"
dependencies = [
"time 0.3.19",
"time 0.3.17",
]
[[package]]
@@ -12763,9 +12778,9 @@ dependencies = [
[[package]]
name = "zstd-sys"
version = "2.0.7+zstd.1.5.4"
version = "2.0.6+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b"
dependencies = [
"cc",
"libc",
+2 -1
View File
@@ -97,9 +97,10 @@ members = [
"frame/democracy",
"frame/fast-unstake",
"frame/try-runtime",
"frame/elections",
"frame/elections-phragmen",
"frame/election-provider-multi-phase",
"frame/election-provider-support",
"frame/election-provider-support/benchmarking",
"frame/election-provider-support/solution-type",
"frame/election-provider-support/solution-type/fuzzer",
"frame/examples/basic",
+7 -5
View File
@@ -66,7 +66,8 @@ pallet-contracts-primitives = { version = "7.0.0", default-features = false, pat
pallet-conviction-voting = { version = "4.0.0-dev", default-features = false, path = "../../../frame/conviction-voting" }
pallet-democracy = { version = "4.0.0-dev", default-features = false, path = "../../../frame/democracy" }
pallet-election-provider-multi-phase = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-multi-phase" }
pallet-elections = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections" }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support/benchmarking", optional = true }
pallet-elections-phragmen = { version = "5.0.0-dev", default-features = false, path = "../../../frame/elections-phragmen" }
pallet-fast-unstake = { version = "4.0.0-dev", default-features = false, path = "../../../frame/fast-unstake" }
pallet-nis = { version = "4.0.0-dev", default-features = false, path = "../../../frame/nis" }
pallet-grandpa = { version = "4.0.0-dev", default-features = false, path = "../../../frame/grandpa" }
@@ -124,6 +125,7 @@ with-tracing = ["frame-executive/with-tracing"]
std = [
"pallet-whitelist/std",
"pallet-offences-benchmarking?/std",
"pallet-election-provider-support-benchmarking?/std",
"pallet-asset-tx-payment/std",
"frame-system-benchmarking?/std",
"frame-election-provider-support/std",
@@ -144,7 +146,7 @@ std = [
"pallet-contracts-primitives/std",
"pallet-conviction-voting/std",
"pallet-democracy/std",
"pallet-elections/std",
"pallet-elections-phragmen/std",
"pallet-fast-unstake/std",
"frame-executive/std",
"pallet-nis/std",
@@ -218,7 +220,6 @@ runtime-benchmarks = [
"frame-benchmarking-pallet-pov/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-alliance/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
@@ -232,7 +233,8 @@ runtime-benchmarks = [
"pallet-conviction-voting/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-elections/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-nis/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
@@ -289,7 +291,7 @@ try-runtime = [
"pallet-conviction-voting/try-runtime",
"pallet-democracy/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-elections/try-runtime",
"pallet-elections-phragmen/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-nis/try-runtime",
"pallet-grandpa/try-runtime",
+12 -18
View File
@@ -24,8 +24,7 @@
use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{
onchain, weights::SubstrateWeight, ApprovalVoting, BalancingConfig, ElectionDataProvider,
SequentialPhragmen, VoteWeight,
onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight,
};
use frame_support::{
construct_runtime,
@@ -1011,21 +1010,18 @@ parameter_types! {
pub const TermDuration: BlockNumber = 7 * DAYS;
pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 7;
pub const MaxVotesPerVoter: u32 = 16;
pub const MaxVoters: u32 = 512;
pub const MaxCandidates: u32 = 64;
pub const MaxVotesPerVoter: u32 = 16;
// The ElectionsPalletId parameter name was changed along with the renaming of the elections
// pallet, but we keep the same lock ID to prevent a migration from current runtimes.
// Related to https://github.com/paritytech/substrate/issues/8250
pub const ElectionsPalletId: LockIdentifier = *b"phrelect";
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
}
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());
impl pallet_elections::Config for Runtime {
impl pallet_elections_phragmen::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type PalletId = ElectionsPalletId;
type PalletId = ElectionsPhragmenPalletId;
type Currency = Balances;
type ChangeMembers = Council;
// NOTE: this implies that council's genesis members cannot be set directly and must come from
@@ -1043,9 +1039,7 @@ impl pallet_elections::Config for Runtime {
type MaxVoters = MaxVoters;
type MaxVotesPerVoter = MaxVotesPerVoter;
type MaxCandidates = MaxCandidates;
type ElectionSolver = ApprovalVoting<Self::AccountId, Perbill>;
type SolverWeightInfo = SubstrateWeight<Runtime>;
type WeightInfo = pallet_elections::weights::SubstrateWeight<Runtime>;
type WeightInfo = pallet_elections_phragmen::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
@@ -1743,7 +1737,7 @@ construct_runtime!(
Democracy: pallet_democracy,
Council: pallet_collective::<Instance1>,
TechnicalCommittee: pallet_collective::<Instance2>,
Elections: pallet_elections,
Elections: pallet_elections_phragmen,
TechnicalMembership: pallet_membership::<Instance1>,
Grandpa: pallet_grandpa,
Treasury: pallet_treasury,
@@ -1857,7 +1851,6 @@ mod benches {
frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[frame_benchmarking_pallet_pov, Pov]
[frame_election_provider_support, EPSBench::<Runtime>]
[pallet_alliance, Alliance]
[pallet_assets, Assets]
[pallet_babe, Babe]
@@ -1870,7 +1863,8 @@ mod benches {
[pallet_contracts, Contracts]
[pallet_democracy, Democracy]
[pallet_election_provider_multi_phase, ElectionProviderMultiPhase]
[pallet_elections, Elections]
[pallet_election_provider_support_benchmarking, EPSBench::<Runtime>]
[pallet_elections_phragmen, Elections]
[pallet_fast_unstake, FastUnstake]
[pallet_nis, Nis]
[pallet_grandpa, Grandpa]
@@ -2329,7 +2323,7 @@ impl_runtime_apis! {
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_election_provider_support::benchmarking::Pallet as EPSBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
@@ -2352,14 +2346,14 @@ impl_runtime_apis! {
// which is why we need these two lines below.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_election_provider_support::benchmarking::Pallet as EPSBench;
use pallet_election_provider_support_benchmarking::Pallet as EPSBench;
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
impl frame_election_provider_support::benchmarking::Config for Runtime {}
impl pallet_election_provider_support_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
impl baseline::Config for Runtime {}
impl pallet_nomination_pools_benchmarking::Config for Runtime {}
@@ -33,6 +33,7 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa
# Optional imports for benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support/benchmarking", optional = true }
rand = { version = "0.8.5", default-features = false, features = ["alloc", "small_rng"], optional = true }
strum = { version = "0.24.1", default-features = false, features = ["derive"], optional = true }
@@ -49,6 +50,7 @@ frame-benchmarking = { version = "4.0.0-dev", path = "../benchmarking" }
[features]
default = ["std"]
std = [
"pallet-election-provider-support-benchmarking?/std",
"codec/std",
"scale-info/std",
"log/std",
@@ -23,8 +23,6 @@ sp-runtime = { version = "7.0.0", default-features = false, path = "../../primit
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
[dev-dependencies]
rand = { version = "0.8.5", features = ["small_rng"] }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
@@ -43,10 +41,6 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"frame-benchmarking?/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
]
runtime-benchmarks = []
try-runtime = []
@@ -0,0 +1,37 @@
[package]
name = "pallet-election-provider-support-benchmarking"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "Benchmarking for election provider support onchain config trait"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false, features = [
"derive",
] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../../benchmarking" }
frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = ".." }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/npos-elections" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime" }
[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-election-provider-support/std",
"frame-system/std",
"sp-npos-elections/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
]
@@ -18,9 +18,12 @@
//! Election provider support pallet benchmarking.
//! This is separated into its own crate to avoid bloating the size of the runtime.
use crate::{ApprovalVoting, NposSolver, PhragMMS, SequentialPhragmen};
#![cfg(feature = "runtime-benchmarks")]
#![cfg_attr(not(feature = "std"), no_std)]
use codec::Decode;
use frame_benchmarking::v1::{benchmarks, Vec};
use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen};
pub struct Pallet<T: Config>(frame_system::Pallet<T>);
pub trait Config: frame_system::Config {}
@@ -85,17 +88,4 @@ benchmarks! {
::solve(d as usize, targets, voters).is_ok()
);
}
approval_voting {
let v in (VOTERS[0]) .. VOTERS[1];
let t in (TARGETS[0]) .. TARGETS[1];
let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1];
let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize);
}: {
assert!(
ApprovalVoting::<T::AccountId, sp_runtime::Perbill>
::solve(d as usize, targets, voters).is_ok()
);
}
}
@@ -199,9 +199,6 @@ pub use sp_arithmetic;
#[doc(hidden)]
pub use sp_std;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod weights;
pub use weights::WeightInfo;
@@ -663,29 +660,6 @@ impl<AccountId: IdentifierT, Accuracy: PerThing128, Balancing: Get<Option<Balanc
}
}
/// A wrapper for [`sp_npos_elections::approval_voting()`] that implements [`NposSolver`]. See the
/// documentation of [`sp_npos_elections::approval_voting()`] for more info.
pub struct ApprovalVoting<AccountId, Accuracy>(sp_std::marker::PhantomData<(AccountId, Accuracy)>);
impl<AccountId: IdentifierT, Accuracy: PerThing128> NposSolver
for ApprovalVoting<AccountId, Accuracy>
{
type AccountId = AccountId;
type Accuracy = Accuracy;
type Error = sp_npos_elections::Error;
fn solve(
winners: usize,
targets: Vec<Self::AccountId>,
voters: Vec<(Self::AccountId, VoteWeight, impl IntoIterator<Item = Self::AccountId>)>,
) -> Result<ElectionResult<Self::AccountId, Self::Accuracy>, Self::Error> {
sp_npos_elections::approval_voting(winners, targets, voters)
}
fn weight<T: WeightInfo>(voters: u32, targets: u32, vote_degree: u32) -> Weight {
T::approval_voting(voters, targets, vote_degree)
}
}
/// A voter, at the level of abstraction of this crate.
pub type Voter<AccountId, Bound> = (AccountId, VoteWeight, BoundedVec<AccountId, Bound>);
@@ -185,7 +185,7 @@ impl<T: Config> ElectionProvider for OnChainExecution<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{ApprovalVoting, ElectionProvider, PhragMMS, SequentialPhragmen};
use crate::{ElectionProvider, PhragMMS, SequentialPhragmen};
use frame_support::{assert_noop, parameter_types, traits::ConstU32};
use sp_npos_elections::Support;
use sp_runtime::Perbill;
@@ -235,7 +235,6 @@ mod tests {
struct PhragmenParams;
struct PhragMMSParams;
struct ApprovalVotingParams;
parameter_types! {
pub static MaxWinners: u32 = 10;
@@ -262,16 +261,6 @@ mod tests {
type TargetsBound = ConstU32<400>;
}
impl Config for ApprovalVotingParams {
type System = Runtime;
type Solver = ApprovalVoting<AccountId, Perbill>;
type DataProvider = mock_data_provider::DataProvider;
type WeightInfo = ();
type MaxWinners = MaxWinners;
type VotersBound = ConstU32<600>;
type TargetsBound = ConstU32<400>;
}
mod mock_data_provider {
use frame_support::{bounded_vec, traits::ConstU32};
@@ -344,21 +333,4 @@ mod tests {
);
})
}
#[test]
fn onchain_approval_voting_works() {
sp_io::TestExternalities::new_empty().execute_with(|| {
DesiredTargets::set(3);
// note that the `OnChainExecution::elect` implementation normalizes the vote weights.
assert_eq!(
<OnChainExecution::<ApprovalVotingParams> as ElectionProvider>::elect().unwrap(),
vec![
(10, Support { total: 20, voters: vec![(1, 5), (3, 15)] }),
(20, Support { total: 15, voters: vec![(1, 5), (2, 10)] }),
(30, Support { total: 25, voters: vec![(2, 10), (3, 15)] })
]
)
})
}
}
@@ -1,13 +1,13 @@
// This file is part of Substrate.
// Copyright (C) 2023 Parity Technologies (UK) Ltd.
// Copyright (C) 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
// 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,
@@ -15,29 +15,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Autogenerated weights for frame_election_provider_support
//! Autogenerated weights for pallet_election_provider_support_benchmarking
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-ehxwxxsd-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! DATE: 2022-04-23, STEPS: `1`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/production/substrate
// target/release/substrate
// benchmark
// pallet
// --steps=50
// --repeat=20
// --chain=dev
// --steps=1
// --repeat=1
// --pallet=pallet_election_provider_support_benchmarking
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json
// --pallet=frame_election_provider_support
// --chain=dev
// --header=./HEADER-APACHE2
// --output=./frame/election-provider-support/src/weights.rs
// --output=frame/election-provider-support/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
@@ -47,108 +43,53 @@
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
/// Weight functions needed for frame_election_provider_support.
/// Weight functions needed for pallet_election_provider_support_benchmarking.
pub trait WeightInfo {
fn phragmen(v: u32, t: u32, d: u32, ) -> Weight;
fn phragmms(v: u32, t: u32, d: u32, ) -> Weight;
fn approval_voting(v: u32, t: u32, d: u32, ) -> Weight;
}
/// Weights for frame_election_provider_support using the Substrate node and recommended hardware.
/// Weights for pallet_election_provider_support_benchmarking using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn phragmen(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 5_789_174 nanoseconds.
Weight::from_ref_time(5_826_449_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 130_342
.saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into()))
// Standard Error: 13_325_769
.saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into()))
fn phragmen(v: u32, t: u32, d: u32, ) -> Weight {
Weight::from_ref_time(0 as u64)
// Standard Error: 667_000
.saturating_add(Weight::from_ref_time(32_973_000 as u64).saturating_mul(v as u64))
// Standard Error: 1_334_000
.saturating_add(Weight::from_ref_time(1_334_000 as u64).saturating_mul(t as u64))
// Standard Error: 60_644_000
.saturating_add(Weight::from_ref_time(2_636_364_000 as u64).saturating_mul(d as u64))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn phragmms(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 4_151_790 nanoseconds.
Weight::from_ref_time(4_215_936_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 125_135
.saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into()))
// Standard Error: 12_793_390
.saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn approval_voting(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 1_800_445 nanoseconds.
Weight::from_ref_time(1_824_645_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 26_266
.saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into()))
// Standard Error: 2_685_343
.saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into()))
fn phragmms(v: u32, t: u32, d: u32, ) -> Weight {
Weight::from_ref_time(0 as u64)
// Standard Error: 73_000
.saturating_add(Weight::from_ref_time(21_073_000 as u64).saturating_mul(v as u64))
// Standard Error: 146_000
.saturating_add(Weight::from_ref_time(65_000 as u64).saturating_mul(t as u64))
// Standard Error: 6_649_000
.saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64))
}
}
// For backwards compatibility and tests
impl WeightInfo for () {
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn phragmen(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 5_789_174 nanoseconds.
Weight::from_ref_time(5_826_449_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 130_342
.saturating_add(Weight::from_ref_time(5_332_741).saturating_mul(v.into()))
// Standard Error: 13_325_769
.saturating_add(Weight::from_ref_time(1_416_874_101).saturating_mul(d.into()))
fn phragmen(v: u32, t: u32, d: u32, ) -> Weight {
Weight::from_ref_time(0 as u64)
// Standard Error: 667_000
.saturating_add(Weight::from_ref_time(32_973_000 as u64).saturating_mul(v as u64))
// Standard Error: 1_334_000
.saturating_add(Weight::from_ref_time(1_334_000 as u64).saturating_mul(t as u64))
// Standard Error: 60_644_000
.saturating_add(Weight::from_ref_time(2_636_364_000 as u64).saturating_mul(d as u64))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn phragmms(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 4_151_790 nanoseconds.
Weight::from_ref_time(4_215_936_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 125_135
.saturating_add(Weight::from_ref_time(4_730_609).saturating_mul(v.into()))
// Standard Error: 12_793_390
.saturating_add(Weight::from_ref_time(1_474_383_961).saturating_mul(d.into()))
}
/// The range of component `v` is `[1000, 2000]`.
/// The range of component `t` is `[500, 1000]`.
/// The range of component `d` is `[5, 16]`.
fn approval_voting(v: u32, _t: u32, d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 1_800_445 nanoseconds.
Weight::from_ref_time(1_824_645_000)
.saturating_add(Weight::from_proof_size(0))
// Standard Error: 26_266
.saturating_add(Weight::from_ref_time(1_229_576).saturating_mul(v.into()))
// Standard Error: 2_685_343
.saturating_add(Weight::from_ref_time(213_080_804).saturating_mul(d.into()))
fn phragmms(v: u32, t: u32, d: u32, ) -> Weight {
Weight::from_ref_time(0 as u64)
// Standard Error: 73_000
.saturating_add(Weight::from_ref_time(21_073_000 as u64).saturating_mul(v as u64))
// Standard Error: 146_000
.saturating_add(Weight::from_ref_time(65_000 as u64).saturating_mul(t as u64))
// Standard Error: 6_649_000
.saturating_add(Weight::from_ref_time(1_711_424_000 as u64).saturating_mul(d as u64))
}
}
@@ -4,17 +4,6 @@ All notable changes to this crate will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [5.0.0] - UNRELEASED
### Added
### Changed
Generalized the pallet to use `NposSolver` instead of hard coding the phragmen algorithm; Changed the name of the pallet from `pallet-elections-phragmen` to `pallet-elections`
### Fixed
### Security
## [4.0.0] - UNRELEASED
### Added
@@ -1,12 +1,12 @@
[package]
name = "pallet-elections"
name = "pallet-elections-phragmen"
version = "5.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME pallet for generic elections."
description = "FRAME pallet based on seq-Phragmén election method."
readme = "README.md"
[package.metadata.docs.rs]
@@ -24,7 +24,6 @@ frame-system = { version = "4.0.0-dev", default-features = false, path = "../sys
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "7.0.0", default-features = false, path = "../../primitives/io" }
sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../primitives/npos-elections" }
frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }
@@ -1,6 +1,6 @@
# Generic Elections Module.
# Phragmén Election Module.
A generic elections module.
An election module based on sequential phragmen.
### Term and Round
@@ -60,7 +60,7 @@ being re-elected at the end of each round.
### Module Information
- [`elections::Config`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/trait.Config.html)
- [`election_sp_phragmen::Config`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/trait.Config.html)
- [`Call`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/enum.Call.html)
- [`Module`](https://docs.rs/pallet-elections-phragmen/latest/pallet_elections_phragmen/struct.Module.html)
@@ -15,14 +15,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Elections pallet benchmarking.
//! Elections-Phragmen pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::v1::{account, benchmarks, whitelist, BenchmarkError, BenchmarkResult};
use frame_support::dispatch::DispatchResultWithPostInfo;
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::OnInitialize};
use frame_system::RawOrigin;
use crate::Pallet as Elections;
@@ -37,7 +37,7 @@ fn endowed_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let amount = default_stake::<T>(T::MaxVoters::get()) * BalanceOf::<T>::from(BALANCE_FACTOR);
let _ = T::Currency::make_free_balance_be(&account, amount);
// important to increase the total issuance since T::CurrencyToVote will need it to be sane for
// the election to work.
// phragmen to work.
T::Currency::issue(amount);
account
@@ -122,7 +122,7 @@ fn distribute_voters<T: Config>(
fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str> {
let _ = submit_candidates_with_self_vote::<T>(m, "fill_seats_up_to")?;
assert_eq!(<Elections<T>>::candidates().len() as u32, m, "wrong number of candidates.");
<Elections<T>>::do_election();
<Elections<T>>::do_phragmen();
assert_eq!(<Elections<T>>::candidates().len(), 0, "some candidates remaining.");
assert_eq!(
<Elections<T>>::members().len() + <Elections<T>>::runners_up().len(),
@@ -382,11 +382,11 @@ benchmarks! {
assert_eq!(<Voting<T>>::iter().count() as u32, 0);
}
pre_solve_election {
// We always select 20 members, this is hard-coded in the runtime and cannot be trivially
// changed at this stage. Yet, change the number of voters, candidates and edge per voter
// to see the impact. Note that we give all candidates a self vote to make sure they are
// all considered.
election_phragmen {
// This is just to focus on phragmen in the context of this module. We always select 20
// members, this is hard-coded in the runtime and cannot be trivially changed at this stage.
// Yet, change the number of voters, candidates and edge per voter to see the impact. Note
// that we give all candidates a self vote to make sure they are all considered.
let c in 1 .. T::MaxCandidates::get();
let v in 1 .. T::MaxVoters::get();
let e in (T::MaxVoters::get()) .. T::MaxVoters::get() * T::MaxVotesPerVoter::get();
@@ -404,44 +404,7 @@ benchmarks! {
let all_candidates = submit_candidates_with_self_vote::<T>(c, "candidates")?;
let _ = distribute_voters::<T>(all_candidates, v.saturating_sub(c), votes_per_voter as usize)?;
}: {
<Elections<T>>::do_pre_solve_election().unwrap();
}
post_solve_election {
// We always select 20 members, this is hard-coded in the runtime and cannot be trivially
// changed at this stage. Yet, change the number of voters, candidates and edge per voter
// to see the impact. Note that we give all candidates a self vote to make sure they are
// all considered.
let c in 1 .. T::MaxCandidates::get();
let v in 1 .. T::MaxVoters::get();
let e in (T::MaxVoters::get()) .. T::MaxVoters::get() as u32 * T::MaxVotesPerVoter::get() as u32;
clean::<T>();
// so we have a situation with v and e. we want e to basically always be in the range of `e
// -> e * T::MaxVotesPerVoter`, but we cannot express that now with the benchmarks. So what we do
// is: when c is being iterated, v, and e are max and fine. when v is being iterated, e is
// being set to max and this is a problem. In these cases, we cap e to a lower value, namely
// v * `T::MaxVotesPerVoter`. when e is being iterated, v is at max, and again fine. all in all,
// votes_per_voter can never be more than `T::MaxVotesPerVoter`. Note that this might cause `v` to be
// an overestimate.
let votes_per_voter = (e / v).min(T::MaxVotesPerVoter::get() as u32);
let all_candidates = submit_candidates_with_self_vote::<T>(c, "candidates")?;
let _ = distribute_voters::<T>(all_candidates, v.saturating_sub(c), votes_per_voter as usize)?;
let pre_election_result = <Elections<T>>::do_pre_solve_election().unwrap();
let election_result = T::ElectionSolver::solve(
pre_election_result.num_to_elect,
pre_election_result.candidate_ids,
pre_election_result.voters_and_votes,
).unwrap();
}: {
<Elections<T>>::do_post_solve_election(
election_result.winners,
pre_election_result.candidates_and_deposit,
pre_election_result.voters_and_stakes,
);
<Elections<T>>::on_initialize(T::TermDuration::get());
}
verify {
assert_eq!(<Elections<T>>::members().len() as u32, T::DesiredMembers::get().min(c));
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! # Generic Election Module.
//! # Phragmén Election Module.
//!
//! An election module based on a generic election algorithm.
//! An election module based on sequential phragmen.
//!
//! ### Term and Round
//!
@@ -99,7 +99,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use frame_election_provider_support::NposSolver;
use frame_support::{
traits::{
defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency,
@@ -109,12 +108,12 @@ use frame_support::{
weights::Weight,
};
use scale_info::TypeInfo;
use sp_npos_elections::{ElectionResult, ExtendedBalance, VoteWeight};
use sp_npos_elections::{ElectionResult, ExtendedBalance};
use sp_runtime::{
traits::{Saturating, StaticLookup, Zero},
DispatchError, RuntimeDebug,
DispatchError, Perbill, RuntimeDebug,
};
use sp_std::{cmp::Ordering, iter::IntoIterator, prelude::*};
use sp_std::{cmp::Ordering, prelude::*};
mod benchmarking;
pub mod weights;
@@ -123,17 +122,7 @@ pub use weights::WeightInfo;
/// All migrations.
pub mod migrations;
pub(crate) const LOG_TARGET: &str = "runtime::elections";
// logging helper.
macro_rules! log {
($level:tt, $patter:expr $(, $values:expr)* $(,)?) => {
log::$level!(
target: crate::LOG_TARGET,
concat!("[{:?}] 🗳️ ", $patter), <frame_system::Pallet<T>>::block_number() $(, $values)*
)
};
}
const LOG_TARGET: &str = "runtime::elections-phragmen";
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
@@ -184,17 +173,6 @@ pub struct SeatHolder<AccountId, Balance> {
pub deposit: Balance,
}
/// The results of running the pre-election step.
#[derive(Debug, Clone)]
struct PreElectionResults<T: Config> {
pub num_to_elect: usize,
pub candidate_ids: Vec<T::AccountId>,
pub candidates_and_deposit: Vec<(T::AccountId, BalanceOf<T>)>,
pub voters_and_stakes: Vec<(T::AccountId, BalanceOf<T>, Vec<T::AccountId>)>,
pub voters_and_votes: Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)>,
pub num_edges: u32,
}
pub use pallet::*;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
@@ -218,7 +196,7 @@ pub mod pallet {
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Identifier for the elections pallet's lock
/// Identifier for the elections-phragmen pallet's lock
#[pallet::constant]
type PalletId: Get<LockIdentifier>;
@@ -271,7 +249,7 @@ pub mod pallet {
#[pallet::constant]
type TermDuration: Get<Self::BlockNumber>;
/// The maximum number of candidates in an election.
/// The maximum number of candidates in a phragmen election.
///
/// Warning: This impacts the size of the election which is run onchain. Chose wisely, and
/// consider how it will impact `T::WeightInfo::election_phragmen`.
@@ -280,7 +258,7 @@ pub mod pallet {
#[pallet::constant]
type MaxCandidates: Get<u32>;
/// The maximum number of voters to allow in an election.
/// The maximum number of voters to allow in a phragmen election.
///
/// Warning: This impacts the size of the election which is run onchain. Chose wisely, and
/// consider how it will impact `T::WeightInfo::election_phragmen`.
@@ -289,12 +267,6 @@ pub mod pallet {
#[pallet::constant]
type MaxVoters: Get<u32>;
/// Something that will calculate the result of elections.
type ElectionSolver: NposSolver<AccountId = Self::AccountId>;
/// Weight information for the [`Config::ElectionSolver`].
type SolverWeightInfo: frame_election_provider_support::WeightInfo;
/// Maximum numbers of votes per voter.
///
/// Warning: This impacts the size of the election which is run onchain. Chose wisely, and
@@ -314,7 +286,7 @@ pub mod pallet {
fn on_initialize(n: T::BlockNumber) -> Weight {
let term_duration = T::TermDuration::get();
if !term_duration.is_zero() && (n % term_duration).is_zero() {
Self::do_election()
Self::do_phragmen()
} else {
Weight::zero()
}
@@ -323,26 +295,11 @@ pub mod pallet {
fn integrity_test() {
let block_weight = T::BlockWeights::get().max_block;
// mind the order.
let pre_solve_weight = T::WeightInfo::pre_solve_election(
let election_weight = T::WeightInfo::election_phragmen(
T::MaxCandidates::get(),
T::MaxVoters::get(),
T::MaxVotesPerVoter::get() * T::MaxVoters::get(),
);
// mind the order.
let post_solve_weight = T::WeightInfo::post_solve_election(
T::MaxCandidates::get(),
T::MaxVoters::get(),
T::MaxVotesPerVoter::get() * T::MaxVoters::get(),
);
// mind the order.
let election_weight = T::ElectionSolver::weight::<T::SolverWeightInfo>(
T::MaxCandidates::get(),
T::MaxVoters::get(),
T::MaxVotesPerVoter::get() * T::MaxVoters::get(),
);
let election_weight = pre_solve_weight
.saturating_sub(post_solve_weight)
.saturating_add(election_weight);
let to_seconds = |w: &Weight| {
w.ref_time() as f32 /
@@ -577,8 +534,8 @@ pub mod pallet {
/// the outgoing member is slashed.
///
/// If a runner-up is available, then the best runner-up will be removed and replaces the
/// outgoing member. Otherwise, if `rerun_election` is `true`, a new election is started,
/// else, nothing happens.
/// outgoing member. Otherwise, if `rerun_election` is `true`, a new phragmen election is
/// started, else, nothing happens.
///
/// If `slash_bond` is set to true, the bond of the member being removed is slashed. Else,
/// it is returned.
@@ -608,7 +565,7 @@ pub mod pallet {
Self::deposit_event(Event::MemberKicked { member: who });
if rerun_election {
Self::do_election();
Self::do_phragmen();
}
// no refund needed.
@@ -707,8 +664,6 @@ pub mod pallet {
InvalidRenouncing,
/// Prediction regarding replacement after member removal is wrong.
InvalidReplacement,
/// No candidates for the next term.
EmptyTerm,
}
/// The current elected members.
@@ -787,7 +742,7 @@ pub mod pallet {
Members::<T>::mutate(|members| {
match members.binary_search_by(|m| m.who.cmp(member)) {
Ok(_) => {
panic!("Duplicate member in elections genesis: {}", member)
panic!("Duplicate member in elections-phragmen genesis: {}", member)
},
Err(pos) => members.insert(
pos,
@@ -979,77 +934,11 @@ impl<T: Config> Pallet<T> {
debug_assert!(_remainder.is_zero());
}
/// Run an election with all required side processes and state updates, if election
/// succeeds. Else, it will emit an `ElectionError` event. The election algorithm is defined
/// by the implementor of `Self::ElectionSolver`.
/// Run the phragmen election with all required side processes and state updates, if election
/// succeeds. Else, it will emit an `ElectionError` event.
///
/// Calls the appropriate [`ChangeMembers`] function variant internally.
fn do_election() -> Weight {
let PreElectionResults {
num_to_elect,
candidate_ids,
candidates_and_deposit,
voters_and_stakes,
voters_and_votes,
num_edges,
} = match Self::do_pre_solve_election() {
Ok(results) => results,
Err(err) => match err {
Error::EmptyTerm => {
Self::deposit_event(Event::EmptyTerm);
return T::DbWeight::get().reads(3)
},
Error::TooManyVotes => {
Self::deposit_event(Event::ElectionError);
log!(error, "Failed to run election. Number of voters exceeded",);
let max_voters = <T as Config>::MaxVoters::get() as usize;
return T::DbWeight::get().reads(3 + max_voters as u64)
},
_ => {
log!(error, "Unexpected pre-election error",);
let max_voters = <T as Config>::MaxVoters::get() as usize;
return T::DbWeight::get().reads(3 + max_voters as u64)
},
},
};
let num_candidates = candidates_and_deposit.len() as u32;
let num_voters = voters_and_votes.len() as u32;
let num_edges = num_edges;
let election_winners =
T::ElectionSolver::solve(num_to_elect, candidate_ids, voters_and_votes)
.map(
|ElectionResult::<
T::AccountId,
<T::ElectionSolver as NposSolver>::Accuracy,
> {
winners,
assignments: _,
}| winners,
)
.map_err(|e| {
log!(warn, "Failed to run election [{:?}].", e);
Self::deposit_event(Event::ElectionError);
});
let post_election_weight = if let Ok(winners) = election_winners {
Self::do_post_solve_election(winners, candidates_and_deposit, voters_and_stakes);
T::WeightInfo::post_solve_election(num_candidates, num_voters, num_edges)
} else {
Weight::zero()
};
T::ElectionSolver::weight::<T::SolverWeightInfo>(num_candidates, num_voters, num_edges)
.saturating_add(T::WeightInfo::pre_solve_election(
num_candidates,
num_voters,
num_edges,
))
.saturating_add(post_election_weight)
}
fn do_pre_solve_election() -> Result<PreElectionResults<T>, Error<T>> {
fn do_phragmen() -> Weight {
let desired_seats = T::DesiredMembers::get() as usize;
let desired_runners_up = T::DesiredRunnersUp::get() as usize;
let num_to_elect = desired_runners_up + desired_seats;
@@ -1059,33 +948,44 @@ impl<T: Config> Pallet<T> {
candidates_and_deposit.append(&mut Self::implicit_candidates_with_deposit());
if candidates_and_deposit.len().is_zero() {
return Err(Error::EmptyTerm)
Self::deposit_event(Event::EmptyTerm);
return T::DbWeight::get().reads(3)
}
// All of the new winners that come out of the election will thus have a deposit recorded.
// All of the new winners that come out of phragmen will thus have a deposit recorded.
let candidate_ids =
candidates_and_deposit.iter().map(|(x, _)| x).cloned().collect::<Vec<_>>();
// helper closures to deal with balance/stake.
let total_issuance = T::Currency::total_issuance();
let to_votes = |b: BalanceOf<T>| T::CurrencyToVote::to_vote(b, total_issuance);
let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance);
let mut num_edges: u32 = 0;
let max_voters = <T as Config>::MaxVoters::get() as usize;
// used for prime election.
let mut voters_and_stakes = Vec::new();
Voting::<T>::iter().try_for_each(|(voter, Voter { stake, votes, .. })| {
match Voting::<T>::iter().try_for_each(|(voter, Voter { stake, votes, .. })| {
if voters_and_stakes.len() < max_voters {
voters_and_stakes.push((voter, stake, votes));
Ok(())
} else {
Err(Error::TooManyVotes)
Err(())
}
})?;
}) {
Ok(_) => (),
Err(_) => {
log::error!(
target: LOG_TARGET,
"Failed to run election. Number of voters exceeded",
);
Self::deposit_event(Event::ElectionError);
return T::DbWeight::get().reads(3 + max_voters as u64)
},
}
// used for elections.
// used for phragmen.
let voters_and_votes = voters_and_stakes
.iter()
.cloned()
@@ -1095,144 +995,157 @@ impl<T: Config> Pallet<T> {
})
.collect::<Vec<_>>();
Ok(PreElectionResults {
num_to_elect,
candidate_ids,
candidates_and_deposit,
voters_and_stakes,
voters_and_votes,
num_edges,
})
}
let weight_candidates = candidates_and_deposit.len() as u32;
let weight_voters = voters_and_votes.len() as u32;
let weight_edges = num_edges;
let _ =
sp_npos_elections::seq_phragmen(num_to_elect, candidate_ids, voters_and_votes, None)
.map(|ElectionResult::<T::AccountId, Perbill> { winners, assignments: _ }| {
// this is already sorted by id.
let old_members_ids_sorted = <Members<T>>::take()
.into_iter()
.map(|m| m.who)
.collect::<Vec<T::AccountId>>();
// this one needs a sort by id.
let mut old_runners_up_ids_sorted = <RunnersUp<T>>::take()
.into_iter()
.map(|r| r.who)
.collect::<Vec<T::AccountId>>();
old_runners_up_ids_sorted.sort();
fn do_post_solve_election(
winners: Vec<(T::AccountId, u128)>,
candidates_and_deposit: Vec<(T::AccountId, BalanceOf<T>)>,
voters_and_stakes: Vec<(T::AccountId, BalanceOf<T>, Vec<T::AccountId>)>,
) {
let desired_seats = T::DesiredMembers::get() as usize;
let total_issuance = T::Currency::total_issuance();
let to_balance = |e: ExtendedBalance| T::CurrencyToVote::to_currency(e, total_issuance);
// filter out those who end up with no backing stake.
let mut new_set_with_stake = winners
.into_iter()
.filter_map(
|(m, b)| if b.is_zero() { None } else { Some((m, to_balance(b))) },
)
.collect::<Vec<(T::AccountId, BalanceOf<T>)>>();
// this is already sorted by id.
let old_members_ids_sorted =
<Members<T>>::take().into_iter().map(|m| m.who).collect::<Vec<T::AccountId>>();
// this one needs sorted by id.
let mut old_runners_up_ids_sorted =
<RunnersUp<T>>::take().into_iter().map(|r| r.who).collect::<Vec<T::AccountId>>();
old_runners_up_ids_sorted.sort();
// OPTIMIZATION NOTE: we could bail out here if `new_set.len() == 0`. There
// isn't much left to do. Yet, re-arranging the code would require duplicating
// the slashing of exposed candidates, cleaning any previous members, and so on.
// For now, in favor of readability and veracity, we keep it simple.
// filter out those who end up with no backing stake.
let mut new_set_with_stake = winners
.into_iter()
.filter_map(|(m, b)| if b.is_zero() { None } else { Some((m, to_balance(b))) })
.collect::<Vec<(T::AccountId, BalanceOf<T>)>>();
// split new set into winners and runners up.
let split_point = desired_seats.min(new_set_with_stake.len());
let mut new_members_sorted_by_id =
new_set_with_stake.drain(..split_point).collect::<Vec<_>>();
new_members_sorted_by_id.sort_by(|i, j| i.0.cmp(&j.0));
// OPTIMIZATION NOTE: we could bail out here if `new_set.len() == 0`. There
// isn't much left to do. Yet, re-arranging the code would require duplicating
// the slashing of exposed candidates, cleaning any previous members, and so on.
// For now, in favor of readability and veracity, we keep it simple.
// all the rest will be runners-up
new_set_with_stake.reverse();
let new_runners_up_sorted_by_rank = new_set_with_stake;
let mut new_runners_up_ids_sorted = new_runners_up_sorted_by_rank
.iter()
.map(|(r, _)| r.clone())
.collect::<Vec<_>>();
new_runners_up_ids_sorted.sort();
// split new set into winners and runners up.
let split_point = desired_seats.min(new_set_with_stake.len());
let mut new_members_sorted_by_id =
new_set_with_stake.drain(..split_point).collect::<Vec<_>>();
new_members_sorted_by_id.sort_by(|i, j| i.0.cmp(&j.0));
// Now we select a prime member using a [Borda
// count](https://en.wikipedia.org/wiki/Borda_count). We weigh everyone's vote for
// that new member by a multiplier based on the order of the votes. i.e. the
// first person a voter votes for gets a 16x multiplier, the next person gets a
// 15x multiplier, an so on... (assuming `T::MaxVotesPerVoter` = 16)
let mut prime_votes = new_members_sorted_by_id
.iter()
.map(|c| (&c.0, BalanceOf::<T>::zero()))
.collect::<Vec<_>>();
for (_, stake, votes) in voters_and_stakes.into_iter() {
for (vote_multiplier, who) in
votes.iter().enumerate().map(|(vote_position, who)| {
((T::MaxVotesPerVoter::get() as usize - vote_position) as u32, who)
}) {
if let Ok(i) = prime_votes.binary_search_by_key(&who, |k| k.0) {
prime_votes[i].1 = prime_votes[i]
.1
.saturating_add(stake.saturating_mul(vote_multiplier.into()));
}
}
}
// We then select the new member with the highest weighted stake. In the case of
// a tie, the last person in the list with the tied score is selected. This is
// the person with the "highest" account id based on the sort above.
let prime = prime_votes.into_iter().max_by_key(|x| x.1).map(|x| x.0.clone());
// all the rest will be runners-up
new_set_with_stake.reverse();
let new_runners_up_sorted_by_rank = new_set_with_stake;
let mut new_runners_up_ids_sorted =
new_runners_up_sorted_by_rank.iter().map(|(r, _)| r.clone()).collect::<Vec<_>>();
new_runners_up_ids_sorted.sort();
// new_members_sorted_by_id is sorted by account id.
let new_members_ids_sorted = new_members_sorted_by_id
.iter()
.map(|(m, _)| m.clone())
.collect::<Vec<T::AccountId>>();
// Now we select a prime member using a [Borda
// count](https://en.wikipedia.org/wiki/Borda_count). We weigh everyone's vote for
// that new member by a multiplier based on the order of the votes. i.e. the
// first person a voter votes for gets a 16x multiplier, the next person gets a
// 15x multiplier, an so on... (assuming `T::MaxVotesPerVoter` = 16).
let mut prime_votes = new_members_sorted_by_id
.iter()
.map(|c| (&c.0, BalanceOf::<T>::zero()))
.collect::<Vec<_>>();
for (_, stake, votes) in voters_and_stakes.into_iter() {
for (vote_multiplier, who) in votes.iter().enumerate().map(|(vote_position, who)| {
((T::MaxVotesPerVoter::get() as usize - vote_position) as u32, who)
}) {
if let Ok(i) = prime_votes.binary_search_by_key(&who, |k| k.0) {
prime_votes[i].1 = prime_votes[i]
.1
.saturating_add(stake.saturating_mul(vote_multiplier.into()));
}
}
}
// We then select the new member with the highest weighted stake. In the case of
// a tie, the last person in the list with the tied score is selected. This is
// the person with the "highest" account id based on the sort above.
let prime = prime_votes.into_iter().max_by_key(|x| x.1).map(|x| x.0.clone());
// report member changes. We compute diff because we need the outgoing list.
let (incoming, outgoing) = T::ChangeMembers::compute_members_diff_sorted(
&new_members_ids_sorted,
&old_members_ids_sorted,
);
T::ChangeMembers::change_members_sorted(
&incoming,
&outgoing,
&new_members_ids_sorted,
);
T::ChangeMembers::set_prime(prime);
// new_members_sorted_by_id is sorted by account id.
let new_members_ids_sorted = new_members_sorted_by_id
.iter()
.map(|(m, _)| m.clone())
.collect::<Vec<T::AccountId>>();
// All candidates/members/runners-up who are no longer retaining a position as a
// seat holder will lose their bond.
candidates_and_deposit.iter().for_each(|(c, d)| {
if new_members_ids_sorted.binary_search(c).is_err() &&
new_runners_up_ids_sorted.binary_search(c).is_err()
{
let (imbalance, _) = T::Currency::slash_reserved(c, *d);
T::LoserCandidate::on_unbalanced(imbalance);
Self::deposit_event(Event::CandidateSlashed {
candidate: c.clone(),
amount: *d,
});
}
});
// report member changes. We compute diff because we need the outgoing list.
let (incoming, outgoing) = T::ChangeMembers::compute_members_diff_sorted(
&new_members_ids_sorted,
&old_members_ids_sorted,
);
T::ChangeMembers::change_members_sorted(&incoming, &outgoing, &new_members_ids_sorted);
T::ChangeMembers::set_prime(prime);
// write final values to storage.
let deposit_of_candidate = |x: &T::AccountId| -> BalanceOf<T> {
// defensive-only. This closure is used against the new members and new
// runners-up, both of which are phragmen winners and thus must have
// deposit.
candidates_and_deposit
.iter()
.find_map(|(c, d)| if c == x { Some(*d) } else { None })
.defensive_unwrap_or_default()
};
// fetch deposits from the one recorded one. This will make sure that a
// candidate who submitted candidacy before a change to candidacy deposit will
// have the correct amount recorded.
<Members<T>>::put(
new_members_sorted_by_id
.iter()
.map(|(who, stake)| SeatHolder {
deposit: deposit_of_candidate(who),
who: who.clone(),
stake: *stake,
})
.collect::<Vec<_>>(),
);
<RunnersUp<T>>::put(
new_runners_up_sorted_by_rank
.into_iter()
.map(|(who, stake)| SeatHolder {
deposit: deposit_of_candidate(&who),
who,
stake,
})
.collect::<Vec<_>>(),
);
// All candidates/members/runners-up who are no longer retaining a position as a
// seat holder will lose their bond.
candidates_and_deposit.iter().for_each(|(c, d)| {
if new_members_ids_sorted.binary_search(c).is_err() &&
new_runners_up_ids_sorted.binary_search(c).is_err()
{
let (imbalance, _) = T::Currency::slash_reserved(c, *d);
T::LoserCandidate::on_unbalanced(imbalance);
Self::deposit_event(Event::CandidateSlashed { candidate: c.clone(), amount: *d });
}
});
// clean candidates.
<Candidates<T>>::kill();
// write final values to storage.
let deposit_of_candidate = |x: &T::AccountId| -> BalanceOf<T> {
// defensive-only. This closure is used against the new members and new
// runners-up, both of which are election winners and thus must have
// deposit.
candidates_and_deposit
.iter()
.find_map(|(c, d)| if c == x { Some(*d) } else { None })
.defensive_unwrap_or_default()
};
// fetch deposits from the one recorded one. This will make sure that a
// candidate who submitted candidacy before a change to candidacy deposit will
// have the correct amount recorded.
<Members<T>>::put(
new_members_sorted_by_id
.iter()
.map(|(who, stake)| SeatHolder {
deposit: deposit_of_candidate(who),
who: who.clone(),
stake: *stake,
Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id });
<ElectionRounds<T>>::mutate(|v| *v += 1);
})
.collect::<Vec<_>>(),
);
<RunnersUp<T>>::put(
new_runners_up_sorted_by_rank
.into_iter()
.map(|(who, stake)| SeatHolder { deposit: deposit_of_candidate(&who), who, stake })
.collect::<Vec<_>>(),
);
.map_err(|e| {
log::error!(target: LOG_TARGET, "Failed to run election [{:?}].", e,);
Self::deposit_event(Event::ElectionError);
});
// clean candidates.
<Candidates<T>>::kill();
log!(info, "New term election successful.");
Self::deposit_event(Event::NewTerm { new_members: new_members_sorted_by_id });
<ElectionRounds<T>>::mutate(|v| *v += 1);
T::WeightInfo::election_phragmen(weight_candidates, weight_voters, weight_edges)
}
}
@@ -1283,8 +1196,7 @@ impl<T: Config> ContainsLengthBound for Pallet<T> {
#[cfg(test)]
mod tests {
use super::*;
use crate as elections;
use frame_election_provider_support::{weights::SubstrateWeight, ApprovalVoting};
use crate as elections_phragmen;
use frame_support::{
assert_noop, assert_ok,
dispatch::DispatchResultWithPostInfo,
@@ -1296,7 +1208,7 @@ mod tests {
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage, Perbill,
BuildStorage,
};
use substrate_test_utils::assert_eq_uvec;
@@ -1395,13 +1307,13 @@ mod tests {
}
parameter_types! {
pub const ElectionsPalletId: LockIdentifier = *b"phrelect";
pub const MaxVoters: u32 = 256;
pub const MaxCandidates: u32 = 64;
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
pub const PhragmenMaxVoters: u32 = 1000;
pub const PhragmenMaxCandidates: u32 = 100;
}
impl Config for Test {
type PalletId = ElectionsPalletId;
type PalletId = ElectionsPhragmenPalletId;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
@@ -1416,11 +1328,9 @@ mod tests {
type LoserCandidate = ();
type KickedMember = ();
type WeightInfo = ();
type MaxVoters = MaxVoters;
type MaxCandidates = MaxCandidates;
type ElectionSolver = ApprovalVoting<Self::AccountId, Perbill>;
type SolverWeightInfo = SubstrateWeight<Test>;
type MaxVoters = PhragmenMaxVoters;
type MaxVotesPerVoter = ConstU32<16>;
type MaxCandidates = PhragmenMaxCandidates;
}
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
@@ -1435,7 +1345,7 @@ mod tests {
{
System: frame_system::{Pallet, Call, Event<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>, Config<T>},
Elections: elections::{Pallet, Call, Event<T>, Config<T>},
Elections: elections_phragmen::{Pallet, Call, Event<T>, Config<T>},
}
);
@@ -1496,7 +1406,9 @@ mod tests {
(6, 60 * self.balance_factor),
],
},
elections: elections::GenesisConfig::<Test> { members: self.genesis_members },
elections: elections_phragmen::GenesisConfig::<Test> {
members: self.genesis_members,
},
}
.build_storage()
.unwrap()
@@ -1554,7 +1466,7 @@ mod tests {
.get(0)
.cloned()
.map(|lock| {
assert_eq!(lock.id, ElectionsPalletId::get());
assert_eq!(lock.id, ElectionsPhragmenPalletId::get());
lock.amount
})
.unwrap_or_default()
@@ -1745,7 +1657,7 @@ mod tests {
}
#[test]
#[should_panic = "Duplicate member in elections genesis: 2"]
#[should_panic = "Duplicate member in elections-phragmen genesis: 2"]
fn genesis_members_cannot_be_duplicate() {
ExtBuilder::default()
.desired_members(3)
@@ -0,0 +1,559 @@
// This file is part of Substrate.
// Copyright (C) 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.
//! Autogenerated weights for pallet_elections_phragmen
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-02-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `runner-b3zmxxc-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/production/substrate
// benchmark
// pallet
// --steps=50
// --repeat=20
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/builds/parity/mirrors/substrate/.git/.artifacts/bench.json
// --pallet=pallet_elections_phragmen
// --chain=dev
// --header=./HEADER-APACHE2
// --output=./frame/elections-phragmen/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
/// Weight functions needed for pallet_elections_phragmen.
pub trait WeightInfo {
fn vote_equal(v: u32, ) -> Weight;
fn vote_more(v: u32, ) -> Weight;
fn vote_less(v: u32, ) -> Weight;
fn remove_voter() -> Weight;
fn submit_candidacy(c: u32, ) -> Weight;
fn renounce_candidacy_candidate(c: u32, ) -> Weight;
fn renounce_candidacy_members() -> Weight;
fn renounce_candidacy_runners_up() -> Weight;
fn remove_member_without_replacement() -> Weight;
fn remove_member_with_replacement() -> Weight;
fn clean_defunct_voters(v: u32, d: u32, ) -> Weight;
fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight;
}
/// Weights for pallet_elections_phragmen using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[1, 16]`.
fn vote_equal(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `499 + v * (80 ±0)`
// Estimated: `9726 + v * (320 ±0)`
// Minimum execution time: 27_362 nanoseconds.
Weight::from_parts(28_497_963, 9726)
// Standard Error: 3_968
.saturating_add(Weight::from_ref_time(176_840).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[2, 16]`.
fn vote_more(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `467 + v * (80 ±0)`
// Estimated: `9598 + v * (320 ±0)`
// Minimum execution time: 37_120 nanoseconds.
Weight::from_parts(38_455_302, 9598)
// Standard Error: 5_478
.saturating_add(Weight::from_ref_time(219_678).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[2, 16]`.
fn vote_less(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `499 + v * (80 ±0)`
// Estimated: `9726 + v * (320 ±0)`
// Minimum execution time: 36_928 nanoseconds.
Weight::from_parts(38_334_669, 9726)
// Standard Error: 5_271
.saturating_add(Weight::from_ref_time(232_355).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
fn remove_voter() -> Weight {
// Proof Size summary in bytes:
// Measured: `989`
// Estimated: `7238`
// Minimum execution time: 34_338 nanoseconds.
Weight::from_parts(35_672_000, 7238)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
fn submit_candidacy(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1697 + c * (48 ±0)`
// Estimated: `6576 + c * (144 ±0)`
// Minimum execution time: 31_864 nanoseconds.
Weight::from_parts(33_490_161, 6576)
// Standard Error: 2_643
.saturating_add(Weight::from_ref_time(158_386).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
.saturating_add(Weight::from_proof_size(144).saturating_mul(c.into()))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
fn renounce_candidacy_candidate(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `349 + c * (48 ±0)`
// Estimated: `844 + c * (48 ±0)`
// Minimum execution time: 27_292 nanoseconds.
Weight::from_parts(28_364_955, 844)
// Standard Error: 1_335
.saturating_add(Weight::from_ref_time(78_086).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
.saturating_add(Weight::from_proof_size(48).saturating_mul(c.into()))
}
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:1 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
fn renounce_candidacy_members() -> Weight {
// Proof Size summary in bytes:
// Measured: `2027`
// Estimated: `12115`
// Minimum execution time: 45_975 nanoseconds.
Weight::from_parts(47_103_000, 12115)
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
fn renounce_candidacy_runners_up() -> Weight {
// Proof Size summary in bytes:
// Measured: `975`
// Estimated: `1470`
// Minimum execution time: 29_243 nanoseconds.
Weight::from_parts(30_582_000, 1470)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: Benchmark Override (r:0 w:0)
/// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured)
fn remove_member_without_replacement() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000_000 nanoseconds.
Weight::from_ref_time(2_000_000_000_000)
}
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:1 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
fn remove_member_with_replacement() -> Weight {
// Proof Size summary in bytes:
// Measured: `2027`
// Estimated: `14718`
// Minimum execution time: 52_527 nanoseconds.
Weight::from_parts(53_538_000, 14718)
.saturating_add(T::DbWeight::get().reads(5_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
/// Storage: Elections Voting (r:513 w:512)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Balances Locks (r:512 w:512)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// Storage: System Account (r:512 w:512)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// The range of component `v` is `[256, 512]`.
/// The range of component `d` is `[0, 256]`.
fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1115 + v * (875 ±0)`
// Estimated: `8448 + v * (12352 ±0)`
// Minimum execution time: 14_934_185 nanoseconds.
Weight::from_parts(15_014_057_000, 8448)
// Standard Error: 245_588
.saturating_add(Weight::from_ref_time(35_586_946).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(v.into())))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(v.into())))
.saturating_add(Weight::from_proof_size(12352).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:513 w:0)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:44 w:44)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Elections ElectionRounds (r:1 w:1)
/// Proof Skipped: Elections ElectionRounds (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:0 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
/// The range of component `v` is `[1, 512]`.
/// The range of component `e` is `[512, 8192]`.
fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0 + v * (638 ±0) + e * (28 ±0)`
// Estimated: `330033 + v * (5229 ±6) + e * (89 ±0) + c * (2135 ±7)`
// Minimum execution time: 1_273_671 nanoseconds.
Weight::from_parts(1_279_716_000, 330033)
// Standard Error: 543_277
.saturating_add(Weight::from_ref_time(20_613_753).saturating_mul(v.into()))
// Standard Error: 34_857
.saturating_add(Weight::from_ref_time(688_354).saturating_mul(e.into()))
.saturating_add(T::DbWeight::get().reads(21_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into())))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into())))
.saturating_add(T::DbWeight::get().writes(6_u64))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into())))
.saturating_add(Weight::from_proof_size(5229).saturating_mul(v.into()))
.saturating_add(Weight::from_proof_size(89).saturating_mul(e.into()))
.saturating_add(Weight::from_proof_size(2135).saturating_mul(c.into()))
}
}
// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[1, 16]`.
fn vote_equal(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `499 + v * (80 ±0)`
// Estimated: `9726 + v * (320 ±0)`
// Minimum execution time: 27_362 nanoseconds.
Weight::from_parts(28_497_963, 9726)
// Standard Error: 3_968
.saturating_add(Weight::from_ref_time(176_840).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[2, 16]`.
fn vote_more(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `467 + v * (80 ±0)`
// Estimated: `9598 + v * (320 ±0)`
// Minimum execution time: 37_120 nanoseconds.
Weight::from_parts(38_455_302, 9598)
// Standard Error: 5_478
.saturating_add(Weight::from_ref_time(219_678).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// The range of component `v` is `[2, 16]`.
fn vote_less(v: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `499 + v * (80 ±0)`
// Estimated: `9726 + v * (320 ±0)`
// Minimum execution time: 36_928 nanoseconds.
Weight::from_parts(38_334_669, 9726)
// Standard Error: 5_271
.saturating_add(Weight::from_ref_time(232_355).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
.saturating_add(Weight::from_proof_size(320).saturating_mul(v.into()))
}
/// Storage: Elections Voting (r:1 w:1)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Balances Locks (r:1 w:1)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
fn remove_voter() -> Weight {
// Proof Size summary in bytes:
// Measured: `989`
// Estimated: `7238`
// Minimum execution time: 34_338 nanoseconds.
Weight::from_parts(35_672_000, 7238)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
fn submit_candidacy(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1697 + c * (48 ±0)`
// Estimated: `6576 + c * (144 ±0)`
// Minimum execution time: 31_864 nanoseconds.
Weight::from_parts(33_490_161, 6576)
// Standard Error: 2_643
.saturating_add(Weight::from_ref_time(158_386).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(3_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
.saturating_add(Weight::from_proof_size(144).saturating_mul(c.into()))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
fn renounce_candidacy_candidate(c: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `349 + c * (48 ±0)`
// Estimated: `844 + c * (48 ±0)`
// Minimum execution time: 27_292 nanoseconds.
Weight::from_parts(28_364_955, 844)
// Standard Error: 1_335
.saturating_add(Weight::from_ref_time(78_086).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
.saturating_add(Weight::from_proof_size(48).saturating_mul(c.into()))
}
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:1 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
fn renounce_candidacy_members() -> Weight {
// Proof Size summary in bytes:
// Measured: `2027`
// Estimated: `12115`
// Minimum execution time: 45_975 nanoseconds.
Weight::from_parts(47_103_000, 12115)
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().writes(4_u64))
}
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
fn renounce_candidacy_runners_up() -> Weight {
// Proof Size summary in bytes:
// Measured: `975`
// Estimated: `1470`
// Minimum execution time: 29_243 nanoseconds.
Weight::from_parts(30_582_000, 1470)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: Benchmark Override (r:0 w:0)
/// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured)
fn remove_member_without_replacement() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 2_000_000_000 nanoseconds.
Weight::from_ref_time(2_000_000_000_000)
}
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:1 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
fn remove_member_with_replacement() -> Weight {
// Proof Size summary in bytes:
// Measured: `2027`
// Estimated: `14718`
// Minimum execution time: 52_527 nanoseconds.
Weight::from_parts(53_538_000, 14718)
.saturating_add(RocksDbWeight::get().reads(5_u64))
.saturating_add(RocksDbWeight::get().writes(5_u64))
}
/// Storage: Elections Voting (r:513 w:512)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:0)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:0)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Candidates (r:1 w:0)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Balances Locks (r:512 w:512)
/// Proof: Balances Locks (max_values: None, max_size: Some(1299), added: 3774, mode: MaxEncodedLen)
/// Storage: System Account (r:512 w:512)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// The range of component `v` is `[256, 512]`.
/// The range of component `d` is `[0, 256]`.
fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1115 + v * (875 ±0)`
// Estimated: `8448 + v * (12352 ±0)`
// Minimum execution time: 14_934_185 nanoseconds.
Weight::from_parts(15_014_057_000, 8448)
// Standard Error: 245_588
.saturating_add(Weight::from_ref_time(35_586_946).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(v.into())))
.saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(v.into())))
.saturating_add(Weight::from_proof_size(12352).saturating_mul(v.into()))
}
/// Storage: Elections Candidates (r:1 w:1)
/// Proof Skipped: Elections Candidates (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Members (r:1 w:1)
/// Proof Skipped: Elections Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections RunnersUp (r:1 w:1)
/// Proof Skipped: Elections RunnersUp (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Elections Voting (r:513 w:0)
/// Proof Skipped: Elections Voting (max_values: None, max_size: None, mode: Measured)
/// Storage: Council Proposals (r:1 w:0)
/// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:44 w:44)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
/// Storage: Elections ElectionRounds (r:1 w:1)
/// Proof Skipped: Elections ElectionRounds (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Members (r:0 w:1)
/// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Council Prime (r:0 w:1)
/// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `c` is `[1, 64]`.
/// The range of component `v` is `[1, 512]`.
/// The range of component `e` is `[512, 8192]`.
fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0 + v * (638 ±0) + e * (28 ±0)`
// Estimated: `330033 + v * (5229 ±6) + e * (89 ±0) + c * (2135 ±7)`
// Minimum execution time: 1_273_671 nanoseconds.
Weight::from_parts(1_279_716_000, 330033)
// Standard Error: 543_277
.saturating_add(Weight::from_ref_time(20_613_753).saturating_mul(v.into()))
// Standard Error: 34_857
.saturating_add(Weight::from_ref_time(688_354).saturating_mul(e.into()))
.saturating_add(RocksDbWeight::get().reads(21_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into())))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(v.into())))
.saturating_add(RocksDbWeight::get().writes(6_u64))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into())))
.saturating_add(Weight::from_proof_size(5229).saturating_mul(v.into()))
.saturating_add(Weight::from_proof_size(89).saturating_mul(e.into()))
.saturating_add(Weight::from_proof_size(2135).saturating_mul(c.into()))
}
}
-397
View File
@@ -1,397 +0,0 @@
// This file is part of Substrate.
// 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.
//! Autogenerated weights for pallet_elections
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-11-22, 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("dev"), DB CACHE: 1024
// Executed Command:
// /home/benchbot/cargo_target_dir/production/substrate
// benchmark
// pallet
// --steps=50
// --repeat=20
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/substrate/.git/.artifacts/bench.json
// --pallet=pallet_elections
// --chain=dev
// --header=./HEADER-APACHE2
// --output=./frame/elections/src/weights.rs
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
/// Weight functions needed for pallet_elections.
pub trait WeightInfo {
fn vote_equal(v: u32, ) -> Weight;
fn vote_more(v: u32, ) -> Weight;
fn vote_less(v: u32, ) -> Weight;
fn remove_voter() -> Weight;
fn submit_candidacy(c: u32, ) -> Weight;
fn renounce_candidacy_candidate(c: u32, ) -> Weight;
fn renounce_candidacy_members() -> Weight;
fn renounce_candidacy_runners_up() -> Weight;
fn remove_member_without_replacement() -> Weight;
fn remove_member_with_replacement() -> Weight;
fn clean_defunct_voters(v: u32, d: u32, ) -> Weight;
fn pre_solve_election(c: u32, v: u32, e: u32, ) -> Weight;
fn post_solve_election(c: u32, v: u32, e: u32, ) -> Weight;
}
/// Weights for pallet_elections using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[1, 16]`.
fn vote_equal(v: u32, ) -> Weight {
// Minimum execution time: 37_500 nanoseconds.
Weight::from_ref_time(38_575_649)
// Standard Error: 2_961
.saturating_add(Weight::from_ref_time(154_225).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[2, 16]`.
fn vote_more(v: u32, ) -> Weight {
// Minimum execution time: 48_836 nanoseconds.
Weight::from_ref_time(49_566_969)
// Standard Error: 3_258
.saturating_add(Weight::from_ref_time(153_342).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[2, 16]`.
fn vote_less(v: u32, ) -> Weight {
// Minimum execution time: 47_664 nanoseconds.
Weight::from_ref_time(48_768_157)
// Standard Error: 3_321
.saturating_add(Weight::from_ref_time(215_112).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn remove_voter() -> Weight {
// Minimum execution time: 47_146 nanoseconds.
Weight::from_ref_time(47_846_000)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:1)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
/// The range of component `c` is `[1, 1000]`.
fn submit_candidacy(c: u32, ) -> Weight {
// Minimum execution time: 42_799 nanoseconds.
Weight::from_ref_time(46_920_164)
// Standard Error: 780
.saturating_add(Weight::from_ref_time(81_672).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage: Elections Candidates (r:1 w:1)
/// The range of component `c` is `[1, 1000]`.
fn renounce_candidacy_candidate(c: u32, ) -> Weight {
// Minimum execution time: 40_946 nanoseconds.
Weight::from_ref_time(53_109_738)
// Standard Error: 1_220
.saturating_add(Weight::from_ref_time(60_643).saturating_mul(c.into()))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage: Elections Members (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Prime (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Council Members (r:0 w:1)
fn renounce_candidacy_members() -> Weight {
// Minimum execution time: 53_454 nanoseconds.
Weight::from_ref_time(53_921_000)
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(4))
}
// Storage: Elections RunnersUp (r:1 w:1)
fn renounce_candidacy_runners_up() -> Weight {
// Minimum execution time: 41_275 nanoseconds.
Weight::from_ref_time(42_444_000)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage: Benchmark Override (r:0 w:0)
fn remove_member_without_replacement() -> Weight {
// Minimum execution time: 2_000_000_000 nanoseconds.
Weight::from_ref_time(2_000_000_000_000)
}
// Storage: Elections Members (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Prime (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Council Members (r:0 w:1)
fn remove_member_with_replacement() -> Weight {
// Minimum execution time: 62_040 nanoseconds.
Weight::from_ref_time(62_569_000)
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(5))
}
// Storage: Elections Voting (r:5001 w:5000)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Candidates (r:1 w:0)
// Storage: Balances Locks (r:5000 w:5000)
// Storage: System Account (r:5000 w:5000)
/// The range of component `v` is `[5000, 10000]`.
/// The range of component `d` is `[0, 5000]`.
fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight {
// Minimum execution time: 298_212_195 nanoseconds.
Weight::from_ref_time(298_678_889_000)
// Standard Error: 264_713
.saturating_add(Weight::from_ref_time(38_222_955).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(v.into())))
.saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(v.into())))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:10001 w:0)
/// The range of component `c` is `[1, 1000]`.
/// The range of component `v` is `[1, 10000]`.
/// The range of component `e` is `[10000, 160000]`.
fn pre_solve_election(_c: u32, v: u32, _e: u32, ) -> Weight {
// Minimum execution time: 6_543_626 nanoseconds.
Weight::from_ref_time(6_627_885_000)
// Standard Error: 14_605
.saturating_add(Weight::from_ref_time(7_613_226).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(296))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into())))
}
// Storage: Elections Members (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Elections ElectionRounds (r:1 w:1)
// Storage: Elections Candidates (r:0 w:1)
// Storage: Council Members (r:0 w:1)
// Storage: Council Prime (r:0 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `c` is `[1, 1000]`.
/// The range of component `v` is `[1, 10000]`.
/// The range of component `e` is `[10000, 160000]`.
fn post_solve_election(c: u32, v: u32, _e: u32, ) -> Weight {
// Minimum execution time: 3_843_566 nanoseconds.
Weight::from_ref_time(3_854_020_000)
// Standard Error: 59_766
.saturating_add(Weight::from_ref_time(9_622_797).saturating_mul(c.into()))
// Standard Error: 5_975
.saturating_add(Weight::from_ref_time(541_471).saturating_mul(v.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into())))
.saturating_add(T::DbWeight::get().writes(6))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into())))
}
}
// For backwards compatibility and tests
impl WeightInfo for () {
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[1, 16]`.
fn vote_equal(v: u32, ) -> Weight {
// Minimum execution time: 37_500 nanoseconds.
Weight::from_ref_time(38_575_649)
// Standard Error: 2_961
.saturating_add(Weight::from_ref_time(154_225).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[2, 16]`.
fn vote_more(v: u32, ) -> Weight {
// Minimum execution time: 48_836 nanoseconds.
Weight::from_ref_time(49_566_969)
// Standard Error: 3_258
.saturating_add(Weight::from_ref_time(153_342).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
/// The range of component `v` is `[2, 16]`.
fn vote_less(v: u32, ) -> Weight {
// Minimum execution time: 47_664 nanoseconds.
Weight::from_ref_time(48_768_157)
// Standard Error: 3_321
.saturating_add(Weight::from_ref_time(215_112).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(2))
}
// Storage: Elections Voting (r:1 w:1)
// Storage: Balances Locks (r:1 w:1)
fn remove_voter() -> Weight {
// Minimum execution time: 47_146 nanoseconds.
Weight::from_ref_time(47_846_000)
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
// Storage: Elections Candidates (r:1 w:1)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
/// The range of component `c` is `[1, 1000]`.
fn submit_candidacy(c: u32, ) -> Weight {
// Minimum execution time: 42_799 nanoseconds.
Weight::from_ref_time(46_920_164)
// Standard Error: 780
.saturating_add(Weight::from_ref_time(81_672).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(1))
}
// Storage: Elections Candidates (r:1 w:1)
/// The range of component `c` is `[1, 1000]`.
fn renounce_candidacy_candidate(c: u32, ) -> Weight {
// Minimum execution time: 40_946 nanoseconds.
Weight::from_ref_time(53_109_738)
// Standard Error: 1_220
.saturating_add(Weight::from_ref_time(60_643).saturating_mul(c.into()))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
// Storage: Elections Members (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Prime (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Council Members (r:0 w:1)
fn renounce_candidacy_members() -> Weight {
// Minimum execution time: 53_454 nanoseconds.
Weight::from_ref_time(53_921_000)
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().writes(4))
}
// Storage: Elections RunnersUp (r:1 w:1)
fn renounce_candidacy_runners_up() -> Weight {
// Minimum execution time: 41_275 nanoseconds.
Weight::from_ref_time(42_444_000)
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
// Storage: Benchmark Override (r:0 w:0)
fn remove_member_without_replacement() -> Weight {
// Minimum execution time: 2_000_000_000 nanoseconds.
Weight::from_ref_time(2_000_000_000_000)
}
// Storage: Elections Members (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Prime (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Council Members (r:0 w:1)
fn remove_member_with_replacement() -> Weight {
// Minimum execution time: 62_040 nanoseconds.
Weight::from_ref_time(62_569_000)
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(5))
}
// Storage: Elections Voting (r:5001 w:5000)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Candidates (r:1 w:0)
// Storage: Balances Locks (r:5000 w:5000)
// Storage: System Account (r:5000 w:5000)
/// The range of component `v` is `[5000, 10000]`.
/// The range of component `d` is `[0, 5000]`.
fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight {
// Minimum execution time: 298_212_195 nanoseconds.
Weight::from_ref_time(298_678_889_000)
// Standard Error: 264_713
.saturating_add(Weight::from_ref_time(38_222_955).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().reads((3_u64).saturating_mul(v.into())))
.saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(v.into())))
}
// Storage: Elections Candidates (r:1 w:0)
// Storage: Elections Members (r:1 w:0)
// Storage: Elections RunnersUp (r:1 w:0)
// Storage: Elections Voting (r:10001 w:0)
/// The range of component `c` is `[1, 1000]`.
/// The range of component `v` is `[1, 10000]`.
/// The range of component `e` is `[10000, 160000]`.
fn pre_solve_election(_c: u32, v: u32, _e: u32, ) -> Weight {
// Minimum execution time: 6_543_626 nanoseconds.
Weight::from_ref_time(6_627_885_000)
// Standard Error: 14_605
.saturating_add(Weight::from_ref_time(7_613_226).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(296))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(v.into())))
}
// Storage: Elections Members (r:1 w:1)
// Storage: Elections RunnersUp (r:1 w:1)
// Storage: Council Proposals (r:1 w:0)
// Storage: Elections ElectionRounds (r:1 w:1)
// Storage: Elections Candidates (r:0 w:1)
// Storage: Council Members (r:0 w:1)
// Storage: Council Prime (r:0 w:1)
// Storage: System Account (r:1 w:1)
/// The range of component `c` is `[1, 1000]`.
/// The range of component `v` is `[1, 10000]`.
/// The range of component `e` is `[10000, 160000]`.
fn post_solve_election(c: u32, v: u32, _e: u32, ) -> Weight {
// Minimum execution time: 3_843_566 nanoseconds.
Weight::from_ref_time(3_854_020_000)
// Standard Error: 59_766
.saturating_add(Weight::from_ref_time(9_622_797).saturating_mul(c.into()))
// Standard Error: 5_975
.saturating_add(Weight::from_ref_time(541_471).saturating_mul(v.into()))
.saturating_add(RocksDbWeight::get().reads(4))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(c.into())))
.saturating_add(RocksDbWeight::get().writes(6))
.saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(c.into())))
}
}
@@ -1,79 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 2023 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.
//! Implementation of the approval voting election method.
//!
//! This method allows voters to select many candidates and backing each of them with the same
//! vote weight. The candidates with the most backing are the election winners.
use crate::{setup_inputs, ElectionResult, IdentifierT, PerThing128, VoteWeight};
use sp_arithmetic::traits::Zero;
use sp_std::{cmp::Reverse, vec::Vec};
/// Execute an approvals voting election scheme. The return type is a list of winners. The weight
/// vector of all voters who contribute to the winners, which for this scheme is always 100% per
/// vote.
///
/// - The vote assignment distribution for each vote is always 100%, since a voter backs a candidate
/// with its full stake, regardless of how many candidates are backed by the same stake. However,
/// the caller may normalize votes on site if required.
/// - Returning winners are sorted based on desirability. Voters are unsorted.
/// - The returning winners are zipped with their final backing stake. Yet, to get the exact final
/// weight distribution from the winner's point of view, one needs to build a support map. See
/// [`crate::SupportMap`] for more info. Note that this backing stake is computed in
/// ExtendedBalance and may be slightly different that what will be computed from the support map,
/// due to accuracy loss.
///
/// This can only fail if the normalization fails. This can happen if for any of the resulting
/// assignments, `assignment.distribution.map(|p| p.deconstruct()).sum()` fails to fit inside
/// `UpperOf<P>`. A user of this crate may statically assert that this can never happen and safely
/// `expect` this to return `Ok`.
pub fn approval_voting<AccountId: IdentifierT, P: PerThing128>(
to_elect: usize,
candidates: Vec<AccountId>,
voters: Vec<(AccountId, VoteWeight, impl IntoIterator<Item = AccountId>)>,
) -> Result<ElectionResult<AccountId, P>, crate::Error> {
let to_elect = to_elect.min(candidates.len());
let (mut candidates, mut voters) = setup_inputs(candidates, voters);
candidates.sort_by_key(|c| Reverse(c.borrow().approval_stake));
let winners = candidates
.into_iter()
.take(to_elect)
.map(|w| {
w.borrow_mut().elected = true;
w
})
.map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().approval_stake))
.collect();
for voter in &mut voters {
for edge in &mut voter.edges {
if edge.candidate.borrow().elected {
edge.weight = voter.budget
} else {
edge.weight = Zero::zero()
}
}
}
let assignments = voters.into_iter().filter_map(|v| v.into_assignment()).collect::<Vec<_>>();
Ok(ElectionResult { winners, assignments })
}
@@ -25,8 +25,6 @@
//! - [`balance`](balancing::balance): Implements the star balancing algorithm. This iterative
//! process can push a solution toward being more "balanced", which in turn can increase its
//! score.
//! - [`approval_voting`](approval_voting::approval_voting): Implements an approval voting electoral
//! system where voters can back multiple candidates with the same stake.
//!
//! ### Terminology
//!
@@ -92,7 +90,6 @@ mod mock;
#[cfg(test)]
mod tests;
pub mod approval_voting;
mod assignments;
pub mod balancing;
pub mod helpers;
@@ -103,7 +100,6 @@ pub mod pjr;
pub mod reduce;
pub mod traits;
pub use approval_voting::*;
pub use assignments::{Assignment, StakedAssignment};
pub use balancing::*;
pub use helpers::*;
@@ -57,7 +57,7 @@ const DEN: ExtendedBalance = ExtendedBalance::max_value();
/// - The returning weight distribution is _normalized_, meaning that it is guaranteed that the sum
/// of the ratios in each voter's distribution sums up to exactly `P::one()`.
///
/// This can only fail if the normalization fails. This can happen if for any of the resulting
/// This can only fail of the normalization fails. This can happen if for any of the resulting
/// assignments, `assignment.distribution.map(|p| p.deconstruct()).sum()` fails to fit inside
/// `UpperOf<P>`. A user of this crate may statically assert that this can never happen and safely
/// `expect` this to return `Ok`.
@@ -18,57 +18,12 @@
//! Tests for npos-elections.
use crate::{
approval_voting::*, balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core,
setup_inputs, to_support_map, Assignment, BalancingConfig, ElectionResult, ExtendedBalance,
StakedAssignment, Support, Voter,
balancing, helpers::*, mock::*, seq_phragmen, seq_phragmen_core, setup_inputs, to_support_map,
Assignment, BalancingConfig, ElectionResult, ExtendedBalance, StakedAssignment, Support, Voter,
};
use sp_arithmetic::{PerU16, Perbill, Percent, Permill};
use substrate_test_utils::assert_eq_uvec;
#[test]
fn approval_voting_works() {
let candidates = vec![1, 2, 3, 4];
let voters = vec![(10, vec![1, 2]), (20, vec![1, 2]), (30, vec![1, 2, 3]), (40, vec![4])];
let stake_of = create_stake_of(&[(10, 10), (20, 20), (30, 30), (40, 40)]);
let voters = voters
.iter()
.map(|(ref v, ref vs)| (*v, stake_of(v), vs.clone()))
.collect::<Vec<_>>();
let ElectionResult::<_, Perbill> { winners, assignments } =
approval_voting(3, candidates, voters).unwrap();
assert_eq_uvec!(winners, vec![(1, 60), (2, 60), (4, 40)]);
assert_eq_uvec!(
assignments,
vec![
Assignment {
who: 10u64,
distribution: vec![
(1, Perbill::from_percent(100)),
(2, Perbill::from_percent(100))
]
},
Assignment {
who: 20u64,
distribution: vec![
(1, Perbill::from_percent(100)),
(2, Perbill::from_percent(100))
]
},
Assignment {
who: 30u64,
distribution: vec![
(1, Perbill::from_percent(100)),
(2, Perbill::from_percent(100))
]
},
Assignment { who: 40u64, distribution: vec![(4, Perbill::from_percent(100))] },
]
);
}
#[test]
fn float_phragmen_poc_works() {
let candidates = vec![1, 2, 3];
+2
View File
@@ -67,6 +67,8 @@ SUBSTRATE=./target/production/substrate
# Manually exclude some pallets.
EXCLUDED_PALLETS=(
# Helper pallets
"pallet_election_provider_support_benchmarking"
# Pallets without automatic benchmarking
"pallet_babe"
"pallet_grandpa"
@@ -25,7 +25,7 @@ futures = "0.3"
[dev-dependencies]
frame-support = { version = "4.0.0-dev", path = "../../../frame/support" }
pallet-elections = { version = "5.0.0-dev", path = "../../../frame/elections" }
pallet-elections-phragmen = { version = "5.0.0-dev", path = "../../../frame/elections-phragmen" }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
[features]