From ea308336aed7843caf15d23254ff6ea6428aab73 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 13 May 2022 14:58:01 +0100 Subject: [PATCH 01/65] make pool roles optional --- Cargo.lock | 1570 +++++++---------- .../nomination-pools/benchmarking/src/lib.rs | 24 +- frame/nomination-pools/src/lib.rs | 87 +- frame/nomination-pools/src/tests.rs | 149 +- frame/staking/src/lib.rs | 7 +- frame/staking/src/tests.rs | 76 +- 6 files changed, 927 insertions(+), 986 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68272e1df9c8c..7a46b20acfeb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,30 +29,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3e798aa0c8239776f54415bc06f3d74b1850f3f830b45c35cfc80556973f70" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] name = "aes" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "495ee669413bfbe9e8cace80f4d3d78e6d8c8d99579f97fb93bde351b185f2d4" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", ] [[package]] name = "aes-gcm" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a930fd487faaa92a30afa92cc9dd1526a5cff67124abbbb1c617ce070f4dcf" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" dependencies = [ "aead", "aes", @@ -68,7 +68,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.6", "once_cell", "version_check", ] @@ -93,24 +93,24 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" [[package]] name = "approx" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" dependencies = [ "num-traits", ] [[package]] name = "arbitrary" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "698b65a961a9d730fb45b6b0327e20207810c9f61ee421b082b27ba003f49e2b" +checksum = "c38b6b6b79f671c25e1a3e785b7b82d7562ffc9cd3efdc98627e5668a2472490" [[package]] name = "arrayref" @@ -135,21 +135,21 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "asn1_der" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3" +checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" [[package]] name = "assert_cmd" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2" +checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" dependencies = [ "bstr", "doc-comment", @@ -188,23 +188,23 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", "once_cell", - "vec-arena", + "slab", ] [[package]] name = "async-global-executor" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" +checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43" dependencies = [ "async-channel", "async-executor", @@ -230,7 +230,7 @@ dependencies = [ "parking", "polling", "slab", - "socket2 0.4.4", + "socket2", "waker-fn", "winapi", ] @@ -293,7 +293,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", "wasm-bindgen-futures", @@ -310,15 +310,15 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2 0.4.4", + "socket2", "trust-dns-resolver", ] [[package]] name = "async-stream" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" dependencies = [ "async-stream-impl", "futures-core", @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ "proc-macro2", "quote", @@ -337,15 +337,15 @@ dependencies = [ [[package]] name = "async-task" -version = "4.0.3" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" +checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" [[package]] name = "async-trait" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600" dependencies = [ "proc-macro2", "quote", @@ -362,16 +362,16 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] [[package]] name = "atomic" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" +checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -393,36 +393,30 @@ dependencies = [ [[package]] name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - -[[package]] -name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.27.1", + "object 0.28.4", "rustc-demangle", ] [[package]] name = "base-x" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" +checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" [[package]] name = "base16ct" @@ -545,17 +539,16 @@ dependencies = [ [[package]] name = "bimap" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50ae17cabbc8a38a1e3e4c1a6a664e9a09672dc14d0896fa8d865d3a5a446b07" +checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" [[package]] name = "bincode" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d175dfa69e619905c4c3cdb7c3c203fa3bdd5d51184e3afdb2742c0280493772" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "byteorder", "serde", ] @@ -598,9 +591,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94ba84325db59637ffc528bbe8c7f86c02c57cff5c0e2b9b00f9a851f42f309" +checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" dependencies = [ "digest 0.10.3", ] @@ -633,7 +626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -644,7 +637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -655,7 +648,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "cc", "cfg-if 1.0.0", "constant_time_eq", @@ -680,16 +673,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding 0.2.1", - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] name = "block-buffer" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -709,9 +702,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.0.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" dependencies = [ "async-channel", "async-task", @@ -729,9 +722,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", @@ -750,15 +743,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "byte-slice-cast" -version = "1.0.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" +checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" [[package]] name = "byte-tools" @@ -768,9 +761,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecheck" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" +checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -778,9 +771,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" +checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" dependencies = [ "proc-macro2", "quote", @@ -789,9 +782,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -812,24 +805,24 @@ dependencies = [ [[package]] name = "cache-padded" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "camino" -version = "1.0.4" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9" +checksum = "07fd178c5af4d59e83498ef15cf3f154e1a6f9d091270cb86283c65ef44e9ef0" dependencies = [ "serde", ] [[package]] name = "cargo-platform" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" dependencies = [ "serde", ] @@ -842,25 +835,25 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.4", + "semver 1.0.9", "serde", "serde_json", ] [[package]] name = "cast" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" +checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" dependencies = [ - "rustc_version 0.2.3", + "rustc_version 0.4.0", ] [[package]] name = "cc" -version = "1.0.71" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] @@ -894,7 +887,7 @@ checksum = "01b72a433d0cf2aef113ba70f62634c56fddb0f244e6377185c56a7cadbd8f91" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures 0.2.1", + "cpufeatures", "zeroize", ] @@ -916,9 +909,9 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 3.1.6", + "clap 3.1.18", "node-cli", - "rand 0.8.4", + "rand 0.8.5", "sc-chain-spec", "sc-keystore", "sp-core", @@ -957,7 +950,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -971,13 +964,13 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" +checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" dependencies = [ "glob", "libc", - "libloading 0.7.0", + "libloading 0.7.3", ] [[package]] @@ -993,16 +986,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.6" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ "atty", "bitflags", "clap_derive", + "clap_lex", "indexmap", "lazy_static", - "os_str_bytes", "strsim", "termcolor", "textwrap 0.15.0", @@ -1010,18 +1003,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.0.2" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a394f7ec0715b42a4e52b294984c27c9a61f77c8d82f7774c5198350be143f19" +checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", ] [[package]] name = "clap_derive" -version = "3.1.4" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -1031,12 +1024,12 @@ dependencies = [ ] [[package]] -name = "cloudabi" -version = "0.0.3" +name = "clap_lex" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" dependencies = [ - "bitflags", + "os_str_bytes", ] [[package]] @@ -1093,38 +1086,22 @@ dependencies = [ [[package]] name = "cpp_demangle" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" dependencies = [ "cfg-if 1.0.0", - "glob", -] - -[[package]] -name = "cpufeatures" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" -dependencies = [ - "libc", ] [[package]] name = "cpufeatures" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" dependencies = [ "libc", ] -[[package]] -name = "cpuid-bool" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" - [[package]] name = "cranelift-bforest" version = "0.76.0" @@ -1276,9 +1253,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if 1.0.0", ] @@ -1323,9 +1300,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.0" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1344,10 +1321,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" dependencies = [ + "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", @@ -1357,9 +1335,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1377,8 +1355,8 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.4", - "rand_core 0.6.2", + "generic-array 0.14.5", + "rand_core 0.6.3", "subtle", "zeroize", ] @@ -1389,7 +1367,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "typenum", ] @@ -1399,7 +1377,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -1409,7 +1387,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -1441,14 +1419,14 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" dependencies = [ - "sct 0.6.0", + "sct 0.6.1", ] [[package]] name = "ctor" -version = "0.1.19" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" dependencies = [ "quote", "syn", @@ -1476,9 +1454,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434e1720189a637d44fe464f4df1e6eb900b4835255b14354497c78af37d9bb8" +checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216" dependencies = [ "byteorder", "digest 0.8.1", @@ -1489,9 +1467,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.0.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f627126b946c25a4638eec0ea634fc52506dea98db118aae985118ce7c3d723f" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", "digest 0.9.0", @@ -1508,16 +1486,16 @@ checksum = "4033478fbf70d6acf2655ac70da91ee65852d69daf7a67bf7a2f518fb47aafcf" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", "zeroize", ] [[package]] name = "darling" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" dependencies = [ "darling_core", "darling_macro", @@ -1525,23 +1503,22 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim", "syn", ] [[package]] name = "darling_macro" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core", "quote", @@ -1556,9 +1533,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a94feec3d2ba66c0b6621bca8bc6f68415b1e5c69af3586fdd0af9fd9f29b17" +checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -1566,9 +1543,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f83e699727abca3c56e187945f303389590305ab2f0185ea445aa66e8d5f2a" +checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" dependencies = [ "data-encoding", "syn", @@ -1585,14 +1562,14 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.16" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.3.3", + "rustc_version 0.4.0", "syn", ] @@ -1623,7 +1600,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -1632,7 +1609,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.0", + "block-buffer 0.10.2", "crypto-common", "subtle", ] @@ -1669,12 +1646,12 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", - "redox_users 0.4.0", + "redox_users 0.4.3", "winapi", ] @@ -1685,15 +1662,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users 0.4.0", + "redox_users 0.4.3", "winapi", ] [[package]] name = "dissimilar" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb" +checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" [[package]] name = "dns-parser" @@ -1773,7 +1750,7 @@ checksum = "64fba5a42bd76a17cad4bfa00de168ee1cbfa06a5e8ce992ae880218c05641a9" dependencies = [ "byteorder", "dynasm", - "memmap2 0.5.0", + "memmap2 0.5.3", ] [[package]] @@ -1790,9 +1767,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.0.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef" +checksum = "d916019f70ae3a1faa1195685e290287f39207d38e6dfee727197cffcc002214" dependencies = [ "signature", ] @@ -1803,11 +1780,11 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "ed25519", "rand 0.7.3", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "zeroize", ] @@ -1827,9 +1804,9 @@ dependencies = [ "crypto-bigint", "der", "ff", - "generic-array 0.14.4", + "generic-array 0.14.5", "group", - "rand_core 0.6.2", + "rand_core 0.6.3", "sec1", "subtle", "zeroize", @@ -1875,9 +1852,9 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b3ab37dc79652c9d85f1f7b6070d77d321d2467f5fe7b00d6b7a86c57b092ae" +checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" dependencies = [ "enumflags2_derive", ] @@ -1895,18 +1872,18 @@ dependencies = [ [[package]] name = "enumset" -version = "1.0.7" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e76129da36102af021b8e5000dab2c1c30dbef85c1e482beeff8da5dde0e0b0" +checksum = "4799cdb24d48f1f8a7a98d06b7fde65a85a2d1e42b25a889f5406aa1fbefe074" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" -version = "0.5.5" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6451128aa6655d880755345d085494cf7561a6bee7c8dc821e5d77e6d267ecd4" +checksum = "ea83a3fbdc1d999ccfbcbee717eab36f8edf2d71693a23ce0d7cca19e085304c" dependencies = [ "darling", "proc-macro2", @@ -1914,19 +1891,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime 1.3.0", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.8.4" @@ -1944,7 +1908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log", "regex", "termcolor", @@ -1969,19 +1933,19 @@ dependencies = [ [[package]] name = "errno-dragonfly" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ - "gcc", + "cc", "libc", ] [[package]] name = "event-listener" -version = "2.5.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" [[package]] name = "exit-future" @@ -2024,21 +1988,21 @@ dependencies = [ [[package]] name = "ff" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2958d04124b9f27f175eaeb9a9f383d026098aa837eadd8ba22c11f13a05b9e" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] [[package]] name = "file-per-thread-logger" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fdbe0d94371f9ce939b555dd342d0686cc4c0cadbcd4b61d70af5ff97eb4126" +checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" dependencies = [ - "env_logger 0.7.1", + "env_logger 0.9.0", "log", ] @@ -2055,7 +2019,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "scale-info", ] @@ -2066,22 +2030,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ "byteorder", - "rand 0.8.4", + "rand 0.8.5", "rustc-hex", "static_assertions", ] [[package]] name = "fixedbitset" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" +checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" [[package]] name = "flate2" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" +checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" dependencies = [ "cfg-if 1.0.0", "crc32fast", @@ -2123,7 +2087,7 @@ dependencies = [ "linregress", "log", "parity-scale-codec", - "paste 1.0.6", + "paste 1.0.7", "scale-info", "serde", "sp-api", @@ -2142,7 +2106,7 @@ version = "4.0.0-dev" dependencies = [ "Inflector", "chrono", - "clap 3.1.6", + "clap 3.1.18", "frame-benchmarking", "frame-support", "frame-system", @@ -2157,7 +2121,7 @@ dependencies = [ "memory-db", "parity-scale-codec", "prettytable-rs", - "rand 0.8.4", + "rand 0.8.5", "rand_pcg 0.3.1", "sc-block-builder", "sc-cli", @@ -2223,13 +2187,13 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", "honggfuzz", "parity-scale-codec", - "rand 0.8.4", + "rand 0.8.5", "scale-info", "sp-arithmetic", "sp-npos-elections", @@ -2283,7 +2247,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-util-mem", - "paste 1.0.6", + "paste 1.0.7", "pretty_assertions", "scale-info", "serde", @@ -2457,12 +2421,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "funty" version = "2.0.0" @@ -2520,16 +2478,16 @@ checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" -version = "1.11.3" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "waker-fn", ] @@ -2551,7 +2509,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01fe9932a224b72b45336d96040aa86386d674a31d0af27d800ea7bc8ca97fe" dependencies = [ "futures-io", - "rustls 0.20.2", + "rustls 0.20.4", "webpki 0.22.0", ] @@ -2586,17 +2544,11 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "generate-bags" version = "4.0.0-dev" @@ -2622,9 +2574,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", @@ -2645,9 +2597,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2656,9 +2608,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b442c439366184de619215247d24e908912b175e824a530253845ac4c251a5c1" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" dependencies = [ "opaque-debug 0.3.0", "polyval", @@ -2707,9 +2659,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" dependencies = [ "aho-corasick", "bstr", @@ -2720,15 +2672,14 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", - "web-sys", ] [[package]] @@ -2738,15 +2689,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "ff", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] [[package]] name = "h2" -version = "0.3.9" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" dependencies = [ "bytes", "fnv", @@ -2757,15 +2708,15 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.6.7", + "tokio-util", "tracing", ] [[package]] name = "half" -version = "1.7.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "handlebars" @@ -2776,7 +2727,7 @@ dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.0", + "quick-error 2.0.1", "serde", "serde_json", ] @@ -2807,18 +2758,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" dependencies = [ "ahash", ] [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] @@ -2831,9 +2782,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -2883,7 +2834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.4", + "generic-array 0.14.5", "hmac 0.8.1", ] @@ -2911,46 +2862,37 @@ dependencies = [ [[package]] name = "http" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" +checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ "bytes", "fnv", - "itoa 0.4.8", + "itoa 1.0.1", ] [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] [[package]] name = "httparse" -version = "1.5.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] name = "httpdate" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" - -[[package]] -name = "humantime" -version = "1.3.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error 1.2.3", -] +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "humantime" @@ -2960,9 +2902,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.16" +version = "0.14.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" dependencies = [ "bytes", "futures-channel", @@ -2973,9 +2915,9 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", - "pin-project-lite 0.2.6", - "socket2 0.4.4", + "itoa 1.0.1", + "pin-project-lite 0.2.9", + "socket2", "tokio", "tower-service", "tracing", @@ -3055,9 +2997,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" +checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" dependencies = [ "serde", ] @@ -3075,11 +3017,11 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown 0.11.2", "serde", ] @@ -3120,7 +3062,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" dependencies = [ - "socket2 0.4.4", + "socket2", "widestring", "winapi", "winreg", @@ -3155,18 +3097,18 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "jobserver" -version = "0.1.21" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.54" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" dependencies = [ "wasm-bindgen", ] @@ -3197,12 +3139,12 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "pin-project 1.0.10", - "rustls-native-certs 0.6.1", + "rustls-native-certs 0.6.2", "soketto", "thiserror", "tokio", - "tokio-rustls 0.23.2", - "tokio-util 0.7.1", + "tokio-rustls 0.23.4", + "tokio-util", "tracing", "webpki-roots", ] @@ -3214,7 +3156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6b13067b615dd050ced7c19517a52cde490eee2c754d5447ce513f2275f7d" dependencies = [ "anyhow", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "async-lock", "async-trait", "beef", @@ -3224,7 +3166,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "rustc-hash", "serde", "serde_json", @@ -3303,7 +3245,7 @@ dependencies = [ "serde_json", "soketto", "tokio", - "tokio-util 0.7.1", + "tokio-util", "tracing", ] @@ -3398,21 +3340,21 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leb128" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" [[package]] name = "libgit2-sys" -version = "0.13.3+1.4.2" +version = "0.13.2+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24d36c3ac9b9996a2418d6bf428cc0bc5d1a814a84303fc60986088c5ed60de" +checksum = "3a42de9a51a5c12e00fc0e4ca6bc2ea43582fc6418488e8f615e905d886f258b" dependencies = [ "cc", "libc", @@ -3432,9 +3374,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -3442,9 +3384,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" +checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" [[package]] name = "libp2p" @@ -3456,7 +3398,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.3", + "getrandom 0.2.6", "instant", "lazy_static", "libp2p-autonat", @@ -3507,7 +3449,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -3534,7 +3476,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "ring", "rw-stream-sink", "sha2 0.10.2", @@ -3676,9 +3618,9 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec", - "socket2 0.4.4", + "socket2", "void", ] @@ -3723,14 +3665,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dd7e0c94051cda67123be68cf6b65211ba3dde7277be9068412de3e7ffd63ef" dependencies = [ "bytes", - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "futures", "lazy_static", "libp2p-core", "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.10.2", "snow", "static_assertions", @@ -3803,7 +3745,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "smallvec", "static_assertions", "thiserror", @@ -3827,7 +3769,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.10.2", "thiserror", "unsigned-varint", @@ -3896,7 +3838,7 @@ dependencies = [ "libc", "libp2p-core", "log", - "socket2 0.4.4", + "socket2", ] [[package]] @@ -3984,9 +3926,9 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.8.4", + "rand 0.8.5", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "typenum", ] @@ -4021,9 +3963,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e" dependencies = [ "cc", "libc", @@ -4082,18 +4024,19 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", "value-bag", @@ -4140,9 +4083,9 @@ dependencies = [ [[package]] name = "lz4" -version = "1.23.2" +version = "1.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aac20ed6991e01bf6a2e68cc73df2b389707403662a8ba89f68511fb340f724c" +checksum = "4edcb94251b1c375c459e5abe9fb0168c1c826c3370172684844f8f3f8d1a885" dependencies = [ "libc", "lz4-sys", @@ -4150,9 +4093,9 @@ dependencies = [ [[package]] name = "lz4-sys" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca79aa95d8b3226213ad454d328369853be3a1382d89532a854f4d69640acae" +checksum = "d7be8908e2ed6f31c02db8a9fa962f03e36c53fbfde437363eae3306b85d7e17" dependencies = [ "cc", "libc", @@ -4190,24 +4133,24 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "matrixmultiply" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a8a15b776d9dfaecd44b03c5828c2199cddff5247215858aac14624f8d6b741" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" dependencies = [ "rawpointer", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap" @@ -4221,29 +4164,29 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e3e85b970d650e2ae6d70592474087051c11c54da7f7b4949725c5735fbcc6" +checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" dependencies = [ "libc", ] [[package]] name = "memmap2" -version = "0.5.0" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4647a11b578fead29cdbb34d4adef8dd3dc35b876c9c6d5240d83f205abfe96e" +checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" dependencies = [ "libc", ] [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -4253,7 +4196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "parity-util-mem", ] @@ -4283,42 +4226,30 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" dependencies = [ "adler", - "autocfg 1.0.1", ] [[package]] name = "mio" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" +checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" dependencies = [ "libc", "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" -dependencies = [ - "socket2 0.3.19", - "winapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", ] [[package]] name = "more-asserts" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" +checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "multiaddr" @@ -4362,7 +4293,7 @@ dependencies = [ "digest 0.10.3", "multihash-derive", "sha2 0.10.2", - "sha3 0.10.0", + "sha3 0.10.1", "unsigned-varint", ] @@ -4382,9 +4313,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" @@ -4412,7 +4343,7 @@ dependencies = [ "num-complex", "num-rational 0.4.0", "num-traits", - "rand 0.8.4", + "rand 0.8.5", "rand_distr", "simba", "typenum", @@ -4435,7 +4366,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d66043b25d4a6cccb23619d10c19c25304b355a7dccd4a8e11423dd2382146" dependencies = [ - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -4472,7 +4403,7 @@ checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" dependencies = [ "anyhow", "byteorder", - "paste 1.0.6", + "paste 1.0.7", "thiserror", ] @@ -4533,7 +4464,7 @@ dependencies = [ name = "node-bench" version = "0.9.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "derive_more", "fs_extra", "futures", @@ -4572,7 +4503,7 @@ version = "3.0.0-dev" dependencies = [ "assert_cmd", "async-std", - "clap 3.1.6", + "clap 3.1.18", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4595,7 +4526,7 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "platforms", - "rand 0.8.4", + "rand 0.8.5", "regex", "remote-externalities", "sc-authority-discovery", @@ -4687,7 +4618,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4837,7 +4768,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "generate-bags", "node-runtime", ] @@ -4846,7 +4777,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -4969,22 +4900,12 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" dependencies = [ "memchr", "minimal-lexical", - "version_check", -] - -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", ] [[package]] @@ -4993,16 +4914,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" +checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790" dependencies = [ "num-traits", ] @@ -5019,11 +4940,11 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] @@ -5033,7 +4954,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -5045,18 +4966,18 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.0.1", + "autocfg", "libm", ] @@ -5083,9 +5004,9 @@ dependencies = [ [[package]] name = "object" -version = "0.28.3" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "crc32fast", "hashbrown 0.11.2", @@ -5119,24 +5040,21 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "os_str_bytes" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] [[package]] name = "output_vt100" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" dependencies = [ "winapi", ] @@ -5308,7 +5226,7 @@ dependencies = [ "frame-election-provider-support", "honggfuzz", "pallet-bags-list", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -5461,7 +5379,7 @@ dependencies = [ "pallet-utility", "parity-scale-codec", "pretty_assertions", - "rand 0.8.4", + "rand 0.8.5", "rand_pcg 0.3.1", "scale-info", "serde", @@ -6464,19 +6382,19 @@ dependencies = [ "libc", "log", "lz4", - "memmap2 0.2.1", + "memmap2 0.2.3", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "snap", ] [[package]] name = "parity-scale-codec" -version = "3.0.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a7f3fcf5e45fc28b84dcdab6b983e77f197ec01f325a33f404ba6855afd1070" +checksum = "e8b44461635bbb1a0300f100a841e571e7d919c81c73075ef5d152ffdb521066" dependencies = [ - "arrayvec 0.7.1", + "arrayvec 0.7.2", "bitvec", "byte-slice-cast", "impl-trait-for-tuples", @@ -6486,9 +6404,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.0.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6e626dc84025ff56bf1476ed0e30d10c84d7f89a475ef46ebabee1095a8fba" +checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6509,7 +6427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.0", @@ -6568,7 +6486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ "lock_api", - "parking_lot_core 0.9.1", + "parking_lot_core 0.9.3", ] [[package]] @@ -6580,20 +6498,20 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "smallvec", "winapi", ] [[package]] name = "parking_lot_core" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "smallvec", "windows-sys", ] @@ -6610,9 +6528,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" [[package]] name = "paste-impl" @@ -6708,11 +6626,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" dependencies = [ - "pin-project-internal 0.4.27", + "pin-project-internal 0.4.29", ] [[package]] @@ -6726,9 +6644,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" dependencies = [ "proc-macro2", "quote", @@ -6754,9 +6672,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -6766,9 +6684,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "platforms" @@ -6791,66 +6709,66 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07fffcddc1cb3a1de753caa4e4df03b79922ba43cf882acc1bdd7e8df9f4590" +checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" [[package]] name = "plotters-svg" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38a02e23bd9604b842a812063aec4ef702b57989c37b655254bb61c471ad211" +checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" dependencies = [ "plotters-backend", ] [[package]] name = "polling" -version = "2.0.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi", ] [[package]] name = "poly1305" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fcffab1f78ebbdf4b93b68c1ffebc24037eedf271edaca795732b24e5e4e349" +checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" dependencies = [ - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "polyval" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6ba6a405ef63530d6cb12802014b22f9c5751bd17cdcddbe9e46d5c8ae83287" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ "cfg-if 1.0.0", - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "predicates" -version = "2.0.2" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308" +checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" dependencies = [ "difflib", "itertools", @@ -6859,18 +6777,18 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" +checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" [[package]] name = "predicates-tree" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" dependencies = [ "predicates-core", - "treeline", + "termtree", ] [[package]] @@ -7015,7 +6933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", - "heck 0.3.2", + "heck 0.3.3", "itertools", "lazy_static", "log", @@ -7053,9 +6971,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" +checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" dependencies = [ "cc", ] @@ -7088,9 +7006,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quick-error" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quickcheck" @@ -7100,7 +7018,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger 0.8.4", "log", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -7129,25 +7047,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg 0.1.2", - "rand_xorshift", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -7158,30 +7057,19 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", "rand_pcg 0.2.1", ] [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "rand_chacha 0.3.1", + "rand_core 0.6.3", ] [[package]] @@ -7196,29 +7084,14 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core 0.6.3", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -7230,11 +7103,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.6", ] [[package]] @@ -7244,16 +7117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.4", -] - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", + "rand 0.8.5", ] [[package]] @@ -7265,59 +7129,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - [[package]] name = "rand_pcg" version = "0.2.1" @@ -7333,16 +7144,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" dependencies = [ - "rand_core 0.6.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", + "rand_core 0.6.3", ] [[package]] @@ -7353,11 +7155,11 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.5.0" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" +checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" dependencies = [ - "autocfg 1.0.1", + "autocfg", "crossbeam-deque", "either", "rayon-core", @@ -7365,26 +7167,16 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.0" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" +checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -7393,9 +7185,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] @@ -7413,28 +7205,29 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.3", - "redox_syscall 0.2.10", + "getrandom 0.2.6", + "redox_syscall 0.2.13", + "thiserror", ] [[package]] name = "ref-cast" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" +checksum = "685d58625b6c2b83e4cc88a27c4bf65adb7b6b16dbdc413e515c9405b47432ab" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" +checksum = "a043824e29c94169374ac5183ac0ed43f5724dc4556b19568007486bd840fa1f" dependencies = [ "proc-macro2", "quote", @@ -7476,11 +7269,10 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "byteorder", "regex-syntax", ] @@ -7563,9 +7355,9 @@ dependencies = [ [[package]] name = "retain_mut" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" +checksum = "8c31b5c4033f8fdde8700e4657be2c497e7288f01515be52168c631e2e4d4086" [[package]] name = "rfc6979" @@ -7595,12 +7387,12 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.37" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f08c8062c1fe1253064043b8fc07bfea1b9702b71b4a86c11ea3588183b12e1" +checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" dependencies = [ "bytecheck", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "ptr_meta", "rend", "rkyv_derive", @@ -7609,9 +7401,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.37" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" +checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" dependencies = [ "proc-macro2", "quote", @@ -7667,9 +7459,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc-hash" @@ -7692,29 +7484,20 @@ dependencies = [ "semver 0.9.0", ] -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.4", + "semver 1.0.9", ] [[package]] name = "rustix" -version = "0.33.5" +version = "0.33.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03627528abcc4a365554d32a9f3bbf67f7694c102cfeda792dc86a2d6057cc85" +checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" dependencies = [ "bitflags", "errno", @@ -7733,15 +7516,15 @@ dependencies = [ "base64", "log", "ring", - "sct 0.6.0", + "sct 0.6.1", "webpki 0.21.4", ] [[package]] name = "rustls" -version = "0.20.2" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84" +checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" dependencies = [ "log", "ring", @@ -7763,9 +7546,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca9ebdfa27d3fc180e42879037b5338ab1c040c06affd00d8338598e7800943" +checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7775,9 +7558,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "0.2.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +checksum = "e7522c9de787ff061458fe9a829dc790a3f5b22dc571694fc5883f448b94d9a9" dependencies = [ "base64", ] @@ -7795,15 +7578,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ "futures", - "pin-project 0.4.27", + "pin-project 0.4.29", "static_assertions", ] [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "safe-mix" @@ -7917,7 +7700,7 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "impl-trait-for-tuples", - "memmap2 0.5.0", + "memmap2 0.5.3", "parity-scale-codec", "sc-chain-spec-derive", "sc-network", @@ -7943,7 +7726,7 @@ name = "sc-cli" version = "0.10.0-dev" dependencies = [ "chrono", - "clap 3.1.6", + "clap 3.1.18", "fdlimit", "futures", "hex", @@ -8293,7 +8076,7 @@ dependencies = [ "lru", "parity-scale-codec", "parking_lot 0.12.0", - "paste 1.0.6", + "paste 1.0.7", "regex", "sc-executor-common", "sc-executor-wasmi", @@ -8388,7 +8171,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -8758,7 +8541,7 @@ dependencies = [ name = "sc-runtime-test" version = "2.0.0" dependencies = [ - "paste 1.0.6", + "paste 1.0.7", "sp-core", "sp-io", "sp-runtime", @@ -9039,9 +8822,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0563970d79bcbf3c537ce3ad36d859b30d36fc5b190efd227f1f7a84d7cf0d42" +checksum = "8980cafbe98a7ee7a9cc16b32ebce542c77883f512d83fbf2ddc8f6a85ea74c9" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -9053,9 +8836,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7805950c36512db9e3251c970bb7ac425f326716941862205d612ab3b5e46e2" +checksum = "4260c630e8a8a33429d1688eff2f163f24c65a4e1b1578ef6b565061336e4b6f" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9081,7 +8864,7 @@ checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" dependencies = [ "arrayref", "arrayvec 0.5.2", - "curve25519-dalek 2.1.2", + "curve25519-dalek 2.1.3", "getrandom 0.1.16", "merlin", "rand 0.7.3", @@ -9099,9 +8882,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ "ring", "untrusted", @@ -9130,18 +8913,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", "zeroize", ] [[package]] name = "secp256k1" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7883017d5b21f011ef8040ea9c6c7ac90834c0df26a69e4c0b06276151f125" +checksum = "9c42e6f1735c5f00f51e43e28d6634141f2bcad10931b2609ddd74a86d751260" dependencies = [ - "rand 0.6.5", "secp256k1-sys", ] @@ -9165,9 +8947,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.3.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b239a3d5db51252f6f48f42172c65317f37202f4a21021bf5f9d40a408f4592c" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -9178,9 +8960,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.3.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -9192,7 +8974,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" dependencies = [ - "semver-parser 0.7.0", + "semver-parser", ] [[package]] @@ -9201,23 +8983,14 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.2", + "semver-parser", ] [[package]] name = "semver" -version = "1.0.4" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" dependencies = [ "serde", ] @@ -9228,38 +9001,29 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" dependencies = [ "serde", ] [[package]] name = "serde_cbor" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" dependencies = [ "half", "serde", @@ -9267,9 +9031,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -9278,9 +9042,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa 1.0.1", "ryu", @@ -9310,13 +9074,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.4" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpuid-bool", + "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9335,13 +9099,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures 0.2.1", + "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9353,7 +9117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ "cfg-if 1.0.0", - "cpufeatures 0.2.1", + "cpufeatures", "digest 0.10.3", ] @@ -9371,9 +9135,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" +checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86" dependencies = [ "digest 0.10.3", "keccak", @@ -9381,24 +9145,24 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "signal-hook" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac" +checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" dependencies = [ "libc", "signal-hook-registry", @@ -9406,9 +9170,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" dependencies = [ "libc", ] @@ -9420,7 +9184,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" dependencies = [ "digest 0.9.0", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -9432,14 +9196,14 @@ dependencies = [ "approx", "num-complex", "num-traits", - "paste 1.0.6", + "paste 1.0.7", ] [[package]] name = "slab" -version = "0.4.2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "smallvec" @@ -9463,24 +9227,13 @@ dependencies = [ "blake2", "chacha20poly1305", "curve25519-dalek 4.0.0-pre.1", - "rand_core 0.6.2", + "rand_core 0.6.3", "ring", "rustc_version 0.4.0", "sha2 0.10.2", "subtle", ] -[[package]] -name = "socket2" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.4.4" @@ -9503,8 +9256,8 @@ dependencies = [ "futures", "httparse", "log", - "rand 0.8.4", - "sha-1 0.9.4", + "rand 0.8.5", + "sha-1 0.9.8", ] [[package]] @@ -9810,7 +9563,7 @@ dependencies = [ "byteorder", "digest 0.10.3", "sha2 0.10.2", - "sha3 0.10.0", + "sha3 0.10.1", "sp-std", "twox-hash", ] @@ -9977,10 +9730,10 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "honggfuzz", "parity-scale-codec", - "rand 0.8.4", + "rand 0.8.5", "scale-info", "sp-npos-elections", "sp-runtime", @@ -10024,7 +9777,7 @@ dependencies = [ "log", "parity-scale-codec", "parity-util-mem", - "paste 1.0.6", + "paste 1.0.7", "rand 0.7.3", "scale-info", "serde", @@ -10339,9 +10092,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b84a70894df7a73666e0694f44b41a9571625e9546fb58a0818a565d2c7e084" +checksum = "ceb8b72a924ccfe7882d0e26144c114503760a4d1248bb5cd06c8ab2d55404cc" dependencies = [ "Inflector", "num-format", @@ -10374,7 +10127,7 @@ dependencies = [ "lazy_static", "nalgebra", "num-traits", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -10398,7 +10151,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" dependencies = [ - "heck 0.3.2", + "heck 0.3.3", "proc-macro2", "quote", "rustversion", @@ -10409,7 +10162,7 @@ dependencies = [ name = "subkey" version = "2.0.1" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "sc-cli", ] @@ -10422,7 +10175,7 @@ dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", "schnorrkel", - "sha2 0.9.8", + "sha2 0.9.9", "zeroize", ] @@ -10437,7 +10190,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-support", "frame-system", "sc-cli", @@ -10671,15 +10424,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.82" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2" dependencies = [ "proc-macro2", "quote", @@ -10688,9 +10441,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", @@ -10740,7 +10493,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "remove_dir_all", "winapi", ] @@ -10758,13 +10511,19 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" + [[package]] name = "textwrap" version = "0.11.0" @@ -10782,18 +10541,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -10826,9 +10585,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.4.2+5.2.1-patched.2" +version = "0.4.3+5.2.1-patched.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5844e429d797c62945a566f8da4e24c7fe3fbd5d6617fd8bf7a0b7dc1ee0f22e" +checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" dependencies = [ "cc", "fs_extra", @@ -10858,7 +10617,7 @@ dependencies = [ "pbkdf2 0.4.0", "rand 0.7.3", "rustc-hash", - "sha2 0.9.8", + "sha2 0.9.9", "thiserror", "unicode-normalization", "wasm-bindgen", @@ -10886,9 +10645,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -10901,9 +10660,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.17.0" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ "bytes", "libc", @@ -10912,9 +10671,9 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.0", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "signal-hook-registry", - "socket2 0.4.4", + "socket2", "tokio-macros", "winapi", ] @@ -10943,23 +10702,23 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.2" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.2", + "rustls 0.20.4", "tokio", "webpki 0.22.0", ] [[package]] name = "tokio-stream" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" dependencies = [ "futures-core", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", ] @@ -10976,20 +10735,6 @@ dependencies = [ "tokio-stream", ] -[[package]] -name = "tokio-util" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.1" @@ -11000,15 +10745,16 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", + "tracing", ] [[package]] name = "toml" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -11021,22 +10767,22 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -11078,9 +10824,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" dependencies = [ "serde", "tracing-core", @@ -11109,12 +10855,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "treeline" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" - [[package]] name = "trie-bench" version = "0.30.0" @@ -11138,7 +10878,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" dependencies = [ "hash-db", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "log", "rustc-hex", "smallvec", @@ -11180,7 +10920,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec", "thiserror", "tinyvec", @@ -11216,7 +10956,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "jsonrpsee", "log", "parity-scale-codec", @@ -11238,9 +10978,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0da18123d1316f5a65fc9b94e30a0fcf58afb1daff1b8e18f41dc30f5bfc38c8" +checksum = "7fc92f558afb6d1d7c6f175eb8d615b8ef49c227543e68e19c123d4ee43d8a7d" dependencies = [ "dissimilar", "glob", @@ -11260,13 +11000,13 @@ checksum = "5e66dcbec4290c69dd03c57e76c2469ea5c7ce109c6dd4351c13055cf71ea055" [[package]] name = "twox-hash" -version = "1.6.2" +version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if 1.0.0", "digest 0.10.3", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] @@ -11284,9 +11024,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uint" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" +checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" dependencies = [ "byteorder", "crunchy", @@ -11305,33 +11045,30 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -11341,11 +11078,11 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "universal-hash" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -11369,9 +11106,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -11387,9 +11124,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.0.0-alpha.8" +version = "1.0.0-alpha.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" dependencies = [ "ctor", "version_check", @@ -11397,21 +11134,15 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" - -[[package]] -name = "vec-arena" -version = "1.0.0" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "void" @@ -11467,11 +11198,17 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -11479,9 +11216,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" dependencies = [ "bumpalo", "lazy_static", @@ -11494,9 +11231,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.20" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -11506,9 +11243,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11516,9 +11253,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", @@ -11529,9 +11266,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" [[package]] name = "wasm-gc-api" @@ -11676,7 +11413,7 @@ dependencies = [ "enumset", "lazy_static", "loupe", - "memmap2 0.5.0", + "memmap2 0.5.3", "more-asserts", "rustc-demangle", "serde", @@ -11698,9 +11435,9 @@ dependencies = [ "enum-iterator", "enumset", "leb128", - "libloading 0.7.0", + "libloading 0.7.3", "loupe", - "object 0.28.3", + "object 0.28.4", "rkyv", "serde", "tempfile", @@ -11739,7 +11476,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ce18ac2877050e59580d27ee1a88f3192d7a31e77fbba0852abc7888d6e0b5" dependencies = [ - "object 0.28.3", + "object 0.28.4", "thiserror", "wasmer-compiler", "wasmer-types", @@ -11800,9 +11537,9 @@ dependencies = [ [[package]] name = "wasmi-validation" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb8e860796d8be48efef530b60eebf84e74a88bce107374fffb0da97d504b8" +checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" dependencies = [ "parity-wasm 0.42.2", ] @@ -11835,7 +11572,7 @@ dependencies = [ "log", "object 0.27.1", "once_cell", - "paste 1.0.6", + "paste 1.0.7", "psm", "rayon", "region 2.2.0", @@ -11864,7 +11601,7 @@ dependencies = [ "log", "rustix", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "toml", "winapi", "zstd", @@ -11965,7 +11702,7 @@ dependencies = [ "mach", "memoffset", "more-asserts", - "rand 0.8.4", + "rand 0.8.5", "region 2.2.0", "rustix", "thiserror", @@ -11988,27 +11725,29 @@ dependencies = [ [[package]] name = "wast" -version = "38.0.0" +version = "40.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ebc29df4629f497e0893aacd40f13a4a56b85ef6eb4ab6d603f07244f1a7bf2" +checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac" dependencies = [ "leb128", + "memchr", + "unicode-width", ] [[package]] name = "wat" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" +checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.54" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" dependencies = [ "js-sys", "wasm-bindgen", @@ -12036,30 +11775,31 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" +checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" dependencies = [ "webpki 0.22.0", ] [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] [[package]] name = "which" -version = "4.0.2" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" dependencies = [ + "either", + "lazy_static", "libc", - "thiserror", ] [[package]] @@ -12114,15 +11854,15 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc 0.32.0", - "windows_i686_gnu 0.32.0", - "windows_i686_msvc 0.32.0", - "windows_x86_64_gnu 0.32.0", - "windows_x86_64_msvc 0.32.0", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] @@ -12133,9 +11873,9 @@ checksum = "c3d027175d00b01e0cbeb97d6ab6ebe03b12330a35786cbaca5252b1c4bf5d9b" [[package]] name = "windows_aarch64_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_i686_gnu" @@ -12145,9 +11885,9 @@ checksum = "8793f59f7b8e8b01eda1a652b2697d87b93097198ae85f823b969ca5b89bba58" [[package]] name = "windows_i686_gnu" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_msvc" @@ -12157,9 +11897,9 @@ checksum = "8602f6c418b67024be2996c512f5f995de3ba417f4c75af68401ab8756796ae4" [[package]] name = "windows_i686_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_x86_64_gnu" @@ -12169,9 +11909,9 @@ checksum = "f3d615f419543e0bd7d2b3323af0d86ff19cbc4f816e6453f36a2c2ce889c354" [[package]] name = "windows_x86_64_gnu" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_msvc" @@ -12181,9 +11921,9 @@ checksum = "11d95421d9ed3672c280884da53201a5c46b7b2765ca6faf34b0d71cf34a3561" [[package]] name = "windows_x86_64_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "winreg" @@ -12205,11 +11945,11 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc614d95359fd7afc321b66d2107ede58b246b844cf5d8a0adcca413e439f088" +checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" dependencies = [ - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "rand_core 0.5.1", "zeroize", ] @@ -12224,7 +11964,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] @@ -12251,18 +11991,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.10.0+zstd.1.5.2" +version = "0.10.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" +checksum = "5f4a6bd64f22b5e3e94b4e238669ff9f10815c27a5180108b849d24174a83847" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.4+zstd.1.5.2" +version = "4.1.6+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" +checksum = "94b61c51bb270702d6167b8ce67340d2754b088d0c091b06e593aa772c3ee9bb" dependencies = [ "libc", "zstd-sys", diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index aa4c093dcf0d4..275b914cda297 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -526,9 +526,9 @@ frame_benchmarking::benchmarks! { member_counter: 1, roles: PoolRoles { depositor: depositor.clone(), - root: depositor.clone(), - nominator: depositor.clone(), - state_toggler: depositor.clone(), + root: Some(depositor.clone()), + nominator: Some(depositor.clone()), + state_toggler: Some(depositor.clone()), }, } ); @@ -567,9 +567,9 @@ frame_benchmarking::benchmarks! { member_counter: 1, roles: PoolRoles { depositor: depositor.clone(), - root: depositor.clone(), - nominator: depositor.clone(), - state_toggler: depositor.clone(), + root: Some(depositor.clone()), + nominator: Some(depositor.clone()), + state_toggler: Some(depositor.clone()), } } ); @@ -638,17 +638,17 @@ frame_benchmarking::benchmarks! { }:_( Origin::Signed(root.clone()), first_id, - Some(random.clone()), - Some(random.clone()), - Some(random.clone()) + ConfigOp::Set(random.clone()), + ConfigOp::Set(random.clone()), + ConfigOp::Set(random.clone()) ) verify { assert_eq!( pallet_nomination_pools::BondedPools::::get(first_id).unwrap().roles, pallet_nomination_pools::PoolRoles { depositor: root, - nominator: random.clone(), - state_toggler: random.clone(), - root: random, + nominator: Some(random.clone()), + state_toggler: Some(random.clone()), + root: Some(random), }, ) } diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 0fff470eec43b..0aa2401584df0 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -502,7 +502,11 @@ pub enum PoolState { Destroying, } -/// Pool adminstration roles. +/// Pool administration roles. +/// +/// Any pool has a depositor, which can never change. But, all the other roles are optional, and +/// cannot exist. Note that if `root` is set to `None`, it basically means that the roles of this +/// pool can never change again (except via governance). #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, Debug, PartialEq, Clone)] pub struct PoolRoles { /// Creates the pool and is the initial member. They can only leave the pool once all other @@ -510,11 +514,11 @@ pub struct PoolRoles { pub depositor: AccountId, /// Can change the nominator, state-toggler, or itself and can perform any of the actions the /// nominator or state-toggler can. - pub root: AccountId, + pub root: Option, /// Can select which validators the pool nominates. - pub nominator: AccountId, + pub nominator: Option, /// Can change the pools state and kick members if the pool is blocked. - pub state_toggler: AccountId, + pub state_toggler: Option, } /// Pool permissions and state @@ -665,25 +669,36 @@ impl BondedPool { .saturating_sub(T::StakingInterface::active_stake(&account).unwrap_or_default()) } + fn is_root(&self, who: &T::AccountId) -> bool { + self.roles.root.as_ref().map_or(false, |root| root == who) + } + + fn is_state_toggler(&self, who: &T::AccountId) -> bool { + self.roles + .state_toggler + .as_ref() + .map_or(false, |state_toggler| state_toggler == who) + } + fn can_update_roles(&self, who: &T::AccountId) -> bool { - *who == self.roles.root + self.is_root(who) } fn can_nominate(&self, who: &T::AccountId) -> bool { - *who == self.roles.root || *who == self.roles.nominator + self.is_root(who) || + self.roles.nominator.as_ref().map_or(false, |nominator| nominator == who) } fn can_kick(&self, who: &T::AccountId) -> bool { - (*who == self.roles.root || *who == self.roles.state_toggler) && - self.state == PoolState::Blocked + self.state == PoolState::Blocked && (self.is_root(who) || self.is_state_toggler(who)) } fn can_toggle_state(&self, who: &T::AccountId) -> bool { - (*who == self.roles.root || *who == self.roles.state_toggler) && !self.is_destroying() + (self.is_root(who) || self.is_state_toggler(who)) && !self.is_destroying() } fn can_set_metadata(&self, who: &T::AccountId) -> bool { - *who == self.roles.root || *who == self.roles.state_toggler + self.is_root(who) || self.is_state_toggler(who) } fn is_destroying(&self) -> bool { @@ -987,11 +1002,12 @@ impl SubPools { /// /// This is often used whilst getting the sub-pool from storage, thus it consumes and returns /// `Self` for ergonomic purposes. - fn maybe_merge_pools(mut self, unbond_era: EraIndex) -> Self { + fn maybe_merge_pools(mut self, current_era: EraIndex) -> Self { // Ex: if `TotalUnbondingPools` is 5 and current era is 10, we only want to retain pools // 6..=10. Note that in the first few eras where `checked_sub` is `None`, we don't remove // anything. - if let Some(newest_era_to_remove) = unbond_era.checked_sub(TotalUnbondingPools::::get()) + if let Some(newest_era_to_remove) = + current_era.checked_sub(T::PostUnbondingPoolsWindow::get()) { self.with_era.retain(|k, v| { if *k > newest_era_to_remove { @@ -1218,8 +1234,13 @@ pub mod pallet { /// /// The removal can be voluntary (withdrawn all unbonded funds) or involuntary (kicked). MemberRemoved { pool_id: PoolId, member: T::AccountId }, - /// The roles of a pool have been updated to the given new roles. - RolesUpdated { root: T::AccountId, state_toggler: T::AccountId, nominator: T::AccountId }, + /// The roles of a pool have been updated to the given new roles. Note that the depositor + /// can never change. + RolesUpdated { + root: Option, + state_toggler: Option, + nominator: Option, + }, } #[pallet::error] @@ -1470,7 +1491,7 @@ pub mod pallet { // Note that we lazily create the unbonding pools here if they don't already exist let mut sub_pools = SubPoolsStorage::::get(member.pool_id) .unwrap_or_default() - .maybe_merge_pools(unbond_era); + .maybe_merge_pools(current_era); // Update the unbond pool associated with the current era with the unbonded funds. Note // that we lazily create the unbond pool if it does not yet exist. @@ -1693,7 +1714,12 @@ pub mod pallet { }); let mut bonded_pool = BondedPool::::new( pool_id, - PoolRoles { root, nominator, state_toggler, depositor: who.clone() }, + PoolRoles { + root: Some(root), + nominator: Some(nominator), + state_toggler: Some(state_toggler), + depositor: who.clone(), + }, ); bonded_pool.try_inc_members()?; @@ -1850,9 +1876,9 @@ pub mod pallet { pub fn update_roles( origin: OriginFor, pool_id: PoolId, - root: Option, - nominator: Option, - state_toggler: Option, + new_root: ConfigOp, + new_nominator: ConfigOp, + new_state_toggler: ConfigOp, ) -> DispatchResult { let mut bonded_pool = match ensure_root(origin.clone()) { Ok(()) => BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?, @@ -1865,17 +1891,20 @@ pub mod pallet { }, }; - match root { - None => (), - Some(v) => bonded_pool.roles.root = v, + match new_root { + ConfigOp::Noop => (), + ConfigOp::Remove => bonded_pool.roles.root = None, + ConfigOp::Set(v) => bonded_pool.roles.root = Some(v), }; - match nominator { - None => (), - Some(v) => bonded_pool.roles.nominator = v, + match new_nominator { + ConfigOp::Noop => (), + ConfigOp::Remove => bonded_pool.roles.nominator = None, + ConfigOp::Set(v) => bonded_pool.roles.nominator = Some(v), }; - match state_toggler { - None => (), - Some(v) => bonded_pool.roles.state_toggler = v, + match new_state_toggler { + ConfigOp::Noop => (), + ConfigOp::Remove => bonded_pool.roles.state_toggler = None, + ConfigOp::Set(v) => bonded_pool.roles.state_toggler = Some(v), }; Self::deposit_event(Event::::RolesUpdated { @@ -2282,7 +2311,7 @@ impl OnStakerSlash> for Pallet { _slashed_bonded: BalanceOf, slashed_unlocking: &BTreeMap>, ) { - if let Some(pool_id) = ReversePoolIdLookup::::get(pool_account) { + if let Some(pool_id) = ReversePoolIdLookup::::get(pool_account).defensive() { let mut sub_pools = match SubPoolsStorage::::get(pool_id).defensive() { Some(sub_pools) => sub_pools, None => return, diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f39b5c92375c4..fe78da3bb14af 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -38,7 +38,7 @@ macro_rules! member_unbonding_eras { } pub const DEFAULT_ROLES: PoolRoles = - PoolRoles { depositor: 10, root: 900, nominator: 901, state_toggler: 902 }; + PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), state_toggler: Some(902) }; #[test] fn test_setup_works() { @@ -333,6 +333,8 @@ mod sub_pools { fn maybe_merge_pools_works() { ExtBuilder::default().build_and_execute(|| { assert_eq!(TotalUnbondingPools::::get(), 5); + assert_eq!(BondingDuration::get(), 3); + assert_eq!(PostUnbondingPoolsWindow::get(), 2); // Given let mut sub_pool_0 = SubPools:: { @@ -347,19 +349,19 @@ mod sub_pools { }; // When `current_era < TotalUnbondingPools`, - let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(3); + let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(0); // Then it exits early without modifications assert_eq!(sub_pool_1, sub_pool_0); // When `current_era == TotalUnbondingPools`, - let sub_pool_1 = sub_pool_1.maybe_merge_pools(4); + let sub_pool_1 = sub_pool_1.maybe_merge_pools(1); // Then it exits early without modifications assert_eq!(sub_pool_1, sub_pool_0); // When `current_era - TotalUnbondingPools == 0`, - let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(5); + let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(2); // Then era 0 is merged into the `no_era` pool sub_pool_0.no_era = sub_pool_0.with_era.remove(&0).unwrap(); @@ -376,7 +378,7 @@ mod sub_pools { .unwrap(); // When `current_era - TotalUnbondingPools == 1` - let sub_pool_2 = sub_pool_1.maybe_merge_pools(6); + let sub_pool_2 = sub_pool_1.maybe_merge_pools(3); let era_1_pool = sub_pool_0.with_era.remove(&1).unwrap(); // Then era 1 is merged into the `no_era` pool @@ -385,7 +387,7 @@ mod sub_pools { assert_eq!(sub_pool_2, sub_pool_0); // When `current_era - TotalUnbondingPools == 5`, so all pools with era <= 4 are removed - let sub_pool_3 = sub_pool_2.maybe_merge_pools(10); + let sub_pool_3 = sub_pool_2.maybe_merge_pools(7); // Then all eras <= 5 are merged into the `no_era` pool for era in 2..=5 { @@ -1723,9 +1725,9 @@ mod unbond { // Given unsafe_set_state(1, PoolState::Blocked).unwrap(); let bonded_pool = BondedPool::::get(1).unwrap(); - assert_eq!(bonded_pool.roles.root, 900); - assert_eq!(bonded_pool.roles.nominator, 901); - assert_eq!(bonded_pool.roles.state_toggler, 902); + assert_eq!(bonded_pool.roles.root.unwrap(), 900); + assert_eq!(bonded_pool.roles.nominator.unwrap(), 901); + assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902); // When the nominator tries to kick, then its a noop assert_noop!( @@ -3143,9 +3145,9 @@ mod create { state: PoolState::Open, roles: PoolRoles { depositor: 11, - root: 123, - nominator: 456, - state_toggler: 789 + root: Some(123), + nominator: Some(456), + state_toggler: Some(789) } } } @@ -3590,71 +3592,164 @@ mod update_roles { ExtBuilder::default().build_and_execute(|| { assert_eq!( BondedPools::::get(1).unwrap().roles, - PoolRoles { depositor: 10, root: 900, nominator: 901, state_toggler: 902 }, + PoolRoles { + depositor: 10, + root: Some(900), + nominator: Some(901), + state_toggler: Some(902) + }, ); // non-existent pools assert_noop!( - Pools::update_roles(Origin::signed(1), 2, Some(5), Some(6), Some(7)), + Pools::update_roles( + Origin::signed(1), + 2, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), Error::::PoolNotFound, ); // depositor cannot change roles. assert_noop!( - Pools::update_roles(Origin::signed(1), 1, Some(5), Some(6), Some(7)), + Pools::update_roles( + Origin::signed(1), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), Error::::DoesNotHavePermission, ); // nominator cannot change roles. assert_noop!( - Pools::update_roles(Origin::signed(901), 1, Some(5), Some(6), Some(7)), + Pools::update_roles( + Origin::signed(901), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), Error::::DoesNotHavePermission, ); // state-toggler assert_noop!( - Pools::update_roles(Origin::signed(902), 1, Some(5), Some(6), Some(7)), + Pools::update_roles( + Origin::signed(902), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), Error::::DoesNotHavePermission, ); // but root can - assert_ok!(Pools::update_roles(Origin::signed(900), 1, Some(5), Some(6), Some(7))); + assert_ok!(Pools::update_roles( + Origin::signed(900), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + )); assert_eq!( pool_events_since_last_call(), vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::RolesUpdated { root: 5, state_toggler: 7, nominator: 6 } + Event::RolesUpdated { + root: Some(5), + state_toggler: Some(7), + nominator: Some(6) + } ] ); assert_eq!( BondedPools::::get(1).unwrap().roles, - PoolRoles { depositor: 10, root: 5, nominator: 6, state_toggler: 7 }, + PoolRoles { + depositor: 10, + root: Some(5), + nominator: Some(6), + state_toggler: Some(7) + }, ); // also root origin can - assert_ok!(Pools::update_roles(Origin::root(), 1, Some(1), Some(2), Some(3))); + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(1), + ConfigOp::Set(2), + ConfigOp::Set(3) + )); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::RolesUpdated { + root: Some(1), + state_toggler: Some(3), + nominator: Some(2) + }] + ); + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { + depositor: 10, + root: Some(1), + nominator: Some(2), + state_toggler: Some(3) + }, + ); + + // Noop works + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(11), + ConfigOp::Noop, + ConfigOp::Noop + )); assert_eq!( pool_events_since_last_call(), - vec![Event::RolesUpdated { root: 1, state_toggler: 3, nominator: 2 }] + vec![Event::RolesUpdated { + root: Some(11), + state_toggler: Some(3), + nominator: Some(2) + }] ); + assert_eq!( BondedPools::::get(1).unwrap().roles, - PoolRoles { depositor: 10, root: 1, nominator: 2, state_toggler: 3 }, + PoolRoles { + depositor: 10, + root: Some(11), + nominator: Some(2), + state_toggler: Some(3) + }, ); - // None is a noop - assert_ok!(Pools::update_roles(Origin::root(), 1, Some(11), None, None)); + // Remove works + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(69), + ConfigOp::Remove, + ConfigOp::Remove + )); assert_eq!( pool_events_since_last_call(), - vec![Event::RolesUpdated { root: 11, state_toggler: 3, nominator: 2 }] + vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }] ); assert_eq!( BondedPools::::get(1).unwrap().roles, - PoolRoles { depositor: 10, root: 11, nominator: 2, state_toggler: 3 }, + PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None }, ); }) } diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 2d4c1ea9a3488..f17d09b413606 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -533,10 +533,12 @@ impl StakingLedger { /// case that either the active bonded or some unlocking chunks become dust after slashing. /// Returns the amount of funds actually slashed. /// + /// `slash_era` is the era in which the slash (which is being enacted now) actually happened. + /// /// # Note /// - /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash - /// was applied. + /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was + /// applied. fn slash( &mut self, slash_amount: BalanceOf, @@ -615,6 +617,7 @@ impl StakingLedger { break } } + self.unlocking.retain(|c| !c.value.is_zero()); T::OnStakerSlash::on_slash(&self.stash, self.active, &slashed_unlocking); pre_slash_total.saturating_sub(self.total) diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 21d4714985c6b..ccd9558c5c21d 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -2787,6 +2787,80 @@ fn deferred_slashes_are_deferred() { }) } +#[test] +fn staker_cannot_bail_deferred_slash() { + // as long as SlashDeferDuration is less than BondingDuration, this should not be possible. + ExtBuilder::default().slash_defer_duration(2).build_and_execute(|| { + mock::start_active_era(1); + + assert_eq!(Balances::free_balance(11), 1000); + assert_eq!(Balances::free_balance(101), 2000); + + let exposure = Staking::eras_stakers(active_era(), 11); + let nominated_value = exposure.others.iter().find(|o| o.who == 101).unwrap().value; + + on_offence_now( + &[OffenceDetails { + offender: (11, Staking::eras_stakers(active_era(), 11)), + reporters: vec![], + }], + &[Perbill::from_percent(10)], + ); + + // now we chill + assert_ok!(Staking::chill(Origin::signed(100))); + assert_ok!(Staking::unbond(Origin::signed(100), 500)); + + assert_eq!(Staking::current_era().unwrap(), 1); + assert_eq!(active_era(), 1); + + assert_eq!( + Ledger::::get(100).unwrap(), + StakingLedger { + active: 0, + total: 500, + stash: 101, + claimed_rewards: Default::default(), + unlocking: bounded_vec![UnlockChunk { era: 4u32, value: 500 }], + } + ); + + // no slash yet. + assert_eq!(Balances::free_balance(11), 1000); + assert_eq!(Balances::free_balance(101), 2000); + + // no slash yet. + mock::start_active_era(2); + assert_eq!(Balances::free_balance(11), 1000); + assert_eq!(Balances::free_balance(101), 2000); + assert_eq!(Staking::current_era().unwrap(), 2); + assert_eq!(active_era(), 2); + + // no slash yet. + mock::start_active_era(3); + assert_eq!(Balances::free_balance(11), 1000); + assert_eq!(Balances::free_balance(101), 2000); + assert_eq!(Staking::current_era().unwrap(), 3); + assert_eq!(active_era(), 3); + + // and cannot yet unbond: + assert_storage_noop!(assert!(Staking::withdraw_unbonded(Origin::signed(100), 0).is_ok())); + assert_eq!( + Ledger::::get(100).unwrap().unlocking.into_inner(), + vec![UnlockChunk { era: 4u32, value: 500 as Balance }], + ); + + // at the start of era 4, slashes from era 1 are processed, + // after being deferred for at least 2 full eras. + mock::start_active_era(4); + + assert_eq!(Balances::free_balance(11), 900); + assert_eq!(Balances::free_balance(101), 2000 - (nominated_value / 10)); + + // and the leftover of the funds can now be unbonded. + }) +} + #[test] fn remove_deferred() { ExtBuilder::default().slash_defer_duration(2).build_and_execute(|| { @@ -4856,7 +4930,7 @@ fn force_apply_min_commission_works() { } #[test] -fn ledger_slash_works() { +fn proportional_ledger_slash_works() { let c = |era, value| UnlockChunk:: { era, value }; // Given let mut ledger = StakingLedger:: { From 00e8c87c869c4f820da79f777c263e595b286077 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 13 May 2022 15:06:50 +0100 Subject: [PATCH 02/65] undo lock file changes? --- Cargo.lock | 1570 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 915 insertions(+), 655 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a46b20acfeb7..68272e1df9c8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,30 +29,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +checksum = "6e3e798aa0c8239776f54415bc06f3d74b1850f3f830b45c35cfc80556973f70" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] name = "aes" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +checksum = "495ee669413bfbe9e8cace80f4d3d78e6d8c8d99579f97fb93bde351b185f2d4" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", ] [[package]] name = "aes-gcm" -version = "0.9.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +checksum = "b2a930fd487faaa92a30afa92cc9dd1526a5cff67124abbbb1c617ce070f4dcf" dependencies = [ "aead", "aes", @@ -68,7 +68,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.3", "once_cell", "version_check", ] @@ -93,24 +93,24 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" [[package]] name = "approx" -version = "0.5.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" dependencies = [ "num-traits", ] [[package]] name = "arbitrary" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c38b6b6b79f671c25e1a3e785b7b82d7562ffc9cd3efdc98627e5668a2472490" +checksum = "698b65a961a9d730fb45b6b0327e20207810c9f61ee421b082b27ba003f49e2b" [[package]] name = "arrayref" @@ -135,21 +135,21 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" [[package]] name = "asn1_der" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" +checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3" [[package]] name = "assert_cmd" -version = "2.0.4" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" +checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2" dependencies = [ "bstr", "doc-comment", @@ -188,23 +188,23 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.4.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", "once_cell", - "slab", + "vec-arena", ] [[package]] name = "async-global-executor" -version = "2.0.4" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43" +checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" dependencies = [ "async-channel", "async-executor", @@ -230,7 +230,7 @@ dependencies = [ "parking", "polling", "slab", - "socket2", + "socket2 0.4.4", "waker-fn", "winapi", ] @@ -293,7 +293,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "pin-utils", "slab", "wasm-bindgen-futures", @@ -310,15 +310,15 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2", + "socket2 0.4.4", "trust-dns-resolver", ] [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" dependencies = [ "async-stream-impl", "futures-core", @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ "proc-macro2", "quote", @@ -337,15 +337,15 @@ dependencies = [ [[package]] name = "async-task" -version = "4.2.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" [[package]] name = "async-trait" -version = "0.1.53" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" dependencies = [ "proc-macro2", "quote", @@ -362,16 +362,16 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", ] [[package]] name = "atomic" -version = "0.5.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" +checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" dependencies = [ - "autocfg", + "autocfg 1.0.1", ] [[package]] @@ -393,30 +393,36 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.28.4", + "object 0.27.1", "rustc-demangle", ] [[package]] name = "base-x" -version = "0.2.10" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" [[package]] name = "base16ct" @@ -539,16 +545,17 @@ dependencies = [ [[package]] name = "bimap" -version = "0.6.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" +checksum = "50ae17cabbc8a38a1e3e4c1a6a664e9a09672dc14d0896fa8d865d3a5a446b07" [[package]] name = "bincode" -version = "1.3.3" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +checksum = "d175dfa69e619905c4c3cdb7c3c203fa3bdd5d51184e3afdb2742c0280493772" dependencies = [ + "byteorder", "serde", ] @@ -591,9 +598,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.4" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +checksum = "b94ba84325db59637ffc528bbe8c7f86c02c57cff5c0e2b9b00f9a851f42f309" dependencies = [ "digest 0.10.3", ] @@ -626,7 +633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "constant_time_eq", ] @@ -637,7 +644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "constant_time_eq", ] @@ -648,7 +655,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "cc", "cfg-if 1.0.0", "constant_time_eq", @@ -673,16 +680,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding 0.2.1", - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -702,9 +709,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.2.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" dependencies = [ "async-channel", "async-task", @@ -722,9 +729,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.17" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" dependencies = [ "lazy_static", "memchr", @@ -743,15 +750,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.9.1" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byte-slice-cast" -version = "1.2.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" +checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" [[package]] name = "byte-tools" @@ -761,9 +768,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecheck" -version = "0.6.8" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" +checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -771,9 +778,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.8" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" +checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" dependencies = [ "proc-macro2", "quote", @@ -782,9 +789,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" @@ -805,24 +812,24 @@ dependencies = [ [[package]] name = "cache-padded" -version = "1.2.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "camino" -version = "1.0.8" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fd178c5af4d59e83498ef15cf3f154e1a6f9d091270cb86283c65ef44e9ef0" +checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9" dependencies = [ "serde", ] [[package]] name = "cargo-platform" -version = "0.1.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" dependencies = [ "serde", ] @@ -835,25 +842,25 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.9", + "semver 1.0.4", "serde", "serde_json", ] [[package]] name = "cast" -version = "0.2.7" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" +checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" dependencies = [ - "rustc_version 0.4.0", + "rustc_version 0.2.3", ] [[package]] name = "cc" -version = "1.0.73" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" dependencies = [ "jobserver", ] @@ -887,7 +894,7 @@ checksum = "01b72a433d0cf2aef113ba70f62634c56fddb0f244e6377185c56a7cadbd8f91" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures", + "cpufeatures 0.2.1", "zeroize", ] @@ -909,9 +916,9 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 3.1.18", + "clap 3.1.6", "node-cli", - "rand 0.8.5", + "rand 0.8.4", "sc-chain-spec", "sc-keystore", "sp-core", @@ -950,7 +957,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -964,13 +971,13 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.3.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" +checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" dependencies = [ "glob", "libc", - "libloading 0.7.3", + "libloading 0.7.0", ] [[package]] @@ -986,16 +993,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.18" +version = "3.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" dependencies = [ "atty", "bitflags", "clap_derive", - "clap_lex", "indexmap", "lazy_static", + "os_str_bytes", "strsim", "termcolor", "textwrap 0.15.0", @@ -1003,18 +1010,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.1.4" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" +checksum = "a394f7ec0715b42a4e52b294984c27c9a61f77c8d82f7774c5198350be143f19" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", ] [[package]] name = "clap_derive" -version = "3.1.18" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -1024,12 +1031,12 @@ dependencies = [ ] [[package]] -name = "clap_lex" -version = "0.2.0" +name = "cloudabi" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "os_str_bytes", + "bitflags", ] [[package]] @@ -1086,22 +1093,38 @@ dependencies = [ [[package]] name = "cpp_demangle" -version = "0.3.5" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390" dependencies = [ "cfg-if 1.0.0", + "glob", ] [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ "libc", ] +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + [[package]] name = "cranelift-bforest" version = "0.76.0" @@ -1253,9 +1276,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ "cfg-if 1.0.0", ] @@ -1300,9 +1323,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1321,11 +1344,10 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ - "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", @@ -1335,9 +1357,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1355,8 +1377,8 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.5", - "rand_core 0.6.3", + "generic-array 0.14.4", + "rand_core 0.6.2", "subtle", "zeroize", ] @@ -1367,7 +1389,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "typenum", ] @@ -1377,7 +1399,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -1387,7 +1409,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -1419,14 +1441,14 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" dependencies = [ - "sct 0.6.1", + "sct 0.6.0", ] [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" dependencies = [ "quote", "syn", @@ -1454,9 +1476,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.1.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216" +checksum = "434e1720189a637d44fe464f4df1e6eb900b4835255b14354497c78af37d9bb8" dependencies = [ "byteorder", "digest 0.8.1", @@ -1467,9 +1489,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "f627126b946c25a4638eec0ea634fc52506dea98db118aae985118ce7c3d723f" dependencies = [ "byteorder", "digest 0.9.0", @@ -1486,16 +1508,16 @@ checksum = "4033478fbf70d6acf2655ac70da91ee65852d69daf7a67bf7a2f518fb47aafcf" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", "zeroize", ] [[package]] name = "darling" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" dependencies = [ "darling_core", "darling_macro", @@ -1503,22 +1525,23 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", + "strsim", "syn", ] [[package]] name = "darling_macro" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" dependencies = [ "darling_core", "quote", @@ -1533,9 +1556,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" -version = "0.1.12" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" +checksum = "0a94feec3d2ba66c0b6621bca8bc6f68415b1e5c69af3586fdd0af9fd9f29b17" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -1543,9 +1566,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" +checksum = "f0f83e699727abca3c56e187945f303389590305ab2f0185ea445aa66e8d5f2a" dependencies = [ "data-encoding", "syn", @@ -1562,14 +1585,14 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.17" +version = "0.99.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version 0.3.3", "syn", ] @@ -1600,7 +1623,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -1609,7 +1632,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.0", "crypto-common", "subtle", ] @@ -1646,12 +1669,12 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.7" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", - "redox_users 0.4.3", + "redox_users 0.4.0", "winapi", ] @@ -1662,15 +1685,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users 0.4.3", + "redox_users 0.4.0", "winapi", ] [[package]] name = "dissimilar" -version = "1.0.4" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" +checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb" [[package]] name = "dns-parser" @@ -1750,7 +1773,7 @@ checksum = "64fba5a42bd76a17cad4bfa00de168ee1cbfa06a5e8ce992ae880218c05641a9" dependencies = [ "byteorder", "dynasm", - "memmap2 0.5.3", + "memmap2 0.5.0", ] [[package]] @@ -1767,9 +1790,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d916019f70ae3a1faa1195685e290287f39207d38e6dfee727197cffcc002214" +checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef" dependencies = [ "signature", ] @@ -1780,11 +1803,11 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "ed25519", "rand 0.7.3", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "zeroize", ] @@ -1804,9 +1827,9 @@ dependencies = [ "crypto-bigint", "der", "ff", - "generic-array 0.14.5", + "generic-array 0.14.4", "group", - "rand_core 0.6.3", + "rand_core 0.6.2", "sec1", "subtle", "zeroize", @@ -1852,9 +1875,9 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" +checksum = "1b3ab37dc79652c9d85f1f7b6070d77d321d2467f5fe7b00d6b7a86c57b092ae" dependencies = [ "enumflags2_derive", ] @@ -1872,18 +1895,18 @@ dependencies = [ [[package]] name = "enumset" -version = "1.0.11" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4799cdb24d48f1f8a7a98d06b7fde65a85a2d1e42b25a889f5406aa1fbefe074" +checksum = "7e76129da36102af021b8e5000dab2c1c30dbef85c1e482beeff8da5dde0e0b0" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" -version = "0.6.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea83a3fbdc1d999ccfbcbee717eab36f8edf2d71693a23ce0d7cca19e085304c" +checksum = "6451128aa6655d880755345d085494cf7561a6bee7c8dc821e5d77e6d267ecd4" dependencies = [ "darling", "proc-macro2", @@ -1891,6 +1914,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -1908,7 +1944,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime", + "humantime 2.1.0", "log", "regex", "termcolor", @@ -1933,19 +1969,19 @@ dependencies = [ [[package]] name = "errno-dragonfly" -version = "0.1.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" dependencies = [ - "cc", + "gcc", "libc", ] [[package]] name = "event-listener" -version = "2.5.2" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] name = "exit-future" @@ -1988,21 +2024,21 @@ dependencies = [ [[package]] name = "ff" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" +checksum = "b2958d04124b9f27f175eaeb9a9f383d026098aa837eadd8ba22c11f13a05b9e" dependencies = [ - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", ] [[package]] name = "file-per-thread-logger" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" +checksum = "4fdbe0d94371f9ce939b555dd342d0686cc4c0cadbcd4b61d70af5ff97eb4126" dependencies = [ - "env_logger 0.9.0", + "env_logger 0.7.1", "log", ] @@ -2019,7 +2055,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.11.2", - "rand 0.8.5", + "rand 0.8.4", "scale-info", ] @@ -2030,22 +2066,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ "byteorder", - "rand 0.8.5", + "rand 0.8.4", "rustc-hex", "static_assertions", ] [[package]] name = "fixedbitset" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" [[package]] name = "flate2" -version = "1.0.23" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ "cfg-if 1.0.0", "crc32fast", @@ -2087,7 +2123,7 @@ dependencies = [ "linregress", "log", "parity-scale-codec", - "paste 1.0.7", + "paste 1.0.6", "scale-info", "serde", "sp-api", @@ -2106,7 +2142,7 @@ version = "4.0.0-dev" dependencies = [ "Inflector", "chrono", - "clap 3.1.18", + "clap 3.1.6", "frame-benchmarking", "frame-support", "frame-system", @@ -2121,7 +2157,7 @@ dependencies = [ "memory-db", "parity-scale-codec", "prettytable-rs", - "rand 0.8.5", + "rand 0.8.4", "rand_pcg 0.3.1", "sc-block-builder", "sc-cli", @@ -2187,13 +2223,13 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", "honggfuzz", "parity-scale-codec", - "rand 0.8.5", + "rand 0.8.4", "scale-info", "sp-arithmetic", "sp-npos-elections", @@ -2247,7 +2283,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-util-mem", - "paste 1.0.7", + "paste 1.0.6", "pretty_assertions", "scale-info", "serde", @@ -2421,6 +2457,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -2478,16 +2520,16 @@ checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" -version = "1.12.0" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "waker-fn", ] @@ -2509,7 +2551,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01fe9932a224b72b45336d96040aa86386d674a31d0af27d800ea7bc8ca97fe" dependencies = [ "futures-io", - "rustls 0.20.4", + "rustls 0.20.2", "webpki 0.22.0", ] @@ -2544,11 +2586,17 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "pin-utils", "slab", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "generate-bags" version = "4.0.0-dev" @@ -2574,9 +2622,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -2597,9 +2645,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2608,9 +2656,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" +checksum = "b442c439366184de619215247d24e908912b175e824a530253845ac4c251a5c1" dependencies = [ "opaque-debug 0.3.0", "polyval", @@ -2659,9 +2707,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.8" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" dependencies = [ "aho-corasick", "bstr", @@ -2672,14 +2720,15 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.4" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", + "web-sys", ] [[package]] @@ -2689,15 +2738,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "ff", - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", ] [[package]] name = "h2" -version = "0.3.13" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" dependencies = [ "bytes", "fnv", @@ -2708,15 +2757,15 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util", + "tokio-util 0.6.7", "tracing", ] [[package]] name = "half" -version = "1.8.2" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "handlebars" @@ -2727,7 +2776,7 @@ dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.1", + "quick-error 2.0.0", "serde", "serde_json", ] @@ -2758,18 +2807,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" dependencies = [ "ahash", ] [[package]] name = "heck" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" dependencies = [ "unicode-segmentation", ] @@ -2782,9 +2831,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -2834,7 +2883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.5", + "generic-array 0.14.4", "hmac 0.8.1", ] @@ -2862,37 +2911,46 @@ dependencies = [ [[package]] name = "http" -version = "0.2.7" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ "bytes", "fnv", - "itoa 1.0.1", + "itoa 0.4.8", ] [[package]] name = "http-body" -version = "0.4.4" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", ] [[package]] name = "httparse" -version = "1.7.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" + +[[package]] +name = "humantime" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error 1.2.3", +] [[package]] name = "humantime" @@ -2902,9 +2960,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.18" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -2915,9 +2973,9 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.1", - "pin-project-lite 0.2.9", - "socket2", + "itoa 0.4.8", + "pin-project-lite 0.2.6", + "socket2 0.4.4", "tokio", "tower-service", "tracing", @@ -2997,9 +3055,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" +checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" dependencies = [ "serde", ] @@ -3017,11 +3075,11 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" dependencies = [ - "autocfg", + "autocfg 1.0.1", "hashbrown 0.11.2", "serde", ] @@ -3062,7 +3120,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" dependencies = [ - "socket2", + "socket2 0.4.4", "widestring", "winapi", "winreg", @@ -3097,18 +3155,18 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" dependencies = [ "wasm-bindgen", ] @@ -3139,12 +3197,12 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-types", "pin-project 1.0.10", - "rustls-native-certs 0.6.2", + "rustls-native-certs 0.6.1", "soketto", "thiserror", "tokio", - "tokio-rustls 0.23.4", - "tokio-util", + "tokio-rustls 0.23.2", + "tokio-util 0.7.1", "tracing", "webpki-roots", ] @@ -3156,7 +3214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31e6b13067b615dd050ced7c19517a52cde490eee2c754d5447ce513f2275f7d" dependencies = [ "anyhow", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "async-lock", "async-trait", "beef", @@ -3166,7 +3224,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "rustc-hash", "serde", "serde_json", @@ -3245,7 +3303,7 @@ dependencies = [ "serde_json", "soketto", "tokio", - "tokio-util", + "tokio-util 0.7.1", "tracing", ] @@ -3340,21 +3398,21 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leb128" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.125" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "libgit2-sys" -version = "0.13.2+1.4.2" +version = "0.13.3+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a42de9a51a5c12e00fc0e4ca6bc2ea43582fc6418488e8f615e905d886f258b" +checksum = "c24d36c3ac9b9996a2418d6bf428cc0bc5d1a814a84303fc60986088c5ed60de" dependencies = [ "cc", "libc", @@ -3374,9 +3432,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -3384,9 +3442,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" +checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" @@ -3398,7 +3456,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.6", + "getrandom 0.2.3", "instant", "lazy_static", "libp2p-autonat", @@ -3449,7 +3507,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -3476,7 +3534,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "ring", "rw-stream-sink", "sha2 0.10.2", @@ -3618,9 +3676,9 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.5", + "rand 0.8.4", "smallvec", - "socket2", + "socket2 0.4.4", "void", ] @@ -3665,14 +3723,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dd7e0c94051cda67123be68cf6b65211ba3dde7277be9068412de3e7ffd63ef" dependencies = [ "bytes", - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "futures", "lazy_static", "libp2p-core", "log", "prost", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "sha2 0.10.2", "snow", "static_assertions", @@ -3745,7 +3803,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "smallvec", "static_assertions", "thiserror", @@ -3769,7 +3827,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "sha2 0.10.2", "thiserror", "unsigned-varint", @@ -3838,7 +3896,7 @@ dependencies = [ "libc", "libp2p-core", "log", - "socket2", + "socket2 0.4.4", ] [[package]] @@ -3926,9 +3984,9 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.8.5", + "rand 0.8.4", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "typenum", ] @@ -3963,9 +4021,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.6" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" dependencies = [ "cc", "libc", @@ -4024,19 +4082,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.17" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" dependencies = [ "cfg-if 1.0.0", "value-bag", @@ -4083,9 +4140,9 @@ dependencies = [ [[package]] name = "lz4" -version = "1.23.3" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4edcb94251b1c375c459e5abe9fb0168c1c826c3370172684844f8f3f8d1a885" +checksum = "aac20ed6991e01bf6a2e68cc73df2b389707403662a8ba89f68511fb340f724c" dependencies = [ "libc", "lz4-sys", @@ -4093,9 +4150,9 @@ dependencies = [ [[package]] name = "lz4-sys" -version = "1.9.3" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7be8908e2ed6f31c02db8a9fa962f03e36c53fbfde437363eae3306b85d7e17" +checksum = "dca79aa95d8b3226213ad454d328369853be3a1382d89532a854f4d69640acae" dependencies = [ "cc", "libc", @@ -4133,24 +4190,24 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "matrixmultiply" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +checksum = "5a8a15b776d9dfaecd44b03c5828c2199cddff5247215858aac14624f8d6b741" dependencies = [ "rawpointer", ] [[package]] name = "memchr" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memmap" @@ -4164,29 +4221,29 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.2.3" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" +checksum = "04e3e85b970d650e2ae6d70592474087051c11c54da7f7b4949725c5735fbcc6" dependencies = [ "libc", ] [[package]] name = "memmap2" -version = "0.5.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" +checksum = "4647a11b578fead29cdbb34d4adef8dd3dc35b876c9c6d5240d83f205abfe96e" dependencies = [ "libc", ] [[package]] name = "memoffset" -version = "0.6.5" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" dependencies = [ - "autocfg", + "autocfg 1.0.1", ] [[package]] @@ -4196,7 +4253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "parity-util-mem", ] @@ -4226,30 +4283,42 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", + "autocfg 1.0.1", ] [[package]] name = "mio" -version = "0.8.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +dependencies = [ + "socket2 0.3.19", + "winapi", ] [[package]] name = "more-asserts" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" +checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" [[package]] name = "multiaddr" @@ -4293,7 +4362,7 @@ dependencies = [ "digest 0.10.3", "multihash-derive", "sha2 0.10.2", - "sha3 0.10.1", + "sha3 0.10.0", "unsigned-varint", ] @@ -4313,9 +4382,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" [[package]] name = "multistream-select" @@ -4343,7 +4412,7 @@ dependencies = [ "num-complex", "num-rational 0.4.0", "num-traits", - "rand 0.8.5", + "rand 0.8.4", "rand_distr", "simba", "typenum", @@ -4366,7 +4435,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d66043b25d4a6cccb23619d10c19c25304b355a7dccd4a8e11423dd2382146" dependencies = [ - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -4403,7 +4472,7 @@ checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" dependencies = [ "anyhow", "byteorder", - "paste 1.0.7", + "paste 1.0.6", "thiserror", ] @@ -4464,7 +4533,7 @@ dependencies = [ name = "node-bench" version = "0.9.0-dev" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "derive_more", "fs_extra", "futures", @@ -4503,7 +4572,7 @@ version = "3.0.0-dev" dependencies = [ "assert_cmd", "async-std", - "clap 3.1.18", + "clap 3.1.6", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4526,7 +4595,7 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "platforms", - "rand 0.8.5", + "rand 0.8.4", "regex", "remote-externalities", "sc-authority-discovery", @@ -4618,7 +4687,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4768,7 +4837,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "generate-bags", "node-runtime", ] @@ -4777,7 +4846,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -4900,12 +4969,22 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.1" +version = "7.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" dependencies = [ "memchr", "minimal-lexical", + "version_check", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", ] [[package]] @@ -4914,16 +4993,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790" +checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" dependencies = [ "num-traits", ] @@ -4940,11 +5019,11 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-traits", ] @@ -4954,7 +5033,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-bigint", "num-integer", "num-traits", @@ -4966,18 +5045,18 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg", + "autocfg 1.0.1", "libm", ] @@ -5004,9 +5083,9 @@ dependencies = [ [[package]] name = "object" -version = "0.28.4" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" dependencies = [ "crc32fast", "hashbrown 0.11.2", @@ -5040,21 +5119,24 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.5" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "os_str_bytes" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] [[package]] name = "output_vt100" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" dependencies = [ "winapi", ] @@ -5226,7 +5308,7 @@ dependencies = [ "frame-election-provider-support", "honggfuzz", "pallet-bags-list", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -5379,7 +5461,7 @@ dependencies = [ "pallet-utility", "parity-scale-codec", "pretty_assertions", - "rand 0.8.5", + "rand 0.8.4", "rand_pcg 0.3.1", "scale-info", "serde", @@ -6382,19 +6464,19 @@ dependencies = [ "libc", "log", "lz4", - "memmap2 0.2.3", + "memmap2 0.2.1", "parking_lot 0.11.2", - "rand 0.8.5", + "rand 0.8.4", "snap", ] [[package]] name = "parity-scale-codec" -version = "3.1.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b44461635bbb1a0300f100a841e571e7d919c81c73075ef5d152ffdb521066" +checksum = "2a7f3fcf5e45fc28b84dcdab6b983e77f197ec01f325a33f404ba6855afd1070" dependencies = [ - "arrayvec 0.7.2", + "arrayvec 0.7.1", "bitvec", "byte-slice-cast", "impl-trait-for-tuples", @@ -6404,9 +6486,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" +checksum = "2c6e626dc84025ff56bf1476ed0e30d10c84d7f89a475ef46ebabee1095a8fba" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6427,7 +6509,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.0", @@ -6486,7 +6568,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.1", ] [[package]] @@ -6498,20 +6580,20 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.13", + "redox_syscall 0.2.10", "smallvec", "winapi", ] [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.13", + "redox_syscall 0.2.10", "smallvec", "windows-sys", ] @@ -6528,9 +6610,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" [[package]] name = "paste-impl" @@ -6626,11 +6708,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.29" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" +checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" dependencies = [ - "pin-project-internal 0.4.29", + "pin-project-internal 0.4.27", ] [[package]] @@ -6644,9 +6726,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "0.4.29" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" +checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" dependencies = [ "proc-macro2", "quote", @@ -6672,9 +6754,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -6684,9 +6766,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "platforms" @@ -6709,66 +6791,66 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "b07fffcddc1cb3a1de753caa4e4df03b79922ba43cf882acc1bdd7e8df9f4590" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "b38a02e23bd9604b842a812063aec4ef702b57989c37b655254bb61c471ad211" dependencies = [ "plotters-backend", ] [[package]] name = "polling" -version = "2.2.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "libc", "log", - "wepoll-ffi", + "wepoll-sys", "winapi", ] [[package]] name = "poly1305" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" +checksum = "9fcffab1f78ebbdf4b93b68c1ffebc24037eedf271edaca795732b24e5e4e349" dependencies = [ - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "polyval" -version = "0.5.3" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +checksum = "a6ba6a405ef63530d6cb12802014b22f9c5751bd17cdcddbe9e46d5c8ae83287" dependencies = [ "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "predicates" -version = "2.1.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" +checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308" dependencies = [ "difflib", "itertools", @@ -6777,18 +6859,18 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" dependencies = [ "predicates-core", - "termtree", + "treeline", ] [[package]] @@ -6933,7 +7015,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", - "heck 0.3.3", + "heck 0.3.2", "itertools", "lazy_static", "log", @@ -6971,9 +7053,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.18" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" +checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" dependencies = [ "cc", ] @@ -7006,9 +7088,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quick-error" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" [[package]] name = "quickcheck" @@ -7018,7 +7100,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger 0.8.4", "log", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -7047,6 +7129,25 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg 0.1.2", + "rand_xorshift", + "winapi", +] + [[package]] name = "rand" version = "0.7.3" @@ -7057,19 +7158,30 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc", + "rand_hc 0.2.0", "rand_pcg 0.2.1", ] [[package]] name = "rand" -version = "0.8.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", ] [[package]] @@ -7084,14 +7196,29 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", ] +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.5.1" @@ -7103,11 +7230,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.3", ] [[package]] @@ -7117,7 +7244,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.5", + "rand 0.8.4", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", ] [[package]] @@ -7129,6 +7265,59 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + [[package]] name = "rand_pcg" version = "0.2.1" @@ -7144,7 +7333,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" dependencies = [ - "rand_core 0.6.3", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", ] [[package]] @@ -7155,11 +7353,11 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.5.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ - "autocfg", + "autocfg 1.0.1", "crossbeam-deque", "either", "rayon-core", @@ -7167,16 +7365,26 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.2" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", + "lazy_static", "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.1.57" @@ -7185,9 +7393,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -7205,29 +7413,28 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.2.6", - "redox_syscall 0.2.13", - "thiserror", + "getrandom 0.2.3", + "redox_syscall 0.2.10", ] [[package]] name = "ref-cast" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685d58625b6c2b83e4cc88a27c4bf65adb7b6b16dbdc413e515c9405b47432ab" +checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a043824e29c94169374ac5183ac0ed43f5724dc4556b19568007486bd840fa1f" +checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" dependencies = [ "proc-macro2", "quote", @@ -7269,10 +7476,11 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ + "byteorder", "regex-syntax", ] @@ -7355,9 +7563,9 @@ dependencies = [ [[package]] name = "retain_mut" -version = "0.1.7" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c31b5c4033f8fdde8700e4657be2c497e7288f01515be52168c631e2e4d4086" +checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" [[package]] name = "rfc6979" @@ -7387,12 +7595,12 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.38" +version = "0.7.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" +checksum = "1f08c8062c1fe1253064043b8fc07bfea1b9702b71b4a86c11ea3588183b12e1" dependencies = [ "bytecheck", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "ptr_meta", "rend", "rkyv_derive", @@ -7401,9 +7609,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.38" +version = "0.7.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" +checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" dependencies = [ "proc-macro2", "quote", @@ -7459,9 +7667,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" [[package]] name = "rustc-hash" @@ -7484,20 +7692,29 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.9", + "semver 1.0.4", ] [[package]] name = "rustix" -version = "0.33.7" +version = "0.33.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" +checksum = "03627528abcc4a365554d32a9f3bbf67f7694c102cfeda792dc86a2d6057cc85" dependencies = [ "bitflags", "errno", @@ -7516,15 +7733,15 @@ dependencies = [ "base64", "log", "ring", - "sct 0.6.1", + "sct 0.6.0", "webpki 0.21.4", ] [[package]] name = "rustls" -version = "0.20.4" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" +checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84" dependencies = [ "log", "ring", @@ -7546,9 +7763,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +checksum = "5ca9ebdfa27d3fc180e42879037b5338ab1c040c06affd00d8338598e7800943" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7558,9 +7775,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7522c9de787ff061458fe9a829dc790a3f5b22dc571694fc5883f448b94d9a9" +checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" dependencies = [ "base64", ] @@ -7578,15 +7795,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ "futures", - "pin-project 0.4.29", + "pin-project 0.4.27", "static_assertions", ] [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "safe-mix" @@ -7700,7 +7917,7 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "impl-trait-for-tuples", - "memmap2 0.5.3", + "memmap2 0.5.0", "parity-scale-codec", "sc-chain-spec-derive", "sc-network", @@ -7726,7 +7943,7 @@ name = "sc-cli" version = "0.10.0-dev" dependencies = [ "chrono", - "clap 3.1.18", + "clap 3.1.6", "fdlimit", "futures", "hex", @@ -8076,7 +8293,7 @@ dependencies = [ "lru", "parity-scale-codec", "parking_lot 0.12.0", - "paste 1.0.7", + "paste 1.0.6", "regex", "sc-executor-common", "sc-executor-wasmi", @@ -8171,7 +8388,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -8541,7 +8758,7 @@ dependencies = [ name = "sc-runtime-test" version = "2.0.0" dependencies = [ - "paste 1.0.7", + "paste 1.0.6", "sp-core", "sp-io", "sp-runtime", @@ -8822,9 +9039,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.1.1" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8980cafbe98a7ee7a9cc16b32ebce542c77883f512d83fbf2ddc8f6a85ea74c9" +checksum = "0563970d79bcbf3c537ce3ad36d859b30d36fc5b190efd227f1f7a84d7cf0d42" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -8836,9 +9053,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.1.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4260c630e8a8a33429d1688eff2f163f24c65a4e1b1578ef6b565061336e4b6f" +checksum = "b7805950c36512db9e3251c970bb7ac425f326716941862205d612ab3b5e46e2" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -8864,7 +9081,7 @@ checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" dependencies = [ "arrayref", "arrayvec 0.5.2", - "curve25519-dalek 2.1.3", + "curve25519-dalek 2.1.2", "getrandom 0.1.16", "merlin", "rand 0.7.3", @@ -8882,9 +9099,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.6.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" dependencies = [ "ring", "untrusted", @@ -8913,17 +9130,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", "zeroize", ] [[package]] name = "secp256k1" -version = "0.21.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c42e6f1735c5f00f51e43e28d6634141f2bcad10931b2609ddd74a86d751260" +checksum = "ab7883017d5b21f011ef8040ea9c6c7ac90834c0df26a69e4c0b06276151f125" dependencies = [ + "rand 0.6.5", "secp256k1-sys", ] @@ -8947,9 +9165,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "b239a3d5db51252f6f48f42172c65317f37202f4a21021bf5f9d40a408f4592c" dependencies = [ "bitflags", "core-foundation", @@ -8960,9 +9178,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" dependencies = [ "core-foundation-sys", "libc", @@ -8974,7 +9192,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", ] [[package]] @@ -8983,14 +9201,23 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", ] [[package]] name = "semver" -version = "1.0.9" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" dependencies = [ "serde", ] @@ -9001,29 +9228,38 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "serde" -version = "1.0.137" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" dependencies = [ "serde", ] [[package]] name = "serde_cbor" -version = "0.11.2" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" dependencies = [ "half", "serde", @@ -9031,9 +9267,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", @@ -9042,9 +9278,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" dependencies = [ "itoa 1.0.1", "ryu", @@ -9074,13 +9310,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.8" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures", + "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9099,13 +9335,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.2.1", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9117,7 +9353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.2.1", "digest 0.10.3", ] @@ -9135,9 +9371,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" dependencies = [ "digest 0.10.3", "keccak", @@ -9145,24 +9381,24 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" [[package]] name = "signal-hook" -version = "0.3.13" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" +checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac" dependencies = [ "libc", "signal-hook-registry", @@ -9170,9 +9406,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" dependencies = [ "libc", ] @@ -9184,7 +9420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" dependencies = [ "digest 0.9.0", - "rand_core 0.6.3", + "rand_core 0.6.2", ] [[package]] @@ -9196,14 +9432,14 @@ dependencies = [ "approx", "num-complex", "num-traits", - "paste 1.0.7", + "paste 1.0.6", ] [[package]] name = "slab" -version = "0.4.6" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" @@ -9227,13 +9463,24 @@ dependencies = [ "blake2", "chacha20poly1305", "curve25519-dalek 4.0.0-pre.1", - "rand_core 0.6.3", + "rand_core 0.6.2", "ring", "rustc_version 0.4.0", "sha2 0.10.2", "subtle", ] +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.4.4" @@ -9256,8 +9503,8 @@ dependencies = [ "futures", "httparse", "log", - "rand 0.8.5", - "sha-1 0.9.8", + "rand 0.8.4", + "sha-1 0.9.4", ] [[package]] @@ -9563,7 +9810,7 @@ dependencies = [ "byteorder", "digest 0.10.3", "sha2 0.10.2", - "sha3 0.10.1", + "sha3 0.10.0", "sp-std", "twox-hash", ] @@ -9730,10 +9977,10 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "honggfuzz", "parity-scale-codec", - "rand 0.8.5", + "rand 0.8.4", "scale-info", "sp-npos-elections", "sp-runtime", @@ -9777,7 +10024,7 @@ dependencies = [ "log", "parity-scale-codec", "parity-util-mem", - "paste 1.0.7", + "paste 1.0.6", "rand 0.7.3", "scale-info", "serde", @@ -10092,9 +10339,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" -version = "1.18.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceb8b72a924ccfe7882d0e26144c114503760a4d1248bb5cd06c8ab2d55404cc" +checksum = "7b84a70894df7a73666e0694f44b41a9571625e9546fb58a0818a565d2c7e084" dependencies = [ "Inflector", "num-format", @@ -10127,7 +10374,7 @@ dependencies = [ "lazy_static", "nalgebra", "num-traits", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -10151,7 +10398,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" dependencies = [ - "heck 0.3.3", + "heck 0.3.2", "proc-macro2", "quote", "rustversion", @@ -10162,7 +10409,7 @@ dependencies = [ name = "subkey" version = "2.0.1" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "sc-cli", ] @@ -10175,7 +10422,7 @@ dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", "schnorrkel", - "sha2 0.9.9", + "sha2 0.9.8", "zeroize", ] @@ -10190,7 +10437,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "frame-support", "frame-system", "sc-cli", @@ -10424,15 +10671,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.93" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2" +checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" dependencies = [ "proc-macro2", "quote", @@ -10441,9 +10688,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.6" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", @@ -10493,7 +10740,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "libc", - "redox_syscall 0.2.13", + "redox_syscall 0.2.10", "remove_dir_all", "winapi", ] @@ -10511,19 +10758,13 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] -[[package]] -name = "termtree" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" - [[package]] name = "textwrap" version = "0.11.0" @@ -10541,18 +10782,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", @@ -10585,9 +10826,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.4.3+5.2.1-patched.2" +version = "0.4.2+5.2.1-patched.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" +checksum = "5844e429d797c62945a566f8da4e24c7fe3fbd5d6617fd8bf7a0b7dc1ee0f22e" dependencies = [ "cc", "fs_extra", @@ -10617,7 +10858,7 @@ dependencies = [ "pbkdf2 0.4.0", "rand 0.7.3", "rustc-hash", - "sha2 0.9.9", + "sha2 0.9.8", "thiserror", "unicode-normalization", "wasm-bindgen", @@ -10645,9 +10886,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -10660,9 +10901,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.18.2" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", @@ -10671,9 +10912,9 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.0", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "signal-hook-registry", - "socket2", + "socket2 0.4.4", "tokio-macros", "winapi", ] @@ -10702,23 +10943,23 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" dependencies = [ - "rustls 0.20.4", + "rustls 0.20.2", "tokio", "webpki 0.22.0", ] [[package]] name = "tokio-stream" -version = "0.1.8" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" dependencies = [ "futures-core", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tokio", ] @@ -10735,6 +10976,20 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "tokio-util" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.2.6", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.1" @@ -10745,16 +11000,15 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.5.9" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] @@ -10767,22 +11021,22 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.34" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.21" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2", "quote", @@ -10824,9 +11078,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" dependencies = [ "serde", "tracing-core", @@ -10855,6 +11109,12 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + [[package]] name = "trie-bench" version = "0.30.0" @@ -10878,7 +11138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" dependencies = [ "hash-db", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "log", "rustc-hex", "smallvec", @@ -10920,7 +11180,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.5", + "rand 0.8.4", "smallvec", "thiserror", "tinyvec", @@ -10956,7 +11216,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ - "clap 3.1.18", + "clap 3.1.6", "jsonrpsee", "log", "parity-scale-codec", @@ -10978,9 +11238,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.61" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc92f558afb6d1d7c6f175eb8d615b8ef49c227543e68e19c123d4ee43d8a7d" +checksum = "0da18123d1316f5a65fc9b94e30a0fcf58afb1daff1b8e18f41dc30f5bfc38c8" dependencies = [ "dissimilar", "glob", @@ -11000,13 +11260,13 @@ checksum = "5e66dcbec4290c69dd03c57e76c2469ea5c7ce109c6dd4351c13055cf71ea055" [[package]] name = "twox-hash" -version = "1.6.3" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ "cfg-if 1.0.0", "digest 0.10.3", - "rand 0.8.5", + "rand 0.8.4", "static_assertions", ] @@ -11024,9 +11284,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" dependencies = [ "byteorder", "crunchy", @@ -11045,30 +11305,33 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -11078,11 +11341,11 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "universal-hash" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -11106,9 +11369,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -11124,9 +11387,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.0.0-alpha.9" +version = "1.0.0-alpha.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" +checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" dependencies = [ "ctor", "version_check", @@ -11134,15 +11397,21 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.15" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + +[[package]] +name = "vec-arena" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "void" @@ -11198,17 +11467,11 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -11216,9 +11479,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" dependencies = [ "bumpalo", "lazy_static", @@ -11231,9 +11494,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.30" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -11243,9 +11506,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11253,9 +11516,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" dependencies = [ "proc-macro2", "quote", @@ -11266,9 +11529,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" [[package]] name = "wasm-gc-api" @@ -11413,7 +11676,7 @@ dependencies = [ "enumset", "lazy_static", "loupe", - "memmap2 0.5.3", + "memmap2 0.5.0", "more-asserts", "rustc-demangle", "serde", @@ -11435,9 +11698,9 @@ dependencies = [ "enum-iterator", "enumset", "leb128", - "libloading 0.7.3", + "libloading 0.7.0", "loupe", - "object 0.28.4", + "object 0.28.3", "rkyv", "serde", "tempfile", @@ -11476,7 +11739,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ce18ac2877050e59580d27ee1a88f3192d7a31e77fbba0852abc7888d6e0b5" dependencies = [ - "object 0.28.4", + "object 0.28.3", "thiserror", "wasmer-compiler", "wasmer-types", @@ -11537,9 +11800,9 @@ dependencies = [ [[package]] name = "wasmi-validation" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +checksum = "a2eb8e860796d8be48efef530b60eebf84e74a88bce107374fffb0da97d504b8" dependencies = [ "parity-wasm 0.42.2", ] @@ -11572,7 +11835,7 @@ dependencies = [ "log", "object 0.27.1", "once_cell", - "paste 1.0.7", + "paste 1.0.6", "psm", "rayon", "region 2.2.0", @@ -11601,7 +11864,7 @@ dependencies = [ "log", "rustix", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "toml", "winapi", "zstd", @@ -11702,7 +11965,7 @@ dependencies = [ "mach", "memoffset", "more-asserts", - "rand 0.8.5", + "rand 0.8.4", "region 2.2.0", "rustix", "thiserror", @@ -11725,29 +11988,27 @@ dependencies = [ [[package]] name = "wast" -version = "40.0.0" +version = "38.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac" +checksum = "0ebc29df4629f497e0893aacd40f13a4a56b85ef6eb4ab6d603f07244f1a7bf2" dependencies = [ "leb128", - "memchr", - "unicode-width", ] [[package]] name = "wat" -version = "1.0.42" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e" +checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" dependencies = [ "js-sys", "wasm-bindgen", @@ -11775,31 +12036,30 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.3" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" +checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" dependencies = [ "webpki 0.22.0", ] [[package]] -name = "wepoll-ffi" -version = "0.1.2" +name = "wepoll-sys" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" dependencies = [ "cc", ] [[package]] name = "which" -version = "4.2.5" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" dependencies = [ - "either", - "lazy_static", "libc", + "thiserror", ] [[package]] @@ -11854,15 +12114,15 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", + "windows_aarch64_msvc 0.32.0", + "windows_i686_gnu 0.32.0", + "windows_i686_msvc 0.32.0", + "windows_x86_64_gnu 0.32.0", + "windows_x86_64_msvc 0.32.0", ] [[package]] @@ -11873,9 +12133,9 @@ checksum = "c3d027175d00b01e0cbeb97d6ab6ebe03b12330a35786cbaca5252b1c4bf5d9b" [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" [[package]] name = "windows_i686_gnu" @@ -11885,9 +12145,9 @@ checksum = "8793f59f7b8e8b01eda1a652b2697d87b93097198ae85f823b969ca5b89bba58" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" [[package]] name = "windows_i686_msvc" @@ -11897,9 +12157,9 @@ checksum = "8602f6c418b67024be2996c512f5f995de3ba417f4c75af68401ab8756796ae4" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" [[package]] name = "windows_x86_64_gnu" @@ -11909,9 +12169,9 @@ checksum = "f3d615f419543e0bd7d2b3323af0d86ff19cbc4f816e6453f36a2c2ce889c354" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" [[package]] name = "windows_x86_64_msvc" @@ -11921,9 +12181,9 @@ checksum = "11d95421d9ed3672c280884da53201a5c46b7b2765ca6faf34b0d71cf34a3561" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "winreg" @@ -11945,11 +12205,11 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" +checksum = "bc614d95359fd7afc321b66d2107ede58b246b844cf5d8a0adcca413e439f088" dependencies = [ - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "rand_core 0.5.1", "zeroize", ] @@ -11964,7 +12224,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "static_assertions", ] @@ -11991,18 +12251,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.10.2+zstd.1.5.2" +version = "0.10.0+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4a6bd64f22b5e3e94b4e238669ff9f10815c27a5180108b849d24174a83847" +checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.6+zstd.1.5.2" +version = "4.1.4+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b61c51bb270702d6167b8ce67340d2754b088d0c091b06e593aa772c3ee9bb" +checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" dependencies = [ "libc", "zstd-sys", From fa5e95af44bc4b5f6c839136009119d2838010c9 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 13 May 2022 17:27:07 +0100 Subject: [PATCH 03/65] add migration --- Cargo.lock | 1 + frame/nomination-pools/Cargo.toml | 2 + frame/nomination-pools/src/lib.rs | 21 ++++++- frame/nomination-pools/src/migration.rs | 78 +++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 frame/nomination-pools/src/migration.rs diff --git a/Cargo.lock b/Cargo.lock index 68272e1df9c8c..0371c2c189c28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5892,6 +5892,7 @@ version = "1.0.0" dependencies = [ "frame-support", "frame-system", + "log", "pallet-balances", "parity-scale-codec", "scale-info", diff --git a/frame/nomination-pools/Cargo.toml b/frame/nomination-pools/Cargo.toml index 8c2f9daf2777b..1ac8caa5f64b4 100644 --- a/frame/nomination-pools/Cargo.toml +++ b/frame/nomination-pools/Cargo.toml @@ -23,6 +23,7 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../primit sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } +log = { version = "0.4.0", default-features = false } [dev-dependencies] pallet-balances = { version = "4.0.0-dev", path = "../balances" } @@ -42,4 +43,5 @@ std = [ "sp-std/std", "sp-staking/std", "sp-core/std", + "log/std", ] diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 0aa2401584df0..d68a6f09c31d1 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -324,11 +324,26 @@ use sp_runtime::traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Satu use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, ops::Div, vec::Vec}; +/// The log target of this pallet. +pub const LOG_TARGET: &'static str = "runtime::nomination-pools"; + +// syntactic sugar for logging. +#[macro_export] +macro_rules! log { + ($level:tt, $patter:expr $(, $values:expr)* $(,)?) => { + log::$level!( + target: crate::LOG_TARGET, + concat!("[{:?}] 🏊‍♂️ ", $patter), >::block_number() $(, $values)* + ) + }; +} + #[cfg(test)] mod mock; #[cfg(test)] mod tests; +pub mod migration; pub mod weights; pub use pallet::*; @@ -1061,11 +1076,15 @@ impl Get for TotalUnbondingPools { #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::transactional; + use frame_support::{traits::StorageVersion, transactional}; use frame_system::{ensure_signed, pallet_prelude::*}; + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] #[pallet::generate_store(pub(crate) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs new file mode 100644 index 0000000000000..0c225e27f79d5 --- /dev/null +++ b/frame/nomination-pools/src/migration.rs @@ -0,0 +1,78 @@ +use super::*; + +pub mod v1 { + use super::*; + use crate::log; + use frame_support::traits::OnRuntimeUpgrade; + + #[derive(Decode)] + pub struct OldPoolRoles { + pub depositor: AccountId, + pub root: AccountId, + pub nominator: AccountId, + pub state_toggler: AccountId, + } + + impl OldPoolRoles { + fn migrate_to_v1(self) -> PoolRoles { + PoolRoles { + depositor: self.depositor, + root: Some(self.root), + nominator: Some(self.nominator), + state_toggler: Some(self.state_toggler), + } + } + } + + #[derive(Decode)] + pub struct OldBondedPoolInner { + pub points: BalanceOf, + pub state: PoolState, + pub member_counter: u32, + pub roles: OldPoolRoles, + } + + impl OldBondedPoolInner { + fn migrate_to_v1(self) -> BondedPoolInner { + BondedPoolInner { + member_counter: self.member_counter, + points: self.points, + state: self.state, + roles: self.roles.migrate_to_v1(), + } + } + } + + pub struct MigrateToV1(sp_std::marker::PhantomData); + impl OnRuntimeUpgrade for MigrateToV1 { + fn on_runtime_upgrade() -> Weight { + let current = Pallet::::current_storage_version(); + let onchain = Pallet::::on_chain_storage_version(); + + log!( + info, + "Running migration with current storage version {:?} / onchain {:?}", + current, + onchain + ); + + if current == 1 && onchain == 0 { + // this is safe to execute on any runtime that has a bounded number of pools. + let mut translated = 0u64; + BondedPools::::translate::, _>(|_key, old_value| { + translated.saturating_inc(); + Some(old_value.migrate_to_v1()) + }); + current.put::>(); + + T::DbWeight::get().reads_writes(translated, translated) + } else { + log!(info, "Migration did not executed. This probably should be removed"); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> {} + } +} From f2df79edd0012015fee461b898d9c5cc542063e0 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 14 May 2022 15:22:32 +0100 Subject: [PATCH 04/65] add the ability for pools to chill themselves --- Cargo.lock | 1602 +++++++++++-------------- frame/nomination-pools/src/lib.rs | 35 +- frame/nomination-pools/src/mock.rs | 4 + frame/nomination-pools/src/weights.rs | 10 +- frame/staking/src/pallet/impls.rs | 20 +- primitives/staking/src/lib.rs | 9 +- 6 files changed, 733 insertions(+), 947 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0371c2c189c28..dcd8f4dae930d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,30 +29,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3e798aa0c8239776f54415bc06f3d74b1850f3f830b45c35cfc80556973f70" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] name = "aes" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "495ee669413bfbe9e8cace80f4d3d78e6d8c8d99579f97fb93bde351b185f2d4" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", ] [[package]] name = "aes-gcm" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a930fd487faaa92a30afa92cc9dd1526a5cff67124abbbb1c617ce070f4dcf" +checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" dependencies = [ "aead", "aes", @@ -68,7 +68,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.6", "once_cell", "version_check", ] @@ -93,24 +93,24 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" [[package]] name = "approx" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" dependencies = [ "num-traits", ] [[package]] name = "arbitrary" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "698b65a961a9d730fb45b6b0327e20207810c9f61ee421b082b27ba003f49e2b" +checksum = "c38b6b6b79f671c25e1a3e785b7b82d7562ffc9cd3efdc98627e5668a2472490" [[package]] name = "arrayref" @@ -135,21 +135,21 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "asn1_der" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3" +checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" [[package]] name = "assert_cmd" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2" +checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" dependencies = [ "bstr", "doc-comment", @@ -188,23 +188,23 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", "once_cell", - "vec-arena", + "slab", ] [[package]] name = "async-global-executor" -version = "2.0.2" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" +checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43" dependencies = [ "async-channel", "async-executor", @@ -230,7 +230,7 @@ dependencies = [ "parking", "polling", "slab", - "socket2 0.4.4", + "socket2", "waker-fn", "winapi", ] @@ -293,7 +293,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", "wasm-bindgen-futures", @@ -310,15 +310,15 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2 0.4.4", + "socket2", "trust-dns-resolver", ] [[package]] name = "async-stream" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" dependencies = [ "async-stream-impl", "futures-core", @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ "proc-macro2", "quote", @@ -337,15 +337,15 @@ dependencies = [ [[package]] name = "async-task" -version = "4.0.3" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" +checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" [[package]] name = "async-trait" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600" dependencies = [ "proc-macro2", "quote", @@ -362,16 +362,16 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] [[package]] name = "atomic" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" +checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -393,36 +393,30 @@ dependencies = [ [[package]] name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - -[[package]] -name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.64" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" +checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.27.1", + "object 0.28.4", "rustc-demangle", ] [[package]] name = "base-x" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" +checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" [[package]] name = "base16ct" @@ -545,17 +539,16 @@ dependencies = [ [[package]] name = "bimap" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50ae17cabbc8a38a1e3e4c1a6a664e9a09672dc14d0896fa8d865d3a5a446b07" +checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" [[package]] name = "bincode" -version = "1.3.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d175dfa69e619905c4c3cdb7c3c203fa3bdd5d51184e3afdb2742c0280493772" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" dependencies = [ - "byteorder", "serde", ] @@ -598,9 +591,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94ba84325db59637ffc528bbe8c7f86c02c57cff5c0e2b9b00f9a851f42f309" +checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" dependencies = [ "digest 0.10.3", ] @@ -633,7 +626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -644,7 +637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -655,7 +648,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "cc", "cfg-if 1.0.0", "constant_time_eq", @@ -680,16 +673,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding 0.2.1", - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] name = "block-buffer" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -709,9 +702,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.0.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" dependencies = [ "async-channel", "async-task", @@ -729,9 +722,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "lazy_static", "memchr", @@ -750,15 +743,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "byte-slice-cast" -version = "1.0.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" +checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" [[package]] name = "byte-tools" @@ -768,9 +761,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecheck" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" +checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -778,9 +771,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" +checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" dependencies = [ "proc-macro2", "quote", @@ -789,9 +782,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -812,24 +805,24 @@ dependencies = [ [[package]] name = "cache-padded" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "camino" -version = "1.0.4" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9" +checksum = "07fd178c5af4d59e83498ef15cf3f154e1a6f9d091270cb86283c65ef44e9ef0" dependencies = [ "serde", ] [[package]] name = "cargo-platform" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" dependencies = [ "serde", ] @@ -842,25 +835,25 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.4", + "semver 1.0.9", "serde", "serde_json", ] [[package]] name = "cast" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" +checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" dependencies = [ - "rustc_version 0.2.3", + "rustc_version 0.4.0", ] [[package]] name = "cc" -version = "1.0.71" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] @@ -894,7 +887,7 @@ checksum = "01b72a433d0cf2aef113ba70f62634c56fddb0f244e6377185c56a7cadbd8f91" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures 0.2.1", + "cpufeatures", "zeroize", ] @@ -916,9 +909,9 @@ name = "chain-spec-builder" version = "2.0.0" dependencies = [ "ansi_term", - "clap 3.1.6", + "clap 3.1.18", "node-cli", - "rand 0.8.4", + "rand 0.8.5", "sc-chain-spec", "sc-keystore", "sp-core", @@ -957,7 +950,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -971,13 +964,13 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" +checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" dependencies = [ "glob", "libc", - "libloading 0.7.0", + "libloading 0.7.3", ] [[package]] @@ -993,16 +986,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.1.6" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ "atty", "bitflags", "clap_derive", + "clap_lex", "indexmap", "lazy_static", - "os_str_bytes", "strsim", "termcolor", "textwrap 0.15.0", @@ -1010,18 +1003,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.0.2" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a394f7ec0715b42a4e52b294984c27c9a61f77c8d82f7774c5198350be143f19" +checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", ] [[package]] name = "clap_derive" -version = "3.1.4" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -1031,12 +1024,12 @@ dependencies = [ ] [[package]] -name = "cloudabi" -version = "0.0.3" +name = "clap_lex" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" dependencies = [ - "bitflags", + "os_str_bytes", ] [[package]] @@ -1093,38 +1086,22 @@ dependencies = [ [[package]] name = "cpp_demangle" -version = "0.3.2" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" dependencies = [ "cfg-if 1.0.0", - "glob", -] - -[[package]] -name = "cpufeatures" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" -dependencies = [ - "libc", ] [[package]] name = "cpufeatures" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" dependencies = [ "libc", ] -[[package]] -name = "cpuid-bool" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" - [[package]] name = "cranelift-bforest" version = "0.76.0" @@ -1276,9 +1253,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if 1.0.0", ] @@ -1323,9 +1300,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.0" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1344,10 +1321,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" dependencies = [ + "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", @@ -1357,9 +1335,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1377,8 +1355,8 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.4", - "rand_core 0.6.2", + "generic-array 0.14.5", + "rand_core 0.6.3", "subtle", "zeroize", ] @@ -1389,7 +1367,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "typenum", ] @@ -1399,7 +1377,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -1409,7 +1387,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -1441,14 +1419,14 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" dependencies = [ - "sct 0.6.0", + "sct 0.6.1", ] [[package]] name = "ctor" -version = "0.1.19" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" dependencies = [ "quote", "syn", @@ -1476,9 +1454,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.1.2" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434e1720189a637d44fe464f4df1e6eb900b4835255b14354497c78af37d9bb8" +checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216" dependencies = [ "byteorder", "digest 0.8.1", @@ -1489,9 +1467,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.0.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f627126b946c25a4638eec0ea634fc52506dea98db118aae985118ce7c3d723f" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", "digest 0.9.0", @@ -1508,16 +1486,16 @@ checksum = "4033478fbf70d6acf2655ac70da91ee65852d69daf7a67bf7a2f518fb47aafcf" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", "zeroize", ] [[package]] name = "darling" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" dependencies = [ "darling_core", "darling_macro", @@ -1525,23 +1503,22 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", - "strsim", "syn", ] [[package]] name = "darling_macro" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core", "quote", @@ -1556,9 +1533,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a94feec3d2ba66c0b6621bca8bc6f68415b1e5c69af3586fdd0af9fd9f29b17" +checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -1566,9 +1543,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f83e699727abca3c56e187945f303389590305ab2f0185ea445aa66e8d5f2a" +checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" dependencies = [ "data-encoding", "syn", @@ -1585,14 +1562,14 @@ dependencies = [ [[package]] name = "derive_more" -version = "0.99.16" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.3.3", + "rustc_version 0.4.0", "syn", ] @@ -1623,7 +1600,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", ] [[package]] @@ -1632,7 +1609,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.0", + "block-buffer 0.10.2", "crypto-common", "subtle", ] @@ -1669,12 +1646,12 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ "libc", - "redox_users 0.4.0", + "redox_users 0.4.3", "winapi", ] @@ -1685,15 +1662,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users 0.4.0", + "redox_users 0.4.3", "winapi", ] [[package]] name = "dissimilar" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb" +checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" [[package]] name = "dns-parser" @@ -1773,7 +1750,7 @@ checksum = "64fba5a42bd76a17cad4bfa00de168ee1cbfa06a5e8ce992ae880218c05641a9" dependencies = [ "byteorder", "dynasm", - "memmap2 0.5.0", + "memmap2 0.5.3", ] [[package]] @@ -1790,9 +1767,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.0.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef" +checksum = "d916019f70ae3a1faa1195685e290287f39207d38e6dfee727197cffcc002214" dependencies = [ "signature", ] @@ -1803,11 +1780,11 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "ed25519", "rand 0.7.3", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "zeroize", ] @@ -1827,9 +1804,9 @@ dependencies = [ "crypto-bigint", "der", "ff", - "generic-array 0.14.4", + "generic-array 0.14.5", "group", - "rand_core 0.6.2", + "rand_core 0.6.3", "sec1", "subtle", "zeroize", @@ -1875,9 +1852,9 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b3ab37dc79652c9d85f1f7b6070d77d321d2467f5fe7b00d6b7a86c57b092ae" +checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" dependencies = [ "enumflags2_derive", ] @@ -1895,18 +1872,18 @@ dependencies = [ [[package]] name = "enumset" -version = "1.0.7" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e76129da36102af021b8e5000dab2c1c30dbef85c1e482beeff8da5dde0e0b0" +checksum = "4799cdb24d48f1f8a7a98d06b7fde65a85a2d1e42b25a889f5406aa1fbefe074" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" -version = "0.5.5" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6451128aa6655d880755345d085494cf7561a6bee7c8dc821e5d77e6d267ecd4" +checksum = "ea83a3fbdc1d999ccfbcbee717eab36f8edf2d71693a23ce0d7cca19e085304c" dependencies = [ "darling", "proc-macro2", @@ -1914,19 +1891,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime 1.3.0", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.8.4" @@ -1944,7 +1908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log", "regex", "termcolor", @@ -1969,19 +1933,19 @@ dependencies = [ [[package]] name = "errno-dragonfly" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ - "gcc", + "cc", "libc", ] [[package]] name = "event-listener" -version = "2.5.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" [[package]] name = "exit-future" @@ -2024,21 +1988,21 @@ dependencies = [ [[package]] name = "ff" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2958d04124b9f27f175eaeb9a9f383d026098aa837eadd8ba22c11f13a05b9e" +checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] [[package]] name = "file-per-thread-logger" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fdbe0d94371f9ce939b555dd342d0686cc4c0cadbcd4b61d70af5ff97eb4126" +checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" dependencies = [ - "env_logger 0.7.1", + "env_logger 0.9.0", "log", ] @@ -2055,7 +2019,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "scale-info", ] @@ -2066,22 +2030,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ "byteorder", - "rand 0.8.4", + "rand 0.8.5", "rustc-hex", "static_assertions", ] [[package]] name = "fixedbitset" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" +checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" [[package]] name = "flate2" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" +checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" dependencies = [ "cfg-if 1.0.0", "crc32fast", @@ -2123,7 +2087,7 @@ dependencies = [ "linregress", "log", "parity-scale-codec", - "paste 1.0.6", + "paste 1.0.7", "scale-info", "serde", "sp-api", @@ -2142,7 +2106,7 @@ version = "4.0.0-dev" dependencies = [ "Inflector", "chrono", - "clap 3.1.6", + "clap 3.1.18", "frame-benchmarking", "frame-support", "frame-system", @@ -2157,7 +2121,7 @@ dependencies = [ "memory-db", "parity-scale-codec", "prettytable-rs", - "rand 0.8.4", + "rand 0.8.5", "rand_pcg 0.3.1", "sc-block-builder", "sc-cli", @@ -2223,13 +2187,13 @@ dependencies = [ name = "frame-election-solution-type-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-support", "honggfuzz", "parity-scale-codec", - "rand 0.8.4", + "rand 0.8.5", "scale-info", "sp-arithmetic", "sp-npos-elections", @@ -2283,7 +2247,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-util-mem", - "paste 1.0.6", + "paste 1.0.7", "pretty_assertions", "scale-info", "serde", @@ -2457,12 +2421,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "funty" version = "2.0.0" @@ -2520,16 +2478,16 @@ checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" -version = "1.11.3" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "waker-fn", ] @@ -2551,7 +2509,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01fe9932a224b72b45336d96040aa86386d674a31d0af27d800ea7bc8ca97fe" dependencies = [ "futures-io", - "rustls 0.20.2", + "rustls 0.20.4", "webpki 0.22.0", ] @@ -2586,17 +2544,11 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "generate-bags" version = "4.0.0-dev" @@ -2622,9 +2574,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", @@ -2645,9 +2597,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2656,9 +2608,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b442c439366184de619215247d24e908912b175e824a530253845ac4c251a5c1" +checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" dependencies = [ "opaque-debug 0.3.0", "polyval", @@ -2707,9 +2659,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" dependencies = [ "aho-corasick", "bstr", @@ -2720,15 +2672,14 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", - "web-sys", ] [[package]] @@ -2738,15 +2689,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "ff", - "rand_core 0.6.2", + "rand_core 0.6.3", "subtle", ] [[package]] name = "h2" -version = "0.3.9" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" dependencies = [ "bytes", "fnv", @@ -2757,15 +2708,15 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.6.7", + "tokio-util", "tracing", ] [[package]] name = "half" -version = "1.7.1" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "handlebars" @@ -2776,7 +2727,7 @@ dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.0", + "quick-error 2.0.1", "serde", "serde_json", ] @@ -2807,18 +2758,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" dependencies = [ "ahash", ] [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] @@ -2831,9 +2782,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -2883,7 +2834,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.4", + "generic-array 0.14.5", "hmac 0.8.1", ] @@ -2911,46 +2862,37 @@ dependencies = [ [[package]] name = "http" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" +checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ "bytes", "fnv", - "itoa 0.4.8", + "itoa 1.0.1", ] [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", ] [[package]] name = "httparse" -version = "1.5.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] name = "httpdate" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" - -[[package]] -name = "humantime" -version = "1.3.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error 1.2.3", -] +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "humantime" @@ -2960,9 +2902,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.16" +version = "0.14.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" dependencies = [ "bytes", "futures-channel", @@ -2973,9 +2915,9 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", - "pin-project-lite 0.2.6", - "socket2 0.4.4", + "itoa 1.0.1", + "pin-project-lite 0.2.9", + "socket2", "tokio", "tower-service", "tracing", @@ -3055,9 +2997,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" +checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" dependencies = [ "serde", ] @@ -3075,11 +3017,11 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown 0.11.2", "serde", ] @@ -3120,7 +3062,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" dependencies = [ - "socket2 0.4.4", + "socket2", "widestring", "winapi", "winreg", @@ -3155,27 +3097,27 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "jobserver" -version = "0.1.21" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.54" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" dependencies = [ "wasm-bindgen", ] [[package]] name = "jsonrpsee" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae63f7fdeb51700b35e9b28bf92e8d233951590968c186ed79510b6c12fa3d9" +checksum = "a1f2ab5a60e558e74ea93bcf5164ebc47939a7fff8938fa9b5233bbc63e16061" dependencies = [ "jsonrpsee-core", "jsonrpsee-http-server", @@ -3188,33 +3130,33 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32feb1f2f0b5ce37a03b96a988a6dadccc3f529a2f930356bac93f13c09cf385" +checksum = "26d682f4a55081a2be3e639280c640523070e4aeb8ee2fd8dd9168fdae57a9db" dependencies = [ "futures-util", "http", "jsonrpsee-core", "jsonrpsee-types", "pin-project 1.0.10", - "rustls-native-certs 0.6.1", + "rustls-native-certs 0.6.2", "soketto", "thiserror", "tokio", - "tokio-rustls 0.23.2", - "tokio-util 0.7.1", + "tokio-rustls 0.23.4", + "tokio-util", "tracing", "webpki-roots", ] [[package]] name = "jsonrpsee-core" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6b13067b615dd050ced7c19517a52cde490eee2c754d5447ce513f2275f7d" +checksum = "6e27462b21279edf9a6a91f46ffbe125e9cdc58b901d2e08bf59b31a47d7d0ab" dependencies = [ "anyhow", - "arrayvec 0.7.1", + "arrayvec 0.7.2", "async-lock", "async-trait", "beef", @@ -3224,7 +3166,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "rustc-hash", "serde", "serde_json", @@ -3236,9 +3178,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-server" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b34f1090bdc8f7f14ad8811fc84501867c23a9046ce79d49c0cd929a256c501e" +checksum = "7178f16eabd7154c094e24d295b9ee355ec1e5f24c328759c56255ff7bbd4548" dependencies = [ "futures-channel", "futures-util", @@ -3255,9 +3197,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8dc7a8b629e371cd5ca9d128883763ae00c5b63158ace4a6a61345726a21b7" +checksum = "8b8d7f449cab3b747f12c3efc27f5cad537f3b597c6a3838b0fac628f4bf730a" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3267,9 +3209,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44f1835f131e77cd766b4dcb025873944cb1e479cd5debb639e2dc11f90df24a" +checksum = "8fd11763134104122ddeb0f97e4bbe393058017dfb077db63fbf44b4dd0dd86e" dependencies = [ "anyhow", "beef", @@ -3281,9 +3223,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d75df866743c9733b3e2f5421e56df2f5b4630f7de39f82c44eaab350604926" +checksum = "76f15180afb3761c7a3a32c0a8b680788176dcfdfe725b24c1758c90b1d1595b" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3292,9 +3234,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-server" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099971913436e7f6b1bc80180d4e5f014ec944660636da45d2f372c23d6308c3" +checksum = "dfb6c21556c551582b56e4e8e6e6249b0bbdb69bb7fa39efe9b9a6b54af9f206" dependencies = [ "futures-channel", "futures-util", @@ -3303,7 +3245,7 @@ dependencies = [ "serde_json", "soketto", "tokio", - "tokio-util 0.7.1", + "tokio-util", "tracing", ] @@ -3398,21 +3340,21 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leb128" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" [[package]] name = "libgit2-sys" -version = "0.13.3+1.4.2" +version = "0.13.2+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24d36c3ac9b9996a2418d6bf428cc0bc5d1a814a84303fc60986088c5ed60de" +checksum = "3a42de9a51a5c12e00fc0e4ca6bc2ea43582fc6418488e8f615e905d886f258b" dependencies = [ "cc", "libc", @@ -3432,9 +3374,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -3442,9 +3384,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" +checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" [[package]] name = "libp2p" @@ -3456,7 +3398,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.3", + "getrandom 0.2.6", "instant", "lazy_static", "libp2p-autonat", @@ -3507,7 +3449,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -3534,7 +3476,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "ring", "rw-stream-sink", "sha2 0.10.2", @@ -3676,9 +3618,9 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec", - "socket2 0.4.4", + "socket2", "void", ] @@ -3723,14 +3665,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dd7e0c94051cda67123be68cf6b65211ba3dde7277be9068412de3e7ffd63ef" dependencies = [ "bytes", - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "futures", "lazy_static", "libp2p-core", "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.10.2", "snow", "static_assertions", @@ -3803,7 +3745,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "smallvec", "static_assertions", "thiserror", @@ -3827,7 +3769,7 @@ dependencies = [ "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.10.2", "thiserror", "unsigned-varint", @@ -3896,7 +3838,7 @@ dependencies = [ "libc", "libp2p-core", "log", - "socket2 0.4.4", + "socket2", ] [[package]] @@ -3984,9 +3926,9 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.8.4", + "rand 0.8.5", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "typenum", ] @@ -4021,9 +3963,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e" dependencies = [ "cc", "libc", @@ -4082,18 +4024,19 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ + "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", "value-bag", @@ -4140,9 +4083,9 @@ dependencies = [ [[package]] name = "lz4" -version = "1.23.2" +version = "1.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aac20ed6991e01bf6a2e68cc73df2b389707403662a8ba89f68511fb340f724c" +checksum = "4edcb94251b1c375c459e5abe9fb0168c1c826c3370172684844f8f3f8d1a885" dependencies = [ "libc", "lz4-sys", @@ -4150,9 +4093,9 @@ dependencies = [ [[package]] name = "lz4-sys" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dca79aa95d8b3226213ad454d328369853be3a1382d89532a854f4d69640acae" +checksum = "d7be8908e2ed6f31c02db8a9fa962f03e36c53fbfde437363eae3306b85d7e17" dependencies = [ "cc", "libc", @@ -4190,24 +4133,24 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "matrixmultiply" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a8a15b776d9dfaecd44b03c5828c2199cddff5247215858aac14624f8d6b741" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" dependencies = [ "rawpointer", ] [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap" @@ -4221,29 +4164,29 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04e3e85b970d650e2ae6d70592474087051c11c54da7f7b4949725c5735fbcc6" +checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" dependencies = [ "libc", ] [[package]] name = "memmap2" -version = "0.5.0" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4647a11b578fead29cdbb34d4adef8dd3dc35b876c9c6d5240d83f205abfe96e" +checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" dependencies = [ "libc", ] [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -4253,7 +4196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "parity-util-mem", ] @@ -4283,42 +4226,30 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" dependencies = [ "adler", - "autocfg 1.0.1", ] [[package]] name = "mio" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" +checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" dependencies = [ "libc", "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" -dependencies = [ - "socket2 0.3.19", - "winapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", ] [[package]] name = "more-asserts" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" +checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "multiaddr" @@ -4362,7 +4293,7 @@ dependencies = [ "digest 0.10.3", "multihash-derive", "sha2 0.10.2", - "sha3 0.10.0", + "sha3 0.10.1", "unsigned-varint", ] @@ -4382,9 +4313,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "multistream-select" @@ -4412,7 +4343,7 @@ dependencies = [ "num-complex", "num-rational 0.4.0", "num-traits", - "rand 0.8.4", + "rand 0.8.5", "rand_distr", "simba", "typenum", @@ -4435,7 +4366,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d66043b25d4a6cccb23619d10c19c25304b355a7dccd4a8e11423dd2382146" dependencies = [ - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -4472,7 +4403,7 @@ checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" dependencies = [ "anyhow", "byteorder", - "paste 1.0.6", + "paste 1.0.7", "thiserror", ] @@ -4533,7 +4464,7 @@ dependencies = [ name = "node-bench" version = "0.9.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "derive_more", "fs_extra", "futures", @@ -4572,7 +4503,7 @@ version = "3.0.0-dev" dependencies = [ "assert_cmd", "async-std", - "clap 3.1.6", + "clap 3.1.18", "clap_complete", "criterion", "frame-benchmarking-cli", @@ -4595,7 +4526,7 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "platforms", - "rand 0.8.4", + "rand 0.8.5", "regex", "remote-externalities", "sc-authority-discovery", @@ -4687,7 +4618,7 @@ dependencies = [ name = "node-inspect" version = "0.9.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "parity-scale-codec", "sc-cli", "sc-client-api", @@ -4837,7 +4768,7 @@ dependencies = [ name = "node-runtime-generate-bags" version = "3.0.0" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "generate-bags", "node-runtime", ] @@ -4846,7 +4777,7 @@ dependencies = [ name = "node-template" version = "4.0.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -4969,22 +4900,12 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" dependencies = [ "memchr", "minimal-lexical", - "version_check", -] - -[[package]] -name = "ntapi" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" -dependencies = [ - "winapi", ] [[package]] @@ -4993,16 +4914,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" +checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790" dependencies = [ "num-traits", ] @@ -5019,11 +4940,11 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] @@ -5033,7 +4954,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -5045,18 +4966,18 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.0.1", + "autocfg", "libm", ] @@ -5083,9 +5004,9 @@ dependencies = [ [[package]] name = "object" -version = "0.28.3" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "crc32fast", "hashbrown 0.11.2", @@ -5119,24 +5040,21 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "os_str_bytes" version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] [[package]] name = "output_vt100" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" dependencies = [ "winapi", ] @@ -5308,7 +5226,7 @@ dependencies = [ "frame-election-provider-support", "honggfuzz", "pallet-bags-list", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -5461,7 +5379,7 @@ dependencies = [ "pallet-utility", "parity-scale-codec", "pretty_assertions", - "rand 0.8.4", + "rand 0.8.5", "rand_pcg 0.3.1", "scale-info", "serde", @@ -6465,19 +6383,19 @@ dependencies = [ "libc", "log", "lz4", - "memmap2 0.2.1", + "memmap2 0.2.3", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "snap", ] [[package]] name = "parity-scale-codec" -version = "3.0.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a7f3fcf5e45fc28b84dcdab6b983e77f197ec01f325a33f404ba6855afd1070" +checksum = "e8b44461635bbb1a0300f100a841e571e7d919c81c73075ef5d152ffdb521066" dependencies = [ - "arrayvec 0.7.1", + "arrayvec 0.7.2", "bitvec", "byte-slice-cast", "impl-trait-for-tuples", @@ -6487,9 +6405,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.0.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6e626dc84025ff56bf1476ed0e30d10c84d7f89a475ef46ebabee1095a8fba" +checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6510,7 +6428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.0", @@ -6569,7 +6487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ "lock_api", - "parking_lot_core 0.9.1", + "parking_lot_core 0.9.3", ] [[package]] @@ -6581,20 +6499,20 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "smallvec", "winapi", ] [[package]] name = "parking_lot_core" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "smallvec", "windows-sys", ] @@ -6611,9 +6529,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" [[package]] name = "paste-impl" @@ -6709,11 +6627,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" dependencies = [ - "pin-project-internal 0.4.27", + "pin-project-internal 0.4.29", ] [[package]] @@ -6727,9 +6645,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" dependencies = [ "proc-macro2", "quote", @@ -6755,9 +6673,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -6767,9 +6685,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.19" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "platforms" @@ -6792,66 +6710,66 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07fffcddc1cb3a1de753caa4e4df03b79922ba43cf882acc1bdd7e8df9f4590" +checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" [[package]] name = "plotters-svg" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38a02e23bd9604b842a812063aec4ef702b57989c37b655254bb61c471ad211" +checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" dependencies = [ "plotters-backend", ] [[package]] name = "polling" -version = "2.0.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi", ] [[package]] name = "poly1305" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fcffab1f78ebbdf4b93b68c1ffebc24037eedf271edaca795732b24e5e4e349" +checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" dependencies = [ - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "polyval" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6ba6a405ef63530d6cb12802014b22f9c5751bd17cdcddbe9e46d5c8ae83287" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" dependencies = [ "cfg-if 1.0.0", - "cpufeatures 0.1.5", + "cpufeatures", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "predicates" -version = "2.0.2" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308" +checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" dependencies = [ "difflib", "itertools", @@ -6860,18 +6778,18 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" +checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" [[package]] name = "predicates-tree" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" dependencies = [ "predicates-core", - "treeline", + "termtree", ] [[package]] @@ -7016,7 +6934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", - "heck 0.3.2", + "heck 0.3.3", "itertools", "lazy_static", "log", @@ -7054,9 +6972,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" +checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" dependencies = [ "cc", ] @@ -7089,9 +7007,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quick-error" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quickcheck" @@ -7101,7 +7019,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger 0.8.4", "log", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -7130,25 +7048,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg 0.1.2", - "rand_xorshift", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -7159,30 +7058,19 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", "rand_pcg 0.2.1", ] [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "rand_chacha 0.3.1", + "rand_core 0.6.3", ] [[package]] @@ -7197,29 +7085,14 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.2", -] - -[[package]] -name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core 0.6.3", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -7231,11 +7104,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.6", ] [[package]] @@ -7245,16 +7118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.4", -] - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", + "rand 0.8.5", ] [[package]] @@ -7266,59 +7130,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - [[package]] name = "rand_pcg" version = "0.2.1" @@ -7334,16 +7145,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" dependencies = [ - "rand_core 0.6.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", + "rand_core 0.6.3", ] [[package]] @@ -7354,11 +7156,11 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.5.0" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" dependencies = [ - "autocfg 1.0.1", + "autocfg", "crossbeam-deque", "either", "rayon-core", @@ -7366,26 +7168,16 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -7394,9 +7186,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] @@ -7414,28 +7206,29 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.3", - "redox_syscall 0.2.10", + "getrandom 0.2.6", + "redox_syscall 0.2.13", + "thiserror", ] [[package]] name = "ref-cast" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" +checksum = "685d58625b6c2b83e4cc88a27c4bf65adb7b6b16dbdc413e515c9405b47432ab" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" +checksum = "a043824e29c94169374ac5183ac0ed43f5724dc4556b19568007486bd840fa1f" dependencies = [ "proc-macro2", "quote", @@ -7477,11 +7270,10 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "byteorder", "regex-syntax", ] @@ -7564,9 +7356,9 @@ dependencies = [ [[package]] name = "retain_mut" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" +checksum = "8c31b5c4033f8fdde8700e4657be2c497e7288f01515be52168c631e2e4d4086" [[package]] name = "rfc6979" @@ -7596,12 +7388,12 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.37" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f08c8062c1fe1253064043b8fc07bfea1b9702b71b4a86c11ea3588183b12e1" +checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" dependencies = [ "bytecheck", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "ptr_meta", "rend", "rkyv_derive", @@ -7610,9 +7402,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.37" +version = "0.7.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" +checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" dependencies = [ "proc-macro2", "quote", @@ -7668,9 +7460,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "rustc-hash" @@ -7693,29 +7485,20 @@ dependencies = [ "semver 0.9.0", ] -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.4", + "semver 1.0.9", ] [[package]] name = "rustix" -version = "0.33.5" +version = "0.33.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03627528abcc4a365554d32a9f3bbf67f7694c102cfeda792dc86a2d6057cc85" +checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" dependencies = [ "bitflags", "errno", @@ -7734,15 +7517,15 @@ dependencies = [ "base64", "log", "ring", - "sct 0.6.0", + "sct 0.6.1", "webpki 0.21.4", ] [[package]] name = "rustls" -version = "0.20.2" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84" +checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" dependencies = [ "log", "ring", @@ -7764,9 +7547,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca9ebdfa27d3fc180e42879037b5338ab1c040c06affd00d8338598e7800943" +checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7776,9 +7559,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "0.2.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" +checksum = "e7522c9de787ff061458fe9a829dc790a3f5b22dc571694fc5883f448b94d9a9" dependencies = [ "base64", ] @@ -7796,15 +7579,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ "futures", - "pin-project 0.4.27", + "pin-project 0.4.29", "static_assertions", ] [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "safe-mix" @@ -7918,7 +7701,7 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "impl-trait-for-tuples", - "memmap2 0.5.0", + "memmap2 0.5.3", "parity-scale-codec", "sc-chain-spec-derive", "sc-network", @@ -7944,7 +7727,7 @@ name = "sc-cli" version = "0.10.0-dev" dependencies = [ "chrono", - "clap 3.1.6", + "clap 3.1.18", "fdlimit", "futures", "hex", @@ -8294,7 +8077,7 @@ dependencies = [ "lru", "parity-scale-codec", "parking_lot 0.12.0", - "paste 1.0.6", + "paste 1.0.7", "regex", "sc-executor-common", "sc-executor-wasmi", @@ -8389,7 +8172,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -8759,7 +8542,7 @@ dependencies = [ name = "sc-runtime-test" version = "2.0.0" dependencies = [ - "paste 1.0.6", + "paste 1.0.7", "sp-core", "sp-io", "sp-runtime", @@ -9040,9 +8823,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0563970d79bcbf3c537ce3ad36d859b30d36fc5b190efd227f1f7a84d7cf0d42" +checksum = "8980cafbe98a7ee7a9cc16b32ebce542c77883f512d83fbf2ddc8f6a85ea74c9" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -9054,9 +8837,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7805950c36512db9e3251c970bb7ac425f326716941862205d612ab3b5e46e2" +checksum = "4260c630e8a8a33429d1688eff2f163f24c65a4e1b1578ef6b565061336e4b6f" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -9082,7 +8865,7 @@ checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" dependencies = [ "arrayref", "arrayvec 0.5.2", - "curve25519-dalek 2.1.2", + "curve25519-dalek 2.1.3", "getrandom 0.1.16", "merlin", "rand 0.7.3", @@ -9100,9 +8883,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ "ring", "untrusted", @@ -9131,18 +8914,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", "zeroize", ] [[package]] name = "secp256k1" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7883017d5b21f011ef8040ea9c6c7ac90834c0df26a69e4c0b06276151f125" +checksum = "9c42e6f1735c5f00f51e43e28d6634141f2bcad10931b2609ddd74a86d751260" dependencies = [ - "rand 0.6.5", "secp256k1-sys", ] @@ -9166,9 +8948,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.3.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b239a3d5db51252f6f48f42172c65317f37202f4a21021bf5f9d40a408f4592c" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -9179,9 +8961,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.3.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -9193,7 +8975,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" dependencies = [ - "semver-parser 0.7.0", + "semver-parser", ] [[package]] @@ -9202,23 +8984,14 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0", + "semver-parser", ] [[package]] name = "semver" -version = "0.11.0" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser 0.10.2", -] - -[[package]] -name = "semver" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" dependencies = [ "serde", ] @@ -9229,38 +9002,29 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" dependencies = [ "serde", ] [[package]] name = "serde_cbor" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" dependencies = [ "half", "serde", @@ -9268,9 +9032,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -9279,9 +9043,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa 1.0.1", "ryu", @@ -9311,13 +9075,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.4" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" +checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpuid-bool", + "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9336,13 +9100,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures 0.2.1", + "cpufeatures", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9354,7 +9118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ "cfg-if 1.0.0", - "cpufeatures 0.2.1", + "cpufeatures", "digest 0.10.3", ] @@ -9372,9 +9136,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" +checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86" dependencies = [ "digest 0.10.3", "keccak", @@ -9382,24 +9146,24 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.1" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "signal-hook" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac" +checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" dependencies = [ "libc", "signal-hook-registry", @@ -9407,9 +9171,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" dependencies = [ "libc", ] @@ -9421,7 +9185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" dependencies = [ "digest 0.9.0", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -9433,14 +9197,14 @@ dependencies = [ "approx", "num-complex", "num-traits", - "paste 1.0.6", + "paste 1.0.7", ] [[package]] name = "slab" -version = "0.4.2" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "smallvec" @@ -9464,24 +9228,13 @@ dependencies = [ "blake2", "chacha20poly1305", "curve25519-dalek 4.0.0-pre.1", - "rand_core 0.6.2", + "rand_core 0.6.3", "ring", "rustc_version 0.4.0", "sha2 0.10.2", "subtle", ] -[[package]] -name = "socket2" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.4.4" @@ -9504,8 +9257,8 @@ dependencies = [ "futures", "httparse", "log", - "rand 0.8.4", - "sha-1 0.9.4", + "rand 0.8.5", + "sha-1 0.9.8", ] [[package]] @@ -9811,7 +9564,7 @@ dependencies = [ "byteorder", "digest 0.10.3", "sha2 0.10.2", - "sha3 0.10.0", + "sha3 0.10.1", "sp-std", "twox-hash", ] @@ -9978,10 +9731,10 @@ dependencies = [ name = "sp-npos-elections-fuzzer" version = "2.0.0-alpha.5" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "honggfuzz", "parity-scale-codec", - "rand 0.8.4", + "rand 0.8.5", "scale-info", "sp-npos-elections", "sp-runtime", @@ -10025,7 +9778,7 @@ dependencies = [ "log", "parity-scale-codec", "parity-util-mem", - "paste 1.0.6", + "paste 1.0.7", "rand 0.7.3", "scale-info", "serde", @@ -10340,9 +10093,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "ss58-registry" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b84a70894df7a73666e0694f44b41a9571625e9546fb58a0818a565d2c7e084" +checksum = "ceb8b72a924ccfe7882d0e26144c114503760a4d1248bb5cd06c8ab2d55404cc" dependencies = [ "Inflector", "num-format", @@ -10375,7 +10128,7 @@ dependencies = [ "lazy_static", "nalgebra", "num-traits", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -10399,7 +10152,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" dependencies = [ - "heck 0.3.2", + "heck 0.3.3", "proc-macro2", "quote", "rustversion", @@ -10410,7 +10163,7 @@ dependencies = [ name = "subkey" version = "2.0.1" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "sc-cli", ] @@ -10423,7 +10176,7 @@ dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", "schnorrkel", - "sha2 0.9.8", + "sha2 0.9.9", "zeroize", ] @@ -10438,7 +10191,7 @@ dependencies = [ name = "substrate-frame-cli" version = "4.0.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "frame-support", "frame-system", "sc-cli", @@ -10672,15 +10425,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.82" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" dependencies = [ "proc-macro2", "quote", @@ -10689,9 +10442,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", @@ -10741,7 +10494,7 @@ dependencies = [ "cfg-if 1.0.0", "fastrand", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.2.13", "remove_dir_all", "winapi", ] @@ -10759,13 +10512,19 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" + [[package]] name = "textwrap" version = "0.11.0" @@ -10783,18 +10542,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -10827,9 +10586,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.4.2+5.2.1-patched.2" +version = "0.4.3+5.2.1-patched.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5844e429d797c62945a566f8da4e24c7fe3fbd5d6617fd8bf7a0b7dc1ee0f22e" +checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" dependencies = [ "cc", "fs_extra", @@ -10859,7 +10618,7 @@ dependencies = [ "pbkdf2 0.4.0", "rand 0.7.3", "rustc-hash", - "sha2 0.9.8", + "sha2 0.9.9", "thiserror", "unicode-normalization", "wasm-bindgen", @@ -10887,9 +10646,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -10902,9 +10661,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.17.0" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ "bytes", "libc", @@ -10913,9 +10672,9 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.0", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "signal-hook-registry", - "socket2 0.4.4", + "socket2", "tokio-macros", "winapi", ] @@ -10944,23 +10703,23 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.2" +version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls 0.20.2", + "rustls 0.20.4", "tokio", "webpki 0.22.0", ] [[package]] name = "tokio-stream" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" dependencies = [ "futures-core", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", ] @@ -10977,20 +10736,6 @@ dependencies = [ "tokio-stream", ] -[[package]] -name = "tokio-util" -version = "0.6.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.2.6", - "tokio", -] - [[package]] name = "tokio-util" version = "0.7.1" @@ -11001,15 +10746,16 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tokio", + "tracing", ] [[package]] name = "toml" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] @@ -11022,22 +10768,22 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.9", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.18" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -11079,9 +10825,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" dependencies = [ "serde", "tracing-core", @@ -11110,12 +10856,6 @@ dependencies = [ "tracing-serde", ] -[[package]] -name = "treeline" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" - [[package]] name = "trie-bench" version = "0.30.0" @@ -11139,7 +10879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" dependencies = [ "hash-db", - "hashbrown 0.12.0", + "hashbrown 0.12.1", "log", "rustc-hex", "smallvec", @@ -11181,7 +10921,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec", "thiserror", "tinyvec", @@ -11217,7 +10957,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" name = "try-runtime-cli" version = "0.10.0-dev" dependencies = [ - "clap 3.1.6", + "clap 3.1.18", "jsonrpsee", "log", "parity-scale-codec", @@ -11239,9 +10979,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0da18123d1316f5a65fc9b94e30a0fcf58afb1daff1b8e18f41dc30f5bfc38c8" +checksum = "7fc92f558afb6d1d7c6f175eb8d615b8ef49c227543e68e19c123d4ee43d8a7d" dependencies = [ "dissimilar", "glob", @@ -11261,13 +11001,13 @@ checksum = "5e66dcbec4290c69dd03c57e76c2469ea5c7ce109c6dd4351c13055cf71ea055" [[package]] name = "twox-hash" -version = "1.6.2" +version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if 1.0.0", "digest 0.10.3", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] @@ -11285,9 +11025,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uint" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" +checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" dependencies = [ "byteorder", "crunchy", @@ -11306,33 +11046,30 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-width" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "unicode-xid" @@ -11342,11 +11079,11 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "universal-hash" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array 0.14.4", + "generic-array 0.14.5", "subtle", ] @@ -11370,9 +11107,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.1" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -11388,9 +11125,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.0.0-alpha.8" +version = "1.0.0-alpha.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" dependencies = [ "ctor", "version_check", @@ -11398,21 +11135,15 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" - -[[package]] -name = "vec-arena" -version = "1.0.0" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "void" @@ -11468,11 +11199,17 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -11480,9 +11217,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" dependencies = [ "bumpalo", "lazy_static", @@ -11495,9 +11232,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.20" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -11507,9 +11244,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11517,9 +11254,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", @@ -11530,9 +11267,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.77" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" [[package]] name = "wasm-gc-api" @@ -11677,7 +11414,7 @@ dependencies = [ "enumset", "lazy_static", "loupe", - "memmap2 0.5.0", + "memmap2 0.5.3", "more-asserts", "rustc-demangle", "serde", @@ -11699,9 +11436,9 @@ dependencies = [ "enum-iterator", "enumset", "leb128", - "libloading 0.7.0", + "libloading 0.7.3", "loupe", - "object 0.28.3", + "object 0.28.4", "rkyv", "serde", "tempfile", @@ -11740,7 +11477,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ce18ac2877050e59580d27ee1a88f3192d7a31e77fbba0852abc7888d6e0b5" dependencies = [ - "object 0.28.3", + "object 0.28.4", "thiserror", "wasmer-compiler", "wasmer-types", @@ -11801,9 +11538,9 @@ dependencies = [ [[package]] name = "wasmi-validation" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb8e860796d8be48efef530b60eebf84e74a88bce107374fffb0da97d504b8" +checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" dependencies = [ "parity-wasm 0.42.2", ] @@ -11836,7 +11573,7 @@ dependencies = [ "log", "object 0.27.1", "once_cell", - "paste 1.0.6", + "paste 1.0.7", "psm", "rayon", "region 2.2.0", @@ -11865,7 +11602,7 @@ dependencies = [ "log", "rustix", "serde", - "sha2 0.9.8", + "sha2 0.9.9", "toml", "winapi", "zstd", @@ -11966,7 +11703,7 @@ dependencies = [ "mach", "memoffset", "more-asserts", - "rand 0.8.4", + "rand 0.8.5", "region 2.2.0", "rustix", "thiserror", @@ -11989,27 +11726,29 @@ dependencies = [ [[package]] name = "wast" -version = "38.0.0" +version = "40.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ebc29df4629f497e0893aacd40f13a4a56b85ef6eb4ab6d603f07244f1a7bf2" +checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac" dependencies = [ "leb128", + "memchr", + "unicode-width", ] [[package]] name = "wat" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" +checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.54" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" dependencies = [ "js-sys", "wasm-bindgen", @@ -12037,30 +11776,31 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.2" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" +checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" dependencies = [ "webpki 0.22.0", ] [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] [[package]] name = "which" -version = "4.0.2" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" dependencies = [ + "either", + "lazy_static", "libc", - "thiserror", ] [[package]] @@ -12115,15 +11855,15 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc 0.32.0", - "windows_i686_gnu 0.32.0", - "windows_i686_msvc 0.32.0", - "windows_x86_64_gnu 0.32.0", - "windows_x86_64_msvc 0.32.0", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] @@ -12134,9 +11874,9 @@ checksum = "c3d027175d00b01e0cbeb97d6ab6ebe03b12330a35786cbaca5252b1c4bf5d9b" [[package]] name = "windows_aarch64_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_i686_gnu" @@ -12146,9 +11886,9 @@ checksum = "8793f59f7b8e8b01eda1a652b2697d87b93097198ae85f823b969ca5b89bba58" [[package]] name = "windows_i686_gnu" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_msvc" @@ -12158,9 +11898,9 @@ checksum = "8602f6c418b67024be2996c512f5f995de3ba417f4c75af68401ab8756796ae4" [[package]] name = "windows_i686_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_x86_64_gnu" @@ -12170,9 +11910,9 @@ checksum = "f3d615f419543e0bd7d2b3323af0d86ff19cbc4f816e6453f36a2c2ce889c354" [[package]] name = "windows_x86_64_gnu" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_msvc" @@ -12182,9 +11922,9 @@ checksum = "11d95421d9ed3672c280884da53201a5c46b7b2765ca6faf34b0d71cf34a3561" [[package]] name = "windows_x86_64_msvc" -version = "0.32.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "winreg" @@ -12206,11 +11946,11 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc614d95359fd7afc321b66d2107ede58b246b844cf5d8a0adcca413e439f088" +checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" dependencies = [ - "curve25519-dalek 3.0.2", + "curve25519-dalek 3.2.0", "rand_core 0.5.1", "zeroize", ] @@ -12225,7 +11965,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.0", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] @@ -12252,18 +11992,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.10.0+zstd.1.5.2" +version = "0.10.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" +checksum = "5f4a6bd64f22b5e3e94b4e238669ff9f10815c27a5180108b849d24174a83847" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.4+zstd.1.5.2" +version = "4.1.6+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" +checksum = "94b61c51bb270702d6167b8ce67340d2754b088d0c091b06e593aa772c3ee9bb" dependencies = [ "libc", "zstd-sys", diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d68a6f09c31d1..8ab93f67ef71b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1276,8 +1276,6 @@ pub mod pallet { /// An account is already delegating in another pool. An account may only belong to one /// pool at a time. AccountBelongsToOtherPool, - /// The pool has insufficient balance to bond as a nominator. - InsufficientBond, /// The member is already unbonding in this era. AlreadyUnbonding, /// The member is fully unbonded (and thus cannot access the bonded and reward pool @@ -1784,6 +1782,13 @@ pub mod pallet { Ok(()) } + /// Nominate on behalf of the pool. + /// + /// The dispatch origin of this call must be signed by the pool nominator or the the pool + /// root role. + /// + /// This directly forward the call to the staking pallet, on behalf of the pool bonded + /// account. #[pallet::weight(T::WeightInfo::nominate(validators.len() as u32))] pub fn nominate( origin: OriginFor, @@ -1793,10 +1798,28 @@ pub mod pallet { let who = ensure_signed(origin)?; let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; ensure!(bonded_pool.can_nominate(&who), Error::::NotNominator); - T::StakingInterface::nominate(bonded_pool.bonded_account(), validators)?; - Ok(()) + T::StakingInterface::nominate(bonded_pool.bonded_account(), validators) + } + + /// Nominate on behalf of the pool. + /// + /// The dispatch origin of this call must be signed by the pool nominator or the the pool + /// root role, same as [`Pallet::nominate`]. + /// + /// This directly forward the call to the staking pallet, on behalf of the pool bonded + /// account. + #[pallet::weight(T::WeightInfo::chill())] + pub fn chill(origin: OriginFor, pool_id: PoolId) -> DispatchResult { + let who = ensure_signed(origin)?; + let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_nominate(&who), Error::::NotNominator); + T::StakingInterface::chill(bonded_pool.bonded_account()) } + /// Set a new state for the pool. + /// + /// The dispatch origin of this call must be signed by the state toggler, or the root role + /// of the pool. #[pallet::weight(T::WeightInfo::set_state())] pub fn set_state( origin: OriginFor, @@ -1823,6 +1846,10 @@ pub mod pallet { Ok(()) } + /// Set a new metadata for the pool. + /// + /// The dispatch origin of this call must be signed by the state toggler, or the root role + /// of the pool. #[pallet::weight(T::WeightInfo::set_metadata(metadata.len() as u32))] pub fn set_metadata( origin: OriginFor, diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 5498496965adb..8fa1c9584f3b5 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -77,6 +77,10 @@ impl sp_staking::StakingInterface for StakingMock { Ok(()) } + fn chill(_: Self::AccountId) -> sp_runtime::DispatchResult { + Ok(()) + } + fn withdraw_unbonded(who: Self::AccountId, _: u32) -> Result { // Simulates removing unlocking chunks and only having the bonded balance locked let _maybe_new_free = UNBONDING_BALANCE_MAP.with(|m| m.borrow_mut().remove(&who)); diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 0b2a84ddd2ac3..697febcd90930 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -1,3 +1,4 @@ + // This file is part of Substrate. // Copyright (C) 2022 Parity Technologies (UK) Ltd. @@ -54,7 +55,8 @@ pub trait WeightInfo { fn withdraw_unbonded_update(s: u32, ) -> Weight; fn withdraw_unbonded_kill(s: u32, ) -> Weight; fn create() -> Weight; - fn nominate(n: u32, ) -> Weight; + fn nominate(n: u32) -> Weight; + fn chill() -> Weight; fn set_state() -> Weight; fn set_metadata(n: u32, ) -> Weight; fn set_configs() -> Weight; @@ -244,6 +246,9 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } + fn chill() -> Weight { + 0 + } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { @@ -460,6 +465,9 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } + fn chill() -> Weight { + 0 + } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 34d7a176670f2..7e5162ab99ba1 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -1386,27 +1386,31 @@ impl StakingInterface for Pallet { Self::current_era().unwrap_or(Zero::zero()) } - fn active_stake(controller: &Self::AccountId) -> Option { - Self::ledger(controller).map(|l| l.active) + fn active_stake(stash: &Self::AccountId) -> Option { + Self::ledger(stash).map(|l| l.active) } - fn total_stake(controller: &Self::AccountId) -> Option { - Self::ledger(controller).map(|l| l.total) + fn total_stake(stash: &Self::AccountId) -> Option { + Self::ledger(stash).map(|l| l.total) } fn bond_extra(stash: Self::AccountId, extra: Self::Balance) -> DispatchResult { Self::bond_extra(RawOrigin::Signed(stash).into(), extra) } - fn unbond(controller: Self::AccountId, value: Self::Balance) -> DispatchResult { - Self::unbond(RawOrigin::Signed(controller).into(), value) + fn unbond(stash: Self::AccountId, value: Self::Balance) -> DispatchResult { + Self::unbond(RawOrigin::Signed(stash).into(), value) + } + + fn chill(stash: Self::AccountId) -> DispatchResult { + Self::chill(RawOrigin::Signed(stash).into()) } fn withdraw_unbonded( - controller: Self::AccountId, + stash: Self::AccountId, num_slashing_spans: u32, ) -> Result { - Self::withdraw_unbonded(RawOrigin::Signed(controller).into(), num_slashing_spans) + Self::withdraw_unbonded(RawOrigin::Signed(stash).into(), num_slashing_spans) .map(|post_info| { post_info .actual_weight diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index a2a6432485be8..1bbcad80fbf0e 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -93,7 +93,7 @@ pub trait StakingInterface { /// non-staking locks on the bonded pair's balance this may not be accurate. fn total_stake(stash: &Self::AccountId) -> Option; - /// Bond (lock) `value` of `stash`'s balance. `controller` will be set as the account + /// Bond (lock) `value` of `stash`'s balance. `stash` will be set as the account /// controlling `stash`. This creates what is referred to as "bonded pair". fn bond( stash: Self::AccountId, @@ -102,12 +102,15 @@ pub trait StakingInterface { payee: Self::AccountId, ) -> DispatchResult; - /// Have `controller` nominate `validators`. + /// Have `stash` nominate `validators`. fn nominate( - controller: Self::AccountId, + stash: Self::AccountId, validators: sp_std::vec::Vec, ) -> DispatchResult; + /// Chill `stash`. + fn chill(stash: Self::AccountId) -> DispatchResult; + /// Bond some extra amount in the _Stash_'s free balance against the active bonded balance of /// the account. The amount extra actually bonded will never be more than the _Stash_'s free /// balance. From 56cf9972922d16425b79c10d379ef5be033b0e2e Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 14 May 2022 18:34:05 +0100 Subject: [PATCH 05/65] boilerplate of tests --- Cargo.lock | 24 +++ Cargo.toml | 1 + .../nomination-pools/test-staking/Cargo.toml | 36 ++++ .../nomination-pools/test-staking/src/lib.rs | 42 ++++ .../nomination-pools/test-staking/src/mock.rs | 203 ++++++++++++++++++ 5 files changed, 306 insertions(+) create mode 100644 frame/nomination-pools/test-staking/Cargo.toml create mode 100644 frame/nomination-pools/test-staking/src/lib.rs create mode 100644 frame/nomination-pools/test-staking/src/mock.rs diff --git a/Cargo.lock b/Cargo.lock index dcd8f4dae930d..990609fa98e9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5845,6 +5845,30 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-nomination-pools-test-staking" +version = "1.0.0" +dependencies = [ + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-bags-list", + "pallet-balances", + "pallet-nomination-pools", + "pallet-staking", + "pallet-staking-reward-curve", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "sp-tracing", +] + [[package]] name = "pallet-offences" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 39ccceeb3a030..c424aee87e0ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,6 +113,7 @@ members = [ "frame/proxy", "frame/nomination-pools", "frame/nomination-pools/benchmarking", + "frame/nomination-pools/test-staking", "frame/randomness-collective-flip", "frame/recovery", "frame/referenda", diff --git a/frame/nomination-pools/test-staking/Cargo.toml b/frame/nomination-pools/test-staking/Cargo.toml new file mode 100644 index 0000000000000..ad36e89e0d68a --- /dev/null +++ b/frame/nomination-pools/test-staking/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "pallet-nomination-pools-test-staking" +version = "1.0.0" +authors = ["Parity Technologies "] +edition = "2021" +license = "Apache-2.0" +homepage = "https://substrate.io" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME nomination pools pallet tests with the staking pallet" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dev-dependencies] +codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] } +scale-info = { version = "2.0.1", features = ["derive"] } + +sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" } +sp-io = { version = "6.0.0", path = "../../../primitives/io" } +sp-std = { version = "4.0.0", path = "../../../primitives/std" } +sp-staking = { version = "4.0.0-dev", path = "../../../primitives/staking" } +sp-core = { version = "6.0.0", path = "../../../primitives/core" } + +frame-system = { version = "4.0.0-dev", path = "../../system" } +frame-support = { version = "4.0.0-dev", path = "../../support" } +frame-election-provider-support = { version = "4.0.0-dev", path = "../../election-provider-support" } + +pallet-timestamp = { version = "4.0.0-dev", path = "../../timestamp" } +pallet-balances = { version = "4.0.0-dev", path = "../../balances" } +pallet-staking = { version = "4.0.0-dev", path = "../../staking" } +pallet-bags-list = { version = "4.0.0-dev", path = "../../bags-list" } +pallet-staking-reward-curve = { version = "4.0.0-dev", path = "../../staking/reward-curve" } +pallet-nomination-pools = { version = "1.0.0-dev", path = ".." } + +sp-tracing = { version = "5.0.0", path = "../../../primitives/tracing" } +log = { version = "0.4.0" } diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs new file mode 100644 index 0000000000000..d4538a0625022 --- /dev/null +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -0,0 +1,42 @@ +// 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. + +#![cfg(test)] + +mod mock; + +use frame_support::{assert_ok, traits::Currency}; +use mock::*; + +#[test] +fn pool_lifecycle_e2e() { + new_test_ext().execute_with(|| { + Balances::make_free_balance_be(&10, 100); + + assert_ok!(Staking::set_staking_configs( + Origin::root(), + pallet_staking::ConfigOp::Set(10), // minimum nominator bond + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + )); + + assert_ok!(Pools::create(Origin::signed(10), 50, 10, 10, 10)); + }) +} diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs new file mode 100644 index 0000000000000..f266e7a6d9a45 --- /dev/null +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -0,0 +1,203 @@ +// 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. + +use frame_election_provider_support::VoteWeight; +use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; +use sp_runtime::traits::{Convert, IdentityLookup}; +use sp_staking::SessionIndex; + +type AccountId = u128; +type AccountIndex = u32; +type BlockNumber = u64; +type Balance = u128; + +impl frame_system::Config for Runtime { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Origin = Origin; + type Index = AccountIndex; + type BlockNumber = BlockNumber; + type Call = Call; + type Hash = sp_core::H256; + type Hashing = sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Header = sp_runtime::testing::Header; + type Event = Event; + type BlockHashCount = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_timestamp::Config for Runtime { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<5>; + type WeightInfo = (); +} + +parameter_types! { + pub static ExistentialDeposit: Balance = 10; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type Balance = Balance; + type Event = Event; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +pallet_staking_reward_curve::build! { + const I_NPOS: sp_runtime::curve::PiecewiseLinear<'static> = curve!( + min_inflation: 0_025_000, + max_inflation: 0_100_000, + ideal_stake: 0_500_000, + falloff: 0_050_000, + max_piece_count: 40, + test_precision: 0_005_000, + ); +} + +parameter_types! { + pub const RewardCurve: &'static sp_runtime::curve::PiecewiseLinear<'static> = &I_NPOS; +} + +impl pallet_staking::Config for Runtime { + type MaxNominations = ConstU32<16>; + type Currency = Balances; + type CurrencyBalance = Balance; + type UnixTime = pallet_timestamp::Pallet; + type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; + type RewardRemainder = (); + type Event = Event; + type Slash = (); + type Reward = (); + type SessionsPerEra = (); + type SlashDeferDuration = (); + type SlashCancelOrigin = frame_system::EnsureRoot; + type BondingDuration = ConstU32<3>; + type SessionInterface = (); + type EraPayout = pallet_staking::ConvertCurve; + type NextNewSession = (); + type MaxNominatorRewardedPerValidator = ConstU32<64>; + type OffendingValidatorsThreshold = (); + type ElectionProvider = + frame_election_provider_support::NoElection<(AccountId, BlockNumber, Staking)>; + type GenesisElectionProvider = Self::ElectionProvider; + type VoterList = pallet_bags_list::Pallet; + type MaxUnlockingChunks = ConstU32<32>; + type OnStakerSlash = Pools; + type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig; + type WeightInfo = (); +} + +parameter_types! { + pub static BagThresholds: &'static [VoteWeight] = &[10, 20, 30, 40, 50, 60, 1_000, 2_000, 10_000]; +} + +impl pallet_bags_list::Config for Runtime { + type Event = Event; + type WeightInfo = (); + type BagThresholds = BagThresholds; + type ScoreProvider = Staking; + type Score = VoteWeight; +} + +pub struct BalanceToU256; +impl Convert for BalanceToU256 { + fn convert(n: Balance) -> sp_core::U256 { + n.into() + } +} + +pub struct U256ToBalance; +impl Convert for U256ToBalance { + fn convert(n: sp_core::U256) -> Balance { + n.try_into().unwrap() + } +} + +parameter_types! { + pub const PostUnbondingPoolsWindow: u32 = 10; + pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); +} + +impl pallet_nomination_pools::Config for Runtime { + type Event = Event; + type WeightInfo = (); + type Currency = Balances; + type BalanceToU256 = BalanceToU256; + type U256ToBalance = U256ToBalance; + type StakingInterface = Staking; + type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow; + type MaxMetadataLen = ConstU32<256>; + type MaxUnbonding = ConstU32<8>; + type PalletId = PoolsPalletId; +} + +impl frame_system::offchain::SendTransactionTypes for Runtime +where + Call: From, +{ + type OverarchingCall = Call; + type Extrinsic = UncheckedExtrinsic; +} + +type Block = frame_system::mocking::MockBlock; +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + +frame_support::construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic + { + System: frame_system::{Pallet, Call, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Staking: pallet_staking::{Pallet, Call, Config, Storage, Event}, + BagsList: pallet_bags_list::{Pallet, Call, Storage, Event}, + Pools: pallet_nomination_pools::{Pallet, Call, Storage, Event}, + } +); + +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); + let _ = pallet_nomination_pools::GenesisConfig:: { + min_join_bond: 2, + min_create_bond: 2, + max_pools: Some(3), + max_members_per_pool: Some(3), + max_members: Some(3 * 3), + } + .assimilate_storage(&mut storage); + sp_io::TestExternalities::from(storage) +} From f83944aec0b09b285f615644fe1b8c26593dba27 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 15 May 2022 21:20:19 +0100 Subject: [PATCH 06/65] somewhat stable, but I think I found another bug as well --- frame/nomination-pools/src/lib.rs | 29 +-- frame/nomination-pools/src/tests.rs | 225 +++++++++++------- .../nomination-pools/test-staking/src/lib.rs | 125 +++++----- .../nomination-pools/test-staking/src/mock.rs | 13 +- 4 files changed, 229 insertions(+), 163 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index cdd9930598897..effd0ec500ea1 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -631,7 +631,7 @@ impl BondedPool { fn points_to_balance(&self, points: BalanceOf) -> BalanceOf { let bonded_balance = T::StakingInterface::active_stake(&self.bonded_account()).unwrap_or(Zero::zero()); - Pallet::::point_to_balance(bonded_balance, self.points, points) + Pallet::::point_to_balance(dbg!(bonded_balance), dbg!(self.points), points) } /// Issue points to [`Self`] for `new_funds`. @@ -827,15 +827,10 @@ impl BondedPool { &self, caller: &T::AccountId, target_account: &T::AccountId, - target_member: &PoolMember, - sub_pools: &SubPools, + bonded_pool: &BondedPool, ) -> Result<(), DispatchError> { if *target_account == self.roles.depositor { - ensure!( - sub_pools.sum_unbonding_points() == target_member.unbonding_points(), - Error::::NotOnlyPoolMember - ); - debug_assert_eq!(self.member_counter, 1, "only member must exist at this point"); + ensure!(bonded_pool.member_counter == 1, Error::::NotOnlyPoolMember); Ok(()) } else { // This isn't a depositor @@ -983,9 +978,13 @@ impl UnbondPool { } /// Issue points and update the balance given `new_balance`. - fn issue(&mut self, new_funds: BalanceOf) { - self.points = self.points.saturating_add(self.balance_to_point(new_funds)); + /// + /// Returns the actual amounts of points issued. + fn issue(&mut self, new_funds: BalanceOf) -> BalanceOf { + let new_points = self.balance_to_point(new_funds); + self.points = self.points.saturating_add(new_points); self.balance = self.balance.saturating_add(new_funds); + new_points } /// Dissolve some points from the unbonding pool, reducing the balance of the pool @@ -1512,6 +1511,7 @@ pub mod pallet { let unbond_era = T::StakingInterface::bonding_duration().saturating_add(current_era); // Try and unbond in the member map. + // TODO: this is wrong, we should use `actual_unbonding_points`. member.try_unbond(unbonding_points, unbond_era)?; // Unbond in the actual underlying nominator. @@ -1534,7 +1534,7 @@ pub mod pallet { .defensive_map_err(|_| Error::::DefensiveError)?; } - sub_pools + let actual_unbonding_points = sub_pools .with_era .get_mut(&unbond_era) // The above check ensures the pool exists. @@ -1614,12 +1614,7 @@ pub mod pallet { let mut sub_pools = SubPoolsStorage::::get(member.pool_id) .defensive_ok_or_else(|| Error::::SubPoolsNotFound)?; - bonded_pool.ok_to_withdraw_unbonded_with( - &caller, - &member_account, - &member, - &sub_pools, - )?; + bonded_pool.ok_to_withdraw_unbonded_with(&caller, &member_account, &bonded_pool)?; // NOTE: must do this after we have done the `ok_to_withdraw_unbonded_other_with` check. let withdrawn_points = member.withdraw_unlocked(current_era); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index fe78da3bb14af..4a8d1f020c075 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1635,12 +1635,15 @@ mod unbond { ); // When + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 40, 0)); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 550, 0)); assert_ok!(fully_unbond_permissioned(10)); // Then assert_eq!( SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 100, balance: 100 }} + unbonding_pools_with_era! { 6 => UnbondPool { points: 2, balance: 2 }} ); assert_eq!( BondedPool::::get(1).unwrap(), @@ -1649,22 +1652,23 @@ mod unbond { inner: BondedPoolInner { state: PoolState::Destroying, points: 0, - member_counter: 3, + member_counter: 1, roles: DEFAULT_ROLES } } ); assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - assert_eq!( - PoolMembers::::get(550).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 550) - ); - assert_eq!(Balances::free_balance(&550), 550 + 550); + + assert_eq!(Balances::free_balance(&550), 550 + 550 + 550); assert_eq!( pool_events_since_last_call(), vec![ + Event::Withdrawn { member: 40, pool_id: 1, amount: 40 }, + Event::MemberRemoved { pool_id: 1, member: 40 }, + Event::Withdrawn { member: 550, pool_id: 1, amount: 550 }, + Event::MemberRemoved { pool_id: 1, member: 550 }, Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 2 } + Event::Unbonded { member: 10, pool_id: 1, amount: 2 }, ] ); }); @@ -1845,27 +1849,32 @@ mod unbond { // Given the pools is destroying unsafe_set_state(1, PoolState::Destroying).unwrap(); - // The depositor can be unbonded by anyone. - assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, amount: 10 }] + // The depositor cannot be unbonded yet. + assert_noop!( + Pools::fully_unbond(Origin::signed(420), 10), + Error::::DoesNotHavePermission, ); + // but when everyone is unbonded it can.. + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 100, 0)); + // still permissionless unbond must be full. assert_noop!( Pools::unbond(Origin::signed(420), 10, 5), Error::::PartialUnbondNotAllowedPermissionlessly, ); + // but full unbond works. + assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); + assert_eq!(BondedPools::::get(1).unwrap().points, 0); assert_eq!( SubPoolsStorage::::get(1).unwrap(), SubPools { no_era: Default::default(), with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { points: 110, balance: 110 } + 3 + 3 => UnbondPool { points: 10, balance: 10 } } } ); @@ -1873,7 +1882,7 @@ mod unbond { assert_eq!( UNBONDING_BALANCE_MAP .with(|m| *m.borrow_mut().get(&default_bonded_account()).unwrap()), - 110 + 10 ); }); } @@ -2259,23 +2268,23 @@ mod withdraw_unbonded { let mut current_era = 1; CurrentEra::set(current_era); - // In a new era, unbond the depositor - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); let mut sub_pools = SubPoolsStorage::::get(1).unwrap(); - let unbond_pool = sub_pools.with_era.get_mut(&(current_era + 3)).unwrap(); + let unbond_pool = sub_pools.with_era.get_mut(&3).unwrap(); // Sanity check - assert_eq!(*unbond_pool, UnbondPool { points: 10, balance: 10 }); + assert_eq!(*unbond_pool, UnbondPool { points: 550 + 40, balance: 550 + 40 }); // Simulate a slash to the pool with_era(current_era), decreasing the balance by // half - unbond_pool.balance = 5; + unbond_pool.balance /= 2; // 295 SubPoolsStorage::::insert(1, sub_pools); // Update the equivalent of the unbonding chunks for the `StakingMock` UNBONDING_BALANCE_MAP - .with(|m| *m.borrow_mut().get_mut(&default_bonded_account()).unwrap() -= 5); - Balances::make_free_balance_be(&default_bonded_account(), 595); + .with(|m| *m.borrow_mut().get_mut(&default_bonded_account()).unwrap() /= 5); + Balances::make_free_balance_be( + &default_bonded_account(), + Balances::free_balance(&default_bonded_account()) / 2, // 300 + ); // Advance the current_era to ensure all `with_era` pools will be merged into // `no_era` pool @@ -2285,27 +2294,45 @@ mod withdraw_unbonded { // Simulate some other call to unbond that would merge `with_era` pools into // `no_era` let sub_pools = - SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era + 3); + SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); SubPoolsStorage::::insert(1, sub_pools); assert_eq!( SubPoolsStorage::::get(1).unwrap(), SubPools { - no_era: UnbondPool { points: 550 + 40 + 10, balance: 550 + 40 + 5 }, + no_era: UnbondPool { points: 550 + 40, balance: 275 + 20 }, with_era: Default::default() } ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::Unbonded { member: 550, pool_id: 1, amount: 550 }, + Event::Unbonded { member: 40, pool_id: 1, amount: 40 }, + ] + ); + // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); // Then assert_eq!( SubPoolsStorage::::get(1).unwrap().no_era, - UnbondPool { points: 40 + 10, balance: 40 + 5 + 5 } + UnbondPool { points: 40, balance: 20 } + ); + assert_eq!(Balances::free_balance(&550), 550 + 550 / 2); + assert_eq!(Balances::free_balance(&default_bonded_account()), (40 + 10) / 2); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 550, pool_id: 1, amount: 275 }, + Event::MemberRemoved { pool_id: 1, member: 550 } + ] ); - assert_eq!(Balances::free_balance(&550), 550 + 545); - assert_eq!(Balances::free_balance(&default_bonded_account()), 50); - assert!(!PoolMembers::::contains_key(550)); // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); @@ -2313,41 +2340,43 @@ mod withdraw_unbonded { // Then assert_eq!( SubPoolsStorage::::get(1).unwrap().no_era, - UnbondPool { points: 10, balance: 10 } + UnbondPool { points: 0, balance: 0 } ); - assert_eq!(Balances::free_balance(&40), 40 + 40); - assert_eq!(Balances::free_balance(&default_bonded_account()), 50 - 40); + // 40 gets even less than half back, because being diluted in the no-era pool. + assert_eq!(Balances::free_balance(&40), 40 + 15); + assert_eq!(Balances::free_balance(&default_bonded_account()), 25 - 15); assert!(!PoolMembers::::contains_key(40)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 40, pool_id: 1, amount: 15 }, + Event::MemberRemoved { pool_id: 1, member: 40 }, + ] + ); - // When + // now, finally, the depositor can take out its share. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(10)); + + current_era += 3; + CurrentEra::set(current_era); + + // when assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - // Then - assert_eq!(Balances::free_balance(&10), 10 + 10); + // then + assert_eq!(Balances::free_balance(&10), 20); assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - assert!(!PoolMembers::::contains_key(10)); - // Pools are removed from storage because the depositor left - assert!(!SubPoolsStorage::::contains_key(1),); - assert!(!RewardPools::::contains_key(1),); - assert!(!BondedPools::::contains_key(1),); + // in this test, 10 actually gets their full share back because they were only in + // the bonded pool and we didn't slash the bonded pool. assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 550, pool_id: 1, amount: 550 }, - Event::Unbonded { member: 40, pool_id: 1, amount: 40 }, Event::Unbonded { member: 10, pool_id: 1, amount: 10 }, - Event::Withdrawn { member: 550, pool_id: 1, amount: 545 }, - Event::MemberRemoved { pool_id: 1, member: 550 }, - Event::Withdrawn { member: 40, pool_id: 1, amount: 40 }, - Event::MemberRemoved { pool_id: 1, member: 40 }, Event::Withdrawn { member: 10, pool_id: 1, amount: 10 }, Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 } + Event::Destroyed { pool_id: 1 }, ] ); }); @@ -2361,20 +2390,21 @@ mod withdraw_unbonded { .add_members(vec![(40, 40), (550, 550)]) .build_and_execute(|| { // Given - StakingMock::set_bonded_balance(default_bonded_account(), 100); // slash bonded balance - Balances::make_free_balance_be(&default_bonded_account(), 100); - assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(100)); + // current bond is 500, we slash it all to 250. + StakingMock::set_bonded_balance(default_bonded_account(), 250); + Balances::make_free_balance_be(&default_bonded_account(), 250); + assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(250)); assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); SubPoolsStorage::::insert( 1, SubPools { no_era: Default::default(), - with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 600, balance: 100 }}, + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 550 + 40, balance: 275 + 20 } + }, }, ); CurrentEra::set(StakingMock::bonding_duration()); @@ -2385,52 +2415,70 @@ mod withdraw_unbonded { // Then assert_eq!( SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 560, balance: 94 }} + unbonding_pools_with_era! { 3 => UnbondPool { points: 550, balance: 275 }} + ); + assert_eq!(Balances::free_balance(&40), 40 + 20); + assert_eq!(Balances::free_balance(&default_bonded_account()), 250 - 20); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::Unbonded { member: 40, pool_id: 1, amount: 16 }, + Event::Unbonded { member: 550, pool_id: 1, amount: 229 }, /* TODO: these + * values should + * prob. be points, + * not unbonding + * balance. */ + Event::Withdrawn { member: 40, pool_id: 1, amount: 20 }, + Event::MemberRemoved { pool_id: 1, member: 40 } + ] ); - assert_eq!(Balances::free_balance(&40), 40 + 6); - assert_eq!(Balances::free_balance(&default_bonded_account()), 94); - assert!(!PoolMembers::::contains_key(40)); // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); // Then + assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); + assert_eq!(Balances::free_balance(&550), 550 + 225); + // The account was dusted because it went below ED(5) + assert_eq!(Balances::free_balance(&default_bonded_account()), 5); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 550, pool_id: 1, amount: 225 }, + Event::MemberRemoved { pool_id: 1, member: 550 } + ] + ); + + // now, finally, the depositor can take out its share. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(10)); + + // because everyone else has left, the points assert_eq!( SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 2 }} + unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} ); - assert_eq!(Balances::free_balance(&550), 550 + 92); - // The account was dusted because it went below ED(5) - assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - assert!(!PoolMembers::::contains_key(550)); - // When + CurrentEra::set(CurrentEra::get() + 3); + + // when assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - // Then - assert_eq!(Balances::free_balance(&10), 10 + 0); + // then + assert_eq!(Balances::free_balance(&10), 10 + 5); assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - assert!(!PoolMembers::::contains_key(10)); - // Pools are removed from storage because the depositor left - assert!(!SubPoolsStorage::::contains_key(1)); - assert!(!RewardPools::::contains_key(1)); - assert!(!BondedPools::::contains_key(1)); + // in this test 10 also gets a fair share of the slash, because the slash was + // applied to the bonded account. assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 40, pool_id: 1, amount: 6 }, - Event::Unbonded { member: 550, pool_id: 1, amount: 92 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 2 }, - Event::Withdrawn { member: 40, pool_id: 1, amount: 6 }, - Event::MemberRemoved { pool_id: 1, member: 40 }, - Event::Withdrawn { member: 550, pool_id: 1, amount: 92 }, - Event::MemberRemoved { pool_id: 1, member: 550 }, - Event::Withdrawn { member: 10, pool_id: 1, amount: 0 }, + Event::Unbonded { member: 10, pool_id: 1, amount: 5 }, + Event::Withdrawn { member: 10, pool_id: 1, amount: 5 }, Event::MemberRemoved { pool_id: 1, member: 10 }, Event::Destroyed { pool_id: 1 } ] @@ -2623,6 +2671,7 @@ mod withdraw_unbonded { } #[test] + #[ignore] fn withdraw_unbonded_depositor_with_era_pool() { ExtBuilder::default() .add_members(vec![(100, 100), (200, 200)]) @@ -2751,11 +2800,13 @@ mod withdraw_unbonded { } #[test] + #[ignore] fn withdraw_unbonded_depositor_no_era_pool() { ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { // Given assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); // Skip ahead to an era where the `with_era` pools can get merged into the `no_era` // pool. diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 1a937a8604d31..2a14852ad11ec 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -29,16 +29,6 @@ use pallet_staking::{CurrentEra, Event as StakingEvent}; #[test] fn pool_lifecycle_e2e() { new_test_ext().execute_with(|| { - // set some limit for nominations. - assert_ok!(Staking::set_staking_configs( - Origin::root(), - pallet_staking::ConfigOp::Set(10), // minimum nominator bond - pallet_staking::ConfigOp::Noop, - pallet_staking::ConfigOp::Noop, - pallet_staking::ConfigOp::Noop, - pallet_staking::ConfigOp::Noop, - pallet_staking::ConfigOp::Noop, - )); assert_eq!(Balances::minimum_balance(), 5); assert_eq!(Staking::current_era(), None); @@ -49,26 +39,30 @@ fn pool_lifecycle_e2e() { // have the pool nominate. assert_ok!(Pools::nominate(Origin::signed(10), 1, vec![1, 2, 3])); - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Bonded(POOL1_BONDED, 50), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::Created { depositor: 10, pool_id: 1 }, - PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 50, joined: true }, - ]); + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 50),]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Created { depositor: 10, pool_id: 1 }, + PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 50, joined: true }, + ] + ); // have two members join assert_ok!(Pools::join(Origin::signed(20), 10, 1)); assert_ok!(Pools::join(Origin::signed(21), 10, 1)); - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Bonded(POOL1_BONDED, 10), - StakingEvent::Bonded(POOL1_BONDED, 10), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - PoolsEvent::Bonded { member: 21, pool_id: 1, bonded: 10, joined: true }, - ]); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Bonded(POOL1_BONDED, 10), StakingEvent::Bonded(POOL1_BONDED, 10),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + PoolsEvent::Bonded { member: 21, pool_id: 1, bonded: 10, joined: true }, + ] + ); // pool goes into destroying assert_ok!(Pools::set_state(Origin::signed(10), 1, PoolState::Destroying)); @@ -88,15 +82,21 @@ fn pool_lifecycle_e2e() { assert_eq!(PoolMembers::::get(21).unwrap().unbonding_eras.len(), 1); assert_eq!(PoolMembers::::get(21).unwrap().points, 0); - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Unbonded(POOL1_BONDED, 10), - StakingEvent::Unbonded(POOL1_BONDED, 10), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, - PoolsEvent::Unbonded { member: 20, pool_id: 1, amount: 10 }, - PoolsEvent::Unbonded { member: 21, pool_id: 1, amount: 10 }, - ]); + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Unbonded(POOL1_BONDED, 10), + StakingEvent::Unbonded(POOL1_BONDED, 10), + ] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, + PoolsEvent::Unbonded { member: 20, pool_id: 1, amount: 10 }, + PoolsEvent::Unbonded { member: 21, pool_id: 1, amount: 10 }, + ] + ); // depositor cannot still unbond assert_noop!( @@ -127,15 +127,19 @@ fn pool_lifecycle_e2e() { assert!(PoolMembers::::get(20).is_none()); assert!(PoolMembers::::get(21).is_none()); - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Withdrawn(POOL1_BONDED, 20), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::Withdrawn { member: 20, pool_id: 1, amount: 10 }, - PoolsEvent::MemberRemoved { pool_id: 1, member: 20 }, - PoolsEvent::Withdrawn { member: 21, pool_id: 1, amount: 10 }, - PoolsEvent::MemberRemoved { pool_id: 1, member: 21 }, - ]); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Withdrawn(POOL1_BONDED, 20),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Withdrawn { member: 20, pool_id: 1, amount: 10 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 20 }, + PoolsEvent::Withdrawn { member: 21, pool_id: 1, amount: 10 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 21 }, + ] + ); // as soon as all members have left, the depositor can try to unbond, but since the // min-nominator intention is set, they must chill first. @@ -147,26 +151,31 @@ fn pool_lifecycle_e2e() { assert_ok!(Pools::chill(Origin::signed(10), 1)); assert_ok!(Pools::unbond(Origin::signed(10), 10, 50)); - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Chilled(POOL1_BONDED), - StakingEvent::Unbonded(POOL1_BONDED, 50), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::Unbonded { member: 10, pool_id: 1, amount: 50 } - ]); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Chilled(POOL1_BONDED), StakingEvent::Unbonded(POOL1_BONDED, 50),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 10, pool_id: 1, amount: 50 }] + ); // waiting another bonding duration: CurrentEra::::set(Some(BondingDuration::get() * 2)); assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 1)); // pools is fully destroyed now. - assert_eq!(staking_events_since_last_call(), vec![ - StakingEvent::Withdrawn(POOL1_BONDED, 50), - ]); - assert_eq!(pool_events_since_last_call(), vec![ - PoolsEvent::Withdrawn { member: 10, pool_id: 1, amount: 50 }, - PoolsEvent::MemberRemoved { pool_id: 1, member: 10 }, - PoolsEvent::Destroyed { pool_id: 1 } - ]); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Withdrawn(POOL1_BONDED, 50),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Withdrawn { member: 10, pool_id: 1, amount: 50 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 10 }, + PoolsEvent::Destroyed { pool_id: 1 } + ] + ); }) } diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index a8a17b2701a3e..ceb0cf0371df2 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -16,7 +16,7 @@ // limitations under the License. use frame_election_provider_support::VoteWeight; -use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; +use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; use sp_runtime::traits::{Convert, IdentityLookup}; type AccountId = u128; @@ -214,6 +214,17 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| { // for events to be deposited. frame_system::Pallet::::set_block_number(1); + + // set some limit for nominations. + assert_ok!(Staking::set_staking_configs( + Origin::root(), + pallet_staking::ConfigOp::Set(10), // minimum nominator bond + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + pallet_staking::ConfigOp::Noop, + )); }); ext From ac48c376cd609736c8da5e3f1e19dd0138b3b031 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 16 May 2022 11:47:02 +0100 Subject: [PATCH 07/65] Fix it all --- frame/nomination-pools/src/lib.rs | 71 +- frame/nomination-pools/src/mock.rs | 49 +- frame/nomination-pools/src/tests.rs | 713 +++++++----------- .../nomination-pools/test-staking/src/lib.rs | 12 +- 4 files changed, 374 insertions(+), 471 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index effd0ec500ea1..fc7306120054d 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -452,16 +452,18 @@ impl PoolMember { /// Returns `Ok(())` and updates `unbonding_eras` and `points` if success, `Err(_)` otherwise. fn try_unbond( &mut self, - points: BalanceOf, + points_dissolved: BalanceOf, + points_issued: BalanceOf, unbonding_era: EraIndex, ) -> Result<(), Error> { - if let Some(new_points) = self.points.checked_sub(&points) { + if let Some(new_points) = self.points.checked_sub(&points_dissolved) { match self.unbonding_eras.get_mut(&unbonding_era) { Some(already_unbonding_points) => - *already_unbonding_points = already_unbonding_points.saturating_add(points), + *already_unbonding_points = + already_unbonding_points.saturating_add(points_issued), None => self .unbonding_eras - .try_insert(unbonding_era, points) + .try_insert(unbonding_era, points_issued) .map(|old| { if old.is_some() { defensive!("value checked to not exist in the map; qed"); @@ -631,7 +633,7 @@ impl BondedPool { fn points_to_balance(&self, points: BalanceOf) -> BalanceOf { let bonded_balance = T::StakingInterface::active_stake(&self.bonded_account()).unwrap_or(Zero::zero()); - Pallet::::point_to_balance(dbg!(bonded_balance), dbg!(self.points), points) + Pallet::::point_to_balance(bonded_balance, self.points, points) } /// Issue points to [`Self`] for `new_funds`. @@ -827,10 +829,15 @@ impl BondedPool { &self, caller: &T::AccountId, target_account: &T::AccountId, - bonded_pool: &BondedPool, + target_member: &PoolMember, + sub_pools: &SubPools, ) -> Result<(), DispatchError> { if *target_account == self.roles.depositor { - ensure!(bonded_pool.member_counter == 1, Error::::NotOnlyPoolMember); + ensure!( + sub_pools.sum_unbonding_points() == target_member.unbonding_points(), + Error::::NotOnlyPoolMember + ); + debug_assert_eq!(self.member_counter, 1, "only member must exist at this point"); Ok(()) } else { // This isn't a depositor @@ -1254,9 +1261,33 @@ pub mod pallet { /// A payout has been made to a member. PaidOut { member: T::AccountId, pool_id: PoolId, payout: BalanceOf }, /// A member has unbonded from their pool. - Unbonded { member: T::AccountId, pool_id: PoolId, amount: BalanceOf }, + /// + /// - `balance` is the corresponding balance of the number of points that have been + /// requested to be unbonded (the argument of the `unbond` transaction) from the bonded + /// pool. + /// - `points` is the number of points that are issued as a result of + /// `balance` into the corresponding unbonding pool. + /// + /// In the absence of slashing, these values will match. In the presence of slashing, the + /// number of points that are issued in the unbonding pool will be less than the amount + /// requested to be unbonded. + Unbonded { + member: T::AccountId, + pool_id: PoolId, + balance: BalanceOf, + points: BalanceOf, + }, /// A member has withdrawn from their pool. - Withdrawn { member: T::AccountId, pool_id: PoolId, amount: BalanceOf }, + /// + /// The given number of `points` have been dissolved in return of `balance`. + /// + /// Similar to `Unbonded` event, in the absence of slashing, these values will match. + Withdrawn { + member: T::AccountId, + pool_id: PoolId, + balance: BalanceOf, + points: BalanceOf, + }, /// A pool has been destroyed. Destroyed { pool_id: PoolId }, /// The state of a pool has changed @@ -1510,10 +1541,6 @@ pub mod pallet { let current_era = T::StakingInterface::current_era(); let unbond_era = T::StakingInterface::bonding_duration().saturating_add(current_era); - // Try and unbond in the member map. - // TODO: this is wrong, we should use `actual_unbonding_points`. - member.try_unbond(unbonding_points, unbond_era)?; - // Unbond in the actual underlying nominator. let unbonding_balance = bonded_pool.dissolve(unbonding_points); T::StakingInterface::unbond(bonded_pool.bonded_account(), unbonding_balance)?; @@ -1541,10 +1568,14 @@ pub mod pallet { .defensive_ok_or_else(|| Error::::DefensiveError)? .issue(unbonding_balance); + // Try and unbond in the member map. + member.try_unbond(unbonding_points, actual_unbonding_points, unbond_era)?; + Self::deposit_event(Event::::Unbonded { member: member_account.clone(), pool_id: member.pool_id, - amount: unbonding_balance, + points: actual_unbonding_points, + balance: unbonding_balance, }); // Now that we know everything has worked write the items to storage. @@ -1614,7 +1645,12 @@ pub mod pallet { let mut sub_pools = SubPoolsStorage::::get(member.pool_id) .defensive_ok_or_else(|| Error::::SubPoolsNotFound)?; - bonded_pool.ok_to_withdraw_unbonded_with(&caller, &member_account, &bonded_pool)?; + bonded_pool.ok_to_withdraw_unbonded_with( + &caller, + &member_account, + &member, + &sub_pools, + )?; // NOTE: must do this after we have done the `ok_to_withdraw_unbonded_other_with` check. let withdrawn_points = member.withdraw_unlocked(current_era); @@ -1627,9 +1663,11 @@ pub mod pallet { num_slashing_spans, )?; + let mut sum_unlocked_points: BalanceOf = Zero::zero(); let balance_to_unbond = withdrawn_points .iter() .fold(BalanceOf::::zero(), |accumulator, (era, unlocked_points)| { + sum_unlocked_points = sum_unlocked_points.saturating_add(*unlocked_points); if let Some(era_pool) = sub_pools.with_era.get_mut(&era) { let balance_to_unbond = era_pool.dissolve(*unlocked_points); if era_pool.points.is_zero() { @@ -1662,7 +1700,8 @@ pub mod pallet { Self::deposit_event(Event::::Withdrawn { member: member_account.clone(), pool_id: member.pool_id, - amount: balance_to_unbond, + points: sum_unlocked_points, + balance: balance_to_unbond, }); let post_info_weight = if member.total_points().is_zero() { diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index b322f9fdce3b6..4c47fce261dac 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -2,7 +2,6 @@ use super::*; use crate::{self as pools}; use frame_support::{assert_ok, parameter_types, PalletId}; use frame_system::RawOrigin; -use std::collections::HashMap; pub type AccountId = u128; pub type Balance = u128; @@ -20,17 +19,19 @@ pub fn default_reward_account() -> AccountId { parameter_types! { pub static CurrentEra: EraIndex = 0; pub static BondingDuration: EraIndex = 3; - static BondedBalanceMap: HashMap = Default::default(); - static UnbondingBalanceMap: HashMap = Default::default(); + pub storage BondedBalanceMap: BTreeMap = Default::default(); + pub storage UnbondingBalanceMap: BTreeMap = Default::default(); #[derive(Clone, PartialEq)] pub static MaxUnbonding: u32 = 8; - pub static Nominations: Vec = vec![]; + pub storage Nominations: Vec = vec![]; } pub struct StakingMock; impl StakingMock { pub(crate) fn set_bonded_balance(who: AccountId, bonded: Balance) { - BONDED_BALANCE_MAP.with(|m| m.borrow_mut().insert(who, bonded)); + let mut x = BondedBalanceMap::get(); + x.insert(who, bonded); + BondedBalanceMap::set(&x) } } @@ -66,14 +67,19 @@ impl sp_staking::StakingInterface for StakingMock { } fn bond_extra(who: Self::AccountId, extra: Self::Balance) -> DispatchResult { - BONDED_BALANCE_MAP.with(|m| *m.borrow_mut().get_mut(&who).unwrap() += extra); + let mut x = BondedBalanceMap::get(); + x.get_mut(&who).map(|v| *v += extra); + BondedBalanceMap::set(&x); Ok(()) } fn unbond(who: Self::AccountId, amount: Self::Balance) -> DispatchResult { - BONDED_BALANCE_MAP.with(|m| *m.borrow_mut().get_mut(&who).unwrap() -= amount); - UNBONDING_BALANCE_MAP - .with(|m| *m.borrow_mut().entry(who).or_insert(Self::Balance::zero()) += amount); + let mut x = BondedBalanceMap::get(); + *x.get_mut(&who).unwrap() = x.get_mut(&who).unwrap().saturating_sub(amount); + BondedBalanceMap::set(&x); + let mut y = UnbondingBalanceMap::get(); + *y.entry(who).or_insert(Self::Balance::zero()) += amount; + UnbondingBalanceMap::set(&y); Ok(()) } @@ -83,7 +89,9 @@ impl sp_staking::StakingInterface for StakingMock { fn withdraw_unbonded(who: Self::AccountId, _: u32) -> Result { // Simulates removing unlocking chunks and only having the bonded balance locked - let _maybe_new_free = UNBONDING_BALANCE_MAP.with(|m| m.borrow_mut().remove(&who)); + let mut x = UnbondingBalanceMap::get(); + x.remove(&who); + UnbondingBalanceMap::set(&x); Ok(UnbondingBalanceMap::get().is_empty()) } @@ -99,7 +107,7 @@ impl sp_staking::StakingInterface for StakingMock { } fn nominate(_: Self::AccountId, nominations: Vec) -> DispatchResult { - Nominations::set(nominations); + Nominations::set(&nominations); Ok(()) } } @@ -267,7 +275,8 @@ pub(crate) fn unsafe_set_state(pool_id: PoolId, state: PoolState) -> Result<(), } parameter_types! { - static ObservedEvents: usize = 0; + static PoolsEvents: usize = 0; + static BalancesEvents: usize = 0; } /// All events of this pallet. @@ -277,8 +286,20 @@ pub(crate) fn pool_events_since_last_call() -> Vec> { .map(|r| r.event) .filter_map(|e| if let Event::Pools(inner) = e { Some(inner) } else { None }) .collect::>(); - let already_seen = ObservedEvents::get(); - ObservedEvents::set(events.len()); + let already_seen = PoolsEvents::get(); + PoolsEvents::set(events.len()); + events.into_iter().skip(already_seen).collect() +} + +/// All events of this pallet. +pub(crate) fn balances_events_since_last_call() -> Vec> { + let events = System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| if let Event::Balances(inner) = e { Some(inner) } else { None }) + .collect::>(); + let already_seen = BalancesEvents::get(); + BalancesEvents::set(events.len()); events.into_iter().skip(already_seen).collect() } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 4a8d1f020c075..421ce34743d94 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -21,6 +21,7 @@ use frame_support::{ assert_noop, assert_ok, assert_storage_noop, bounded_btree_map, storage::{with_transaction, TransactionOutcome}, }; +use pallet_balances::Event as BEvent; macro_rules! unbonding_pools_with_era { ($($k:expr => $v:expr),* $(,)?) => {{ @@ -90,100 +91,104 @@ mod bonded_pool { use super::*; #[test] fn points_to_issue_works() { - let mut bonded_pool = BondedPool:: { - id: 123123, - inner: BondedPoolInner { - state: PoolState::Open, - points: 100, - member_counter: 1, - roles: DEFAULT_ROLES, - }, - }; + ExtBuilder::default().build_and_execute(|| { + let mut bonded_pool = BondedPool:: { + id: 123123, + inner: BondedPoolInner { + state: PoolState::Open, + points: 100, + member_counter: 1, + roles: DEFAULT_ROLES, + }, + }; - // 1 points : 1 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - assert_eq!(bonded_pool.balance_to_point(10), 10); - assert_eq!(bonded_pool.balance_to_point(0), 0); - - // 2 points : 1 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 50); - assert_eq!(bonded_pool.balance_to_point(10), 20); - - // 1 points : 2 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - bonded_pool.points = 50; - assert_eq!(bonded_pool.balance_to_point(10), 5); - - // 100 points : 0 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); - bonded_pool.points = 100; - assert_eq!(bonded_pool.balance_to_point(10), 100 * 10); - - // 0 points : 100 balance - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - bonded_pool.points = 100; - assert_eq!(bonded_pool.balance_to_point(10), 10); - - // 10 points : 3 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 30); - assert_eq!(bonded_pool.balance_to_point(10), 33); - - // 2 points : 3 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 300); - bonded_pool.points = 200; - assert_eq!(bonded_pool.balance_to_point(10), 6); - - // 4 points : 9 balance ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 900); - bonded_pool.points = 400; - assert_eq!(bonded_pool.balance_to_point(90), 40); - } + // 1 points : 1 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); + assert_eq!(bonded_pool.balance_to_point(10), 10); + assert_eq!(bonded_pool.balance_to_point(0), 0); - #[test] - fn balance_to_unbond_works() { - // 1 balance : 1 points ratio - let mut bonded_pool = BondedPool:: { - id: 123123, - inner: BondedPoolInner { - state: PoolState::Open, - points: 100, - member_counter: 1, - roles: DEFAULT_ROLES, - }, - }; + // 2 points : 1 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 50); + assert_eq!(bonded_pool.balance_to_point(10), 20); - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - assert_eq!(bonded_pool.points_to_balance(10), 10); - assert_eq!(bonded_pool.points_to_balance(0), 0); + // 1 points : 2 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); + bonded_pool.points = 50; + assert_eq!(bonded_pool.balance_to_point(10), 5); - // 2 balance : 1 points ratio - bonded_pool.points = 50; - assert_eq!(bonded_pool.points_to_balance(10), 20); + // 100 points : 0 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); + bonded_pool.points = 100; + assert_eq!(bonded_pool.balance_to_point(10), 100 * 10); - // 100 balance : 0 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); - bonded_pool.points = 0; - assert_eq!(bonded_pool.points_to_balance(10), 0); + // 0 points : 100 balance + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); + bonded_pool.points = 100; + assert_eq!(bonded_pool.balance_to_point(10), 10); - // 0 balance : 100 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); - bonded_pool.points = 100; - assert_eq!(bonded_pool.points_to_balance(10), 0); + // 10 points : 3 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 30); + assert_eq!(bonded_pool.balance_to_point(10), 33); - // 10 balance : 3 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - bonded_pool.points = 30; - assert_eq!(bonded_pool.points_to_balance(10), 33); + // 2 points : 3 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 300); + bonded_pool.points = 200; + assert_eq!(bonded_pool.balance_to_point(10), 6); - // 2 balance : 3 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 200); - bonded_pool.points = 300; - assert_eq!(bonded_pool.points_to_balance(10), 6); + // 4 points : 9 balance ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 900); + bonded_pool.points = 400; + assert_eq!(bonded_pool.balance_to_point(90), 40); + }) + } - // 4 balance : 9 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 400); - bonded_pool.points = 900; - assert_eq!(bonded_pool.points_to_balance(90), 40); + #[test] + fn balance_to_unbond_works() { + ExtBuilder::default().build_and_execute(|| { + // 1 balance : 1 points ratio + let mut bonded_pool = BondedPool:: { + id: 123123, + inner: BondedPoolInner { + state: PoolState::Open, + points: 100, + member_counter: 1, + roles: DEFAULT_ROLES, + }, + }; + + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); + assert_eq!(bonded_pool.points_to_balance(10), 10); + assert_eq!(bonded_pool.points_to_balance(0), 0); + + // 2 balance : 1 points ratio + bonded_pool.points = 50; + assert_eq!(bonded_pool.points_to_balance(10), 20); + + // 100 balance : 0 points ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); + bonded_pool.points = 0; + assert_eq!(bonded_pool.points_to_balance(10), 0); + + // 0 balance : 100 points ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); + bonded_pool.points = 100; + assert_eq!(bonded_pool.points_to_balance(10), 0); + + // 10 balance : 3 points ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); + bonded_pool.points = 30; + assert_eq!(bonded_pool.points_to_balance(10), 33); + + // 2 balance : 3 points ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 200); + bonded_pool.points = 300; + assert_eq!(bonded_pool.points_to_balance(10), 6); + + // 4 balance : 9 points ratio + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 400); + bonded_pool.points = 900; + assert_eq!(bonded_pool.points_to_balance(90), 40); + }) } #[test] @@ -255,38 +260,40 @@ mod unbond_pool { #[test] fn points_to_issue_works() { - // 1 points : 1 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 10); - assert_eq!(unbond_pool.balance_to_point(0), 0); - - // 2 points : 1 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; - assert_eq!(unbond_pool.balance_to_point(10), 20); - - // 1 points : 2 balance ratio - let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 5); - - // 100 points : 0 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; - assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); - - // 0 points : 100 balance - let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 10); - - // 10 points : 3 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; - assert_eq!(unbond_pool.balance_to_point(10), 33); - - // 2 points : 3 balance ratio - let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; - assert_eq!(unbond_pool.balance_to_point(10), 6); - - // 4 points : 9 balance ratio - let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; - assert_eq!(unbond_pool.balance_to_point(90), 40); + ExtBuilder::default().build_and_execute(|| { + // 1 points : 1 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 10); + assert_eq!(unbond_pool.balance_to_point(0), 0); + + // 2 points : 1 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; + assert_eq!(unbond_pool.balance_to_point(10), 20); + + // 1 points : 2 balance ratio + let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 5); + + // 100 points : 0 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; + assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); + + // 0 points : 100 balance + let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 10); + + // 10 points : 3 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; + assert_eq!(unbond_pool.balance_to_point(10), 33); + + // 2 points : 3 balance ratio + let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; + assert_eq!(unbond_pool.balance_to_point(10), 6); + + // 4 points : 9 balance ratio + let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; + assert_eq!(unbond_pool.balance_to_point(90), 40); + }) } #[test] @@ -946,7 +953,7 @@ mod claim_payout { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true }, - Event::Unbonded { member: 11, pool_id: 1, amount: 11 } + Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 } ] ); }); @@ -1588,14 +1595,14 @@ mod unbond { Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, - Event::Unbonded { member: 40, pool_id: 1, amount: 6 } + Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 } ] ); assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); assert_eq!( PoolMembers::::get(40).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 40) + member_unbonding_eras!(0 + 3 => 6) ); assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding @@ -1623,14 +1630,14 @@ mod unbond { assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); assert_eq!( PoolMembers::::get(550).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 550) + member_unbonding_eras!(0 + 3 => 92) ); assert_eq!(Balances::free_balance(&550), 550 + 550); assert_eq!( pool_events_since_last_call(), vec![ Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, - Event::Unbonded { member: 550, pool_id: 1, amount: 92 } + Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 } ] ); @@ -1659,16 +1666,16 @@ mod unbond { ); assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - assert_eq!(Balances::free_balance(&550), 550 + 550 + 550); + assert_eq!(Balances::free_balance(&550), 550 + 550 + 92); assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 40, pool_id: 1, amount: 40 }, + Event::Withdrawn { member: 40, pool_id: 1, points: 6, balance: 6 }, Event::MemberRemoved { pool_id: 1, member: 40 }, - Event::Withdrawn { member: 550, pool_id: 1, amount: 550 }, + Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, Event::MemberRemoved { pool_id: 1, member: 550 }, Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 2 }, + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } ] ); }); @@ -1714,7 +1721,7 @@ mod unbond { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 10 } + Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } ] ); }); @@ -1749,7 +1756,7 @@ mod unbond { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, ] ); @@ -1758,7 +1765,7 @@ mod unbond { assert_eq!( pool_events_since_last_call(), - vec![Event::Unbonded { member: 200, pool_id: 1, amount: 200 }] + vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }] ); assert_eq!( @@ -1784,8 +1791,7 @@ mod unbond { } ); assert_eq!( - UNBONDING_BALANCE_MAP - .with(|m| *m.borrow_mut().get(&default_bonded_account()).unwrap()), + *UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 100 + 200 ); }); @@ -1827,7 +1833,7 @@ mod unbond { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 } + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 } ] ); @@ -1879,11 +1885,7 @@ mod unbond { } ); assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - assert_eq!( - UNBONDING_BALANCE_MAP - .with(|m| *m.borrow_mut().get(&default_bonded_account()).unwrap()), - 10 - ); + assert_eq!(*UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 10); }); } @@ -1971,7 +1973,7 @@ mod unbond { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 1 } + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } ] ); @@ -1997,7 +1999,7 @@ mod unbond { ); assert_eq!( pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, amount: 5 }] + vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }] ); // when: casual further unbond, next era. @@ -2024,7 +2026,7 @@ mod unbond { ); assert_eq!( pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, amount: 1 }] + vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }] ); // when: unbonding more than our active: error @@ -2055,7 +2057,7 @@ mod unbond { ); assert_eq!( pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, amount: 3 }] + vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }] ); }); } @@ -2095,9 +2097,9 @@ mod unbond { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 2 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 3 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 1 } + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } ] ); }) @@ -2128,7 +2130,7 @@ mod unbond { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 3 } + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } ] ); }); @@ -2184,7 +2186,7 @@ mod unbond { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, // exactly equal to ed, all that can be claimed. Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 2 } + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } ] ); @@ -2200,7 +2202,7 @@ mod unbond { vec![ // exactly equal to ed, all that can be claimed. Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 3 } + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } ] ); @@ -2215,7 +2217,7 @@ mod unbond { pool_events_since_last_call(), vec![ Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 5 } + Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 } ] ); @@ -2260,6 +2262,9 @@ mod withdraw_unbonded { ExtBuilder::default() .add_members(vec![(40, 40), (550, 550)]) .build_and_execute(|| { + // reduce the noise a bit. + let _ = balances_events_since_last_call(); + // Given assert_eq!(StakingMock::bonding_duration(), 3); assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); @@ -2276,15 +2281,22 @@ mod withdraw_unbonded { // Simulate a slash to the pool with_era(current_era), decreasing the balance by // half - unbond_pool.balance /= 2; // 295 - SubPoolsStorage::::insert(1, sub_pools); - // Update the equivalent of the unbonding chunks for the `StakingMock` - UNBONDING_BALANCE_MAP - .with(|m| *m.borrow_mut().get_mut(&default_bonded_account()).unwrap() /= 5); - Balances::make_free_balance_be( - &default_bonded_account(), - Balances::free_balance(&default_bonded_account()) / 2, // 300 - ); + { + unbond_pool.balance /= 2; // 295 + SubPoolsStorage::::insert(1, sub_pools); + // Update the equivalent of the unbonding chunks for the `StakingMock` + let mut x = UnbondingBalanceMap::get(); + *x.get_mut(&default_bonded_account()).unwrap() /= 5; + UnbondingBalanceMap::set(&x); + Balances::make_free_balance_be( + &default_bonded_account(), + Balances::free_balance(&default_bonded_account()) / 2, // 300 + ); + StakingMock::set_bonded_balance( + default_bonded_account(), + StakingMock::active_stake(&default_bonded_account()).unwrap() / 2, + ); + }; // Advance the current_era to ensure all `with_era` pools will be merged into // `no_era` pool @@ -2296,6 +2308,7 @@ mod withdraw_unbonded { let sub_pools = SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); SubPoolsStorage::::insert(1, sub_pools); + assert_eq!( SubPoolsStorage::::get(1).unwrap(), SubPools { @@ -2311,10 +2324,18 @@ mod withdraw_unbonded { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 550, pool_id: 1, amount: 550 }, - Event::Unbonded { member: 40, pool_id: 1, amount: 40 }, + Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 }, + Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 }, ] ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::BalanceSet { + who: default_bonded_account(), + free: 300, + reserved: 0 + }] + ); // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); @@ -2324,15 +2345,17 @@ mod withdraw_unbonded { SubPoolsStorage::::get(1).unwrap().no_era, UnbondPool { points: 40, balance: 20 } ); - assert_eq!(Balances::free_balance(&550), 550 + 550 / 2); - assert_eq!(Balances::free_balance(&default_bonded_account()), (40 + 10) / 2); assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 550, pool_id: 1, amount: 275 }, + Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 550 }, Event::MemberRemoved { pool_id: 1, member: 550 } ] ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 }] + ); // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); @@ -2342,17 +2365,18 @@ mod withdraw_unbonded { SubPoolsStorage::::get(1).unwrap().no_era, UnbondPool { points: 0, balance: 0 } ); - // 40 gets even less than half back, because being diluted in the no-era pool. - assert_eq!(Balances::free_balance(&40), 40 + 15); - assert_eq!(Balances::free_balance(&default_bonded_account()), 25 - 15); assert!(!PoolMembers::::contains_key(40)); assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 40, pool_id: 1, amount: 15 }, - Event::MemberRemoved { pool_id: 1, member: 40 }, + Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 40 }, + Event::MemberRemoved { pool_id: 1, member: 40 } ] ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 }] + ); // now, finally, the depositor can take out its share. unsafe_set_state(1, PoolState::Destroying).unwrap(); @@ -2363,50 +2387,66 @@ mod withdraw_unbonded { // when assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - - // then - assert_eq!(Balances::free_balance(&10), 20); - assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - - // in this test, 10 actually gets their full share back because they were only in - // the bonded pool and we didn't slash the bonded pool. assert_eq!( pool_events_since_last_call(), vec![ - Event::Unbonded { member: 10, pool_id: 1, amount: 10 }, - Event::Withdrawn { member: 10, pool_id: 1, amount: 10 }, + Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 }, + Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 }, Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 }, + Event::Destroyed { pool_id: 1 } + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![ + BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, + BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } ] ); }); } - // This test also documents the case when the pools free balance goes below ED before all - // members have unbonded. #[test] fn withdraw_unbonded_works_against_slashed_with_era_sub_pools() { ExtBuilder::default() .add_members(vec![(40, 40), (550, 550)]) .build_and_execute(|| { + let _ = balances_events_since_last_call(); + // Given - // current bond is 500, we slash it all to 250. - StakingMock::set_bonded_balance(default_bonded_account(), 250); - Balances::make_free_balance_be(&default_bonded_account(), 250); - assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(250)); + // current bond is 600, we slash it all to 300. + StakingMock::set_bonded_balance(default_bonded_account(), 300); + Balances::make_free_balance_be(&default_bonded_account(), 300); + assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(300)); - assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); - assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); + assert_ok!(fully_unbond_permissioned(40)); + assert_ok!(fully_unbond_permissioned(550)); - SubPoolsStorage::::insert( - 1, - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 550 + 40, balance: 275 + 20 } - }, - }, + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 }} + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 }, + Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 }, + ] ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::BalanceSet { + who: default_bonded_account(), + free: 300, + reserved: 0 + },] + ); + CurrentEra::set(StakingMock::bonding_duration()); // When @@ -2414,44 +2454,38 @@ mod withdraw_unbonded { // Then assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 3 => UnbondPool { points: 550, balance: 275 }} + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 },] ); - assert_eq!(Balances::free_balance(&40), 40 + 20); - assert_eq!(Balances::free_balance(&default_bonded_account()), 250 - 20); assert_eq!( pool_events_since_last_call(), vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 40, pool_id: 1, amount: 16 }, - Event::Unbonded { member: 550, pool_id: 1, amount: 229 }, /* TODO: these - * values should - * prob. be points, - * not unbonding - * balance. */ - Event::Withdrawn { member: 40, pool_id: 1, amount: 20 }, + Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 20 }, Event::MemberRemoved { pool_id: 1, member: 40 } ] ); + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} + ); + // When assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); // Then - assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); - assert_eq!(Balances::free_balance(&550), 550 + 225); - // The account was dusted because it went below ED(5) - assert_eq!(Balances::free_balance(&default_bonded_account()), 5); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 },] + ); assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 550, pool_id: 1, amount: 225 }, + Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 275 }, Event::MemberRemoved { pool_id: 1, member: 550 } ] ); + assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); // now, finally, the depositor can take out its share. unsafe_set_state(1, PoolState::Destroying).unwrap(); @@ -2477,12 +2511,19 @@ mod withdraw_unbonded { assert_eq!( pool_events_since_last_call(), vec![ - Event::Unbonded { member: 10, pool_id: 1, amount: 5 }, - Event::Withdrawn { member: 10, pool_id: 1, amount: 5 }, + Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }, + Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 }, Event::MemberRemoved { pool_id: 1, member: 10 }, Event::Destroyed { pool_id: 1 } ] ); + assert_eq!( + balances_events_since_last_call(), + vec![ + BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, + BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } + ] + ); }); } @@ -2584,8 +2625,8 @@ mod withdraw_unbonded { Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 }, - Event::Unbonded { member: 200, pool_id: 1, amount: 200 } + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 } ] ); @@ -2612,9 +2653,9 @@ mod withdraw_unbonded { assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 100, pool_id: 1, amount: 100 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, Event::MemberRemoved { pool_id: 1, member: 100 }, - Event::Withdrawn { member: 200, pool_id: 1, amount: 200 }, + Event::Withdrawn { member: 200, pool_id: 1, points: 200, balance: 200 }, Event::MemberRemoved { pool_id: 1, member: 200 } ] ); @@ -2662,212 +2703,14 @@ mod withdraw_unbonded { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 }, - Event::Withdrawn { member: 100, pool_id: 1, amount: 100 }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, Event::MemberRemoved { pool_id: 1, member: 100 } ] ); }); } - #[test] - #[ignore] - fn withdraw_unbonded_depositor_with_era_pool() { - ExtBuilder::default() - .add_members(vec![(100, 100), (200, 200)]) - .build_and_execute(|| { - // Given - assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 } - ] - ); - - let mut current_era = 1; - CurrentEra::set(current_era); - - assert_ok!(Pools::fully_unbond(Origin::signed(200), 200)); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 200, pool_id: 1, amount: 200 }] - ); - - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, amount: 10 }] - ); - - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { points: 100, balance: 100}, - 1 + 3 => UnbondPool { points: 200 + 10, balance: 200 + 10 } - } - } - ); - - // Skip ahead eras to where its valid for the members to withdraw - current_era += StakingMock::bonding_duration(); - CurrentEra::set(current_era); - - // Cannot withdraw the depositor if their is a member in another `with_era` pool. - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(420), 10, 0), - Error::::NotOnlyPoolMember - ); - - // Given - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 100, pool_id: 1, amount: 100 }, - Event::MemberRemoved { pool_id: 1, member: 100 } - ] - ); - - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - // Note that era 0+3 unbond pool is destroyed because points went to 0 - 1 + 3 => UnbondPool { points: 200 + 10, balance: 200 + 10 } - } - } - ); - - // Cannot withdraw the depositor if their is a member in another `with_era` pool. - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(420), 10, 0), - Error::::NotOnlyPoolMember - ); - - // Given - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 200, 0)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 200, pool_id: 1, amount: 200 }, - Event::MemberRemoved { pool_id: 1, member: 200 } - ] - ); - - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 1 + 3 => UnbondPool { points: 10, balance: 10 } - } - } - ); - - // The depositor can withdraw - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 10, 0)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 10, pool_id: 1, amount: 10 }, - Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 } - ] - ); - - assert!(!PoolMembers::::contains_key(10)); - assert_eq!(Balances::free_balance(10), 10 + 10); - // Pools are removed from storage because the depositor left - assert!(!SubPoolsStorage::::contains_key(1)); - assert!(!RewardPools::::contains_key(1)); - assert!(!BondedPools::::contains_key(1)); - }); - } - - #[test] - #[ignore] - fn withdraw_unbonded_depositor_no_era_pool() { - ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { - // Given - assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); - // Skip ahead to an era where the `with_era` pools can get merged into the `no_era` - // pool. - let current_era = TotalUnbondingPools::::get(); - CurrentEra::set(current_era); - - // Simulate some other withdraw that caused the pool to merge - let sub_pools = - SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era + 3); - SubPoolsStorage::::insert(1, sub_pools); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: UnbondPool { points: 100 + 10, balance: 100 + 10 }, - with_era: Default::default(), - } - ); - - // Cannot withdraw depositor with another member in the `no_era` pool - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(420), 10, 0), - Error::::NotOnlyPoolMember - ); - - // Given - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: UnbondPool { points: 10, balance: 10 }, - with_era: Default::default(), - } - ); - - // The depositor can withdraw - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 10, 0)); - assert!(!PoolMembers::::contains_key(10)); - assert_eq!(Balances::free_balance(10), 10 + 10); - // Pools are removed from storage because the depositor left - assert!(!SubPoolsStorage::::contains_key(1)); - assert!(!RewardPools::::contains_key(1)); - assert!(!BondedPools::::contains_key(1)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 100 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 10 }, - Event::Withdrawn { member: 100, pool_id: 1, amount: 100 }, - Event::MemberRemoved { pool_id: 1, member: 100 }, - Event::Withdrawn { member: 10, pool_id: 1, amount: 10 }, - Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 } - ] - ); - }); - } - #[test] fn partial_withdraw_unbonded_depositor() { ExtBuilder::default().ed(1).build_and_execute(|| { @@ -2899,8 +2742,8 @@ mod withdraw_unbonded { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 6 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 1 } + Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 }, + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } ] ); @@ -2931,7 +2774,7 @@ mod withdraw_unbonded { ); assert_eq!( pool_events_since_last_call(), - vec![Event::Withdrawn { member: 10, pool_id: 1, amount: 6 }] + vec![Event::Withdrawn { member: 10, pool_id: 1, points: 6, balance: 6 }] ); // when @@ -2946,7 +2789,7 @@ mod withdraw_unbonded { assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); assert_eq!( pool_events_since_last_call(), - vec![Event::Withdrawn { member: 10, pool_id: 1, amount: 1 },] + vec![Event::Withdrawn { member: 10, pool_id: 1, points: 1, balance: 1 },] ); // when repeating: @@ -2986,8 +2829,8 @@ mod withdraw_unbonded { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 11, pool_id: 1, amount: 6 }, - Event::Unbonded { member: 11, pool_id: 1, amount: 1 } + Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 }, + Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 } ] ); @@ -3018,7 +2861,7 @@ mod withdraw_unbonded { ); assert_eq!( pool_events_since_last_call(), - vec![Event::Withdrawn { member: 11, pool_id: 1, amount: 6 }] + vec![Event::Withdrawn { member: 11, pool_id: 1, points: 6, balance: 6 }] ); // when @@ -3033,7 +2876,7 @@ mod withdraw_unbonded { assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); assert_eq!( pool_events_since_last_call(), - vec![Event::Withdrawn { member: 11, pool_id: 1, amount: 1 }] + vec![Event::Withdrawn { member: 11, pool_id: 1, points: 1, balance: 1 }] ); // when repeating: @@ -3076,9 +2919,9 @@ mod withdraw_unbonded { Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, amount: 75 }, - Event::Unbonded { member: 100, pool_id: 1, amount: 25 }, - Event::Withdrawn { member: 100, pool_id: 1, amount: 75 }, + Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 }, + Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 }, ] ); assert_eq!( @@ -3092,7 +2935,7 @@ mod withdraw_unbonded { assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 100, pool_id: 1, amount: 25 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 25, balance: 25 }, Event::MemberRemoved { pool_id: 1, member: 100 } ] ); @@ -3127,9 +2970,9 @@ mod withdraw_unbonded { vec![ Event::Created { depositor: 10, pool_id: 1 }, Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, amount: 7 }, - Event::Unbonded { member: 10, pool_id: 1, amount: 3 }, - Event::Withdrawn { member: 10, pool_id: 1, amount: 7 } + Event::Unbonded { member: 10, pool_id: 1, points: 7, balance: 7 }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, + Event::Withdrawn { member: 10, pool_id: 1, points: 7, balance: 7 } ] ); assert_eq!( @@ -3143,7 +2986,7 @@ mod withdraw_unbonded { assert_eq!( pool_events_since_last_call(), vec![ - Event::Withdrawn { member: 10, pool_id: 1, amount: 3 }, + Event::Withdrawn { member: 10, pool_id: 1, points: 3, balance: 3 }, Event::MemberRemoved { pool_id: 1, member: 10 }, // the pool is also destroyed now. Event::Destroyed { pool_id: 1 }, diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 2a14852ad11ec..c4ffdb8b59eb9 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -93,8 +93,8 @@ fn pool_lifecycle_e2e() { pool_events_since_last_call(), vec![ PoolsEvent::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, - PoolsEvent::Unbonded { member: 20, pool_id: 1, amount: 10 }, - PoolsEvent::Unbonded { member: 21, pool_id: 1, amount: 10 }, + PoolsEvent::Unbonded { member: 20, pool_id: 1, points: 10, balance: 10 }, + PoolsEvent::Unbonded { member: 21, pool_id: 1, points: 10, balance: 10 }, ] ); @@ -134,9 +134,9 @@ fn pool_lifecycle_e2e() { assert_eq!( pool_events_since_last_call(), vec![ - PoolsEvent::Withdrawn { member: 20, pool_id: 1, amount: 10 }, + PoolsEvent::Withdrawn { member: 20, pool_id: 1, points: 10, balance: 10 }, PoolsEvent::MemberRemoved { pool_id: 1, member: 20 }, - PoolsEvent::Withdrawn { member: 21, pool_id: 1, amount: 10 }, + PoolsEvent::Withdrawn { member: 21, pool_id: 1, points: 10, balance: 10 }, PoolsEvent::MemberRemoved { pool_id: 1, member: 21 }, ] ); @@ -157,7 +157,7 @@ fn pool_lifecycle_e2e() { ); assert_eq!( pool_events_since_last_call(), - vec![PoolsEvent::Unbonded { member: 10, pool_id: 1, amount: 50 }] + vec![PoolsEvent::Unbonded { member: 10, pool_id: 1, points: 50, balance: 50 }] ); // waiting another bonding duration: @@ -172,7 +172,7 @@ fn pool_lifecycle_e2e() { assert_eq!( pool_events_since_last_call(), vec![ - PoolsEvent::Withdrawn { member: 10, pool_id: 1, amount: 50 }, + PoolsEvent::Withdrawn { member: 10, pool_id: 1, points: 50, balance: 50 }, PoolsEvent::MemberRemoved { pool_id: 1, member: 10 }, PoolsEvent::Destroyed { pool_id: 1 } ] From 031040f5fdc5fd0548a5dec7398cfd64079a2de6 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 16 May 2022 23:27:28 +0100 Subject: [PATCH 08/65] Add more more sophisticated test + capture one more bug. --- frame/nomination-pools/src/lib.rs | 13 +- .../nomination-pools/test-staking/src/lib.rs | 198 +++++++++++++++++- .../nomination-pools/test-staking/src/mock.rs | 4 +- frame/staking/src/lib.rs | 8 +- 4 files changed, 214 insertions(+), 9 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index fc7306120054d..d2cdb9081332a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1303,6 +1303,10 @@ pub mod pallet { state_toggler: Option, nominator: Option, }, + /// The active balance of pool `pool_id` has been slashed to `balance`. + PoolSlashed { pool_id: PoolId, balance: BalanceOf }, + /// The unbond pool at `era` of pool `pool_id` has been slashed to `balance`. + UnbondingPoolSlashed { pool_id: PoolId, era: EraIndex, balance: BalanceOf }, } #[pallet::error] @@ -2412,9 +2416,16 @@ impl OnStakerSlash> for Pallet { }; for (era, slashed_balance) in slashed_unlocking.iter() { if let Some(pool) = sub_pools.with_era.get_mut(era) { - pool.balance = *slashed_balance + pool.balance = *slashed_balance; + Self::deposit_event(Event::::UnbondingPoolSlashed { + era: *era, + pool_id, + balance: *slashed_balance, + }); } } + + Self::deposit_event(Event::::PoolSlashed { pool_id, balance: _slashed_bonded }); SubPoolsStorage::::insert(pool_id, sub_pools); } } diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index c4ffdb8b59eb9..571e54bcbf0b8 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -19,12 +19,12 @@ mod mock; -use frame_support::{assert_noop, assert_ok, traits::Currency}; +use frame_support::{assert_noop, assert_ok, bounded_btree_map, traits::Currency}; use mock::*; use pallet_nomination_pools::{ - Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMembers, PoolState, + Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers, PoolState, }; -use pallet_staking::{CurrentEra, Event as StakingEvent}; +use pallet_staking::{CurrentEra, Event as StakingEvent, Ledger, Payee, RewardDestination}; #[test] fn pool_lifecycle_e2e() { @@ -179,3 +179,195 @@ fn pool_lifecycle_e2e() { ); }) } + +#[test] +fn pool_slash_e2e() { + new_test_ext().execute_with(|| { + ExistentialDeposit::set(1); + assert_eq!(Balances::minimum_balance(), 1); + assert_eq!(Staking::current_era(), None); + + // create the pool, we know this has id 1. + assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10)); + assert_eq!(LastPoolId::::get(), 1); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Created { depositor: 10, pool_id: 1 }, + PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 40, joined: true }, + ] + ); + + assert_eq!(Payee::::get(POOL1_BONDED), RewardDestination::Account(POOL1_REWARD)); + + // have two members join + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + assert_ok!(Pools::join(Origin::signed(21), 20, 1)); + + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Bonded(POOL1_BONDED, 20), StakingEvent::Bonded(POOL1_BONDED, 20)] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + PoolsEvent::Bonded { member: 21, pool_id: 1, bonded: 20, joined: true }, + ] + ); + + // now let's progress a bit. + CurrentEra::::set(Some(1)); + + // 20 / 80 of the total funds are unlocked, and safe from any further slash. + assert_ok!(Pools::unbond(Origin::signed(10), 10, 10)); + assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); + + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Unbonded(POOL1_BONDED, 10), + StakingEvent::Unbonded(POOL1_BONDED, 10) + ] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10 }, + PoolsEvent::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 } + ] + ); + + CurrentEra::::set(Some(2)); + + // note: depositor cannot fully unbond at this point. + // these funds will still get slashed. + assert_ok!(Pools::unbond(Origin::signed(10), 10, 10)); + assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); + assert_ok!(Pools::unbond(Origin::signed(21), 21, 10)); + + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Unbonded(POOL1_BONDED, 10), + StakingEvent::Unbonded(POOL1_BONDED, 10), + StakingEvent::Unbonded(POOL1_BONDED, 10), + ] + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10 }, + PoolsEvent::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 }, + PoolsEvent::Unbonded { member: 21, pool_id: 1, balance: 10, points: 10 }, + ] + ); + + // At this point, 20 are safe from slash, 30 are unlocking but vulnerable to slash, and and + // another 30 are active and vulnerable to slash. Let's slash half of them. + pallet_staking::slashing::do_slash::( + &POOL1_BONDED, + 30, + &mut Default::default(), + &mut Default::default(), + 1, // slash era 1, affects chunks at era 5 onwards. + ); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 30)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + // 30 has been slashed to 15 (15 slash) + PoolsEvent::UnbondingPoolSlashed { pool_id: 1, era: 5, balance: 15 }, + // 30 has been slashed to 15 (15 slash) + PoolsEvent::PoolSlashed { pool_id: 1, balance: 15 } + ] + ); + + CurrentEra::::set(Some(3)); + assert_ok!(Pools::unbond(Origin::signed(21), 21, 10)); + + assert_eq!( + PoolMembers::::get(21).unwrap(), + PoolMember { + pool_id: 1, + points: 0, + reward_pool_total_earnings: 0, + // the 10 points unlocked just now correspond to 5 points in the unbond pool. + unbonding_eras: bounded_btree_map!(5 => 10, 6 => 5) + } + ); + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Unbonded(POOL1_BONDED, 5)]); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 21, pool_id: 1, balance: 5, points: 5 }] + ); + + // now we start withdrawing. we do it all at once, at era 6 where 20 and 21 are fully free. + CurrentEra::::set(Some(6)); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(20), 20, 0)); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(21), 21, 0)); + + assert_eq!( + pool_events_since_last_call(), + vec![ + // 20 had unbonded 10 safely, and 10 got slashed by half. + PoolsEvent::Withdrawn { member: 20, pool_id: 1, balance: 10 + 5, points: 20 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 20 }, + // 21 unbonded all of it after the slash + PoolsEvent::Withdrawn { member: 21, pool_id: 1, balance: 5 + 5, points: 15 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 21 } + ] + ); + assert_eq!( + staking_events_since_last_call(), + // a 10 (un-slashed) + 10/2 (slashed) balance from 10 has also been unlocked + vec![StakingEvent::Withdrawn(POOL1_BONDED, 15 + 10 + 15)] + ); + + // now, finally, we can unbond the depositor further than their current limit. + assert_ok!(Pools::set_state(Origin::signed(10), 1, PoolState::Destroying)); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 20)); + + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, 10)] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, + PoolsEvent::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } + ] + ); + + CurrentEra::::set(Some(9)); + assert_eq!( + PoolMembers::::get(10).unwrap(), + PoolMember { + pool_id: 1, + points: 0, + reward_pool_total_earnings: 0, + unbonding_eras: bounded_btree_map!(4 => 10, 5 => 10, 9 => 10) + } + ); + // withdraw the depositor, they should lose 12 balance in total due to slash. + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Withdrawn(POOL1_BONDED, 10)] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Withdrawn { member: 10, pool_id: 1, balance: 10 + 15, points: 30 }, + PoolsEvent::MemberRemoved { pool_id: 1, member: 10 }, + PoolsEvent::Destroyed { pool_id: 1 } + ] + ); + }); +} diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index ceb0cf0371df2..a8710f261f212 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -25,6 +25,7 @@ type BlockNumber = u64; type Balance = u128; pub(crate) const POOL1_BONDED: AccountId = 20318131474730217858575332831085u128; +pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128; impl frame_system::Config for Runtime { type BaseCallFilter = frame_support::traits::Everything; @@ -204,7 +205,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .unwrap(); let _ = pallet_balances::GenesisConfig:: { - balances: vec![(10, 100), (20, 100), (21, 100)], + balances: vec![(10, 100), (20, 100), (21, 100), (22, 100)], } .assimilate_storage(&mut storage) .unwrap(); @@ -233,6 +234,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { parameter_types! { static ObservedEventsPools: usize = 0; static ObservedEventsStaking: usize = 0; + static ObservedEventsBalances: usize = 0; } pub(crate) fn pool_events_since_last_call() -> Vec> { diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index c4ec1dbc0e1e8..cb143fc715909 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -539,7 +539,7 @@ impl StakingLedger { /// /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was /// applied. - fn slash( + pub fn slash( &mut self, slash_amount: BalanceOf, minimum_balance: BalanceOf, @@ -607,12 +607,12 @@ impl StakingLedger { let mut slashed_unlocking = BTreeMap::<_, _>::new(); for i in slash_chunks_priority { if let Some(chunk) = self.unlocking.get_mut(i).defensive() { - slash_out_of(&mut chunk.value, &mut remaining_slash); - // write the new slashed value of this chunk to the map. - slashed_unlocking.insert(chunk.era, chunk.value); if remaining_slash.is_zero() { break } + slash_out_of(&mut chunk.value, &mut remaining_slash); + // write the new slashed value of this chunk to the map. + slashed_unlocking.insert(chunk.era, chunk.value); } else { break } From efc7b4f1867a82d305c9e8d80cbb0aa93386614e Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 16 May 2022 23:35:22 +0100 Subject: [PATCH 09/65] Update frame/staking/src/lib.rs --- frame/staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index cb143fc715909..1dfe9f04033fa 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -539,7 +539,7 @@ impl StakingLedger { /// /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was /// applied. - pub fn slash( + fn slash( &mut self, slash_amount: BalanceOf, minimum_balance: BalanceOf, From 60d42f1691aedff592272e812a69cb34747fdfc6 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 17 May 2022 10:59:03 +0100 Subject: [PATCH 10/65] reduce the diff a little bit --- frame/nomination-pools/src/lib.rs | 16 +++++++++++++++- frame/nomination-pools/src/mock.rs | 2 +- frame/staking/src/lib.rs | 3 ++- frame/staking/src/pallet/impls.rs | 22 +++++++++++----------- primitives/staking/src/lib.rs | 4 ++-- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d2cdb9081332a..c80d87e895723 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -447,7 +447,11 @@ impl PoolMember { .fold(BalanceOf::::zero(), |acc, (_, v)| acc.saturating_add(*v)) } - /// Try and unbond `points` from self, with the given target unbonding era. + /// Try and unbond `points_dissolved` from self, and in return mint `points_issued` into the + /// corresponding `era`. + /// + /// In the absence of slashing, these two points are always the same. In the presence of + /// slashing, the value of points in different pools varies. /// /// Returns `Ok(())` and updates `unbonding_eras` and `points` if success, `Err(_)` otherwise. fn try_unbond( @@ -1309,6 +1313,8 @@ pub mod pallet { UnbondingPoolSlashed { pool_id: PoolId, era: EraIndex, balance: BalanceOf }, } + #[cfg_attr(test, derive(PartialEq))] + pub enum InnerError {} #[pallet::error] #[cfg_attr(test, derive(PartialEq))] pub enum Error { @@ -1562,6 +1568,7 @@ pub mod pallet { .try_insert(unbond_era, UnbondPool::default()) // The above call to `maybe_merge_pools` should ensure there is // always enough space to insert. + // TODO: make this visible and transparent #11439 .defensive_map_err(|_| Error::::DefensiveError)?; } @@ -1667,6 +1674,13 @@ pub mod pallet { num_slashing_spans, )?; + // defensive-only: the depositor puts enough funds into the stash so that it will only + // be destroyed when they are leaving. + ensure!( + !destroyed || caller == bonded_pool.roles.depositor, + Error::::DefensiveError + ); + let mut sum_unlocked_points: BalanceOf = Zero::zero(); let balance_to_unbond = withdrawn_points .iter() diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 4c47fce261dac..fe0ab8ab3bc14 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -93,7 +93,7 @@ impl sp_staking::StakingInterface for StakingMock { x.remove(&who); UnbondingBalanceMap::set(&x); - Ok(UnbondingBalanceMap::get().is_empty()) + Ok(UnbondingBalanceMap::get().is_empty() && BondedBalanceMap::get().is_empty()) } fn bond( diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index cb143fc715909..f5d9b112d55ad 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -539,7 +539,7 @@ impl StakingLedger { /// /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was /// applied. - pub fn slash( + fn slash( &mut self, slash_amount: BalanceOf, minimum_balance: BalanceOf, @@ -608,6 +608,7 @@ impl StakingLedger { for i in slash_chunks_priority { if let Some(chunk) = self.unlocking.get_mut(i).defensive() { if remaining_slash.is_zero() { + // TODO: test for this fix in the staking pallet. break } slash_out_of(&mut chunk.value, &mut remaining_slash); diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 04f4cbd2f18c2..9f8d5aeab7785 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -1386,32 +1386,32 @@ impl StakingInterface for Pallet { Self::current_era().unwrap_or(Zero::zero()) } - fn active_stake(stash: &Self::AccountId) -> Option { - Self::ledger(stash).map(|l| l.active) + fn active_stake(controller: &Self::AccountId) -> Option { + Self::ledger(controller).map(|l| l.active) } - fn total_stake(stash: &Self::AccountId) -> Option { - Self::ledger(stash).map(|l| l.total) + fn total_stake(controller: &Self::AccountId) -> Option { + Self::ledger(controller).map(|l| l.total) } fn bond_extra(stash: Self::AccountId, extra: Self::Balance) -> DispatchResult { Self::bond_extra(RawOrigin::Signed(stash).into(), extra) } - fn unbond(stash: Self::AccountId, value: Self::Balance) -> DispatchResult { - Self::unbond(RawOrigin::Signed(stash).into(), value) + fn unbond(controller: Self::AccountId, value: Self::Balance) -> DispatchResult { + Self::unbond(RawOrigin::Signed(controller).into(), value) } - fn chill(stash: Self::AccountId) -> DispatchResult { - Self::chill(RawOrigin::Signed(stash).into()) + fn chill(controller: Self::AccountId) -> DispatchResult { + Self::chill(RawOrigin::Signed(controller).into()) } fn withdraw_unbonded( - stash: Self::AccountId, + controller: Self::AccountId, num_slashing_spans: u32, ) -> Result { - Self::withdraw_unbonded(RawOrigin::Signed(stash.clone()).into(), num_slashing_spans) - .map(|_| Ledger::::contains_key(&stash)) + Self::withdraw_unbonded(RawOrigin::Signed(controller.clone()).into(), num_slashing_spans) + .map(|_| !Ledger::::contains_key(&controller)) .map_err(|with_post| with_post.error) } diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index e4e794e275048..be6a6d6986dd9 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -104,12 +104,12 @@ pub trait StakingInterface { /// Have `stash` nominate `validators`. fn nominate( - stash: Self::AccountId, + controller: Self::AccountId, validators: sp_std::vec::Vec, ) -> DispatchResult; /// Chill `stash`. - fn chill(stash: Self::AccountId) -> DispatchResult; + fn chill(controller: Self::AccountId) -> DispatchResult; /// Bond some extra amount in the _Stash_'s free balance against the active bonded balance of /// the account. The amount extra actually bonded will never be more than the _Stash_'s free From 02aa7d48e5d757c926b7b6e1bb1a015fbf20b3c4 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 19 May 2022 14:55:51 +0100 Subject: [PATCH 11/65] add some test for the slashing bug --- .../nomination-pools/test-staking/src/lib.rs | 2 +- frame/staking/src/lib.rs | 7 +++++-- frame/staking/src/tests.rs | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 571e54bcbf0b8..2e40e8c6d917d 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -24,7 +24,7 @@ use mock::*; use pallet_nomination_pools::{ Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers, PoolState, }; -use pallet_staking::{CurrentEra, Event as StakingEvent, Ledger, Payee, RewardDestination}; +use pallet_staking::{CurrentEra, Event as StakingEvent, Payee, RewardDestination}; #[test] fn pool_lifecycle_e2e() { diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index f5d9b112d55ad..37ef4d9cb4f8d 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -608,7 +608,6 @@ impl StakingLedger { for i in slash_chunks_priority { if let Some(chunk) = self.unlocking.get_mut(i).defensive() { if remaining_slash.is_zero() { - // TODO: test for this fix in the staking pallet. break } slash_out_of(&mut chunk.value, &mut remaining_slash); @@ -619,9 +618,13 @@ impl StakingLedger { } } + // clear leftover chunks.. self.unlocking.retain(|c| !c.value.is_zero()); + // report this slash.. T::OnStakerSlash::on_slash(&self.stash, self.active, &slashed_unlocking); - pre_slash_total.saturating_sub(self.total) + // and report the final grand total slash amount. + let final_effective_slash = pre_slash_total.saturating_sub(self.total); + final_effective_slash } } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index ccd9558c5c21d..3c12aaa1290bd 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -4929,6 +4929,25 @@ fn force_apply_min_commission_works() { }); } +#[test] +fn proportional_slash_stop_slashing_if_remaining_zero() { + let c = |era, value| UnlockChunk:: { era, value }; + // Given + let mut ledger = StakingLedger:: { + stash: 123, + total: 40, + active: 20, + // we have some chunks, but they are not affected. + unlocking: bounded_vec![c(1, 10), c(2, 10)], + claimed_rewards: vec![], + }; + + assert_eq!(BondingDuration::get(), 3); + + // should not slash more than the amount requested, by accidentally slashing the first chunk. + assert_eq!(ledger.slash(18, 1, 0), 18); +} + #[test] fn proportional_ledger_slash_works() { let c = |era, value| UnlockChunk:: { era, value }; From 90db26e6318a8980e5c7f471e71679c8c4a602b5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 19 May 2022 18:28:31 +0200 Subject: [PATCH 12/65] cleanup --- frame/nomination-pools/src/lib.rs | 37 +++++++++++-------------------- frame/staking/src/lib.rs | 6 +---- primitives/staking/src/lib.rs | 4 ++-- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index c80d87e895723..cac74ed14fa3b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -448,7 +448,7 @@ impl PoolMember { } /// Try and unbond `points_dissolved` from self, and in return mint `points_issued` into the - /// corresponding `era`. + /// corresponding `era`'s unlock schedule. /// /// In the absence of slashing, these two points are always the same. In the presence of /// slashing, the value of points in different pools varies. @@ -988,7 +988,7 @@ impl UnbondPool { Pallet::::point_to_balance(self.balance, self.points, points) } - /// Issue points and update the balance given `new_balance`. + /// Issue the equivalent points of `new_funds` into self. /// /// Returns the actual amounts of points issued. fn issue(&mut self, new_funds: BalanceOf) -> BalanceOf { @@ -1153,12 +1153,6 @@ pub mod pallet { /// /// This is the value that will always exist in the staking ledger of the pool bonded account /// while all other accounts leave. - /// - /// A sane configuration should thus ensure that this value is large enough such that it is more - /// than `MinimumNominatorBond` and `ExistentialDeposit`. The pool's bonded account's stash - /// falling behind `MinimumNominatorBond` it cannot call unbond, and the pool bonded account's - /// stash falling below `ExistentialDeposit` means the ledger can be killed prematurely in a - /// call to `T::StakingInterface::withdraw_unbonded`. #[pallet::storage] pub type MinCreateBond = StorageValue<_, BalanceOf, ValueQuery>; @@ -1266,11 +1260,10 @@ pub mod pallet { PaidOut { member: T::AccountId, pool_id: PoolId, payout: BalanceOf }, /// A member has unbonded from their pool. /// - /// - `balance` is the corresponding balance of the number of points that have been - /// requested to be unbonded (the argument of the `unbond` transaction) from the bonded - /// pool. - /// - `points` is the number of points that are issued as a result of - /// `balance` into the corresponding unbonding pool. + /// - `balance` is the corresponding balance of the number of points that has been requested + /// to be unbonded (the argument of the `unbond` transaction) from the bonded pool. + /// - `points` is the number of points that are issued as a result of `balance` being + /// dissolved into the corresponding unbonding pool. /// /// In the absence of slashing, these values will match. In the presence of slashing, the /// number of points that are issued in the unbonding pool will be less than the amount @@ -1285,7 +1278,8 @@ pub mod pallet { /// /// The given number of `points` have been dissolved in return of `balance`. /// - /// Similar to `Unbonded` event, in the absence of slashing, these values will match. + /// Similar to `Unbonded` event, in the absence of slashing, the ratio of point to balance + /// will be 1. Withdrawn { member: T::AccountId, pool_id: PoolId, @@ -1313,8 +1307,6 @@ pub mod pallet { UnbondingPoolSlashed { pool_id: PoolId, era: EraIndex, balance: BalanceOf }, } - #[cfg_attr(test, derive(PartialEq))] - pub enum InnerError {} #[pallet::error] #[cfg_attr(test, derive(PartialEq))] pub enum Error { @@ -1329,8 +1321,6 @@ pub mod pallet { /// An account is already delegating in another pool. An account may only belong to one /// pool at a time. AccountBelongsToOtherPool, - /// The member is already unbonding in this era. - AlreadyUnbonding, /// The member is fully unbonded (and thus cannot access the bonded and reward pool /// anymore to, for example, collect rewards). FullyUnbonding, @@ -1499,7 +1489,7 @@ pub mod pallet { /// Unbond up to `unbonding_points` of the `member_account`'s funds from the pool. It /// implicitly collects the rewards one last time, since not doing so would mean some - /// rewards would go forfeited. + /// rewards would be forfeited. /// /// Under certain conditions, this call can be dispatched permissionlessly (i.e. by any /// account). @@ -1568,11 +1558,11 @@ pub mod pallet { .try_insert(unbond_era, UnbondPool::default()) // The above call to `maybe_merge_pools` should ensure there is // always enough space to insert. - // TODO: make this visible and transparent #11439 + // TODO: make this error type transparent #11439 .defensive_map_err(|_| Error::::DefensiveError)?; } - let actual_unbonding_points = sub_pools + let points_unbonded = sub_pools .with_era .get_mut(&unbond_era) // The above check ensures the pool exists. @@ -1580,12 +1570,12 @@ pub mod pallet { .issue(unbonding_balance); // Try and unbond in the member map. - member.try_unbond(unbonding_points, actual_unbonding_points, unbond_era)?; + member.try_unbond(unbonding_points, points_unbonded, unbond_era)?; Self::deposit_event(Event::::Unbonded { member: member_account.clone(), pool_id: member.pool_id, - points: actual_unbonding_points, + points: points_unbonded, balance: unbonding_balance, }); @@ -2329,7 +2319,6 @@ impl Pallet { if level.is_zero() { return Ok(()) } - // note: while a bit wacky, since they have the same key, even collecting to vec should // result in the same set of keys, in the same order. let bonded_pools = BondedPools::::iter_keys().collect::>(); diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 37ef4d9cb4f8d..1dfe9f04033fa 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -618,13 +618,9 @@ impl StakingLedger { } } - // clear leftover chunks.. self.unlocking.retain(|c| !c.value.is_zero()); - // report this slash.. T::OnStakerSlash::on_slash(&self.stash, self.active, &slashed_unlocking); - // and report the final grand total slash amount. - let final_effective_slash = pre_slash_total.saturating_sub(self.total); - final_effective_slash + pre_slash_total.saturating_sub(self.total) } } diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index be6a6d6986dd9..50abfb0121621 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -93,7 +93,7 @@ pub trait StakingInterface { /// non-staking locks on the bonded pair's balance this may not be accurate. fn total_stake(stash: &Self::AccountId) -> Option; - /// Bond (lock) `value` of `stash`'s balance. `stash` will be set as the account + /// Bond (lock) `value` of `stash`'s balance. `controller` will be set as the account /// controlling `stash`. This creates what is referred to as "bonded pair". fn bond( stash: Self::AccountId, @@ -102,7 +102,7 @@ pub trait StakingInterface { payee: Self::AccountId, ) -> DispatchResult; - /// Have `stash` nominate `validators`. + /// Have `controller` nominate `validators`. fn nominate( controller: Self::AccountId, validators: sp_std::vec::Vec, From a51e408515a4ffb32dca44723ec62cc519d70319 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 20 May 2022 13:10:36 +0200 Subject: [PATCH 13/65] fix lock file? --- Cargo.lock | 1434 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 826 insertions(+), 608 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 536c89d2ddb64..47d5aecd87eeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,30 +29,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aead" -version = "0.4.3" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +checksum = "6e3e798aa0c8239776f54415bc06f3d74b1850f3f830b45c35cfc80556973f70" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] name = "aes" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +checksum = "495ee669413bfbe9e8cace80f4d3d78e6d8c8d99579f97fb93bde351b185f2d4" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", ] [[package]] name = "aes-gcm" -version = "0.9.4" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +checksum = "b2a930fd487faaa92a30afa92cc9dd1526a5cff67124abbbb1c617ce070f4dcf" dependencies = [ "aead", "aes", @@ -68,7 +68,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.3", "once_cell", "version_check", ] @@ -93,24 +93,24 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" [[package]] name = "approx" -version = "0.5.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +checksum = "072df7202e63b127ab55acfe16ce97013d5b97bf160489336d3f1840fd78e99e" dependencies = [ "num-traits", ] [[package]] name = "arbitrary" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c38b6b6b79f671c25e1a3e785b7b82d7562ffc9cd3efdc98627e5668a2472490" +checksum = "698b65a961a9d730fb45b6b0327e20207810c9f61ee421b082b27ba003f49e2b" [[package]] name = "arrayref" @@ -135,21 +135,21 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd" [[package]] name = "asn1_der" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" +checksum = "9d6e24d2cce90c53b948c46271bfb053e4bdc2db9b5d3f65e20f8cf28a1b7fc3" [[package]] name = "assert_cmd" -version = "2.0.4" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e" +checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2" dependencies = [ "bstr", "doc-comment", @@ -188,23 +188,23 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.4.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", "once_cell", - "slab", + "vec-arena", ] [[package]] name = "async-global-executor" -version = "2.0.4" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43" +checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" dependencies = [ "async-channel", "async-executor", @@ -230,7 +230,7 @@ dependencies = [ "parking", "polling", "slab", - "socket2", + "socket2 0.4.4", "waker-fn", "winapi", ] @@ -293,7 +293,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "pin-utils", "slab", "wasm-bindgen-futures", @@ -310,15 +310,15 @@ dependencies = [ "futures-io", "futures-util", "pin-utils", - "socket2", + "socket2 0.4.4", "trust-dns-resolver", ] [[package]] name = "async-stream" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" dependencies = [ "async-stream-impl", "futures-core", @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "async-stream-impl" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" dependencies = [ "proc-macro2", "quote", @@ -337,15 +337,15 @@ dependencies = [ [[package]] name = "async-task" -version = "4.2.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" [[package]] name = "async-trait" -version = "0.1.53" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" dependencies = [ "proc-macro2", "quote", @@ -362,16 +362,16 @@ dependencies = [ "futures-sink", "futures-util", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", ] [[package]] name = "atomic" -version = "0.5.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" +checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" dependencies = [ - "autocfg", + "autocfg 1.0.1", ] [[package]] @@ -393,30 +393,36 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" +checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.28.4", + "object 0.27.1", "rustc-demangle", ] [[package]] name = "base-x" -version = "0.2.10" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" [[package]] name = "base16ct" @@ -539,16 +545,17 @@ dependencies = [ [[package]] name = "bimap" -version = "0.6.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0455254eb5c6964c4545d8bac815e1a1be4f3afe0ae695ea539c12d728d44b" +checksum = "50ae17cabbc8a38a1e3e4c1a6a664e9a09672dc14d0896fa8d865d3a5a446b07" [[package]] name = "bincode" -version = "1.3.3" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +checksum = "d175dfa69e619905c4c3cdb7c3c203fa3bdd5d51184e3afdb2742c0280493772" dependencies = [ + "byteorder", "serde", ] @@ -591,9 +598,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.4" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +checksum = "b94ba84325db59637ffc528bbe8c7f86c02c57cff5c0e2b9b00f9a851f42f309" dependencies = [ "digest 0.10.3", ] @@ -615,7 +622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "constant_time_eq", ] @@ -626,7 +633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "constant_time_eq", ] @@ -637,7 +644,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "cc", "cfg-if 1.0.0", "constant_time_eq", @@ -662,16 +669,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding 0.2.1", - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -691,9 +698,9 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.2.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" dependencies = [ "async-channel", "async-task", @@ -711,9 +718,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.17" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" dependencies = [ "lazy_static", "memchr", @@ -732,15 +739,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.9.1" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byte-slice-cast" -version = "1.2.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" +checksum = "65c1bf4a04a88c54f589125563643d773f3254b5c38571395e2b591c693bbc81" [[package]] name = "byte-tools" @@ -750,9 +757,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytecheck" -version = "0.6.8" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a31f923c2db9513e4298b72df143e6e655a759b3d6a0966df18f81223fff54f" +checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -760,9 +767,9 @@ dependencies = [ [[package]] name = "bytecheck_derive" -version = "0.6.8" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb17c862a905d912174daa27ae002326fff56dc8b8ada50a0a5f0976cb174f0" +checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" dependencies = [ "proc-macro2", "quote", @@ -771,9 +778,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" @@ -794,24 +801,24 @@ dependencies = [ [[package]] name = "cache-padded" -version = "1.2.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "camino" -version = "1.0.8" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fd178c5af4d59e83498ef15cf3f154e1a6f9d091270cb86283c65ef44e9ef0" +checksum = "d4648c6d00a709aa069a236adcaae4f605a6241c72bf5bee79331a4b625921a9" dependencies = [ "serde", ] [[package]] name = "cargo-platform" -version = "0.1.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" dependencies = [ "serde", ] @@ -824,25 +831,25 @@ checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.9", + "semver 1.0.4", "serde", "serde_json", ] [[package]] name = "cast" -version = "0.2.7" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" +checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" dependencies = [ - "rustc_version 0.4.0", + "rustc_version 0.2.3", ] [[package]] name = "cc" -version = "1.0.73" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" dependencies = [ "jobserver", ] @@ -876,7 +883,7 @@ checksum = "01b72a433d0cf2aef113ba70f62634c56fddb0f244e6377185c56a7cadbd8f91" dependencies = [ "cfg-if 1.0.0", "cipher", - "cpufeatures", + "cpufeatures 0.2.1", "zeroize", ] @@ -900,7 +907,7 @@ dependencies = [ "ansi_term", "clap 3.1.18", "node-cli", - "rand 0.8.5", + "rand 0.8.4", "sc-chain-spec", "sc-keystore", "sp-core", @@ -939,7 +946,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -953,13 +960,13 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.3.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" +checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" dependencies = [ "glob", "libc", - "libloading 0.7.3", + "libloading 0.7.0", ] [[package]] @@ -992,9 +999,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.1.4" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" +checksum = "a394f7ec0715b42a4e52b294984c27c9a61f77c8d82f7774c5198350be143f19" dependencies = [ "clap 3.1.18", ] @@ -1089,22 +1096,38 @@ dependencies = [ [[package]] name = "cpp_demangle" -version = "0.3.5" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +checksum = "44919ecaf6f99e8e737bc239408931c9a01e9a6c74814fee8242dd2506b65390" dependencies = [ "cfg-if 1.0.0", + "glob", ] [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" dependencies = [ "libc", ] +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + [[package]] name = "cranelift-bforest" version = "0.76.0" @@ -1256,9 +1279,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ "cfg-if 1.0.0", ] @@ -1303,9 +1326,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1324,11 +1347,10 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ - "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", @@ -1338,9 +1360,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1358,8 +1380,8 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.5", - "rand_core 0.6.3", + "generic-array 0.14.4", + "rand_core 0.6.2", "subtle", "zeroize", ] @@ -1370,7 +1392,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "typenum", ] @@ -1380,7 +1402,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -1390,7 +1412,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -1418,9 +1440,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" dependencies = [ "quote", "syn", @@ -1448,9 +1470,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "2.1.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9b85542f99a2dfa2a1b8e192662741c9859a846b296bef1c92ef9b58b5a216" +checksum = "434e1720189a637d44fe464f4df1e6eb900b4835255b14354497c78af37d9bb8" dependencies = [ "byteorder", "digest 0.8.1", @@ -1461,9 +1483,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "f627126b946c25a4638eec0ea634fc52506dea98db118aae985118ce7c3d723f" dependencies = [ "byteorder", "digest 0.9.0", @@ -1480,16 +1502,16 @@ checksum = "4033478fbf70d6acf2655ac70da91ee65852d69daf7a67bf7a2f518fb47aafcf" dependencies = [ "byteorder", "digest 0.9.0", - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", "zeroize", ] [[package]] name = "darling" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" dependencies = [ "darling_core", "darling_macro", @@ -1497,22 +1519,23 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", + "strsim", "syn", ] [[package]] name = "darling_macro" -version = "0.13.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" dependencies = [ "darling_core", "quote", @@ -1527,9 +1550,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "data-encoding-macro" -version = "0.1.12" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86927b7cd2fe88fa698b87404b287ab98d1a0063a34071d92e575b72d3029aca" +checksum = "0a94feec3d2ba66c0b6621bca8bc6f68415b1e5c69af3586fdd0af9fd9f29b17" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -1537,9 +1560,9 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5bbed42daaa95e780b60a50546aa345b8413a1e46f9a40a12907d3598f038db" +checksum = "f0f83e699727abca3c56e187945f303389590305ab2f0185ea445aa66e8d5f2a" dependencies = [ "data-encoding", "syn", @@ -1592,7 +1615,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", ] [[package]] @@ -1601,7 +1624,7 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.0", "crypto-common", "subtle", ] @@ -1627,9 +1650,9 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.7" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" dependencies = [ "libc", "redox_users", @@ -1649,9 +1672,9 @@ dependencies = [ [[package]] name = "dissimilar" -version = "1.0.4" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" +checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb" [[package]] name = "dns-parser" @@ -1731,7 +1754,7 @@ checksum = "64fba5a42bd76a17cad4bfa00de168ee1cbfa06a5e8ce992ae880218c05641a9" dependencies = [ "byteorder", "dynasm", - "memmap2 0.5.3", + "memmap2 0.5.0", ] [[package]] @@ -1748,9 +1771,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d916019f70ae3a1faa1195685e290287f39207d38e6dfee727197cffcc002214" +checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef" dependencies = [ "signature", ] @@ -1761,11 +1784,11 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "ed25519", "rand 0.7.3", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "zeroize", ] @@ -1785,9 +1808,9 @@ dependencies = [ "crypto-bigint", "der", "ff", - "generic-array 0.14.5", + "generic-array 0.14.4", "group", - "rand_core 0.6.3", + "rand_core 0.6.2", "sec1", "subtle", "zeroize", @@ -1827,9 +1850,9 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" +checksum = "1b3ab37dc79652c9d85f1f7b6070d77d321d2467f5fe7b00d6b7a86c57b092ae" dependencies = [ "enumflags2_derive", ] @@ -1847,18 +1870,18 @@ dependencies = [ [[package]] name = "enumset" -version = "1.0.11" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4799cdb24d48f1f8a7a98d06b7fde65a85a2d1e42b25a889f5406aa1fbefe074" +checksum = "7e76129da36102af021b8e5000dab2c1c30dbef85c1e482beeff8da5dde0e0b0" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" -version = "0.6.0" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea83a3fbdc1d999ccfbcbee717eab36f8edf2d71693a23ce0d7cca19e085304c" +checksum = "6451128aa6655d880755345d085494cf7561a6bee7c8dc821e5d77e6d267ecd4" dependencies = [ "darling", "proc-macro2", @@ -1886,7 +1909,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime", + "humantime 2.1.0", "log", "regex", "termcolor", @@ -1911,19 +1934,19 @@ dependencies = [ [[package]] name = "errno-dragonfly" -version = "0.1.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" dependencies = [ - "cc", + "gcc", "libc", ] [[package]] name = "event-listener" -version = "2.5.2" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] name = "exit-future" @@ -1966,21 +1989,21 @@ dependencies = [ [[package]] name = "ff" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "131655483be284720a17d74ff97592b8e76576dc25563148601df2d7c9080924" +checksum = "b2958d04124b9f27f175eaeb9a9f383d026098aa837eadd8ba22c11f13a05b9e" dependencies = [ - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", ] [[package]] name = "file-per-thread-logger" -version = "0.1.5" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e16290574b39ee41c71aeb90ae960c504ebaf1e2a1c87bd52aa56ed6e1a02f" +checksum = "4fdbe0d94371f9ce939b555dd342d0686cc4c0cadbcd4b61d70af5ff97eb4126" dependencies = [ - "env_logger 0.9.0", + "env_logger 0.7.1", "log", ] @@ -1997,7 +2020,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.11.2", - "rand 0.8.5", + "rand 0.8.4", "scale-info", ] @@ -2008,22 +2031,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" dependencies = [ "byteorder", - "rand 0.8.5", + "rand 0.8.4", "rustc-hex", "static_assertions", ] [[package]] name = "fixedbitset" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" +checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" [[package]] name = "flate2" -version = "1.0.23" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ "cfg-if 1.0.0", "crc32fast", @@ -2065,7 +2088,7 @@ dependencies = [ "linregress", "log", "parity-scale-codec", - "paste 1.0.7", + "paste 1.0.6", "scale-info", "serde", "sp-api", @@ -2171,7 +2194,7 @@ dependencies = [ "frame-support", "honggfuzz", "parity-scale-codec", - "rand 0.8.5", + "rand 0.8.4", "scale-info", "sp-arithmetic", "sp-npos-elections", @@ -2225,7 +2248,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parity-util-mem", - "paste 1.0.7", + "paste 1.0.6", "pretty_assertions", "scale-info", "serde", @@ -2400,6 +2423,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "funty" version = "2.0.0" @@ -2457,16 +2486,16 @@ checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" -version = "1.12.0" +version = "1.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", "parking", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "waker-fn", ] @@ -2523,11 +2552,17 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "pin-utils", "slab", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "generate-bags" version = "4.0.0-dev" @@ -2553,9 +2588,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", "version_check", @@ -2576,9 +2611,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.6" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2587,9 +2622,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" +checksum = "b442c439366184de619215247d24e908912b175e824a530253845ac4c251a5c1" dependencies = [ "opaque-debug 0.3.0", "polyval", @@ -2638,9 +2673,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "globset" -version = "0.4.8" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +checksum = "c152169ef1e421390738366d2f796655fec62621dabbd0fd476f905934061e4a" dependencies = [ "aho-corasick", "bstr", @@ -2651,14 +2686,15 @@ dependencies = [ [[package]] name = "gloo-timers" -version = "0.2.4" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", + "web-sys", ] [[package]] @@ -2668,15 +2704,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "ff", - "rand_core 0.6.3", + "rand_core 0.6.2", "subtle", ] [[package]] name = "h2" -version = "0.3.13" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd" dependencies = [ "bytes", "fnv", @@ -2687,15 +2723,15 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util", + "tokio-util 0.6.7", "tracing", ] [[package]] name = "half" -version = "1.8.2" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "handlebars" @@ -2706,7 +2742,7 @@ dependencies = [ "log", "pest", "pest_derive", - "quick-error 2.0.1", + "quick-error 2.0.0", "serde", "serde_json", ] @@ -2737,18 +2773,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" dependencies = [ "ahash", ] [[package]] name = "heck" -version = "0.3.3" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" dependencies = [ "unicode-segmentation", ] @@ -2761,9 +2797,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -2813,7 +2849,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.5", + "generic-array 0.14.4", "hmac 0.8.1", ] @@ -2841,37 +2877,46 @@ dependencies = [ [[package]] name = "http" -version = "0.2.7" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ "bytes", "fnv", - "itoa 1.0.1", + "itoa 0.4.8", ] [[package]] name = "http-body" -version = "0.4.4" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ "bytes", "http", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", ] [[package]] name = "httparse" -version = "1.7.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" + +[[package]] +name = "humantime" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error 1.2.3", +] [[package]] name = "humantime" @@ -2881,9 +2926,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.18" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -2894,9 +2939,9 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.1", - "pin-project-lite 0.2.9", - "socket2", + "itoa 0.4.8", + "pin-project-lite 0.2.6", + "socket2 0.4.4", "tokio", "tower-service", "tracing", @@ -2974,9 +3019,9 @@ dependencies = [ [[package]] name = "impl-serde" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" +checksum = "b47ca4d2b6931707a55fce5cf66aff80e2178c8b63bbb4ecb5695cbc870ddf6f" dependencies = [ "serde", ] @@ -2994,11 +3039,11 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.8.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" dependencies = [ - "autocfg", + "autocfg 1.0.1", "hashbrown 0.11.2", "serde", ] @@ -3039,7 +3084,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "723519edce41262b05d4143ceb95050e4c614f483e78e9fd9e39a8275a84ad98" dependencies = [ - "socket2", + "socket2 0.4.4", "widestring", "winapi", "winreg", @@ -3074,27 +3119,27 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254" dependencies = [ "wasm-bindgen", ] [[package]] name = "jsonrpsee" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f2ab5a60e558e74ea93bcf5164ebc47939a7fff8938fa9b5233bbc63e16061" +checksum = "eae63f7fdeb51700b35e9b28bf92e8d233951590968c186ed79510b6c12fa3d9" dependencies = [ "jsonrpsee-core", "jsonrpsee-http-server", @@ -3107,9 +3152,9 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d682f4a55081a2be3e639280c640523070e4aeb8ee2fd8dd9168fdae57a9db" +checksum = "32feb1f2f0b5ce37a03b96a988a6dadccc3f529a2f930356bac93f13c09cf385" dependencies = [ "futures-util", "http", @@ -3128,12 +3173,12 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e27462b21279edf9a6a91f46ffbe125e9cdc58b901d2e08bf59b31a47d7d0ab" +checksum = "31e6b13067b615dd050ced7c19517a52cde490eee2c754d5447ce513f2275f7d" dependencies = [ "anyhow", - "arrayvec 0.7.2", + "arrayvec 0.7.1", "async-lock", "async-trait", "beef", @@ -3143,7 +3188,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "rustc-hash", "serde", "serde_json", @@ -3155,9 +3200,9 @@ dependencies = [ [[package]] name = "jsonrpsee-http-server" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7178f16eabd7154c094e24d295b9ee355ec1e5f24c328759c56255ff7bbd4548" +checksum = "b34f1090bdc8f7f14ad8811fc84501867c23a9046ce79d49c0cd929a256c501e" dependencies = [ "futures-channel", "futures-util", @@ -3174,9 +3219,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8d7f449cab3b747f12c3efc27f5cad537f3b597c6a3838b0fac628f4bf730a" +checksum = "5d8dc7a8b629e371cd5ca9d128883763ae00c5b63158ace4a6a61345726a21b7" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3186,9 +3231,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd11763134104122ddeb0f97e4bbe393058017dfb077db63fbf44b4dd0dd86e" +checksum = "44f1835f131e77cd766b4dcb025873944cb1e479cd5debb639e2dc11f90df24a" dependencies = [ "anyhow", "beef", @@ -3200,9 +3245,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f15180afb3761c7a3a32c0a8b680788176dcfdfe725b24c1758c90b1d1595b" +checksum = "9d75df866743c9733b3e2f5421e56df2f5b4630f7de39f82c44eaab350604926" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3211,9 +3256,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-server" -version = "0.13.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb6c21556c551582b56e4e8e6e6249b0bbdb69bb7fa39efe9b9a6b54af9f206" +checksum = "099971913436e7f6b1bc80180d4e5f014ec944660636da45d2f372c23d6308c3" dependencies = [ "futures-channel", "futures-util", @@ -3222,7 +3267,7 @@ dependencies = [ "serde_json", "soketto", "tokio", - "tokio-util", + "tokio-util 0.7.1", "tracing", ] @@ -3317,15 +3362,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leb128" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.125" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "libgit2-sys" @@ -3351,9 +3396,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -3361,9 +3406,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" +checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libp2p" @@ -3375,7 +3420,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.6", + "getrandom 0.2.3", "instant", "lazy_static", "libp2p-autonat", @@ -3426,7 +3471,7 @@ dependencies = [ "log", "prost 0.9.0", "prost-build", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -3453,7 +3498,7 @@ dependencies = [ "pin-project 1.0.10", "prost 0.9.0", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "ring", "rw-stream-sink", "sha2 0.10.2", @@ -3595,9 +3640,9 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.5", + "rand 0.8.4", "smallvec", - "socket2", + "socket2 0.4.4", "void", ] @@ -3642,14 +3687,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dd7e0c94051cda67123be68cf6b65211ba3dde7277be9068412de3e7ffd63ef" dependencies = [ "bytes", - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "futures", "lazy_static", "libp2p-core", "log", "prost 0.9.0", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "sha2 0.10.2", "snow", "static_assertions", @@ -3722,7 +3767,7 @@ dependencies = [ "pin-project 1.0.10", "prost 0.9.0", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "smallvec", "static_assertions", "thiserror", @@ -3746,7 +3791,7 @@ dependencies = [ "log", "prost 0.9.0", "prost-build", - "rand 0.8.5", + "rand 0.8.4", "sha2 0.10.2", "thiserror", "unsigned-varint", @@ -3815,7 +3860,7 @@ dependencies = [ "libc", "libp2p-core", "log", - "socket2", + "socket2 0.4.4", ] [[package]] @@ -3903,9 +3948,9 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.8.5", + "rand 0.8.4", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "typenum", ] @@ -3940,9 +3985,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.6" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e7e15d7610cce1d9752e137625f14e61a28cd45929b6e12e47b50fe154ee2e" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" dependencies = [ "cc", "libc", @@ -4001,11 +4046,10 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" dependencies = [ - "autocfg", "scopeguard", ] @@ -4060,9 +4104,9 @@ dependencies = [ [[package]] name = "lz4" -version = "1.23.3" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4edcb94251b1c375c459e5abe9fb0168c1c826c3370172684844f8f3f8d1a885" +checksum = "aac20ed6991e01bf6a2e68cc73df2b389707403662a8ba89f68511fb340f724c" dependencies = [ "libc", "lz4-sys", @@ -4070,9 +4114,9 @@ dependencies = [ [[package]] name = "lz4-sys" -version = "1.9.3" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7be8908e2ed6f31c02db8a9fa962f03e36c53fbfde437363eae3306b85d7e17" +checksum = "dca79aa95d8b3226213ad454d328369853be3a1382d89532a854f4d69640acae" dependencies = [ "cc", "libc", @@ -4110,24 +4154,24 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "matrixmultiply" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +checksum = "5a8a15b776d9dfaecd44b03c5828c2199cddff5247215858aac14624f8d6b741" dependencies = [ "rawpointer", ] [[package]] name = "memchr" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memfd" @@ -4150,29 +4194,29 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.2.3" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" +checksum = "04e3e85b970d650e2ae6d70592474087051c11c54da7f7b4949725c5735fbcc6" dependencies = [ "libc", ] [[package]] name = "memmap2" -version = "0.5.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" +checksum = "4647a11b578fead29cdbb34d4adef8dd3dc35b876c9c6d5240d83f205abfe96e" dependencies = [ "libc", ] [[package]] name = "memoffset" -version = "0.6.5" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" dependencies = [ - "autocfg", + "autocfg 1.0.1", ] [[package]] @@ -4182,7 +4226,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "parity-util-mem", ] @@ -4212,30 +4256,42 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.5.1" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", + "autocfg 1.0.1", ] [[package]] name = "mio" -version = "0.8.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" +checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" +dependencies = [ + "socket2 0.3.19", + "winapi", ] [[package]] name = "more-asserts" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" +checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" [[package]] name = "multiaddr" @@ -4279,7 +4335,7 @@ dependencies = [ "digest 0.10.3", "multihash-derive", "sha2 0.10.2", - "sha3 0.10.1", + "sha3 0.10.0", "unsigned-varint", ] @@ -4299,9 +4355,9 @@ dependencies = [ [[package]] name = "multimap" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" [[package]] name = "multistream-select" @@ -4329,7 +4385,7 @@ dependencies = [ "num-complex", "num-rational 0.4.0", "num-traits", - "rand 0.8.5", + "rand 0.8.4", "rand_distr", "simba", "typenum", @@ -4352,7 +4408,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d66043b25d4a6cccb23619d10c19c25304b355a7dccd4a8e11423dd2382146" dependencies = [ - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -4389,7 +4445,7 @@ checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" dependencies = [ "anyhow", "byteorder", - "paste 1.0.7", + "paste 1.0.6", "thiserror", ] @@ -4512,7 +4568,7 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "platforms", - "rand 0.8.5", + "rand 0.8.4", "regex", "remote-externalities", "sc-authority-discovery", @@ -4886,12 +4942,22 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.1" +version = "7.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" dependencies = [ "memchr", "minimal-lexical", + "version_check", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", ] [[package]] @@ -4900,16 +4966,16 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fbc387afefefd5e9e39493299f3069e14a140dd34dc19b4c1c1a8fddb6a790" +checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" dependencies = [ "num-traits", ] @@ -4926,11 +4992,11 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-traits", ] @@ -4940,7 +5006,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-bigint", "num-integer", "num-traits", @@ -4952,18 +5018,18 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ - "autocfg", + "autocfg 1.0.1", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg", + "autocfg 1.0.1", "libm", ] @@ -4990,9 +5056,9 @@ dependencies = [ [[package]] name = "object" -version = "0.28.4" +version = "0.28.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +checksum = "40bec70ba014595f99f7aa110b84331ffe1ee9aece7fe6f387cc7e3ecda4d456" dependencies = [ "crc32fast", "hashbrown 0.11.2", @@ -5026,9 +5092,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl-probe" -version = "0.1.5" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "os_str_bytes" @@ -5038,9 +5104,9 @@ checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "output_vt100" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" dependencies = [ "winapi", ] @@ -5212,7 +5278,7 @@ dependencies = [ "frame-election-provider-support", "honggfuzz", "pallet-bags-list", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -5365,7 +5431,7 @@ dependencies = [ "pallet-utility", "parity-scale-codec", "pretty_assertions", - "rand 0.8.5", + "rand 0.8.4", "rand_pcg 0.3.1", "scale-info", "serde", @@ -6393,19 +6459,19 @@ dependencies = [ "libc", "log", "lz4", - "memmap2 0.2.3", + "memmap2 0.2.1", "parking_lot 0.11.2", - "rand 0.8.5", + "rand 0.8.4", "snap", ] [[package]] name = "parity-scale-codec" -version = "3.1.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8b44461635bbb1a0300f100a841e571e7d919c81c73075ef5d152ffdb521066" +checksum = "2a7f3fcf5e45fc28b84dcdab6b983e77f197ec01f325a33f404ba6855afd1070" dependencies = [ - "arrayvec 0.7.2", + "arrayvec 0.7.1", "bitvec", "byte-slice-cast", "impl-trait-for-tuples", @@ -6415,9 +6481,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.2" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45ed1f39709f5a89338fab50e59816b2e8815f5bb58276e7ddf9afd495f73f8" +checksum = "2c6e626dc84025ff56bf1476ed0e30d10c84d7f89a475ef46ebabee1095a8fba" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -6438,7 +6504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.0", @@ -6497,7 +6563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.1", ] [[package]] @@ -6516,9 +6582,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" dependencies = [ "cfg-if 1.0.0", "libc", @@ -6539,9 +6605,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" [[package]] name = "paste-impl" @@ -6637,11 +6703,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.29" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909" +checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" dependencies = [ - "pin-project-internal 0.4.29", + "pin-project-internal 0.4.27", ] [[package]] @@ -6655,9 +6721,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "0.4.29" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a" +checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" dependencies = [ "proc-macro2", "quote", @@ -6683,9 +6749,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -6695,9 +6761,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "platforms" @@ -6720,66 +6786,66 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "b07fffcddc1cb3a1de753caa4e4df03b79922ba43cf882acc1bdd7e8df9f4590" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "b38a02e23bd9604b842a812063aec4ef702b57989c37b655254bb61c471ad211" dependencies = [ "plotters-backend", ] [[package]] name = "polling" -version = "2.2.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "libc", "log", - "wepoll-ffi", + "wepoll-sys", "winapi", ] [[package]] name = "poly1305" -version = "0.7.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048aeb476be11a4b6ca432ca569e375810de9294ae78f4774e78ea98a9246ede" +checksum = "9fcffab1f78ebbdf4b93b68c1ffebc24037eedf271edaca795732b24e5e4e349" dependencies = [ - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "polyval" -version = "0.5.3" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +checksum = "a6ba6a405ef63530d6cb12802014b22f9c5751bd17cdcddbe9e46d5c8ae83287" dependencies = [ "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.1.5", "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "predicates" -version = "2.1.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" +checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308" dependencies = [ "difflib", "itertools", @@ -6788,18 +6854,18 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.5" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" dependencies = [ "predicates-core", - "termtree", + "treeline", ] [[package]] @@ -6940,7 +7006,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", - "heck 0.3.3", + "heck 0.3.2", "itertools", "lazy_static", "log", @@ -6991,9 +7057,9 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.18" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" +checksum = "3abf49e5417290756acfd26501536358560c4a5cc4a0934d390939acb3e7083a" dependencies = [ "cc", ] @@ -7026,9 +7092,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quick-error" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +checksum = "3ac73b1112776fc109b2e61909bc46c7e1bf0d7f690ffb1676553acce16d5cda" [[package]] name = "quickcheck" @@ -7065,6 +7131,25 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg 0.1.2", + "rand_xorshift", + "winapi", +] + [[package]] name = "rand" version = "0.7.3" @@ -7075,19 +7160,30 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc", + "rand_hc 0.2.0", "rand_pcg 0.2.1", ] [[package]] name = "rand" -version = "0.8.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.3", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", ] [[package]] @@ -7102,14 +7198,29 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", ] +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.5.1" @@ -7121,11 +7232,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "getrandom 0.2.6", + "getrandom 0.2.3", ] [[package]] @@ -7135,7 +7246,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.5", + "rand 0.8.4", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", ] [[package]] @@ -7147,6 +7267,59 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + [[package]] name = "rand_pcg" version = "0.2.1" @@ -7162,7 +7335,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" dependencies = [ - "rand_core 0.6.3", + "rand_core 0.6.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", ] [[package]] @@ -7173,11 +7355,11 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.5.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ - "autocfg", + "autocfg 1.0.1", "crossbeam-deque", "either", "rayon-core", @@ -7185,21 +7367,31 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.3" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", + "lazy_static", "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -7208,7 +7400,7 @@ dependencies = [ name = "redox_users" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ "getrandom 0.2.3", "redox_syscall", @@ -7216,18 +7408,18 @@ dependencies = [ [[package]] name = "ref-cast" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685d58625b6c2b83e4cc88a27c4bf65adb7b6b16dbdc413e515c9405b47432ab" +checksum = "300f2a835d808734ee295d45007adacb9ebb29dd3ae2424acfa17930cae541da" dependencies = [ "ref-cast-impl", ] [[package]] name = "ref-cast-impl" -version = "1.0.7" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a043824e29c94169374ac5183ac0ed43f5724dc4556b19568007486bd840fa1f" +checksum = "4c38e3aecd2b21cb3959637b883bb3714bc7e43f0268b9a29d3743ee3e55cdd2" dependencies = [ "proc-macro2", "quote", @@ -7269,10 +7461,11 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" dependencies = [ + "byteorder", "regex-syntax", ] @@ -7355,9 +7548,9 @@ dependencies = [ [[package]] name = "retain_mut" -version = "0.1.7" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c31b5c4033f8fdde8700e4657be2c497e7288f01515be52168c631e2e4d4086" +checksum = "448296241d034b96c11173591deaa1302f2c17b56092106c1f92c1bc0183a8c9" [[package]] name = "rfc6979" @@ -7387,12 +7580,12 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.38" +version = "0.7.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6" +checksum = "1f08c8062c1fe1253064043b8fc07bfea1b9702b71b4a86c11ea3588183b12e1" dependencies = [ "bytecheck", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "ptr_meta", "rend", "rkyv_derive", @@ -7401,9 +7594,9 @@ dependencies = [ [[package]] name = "rkyv_derive" -version = "0.7.38" +version = "0.7.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd" +checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" dependencies = [ "proc-macro2", "quote", @@ -7447,9 +7640,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" [[package]] name = "rustc-hash" @@ -7478,14 +7671,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.9", + "semver 1.0.4", ] [[package]] name = "rustix" -version = "0.33.7" +version = "0.33.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" +checksum = "03627528abcc4a365554d32a9f3bbf67f7694c102cfeda792dc86a2d6057cc85" dependencies = [ "bitflags", "errno", @@ -7499,7 +7692,7 @@ dependencies = [ name = "rustls" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbfeb8d0ddb84706bc597a5574ab8912817c52a397f819e5b614e2265206921" +checksum = "d37e5e2290f3e040b594b1a9e04377c2c671f1a1cfd9bfdef82106ac1c113f84" dependencies = [ "log", "ring", @@ -7509,9 +7702,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.6.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50" +checksum = "5ca9ebdfa27d3fc180e42879037b5338ab1c040c06affd00d8338598e7800943" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -7521,9 +7714,9 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7522c9de787ff061458fe9a829dc790a3f5b22dc571694fc5883f448b94d9a9" +checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" dependencies = [ "base64", ] @@ -7541,15 +7734,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ "futures", - "pin-project 0.4.29", + "pin-project 0.4.27", "static_assertions", ] [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "safe-mix" @@ -7663,7 +7856,7 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "impl-trait-for-tuples", - "memmap2 0.5.3", + "memmap2 0.5.0", "parity-scale-codec", "sc-chain-spec-derive", "sc-network", @@ -8040,7 +8233,7 @@ dependencies = [ "num_cpus", "parity-scale-codec", "parking_lot 0.12.0", - "paste 1.0.7", + "paste 1.0.6", "regex", "sc-executor-common", "sc-executor-wasmi", @@ -8137,7 +8330,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -8526,7 +8719,7 @@ dependencies = [ name = "sc-runtime-test" version = "2.0.0" dependencies = [ - "paste 1.0.7", + "paste 1.0.6", "sp-core", "sp-io", "sp-runtime", @@ -8849,7 +9042,7 @@ checksum = "021b403afe70d81eea68f6ea12f6b3c9588e5d536a94c3bf80f15e7faa267862" dependencies = [ "arrayref", "arrayvec 0.5.2", - "curve25519-dalek 2.1.3", + "curve25519-dalek 2.1.2", "getrandom 0.1.16", "merlin", "rand 0.7.3", @@ -8888,17 +9081,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", "zeroize", ] [[package]] name = "secp256k1" -version = "0.21.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c42e6f1735c5f00f51e43e28d6634141f2bcad10931b2609ddd74a86d751260" +checksum = "ab7883017d5b21f011ef8040ea9c6c7ac90834c0df26a69e4c0b06276151f125" dependencies = [ + "rand 0.6.5", "secp256k1-sys", ] @@ -8922,9 +9116,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "b239a3d5db51252f6f48f42172c65317f37202f4a21021bf5f9d40a408f4592c" dependencies = [ "bitflags", "core-foundation", @@ -8935,9 +9129,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284" dependencies = [ "core-foundation-sys", "libc", @@ -8963,9 +9157,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.9" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" dependencies = [ "serde", ] @@ -8978,27 +9172,27 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.137" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.6" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" dependencies = [ "serde", ] [[package]] name = "serde_cbor" -version = "0.11.2" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" dependencies = [ "half", "serde", @@ -9006,9 +9200,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", @@ -9017,9 +9211,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.81" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" dependencies = [ "itoa 1.0.1", "ryu", @@ -9049,13 +9243,13 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.8" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" +checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures", + "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9074,13 +9268,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.2.1", "digest 0.9.0", "opaque-debug 0.3.0", ] @@ -9092,7 +9286,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ "cfg-if 1.0.0", - "cpufeatures", + "cpufeatures 0.2.1", "digest 0.10.3", ] @@ -9110,9 +9304,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881bf8156c87b6301fc5ca6b27f11eeb2761224c7081e69b409d5a1951a70c86" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" dependencies = [ "digest 0.10.3", "keccak", @@ -9120,24 +9314,24 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.4" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" dependencies = [ "lazy_static", ] [[package]] name = "shlex" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d" [[package]] name = "signal-hook" -version = "0.3.13" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" +checksum = "ef33d6d0cd06e0840fba9985aab098c147e67e05cee14d412d3345ed14ff30ac" dependencies = [ "libc", "signal-hook-registry", @@ -9145,9 +9339,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" dependencies = [ "libc", ] @@ -9159,7 +9353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" dependencies = [ "digest 0.9.0", - "rand_core 0.6.3", + "rand_core 0.6.2", ] [[package]] @@ -9171,14 +9365,14 @@ dependencies = [ "approx", "num-complex", "num-traits", - "paste 1.0.7", + "paste 1.0.6", ] [[package]] name = "slab" -version = "0.4.6" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" @@ -9202,13 +9396,24 @@ dependencies = [ "blake2", "chacha20poly1305", "curve25519-dalek 4.0.0-pre.1", - "rand_core 0.6.3", + "rand_core 0.6.2", "ring", "rustc_version 0.4.0", "sha2 0.10.2", "subtle", ] +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.4.4" @@ -9231,8 +9436,8 @@ dependencies = [ "futures", "httparse", "log", - "rand 0.8.5", - "sha-1 0.9.8", + "rand 0.8.4", + "sha-1 0.9.4", ] [[package]] @@ -9538,7 +9743,7 @@ dependencies = [ "byteorder", "digest 0.10.3", "sha2 0.10.2", - "sha3 0.10.1", + "sha3 0.10.0", "sp-std", "twox-hash", ] @@ -9708,7 +9913,7 @@ dependencies = [ "clap 3.1.18", "honggfuzz", "parity-scale-codec", - "rand 0.8.5", + "rand 0.8.4", "scale-info", "sp-npos-elections", "sp-runtime", @@ -9752,7 +9957,7 @@ dependencies = [ "log", "parity-scale-codec", "parity-util-mem", - "paste 1.0.7", + "paste 1.0.6", "rand 0.7.3", "scale-info", "serde", @@ -10102,7 +10307,7 @@ dependencies = [ "lazy_static", "nalgebra", "num-traits", - "rand 0.8.5", + "rand 0.8.4", ] [[package]] @@ -10126,7 +10331,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" dependencies = [ - "heck 0.3.3", + "heck 0.3.2", "proc-macro2", "quote", "rustversion", @@ -10150,7 +10355,7 @@ dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", "schnorrkel", - "sha2 0.9.9", + "sha2 0.9.8", "zeroize", ] @@ -10399,15 +10604,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.1" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.94" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a07e33e919ebcd69113d5be0e4d70c5707004ff45188910106854f38b960df4a" +checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" dependencies = [ "proc-macro2", "quote", @@ -10416,9 +10621,9 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.6" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2", "quote", @@ -10475,19 +10680,13 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ "winapi-util", ] -[[package]] -name = "termtree" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" - [[package]] name = "textwrap" version = "0.11.0" @@ -10505,18 +10704,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", @@ -10549,9 +10748,9 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.4.3+5.2.1-patched.2" +version = "0.4.2+5.2.1-patched.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1792ccb507d955b46af42c123ea8863668fae24d03721e40cad6a41773dbb49" +checksum = "5844e429d797c62945a566f8da4e24c7fe3fbd5d6617fd8bf7a0b7dc1ee0f22e" dependencies = [ "cc", "fs_extra", @@ -10581,7 +10780,7 @@ dependencies = [ "pbkdf2 0.4.0", "rand 0.7.3", "rustc-hash", - "sha2 0.9.9", + "sha2 0.9.8", "thiserror", "unicode-normalization", "wasm-bindgen", @@ -10609,9 +10808,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -10624,9 +10823,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.18.2" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", @@ -10635,9 +10834,9 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.12.0", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "signal-hook-registry", - "socket2", + "socket2 0.4.4", "tokio-macros", "winapi", ] @@ -10657,7 +10856,7 @@ dependencies = [ name = "tokio-rustls" version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" dependencies = [ "rustls", "tokio", @@ -10666,12 +10865,12 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.8" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" dependencies = [ "futures-core", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tokio", ] @@ -10688,6 +10887,20 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "tokio-util" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.2.6", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.1" @@ -10698,16 +10911,15 @@ dependencies = [ "futures-core", "futures-io", "futures-sink", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.5.9" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ "serde", ] @@ -10720,22 +10932,22 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.34" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.9", + "pin-project-lite 0.2.6", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.21" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ "proc-macro2", "quote", @@ -10777,9 +10989,9 @@ dependencies = [ [[package]] name = "tracing-serde" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" dependencies = [ "serde", "tracing-core", @@ -10808,6 +11020,12 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "treeline" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" + [[package]] name = "trie-bench" version = "0.30.0" @@ -10831,7 +11049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" dependencies = [ "hash-db", - "hashbrown 0.12.1", + "hashbrown 0.12.0", "log", "rustc-hex", "smallvec", @@ -10873,7 +11091,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.5", + "rand 0.8.4", "smallvec", "thiserror", "tinyvec", @@ -10931,9 +11149,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.61" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc92f558afb6d1d7c6f175eb8d615b8ef49c227543e68e19c123d4ee43d8a7d" +checksum = "0da18123d1316f5a65fc9b94e30a0fcf58afb1daff1b8e18f41dc30f5bfc38c8" dependencies = [ "dissimilar", "glob", @@ -10953,13 +11171,13 @@ checksum = "5e66dcbec4290c69dd03c57e76c2469ea5c7ce109c6dd4351c13055cf71ea055" [[package]] name = "twox-hash" -version = "1.6.3" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ "cfg-if 1.0.0", "digest 0.10.3", - "rand 0.8.5", + "rand 0.8.4", "static_assertions", ] @@ -10977,9 +11195,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "e11fe9a9348741cf134085ad57c249508345fe16411b3d7fb4ff2da2f1d6382e" dependencies = [ "byteorder", "crunchy", @@ -10998,30 +11216,33 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -11031,11 +11252,11 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "universal-hash" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ - "generic-array 0.14.5", + "generic-array 0.14.4", "subtle", ] @@ -11059,9 +11280,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -11087,15 +11308,21 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.15" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + +[[package]] +name = "vec-arena" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "void" @@ -11151,17 +11378,11 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -11169,9 +11390,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523" dependencies = [ "bumpalo", "lazy_static", @@ -11184,9 +11405,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.30" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -11196,9 +11417,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -11206,9 +11427,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92" dependencies = [ "proc-macro2", "quote", @@ -11219,9 +11440,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4" [[package]] name = "wasm-gc-api" @@ -11366,7 +11587,7 @@ dependencies = [ "enumset", "lazy_static", "loupe", - "memmap2 0.5.3", + "memmap2 0.5.0", "more-asserts", "rustc-demangle", "serde", @@ -11388,9 +11609,9 @@ dependencies = [ "enum-iterator", "enumset", "leb128", - "libloading 0.7.3", + "libloading 0.7.0", "loupe", - "object 0.28.4", + "object 0.28.3", "rkyv", "serde", "tempfile", @@ -11429,7 +11650,7 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24ce18ac2877050e59580d27ee1a88f3192d7a31e77fbba0852abc7888d6e0b5" dependencies = [ - "object 0.28.4", + "object 0.28.3", "thiserror", "wasmer-compiler", "wasmer-types", @@ -11490,9 +11711,9 @@ dependencies = [ [[package]] name = "wasmi-validation" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +checksum = "a2eb8e860796d8be48efef530b60eebf84e74a88bce107374fffb0da97d504b8" dependencies = [ "parity-wasm 0.42.2", ] @@ -11525,7 +11746,7 @@ dependencies = [ "log", "object 0.27.1", "once_cell", - "paste 1.0.7", + "paste 1.0.6", "psm", "rayon", "region 2.2.0", @@ -11554,7 +11775,7 @@ dependencies = [ "log", "rustix", "serde", - "sha2 0.9.9", + "sha2 0.9.8", "toml", "winapi", "zstd", @@ -11656,7 +11877,7 @@ dependencies = [ "memfd", "memoffset", "more-asserts", - "rand 0.8.5", + "rand 0.8.4", "region 2.2.0", "rustix", "thiserror", @@ -11679,29 +11900,27 @@ dependencies = [ [[package]] name = "wast" -version = "40.0.0" +version = "38.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb4f48a8b083dbc50e291e430afb8f524092bb00428957bcc63f49f856c64ac" +checksum = "0ebc29df4629f497e0893aacd40f13a4a56b85ef6eb4ab6d603f07244f1a7bf2" dependencies = [ "leb128", - "memchr", - "unicode-width", ] [[package]] name = "wat" -version = "1.0.42" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0401b6395ce0db91629a75b29597ccb66ea29950af9fc859f1bb3a736609c76e" +checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" dependencies = [ "wast", ] [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a" dependencies = [ "js-sys", "wasm-bindgen", @@ -11719,31 +11938,30 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.3" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" +checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" dependencies = [ "webpki", ] [[package]] -name = "wepoll-ffi" -version = "0.1.2" +name = "wepoll-sys" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" dependencies = [ "cc", ] [[package]] name = "which" -version = "4.2.5" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" dependencies = [ - "either", - "lazy_static", "libc", + "thiserror", ] [[package]] @@ -11798,15 +12016,15 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", + "windows_aarch64_msvc 0.32.0", + "windows_i686_gnu 0.32.0", + "windows_i686_msvc 0.32.0", + "windows_x86_64_gnu 0.32.0", + "windows_x86_64_msvc 0.32.0", ] [[package]] @@ -11817,9 +12035,9 @@ checksum = "c3d027175d00b01e0cbeb97d6ab6ebe03b12330a35786cbaca5252b1c4bf5d9b" [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" [[package]] name = "windows_i686_gnu" @@ -11829,9 +12047,9 @@ checksum = "8793f59f7b8e8b01eda1a652b2697d87b93097198ae85f823b969ca5b89bba58" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" [[package]] name = "windows_i686_msvc" @@ -11841,9 +12059,9 @@ checksum = "8602f6c418b67024be2996c512f5f995de3ba417f4c75af68401ab8756796ae4" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" [[package]] name = "windows_x86_64_gnu" @@ -11853,9 +12071,9 @@ checksum = "f3d615f419543e0bd7d2b3323af0d86ff19cbc4f816e6453f36a2c2ce889c354" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" [[package]] name = "windows_x86_64_msvc" @@ -11865,9 +12083,9 @@ checksum = "11d95421d9ed3672c280884da53201a5c46b7b2765ca6faf34b0d71cf34a3561" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" [[package]] name = "winreg" @@ -11889,11 +12107,11 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" +checksum = "bc614d95359fd7afc321b66d2107ede58b246b844cf5d8a0adcca413e439f088" dependencies = [ - "curve25519-dalek 3.2.0", + "curve25519-dalek 3.0.2", "rand_core 0.5.1", "zeroize", ] @@ -11908,7 +12126,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.0", - "rand 0.8.5", + "rand 0.8.4", "static_assertions", ] @@ -11935,18 +12153,18 @@ dependencies = [ [[package]] name = "zstd" -version = "0.10.2+zstd.1.5.2" +version = "0.10.0+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4a6bd64f22b5e3e94b4e238669ff9f10815c27a5180108b849d24174a83847" +checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.6+zstd.1.5.2" +version = "4.1.4+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b61c51bb270702d6167b8ce67340d2754b088d0c091b06e593aa772c3ee9bb" +checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" dependencies = [ "libc", "zstd-sys", From 28c8852866d5fdfd2585694971341d16be6c9dfa Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 20 May 2022 13:58:31 +0200 Subject: [PATCH 14/65] Fix --- frame/nomination-pools/src/mock.rs | 3 +-- frame/nomination-pools/src/tests.rs | 6 ++++-- frame/nomination-pools/test-staking/src/mock.rs | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 557def539b120..2143a04b984f9 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -174,7 +174,6 @@ parameter_types! { pub static MaxMetadataLen: u32 = 2; pub static CheckLevel: u8 = 255; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const MinPointsToBalance: u32 = 10; } impl pools::Config for Runtime { type Event = Event; @@ -187,7 +186,7 @@ impl pools::Config for Runtime { type PalletId = PoolsPalletId; type MaxMetadataLen = MaxMetadataLen; type MaxUnbonding = MaxUnbonding; - type MinPointsToBalance = MinPointsToBalance; + type MinPointsToBalance = frame_support::traits::ConstU32<10>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f068d010334d5..a2855f6a8e62e 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -204,7 +204,8 @@ mod bonded_pool { }, }; - let min_points_to_balance: u128 = MinPointsToBalance::get().into(); + let min_points_to_balance: u128 = + <::MinPointsToBalance as Get>::get().into(); // Simulate a 100% slashed pool StakingMock::set_bonded_balance(pool.bonded_account(), 0); @@ -522,7 +523,8 @@ mod join { ); // Force the points:balance ratio to `MinPointsToBalance` (100/10) - let min_points_to_balance: u128 = MinPointsToBalance::get().into(); + let min_points_to_balance: u128 = + <::MinPointsToBalance as Get>::get().into(); StakingMock::set_bonded_balance( Pools::create_bonded_account(123), diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index a8710f261f212..7b720c009b29b 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -163,6 +163,7 @@ impl pallet_nomination_pools::Config for Runtime { type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow; type MaxMetadataLen = ConstU32<256>; type MaxUnbonding = ConstU32<8>; + type MinPointsToBalance = ConstU32<10>; type PalletId = PoolsPalletId; } From c9413a2aff706136c7e5279459f72c2b75267b38 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 20 May 2022 14:19:32 +0200 Subject: [PATCH 15/65] fmt --- frame/nomination-pools/src/lib.rs | 5 +++-- frame/support/src/storage/types/nmap.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a931673661ffb..06a6f68e09e7a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1274,8 +1274,9 @@ pub mod pallet { PaidOut { member: T::AccountId, pool_id: PoolId, payout: BalanceOf }, /// A member has unbonded from their pool. /// - /// - `balance` is the corresponding balance of the number of points that has been requested - /// to be unbonded (the argument of the `unbond` transaction) from the bonded pool. + /// - `balance` is the corresponding balance of the number of points that has been + /// requested to be unbonded (the argument of the `unbond` transaction) from the bonded + /// pool. /// - `points` is the number of points that are issued as a result of `balance` being /// dissolved into the corresponding unbonding pool. /// diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index 5faeb5d8cac28..26facf8b236d2 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -544,7 +544,7 @@ mod test { use crate::{ hash::{StorageHasher as _, *}, metadata::{StorageEntryModifier, StorageHasher}, - storage::types::{Key, Key as NMapKey, ValueQuery}, + storage::types::{Key, ValueQuery}, }; use sp_io::{hashing::twox_128, TestExternalities}; From c34b6551241ca0b8b624aaaa8da03897d53c5363 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 23 May 2022 13:12:06 +0100 Subject: [PATCH 16/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 06a6f68e09e7a..685fb7da41b93 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1873,7 +1873,7 @@ pub mod pallet { /// Nominate on behalf of the pool. /// - /// The dispatch origin of this call must be signed by the pool nominator or the the pool + /// The dispatch origin of this call must be signed by the pool nominator or the pool /// root role, same as [`Pallet::nominate`]. /// /// This directly forward the call to the staking pallet, on behalf of the pool bonded From d0d75a1e829d0502a27e9a4dc0e0f2a5e6d8354c Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 23 May 2022 13:12:11 +0100 Subject: [PATCH 17/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 685fb7da41b93..44c3e0864202f 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1871,7 +1871,7 @@ pub mod pallet { T::StakingInterface::nominate(bonded_pool.bonded_account(), validators) } - /// Nominate on behalf of the pool. + /// Chill on behalf of the pool. /// /// The dispatch origin of this call must be signed by the pool nominator or the pool /// root role, same as [`Pallet::nominate`]. From a6afb06c11180ae4dd0f3d58c3b38ad7c8cf6cf8 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 23 May 2022 13:12:17 +0100 Subject: [PATCH 18/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 44c3e0864202f..5e61c1e446fcb 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1854,7 +1854,7 @@ pub mod pallet { /// Nominate on behalf of the pool. /// - /// The dispatch origin of this call must be signed by the pool nominator or the the pool + /// The dispatch origin of this call must be signed by the pool nominator or the pool /// root role. /// /// This directly forward the call to the staking pallet, on behalf of the pool bonded From a3a43e7f9c38b31c480029afdb655e6ca7574185 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Mon, 23 May 2022 13:14:45 +0100 Subject: [PATCH 19/65] Update frame/nomination-pools/src/mock.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 2143a04b984f9..d347d1c5c6023 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -292,7 +292,7 @@ pub(crate) fn pool_events_since_last_call() -> Vec> { events.into_iter().skip(already_seen).collect() } -/// All events of this pallet. +/// All events of the `Balances` pallet. pub(crate) fn balances_events_since_last_call() -> Vec> { let events = System::events() .into_iter() From 4b7b0c778988bd399349eac640a93de214707744 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 23 May 2022 14:44:30 +0200 Subject: [PATCH 20/65] Fix build --- frame/support/src/storage/types/nmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index 26facf8b236d2..a15c7482105e9 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -590,7 +590,7 @@ mod test { { #[crate::storage_alias] - type Foo = StorageNMap), u32>; + type Foo = StorageNMap), u32>; assert_eq!(Foo::contains_key((3,)), true); assert_eq!(Foo::get((3,)), Some(10)); From 640ec312d86f50783740d1c7bf28755442dfa6e4 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 23 May 2022 14:56:50 +0200 Subject: [PATCH 21/65] fix some fishy tests.. --- frame/nomination-pools/src/tests.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index a2855f6a8e62e..317fc7206fce1 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -90,7 +90,7 @@ fn test_setup_works() { mod bonded_pool { use super::*; #[test] - fn points_to_issue_works() { + fn balance_to_point_works() { ExtBuilder::default().build_and_execute(|| { let mut bonded_pool = BondedPool:: { id: 123123, @@ -123,11 +123,12 @@ mod bonded_pool { // 0 points : 100 balance StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); - bonded_pool.points = 100; + bonded_pool.points = 0; assert_eq!(bonded_pool.balance_to_point(10), 10); // 10 points : 3 balance ratio StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 30); + bonded_pool.points = 100; assert_eq!(bonded_pool.balance_to_point(10), 33); // 2 points : 3 balance ratio @@ -143,7 +144,7 @@ mod bonded_pool { } #[test] - fn balance_to_unbond_works() { + fn points_to_balance_works() { ExtBuilder::default().build_and_execute(|| { // 1 balance : 1 points ratio let mut bonded_pool = BondedPool:: { @@ -165,7 +166,7 @@ mod bonded_pool { assert_eq!(bonded_pool.points_to_balance(10), 20); // 100 balance : 0 points ratio - StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 0); + StakingMock::set_bonded_balance(bonded_pool.bonded_account(), 100); bonded_pool.points = 0; assert_eq!(bonded_pool.points_to_balance(10), 0); From 398ddfe8e066129b80704423757a7616143b38be Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 24 May 2022 08:13:26 +0200 Subject: [PATCH 22/65] add one last integrity check for MinCreateBond --- bin/node/cli/src/chain_spec.rs | 11 ++++++++--- frame/nomination-pools/Cargo.toml | 3 ++- frame/nomination-pools/src/lib.rs | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/node/cli/src/chain_spec.rs b/bin/node/cli/src/chain_spec.rs index 221c229876275..7c4e54e61ec18 100644 --- a/bin/node/cli/src/chain_spec.rs +++ b/bin/node/cli/src/chain_spec.rs @@ -23,8 +23,9 @@ use hex_literal::hex; use node_runtime::{ constants::currency::*, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, Block, CouncilConfig, DemocracyConfig, ElectionsConfig, GrandpaConfig, - ImOnlineConfig, IndicesConfig, MaxNominations, SessionConfig, SessionKeys, SocietyConfig, - StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, + ImOnlineConfig, IndicesConfig, MaxNominations, NominationPoolsConfig, SessionConfig, + SessionKeys, SocietyConfig, StakerStatus, StakingConfig, SudoConfig, SystemConfig, + TechnicalCommitteeConfig, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::ChainSpecExtension; @@ -363,7 +364,11 @@ pub fn testnet_genesis( gilt: Default::default(), transaction_storage: Default::default(), transaction_payment: Default::default(), - nomination_pools: Default::default(), + nomination_pools: NominationPoolsConfig { + min_create_bond: 10 * DOLLARS, + min_join_bond: 1 * DOLLARS, + ..Default::default() + }, } } diff --git a/frame/nomination-pools/Cargo.toml b/frame/nomination-pools/Cargo.toml index 0820125d77f44..5679f52696722 100644 --- a/frame/nomination-pools/Cargo.toml +++ b/frame/nomination-pools/Cargo.toml @@ -23,11 +23,11 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../primit sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } +sp-io = { default-features = false, path = "../../primitives/io" } log = { version = "0.4.0", default-features = false } [dev-dependencies] pallet-balances = { version = "4.0.0-dev", path = "../balances" } -sp-io = { version = "6.0.0", path = "../../primitives/io" } sp-tracing = { version = "5.0.0", path = "../../primitives/tracing" } [features] @@ -41,6 +41,7 @@ std = [ "frame-system/std", "sp-runtime/std", "sp-std/std", + "sp-io/std", "sp-staking/std", "sp-core/std", "log/std", diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5e61c1e446fcb..7c21067d79f01 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2051,6 +2051,18 @@ pub mod pallet { so a slash can be applied to relevant unboding pools. (We assume / the bonding duration > slash deffer duration.", ); + // check genesis value of `MinCreateBond`: it should be more than staking's minimum + // bond. + sp_std::if_std! { + sp_io::TestExternalities::new_empty().execute_with(|| + assert!( + MinCreateBond::::get() >= T::StakingInterface::minimum_bond(), + "MinCreateBond ({:?}) should be more than staking's minimum_bond ({:?})", + MinCreateBond::::get(), + T::StakingInterface::minimum_bond() + ) + ); + } } } } From d5dc6972e1f042a25e646d667c47f6e1e7cf57f5 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 24 May 2022 10:48:33 +0200 Subject: [PATCH 23/65] remove bad assertion -- needs to be dealt with later --- frame/nomination-pools/src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 7c21067d79f01..5e61c1e446fcb 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2051,18 +2051,6 @@ pub mod pallet { so a slash can be applied to relevant unboding pools. (We assume / the bonding duration > slash deffer duration.", ); - // check genesis value of `MinCreateBond`: it should be more than staking's minimum - // bond. - sp_std::if_std! { - sp_io::TestExternalities::new_empty().execute_with(|| - assert!( - MinCreateBond::::get() >= T::StakingInterface::minimum_bond(), - "MinCreateBond ({:?}) should be more than staking's minimum_bond ({:?})", - MinCreateBond::::get(), - T::StakingInterface::minimum_bond() - ) - ); - } } } } From f4dbd0af044662d5903016198686d46408a8e608 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 24 May 2022 23:58:06 -0400 Subject: [PATCH 24/65] nits --- frame/nomination-pools/Cargo.toml | 2 +- frame/nomination-pools/src/lib.rs | 34 +++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frame/nomination-pools/Cargo.toml b/frame/nomination-pools/Cargo.toml index 5679f52696722..be5c38d85552c 100644 --- a/frame/nomination-pools/Cargo.toml +++ b/frame/nomination-pools/Cargo.toml @@ -23,7 +23,7 @@ sp-runtime = { version = "6.0.0", default-features = false, path = "../../primit sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" } sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../primitives/staking" } sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" } -sp-io = { default-features = false, path = "../../primitives/io" } +sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" } log = { version = "0.4.0", default-features = false } [dev-dependencies] diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5e61c1e446fcb..d3a388d5b7992 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1871,21 +1871,6 @@ pub mod pallet { T::StakingInterface::nominate(bonded_pool.bonded_account(), validators) } - /// Chill on behalf of the pool. - /// - /// The dispatch origin of this call must be signed by the pool nominator or the pool - /// root role, same as [`Pallet::nominate`]. - /// - /// This directly forward the call to the staking pallet, on behalf of the pool bonded - /// account. - #[pallet::weight(T::WeightInfo::chill())] - pub fn chill(origin: OriginFor, pool_id: PoolId) -> DispatchResult { - let who = ensure_signed(origin)?; - let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; - ensure!(bonded_pool.can_nominate(&who), Error::::NotNominator); - T::StakingInterface::chill(bonded_pool.bonded_account()) - } - /// Set a new state for the pool. /// /// The dispatch origin of this call must be signed by the state toggler, or the root role @@ -2031,6 +2016,21 @@ pub mod pallet { bonded_pool.put(); Ok(()) } + + /// Chill on behalf of the pool. + /// + /// The dispatch origin of this call must be signed by the pool nominator or the pool + /// root role, same as [`Pallet::nominate`]. + /// + /// This directly forward the call to the staking pallet, on behalf of the pool bonded + /// account. + #[pallet::weight(T::WeightInfo::chill())] + pub fn chill(origin: OriginFor, pool_id: PoolId) -> DispatchResult { + let who = ensure_signed(origin)?; + let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; + ensure!(bonded_pool.can_nominate(&who), Error::::NotNominator); + T::StakingInterface::chill(bonded_pool.bonded_account()) + } } #[pallet::hooks] @@ -2425,7 +2425,7 @@ impl OnStakerSlash> for Pallet { pool_account: &T::AccountId, // Bonded balance is always read directly from staking, therefore we need not update // anything here. - _slashed_bonded: BalanceOf, + slashed_bonded: BalanceOf, slashed_unlocking: &BTreeMap>, ) { if let Some(pool_id) = ReversePoolIdLookup::::get(pool_account).defensive() { @@ -2444,7 +2444,7 @@ impl OnStakerSlash> for Pallet { } } - Self::deposit_event(Event::::PoolSlashed { pool_id, balance: _slashed_bonded }); + Self::deposit_event(Event::::PoolSlashed { pool_id, balance: slashed_bonded }); SubPoolsStorage::::insert(pool_id, sub_pools); } } From 0fb112564281797f05aad0b35075906b5532be93 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 9 Jun 2022 17:55:33 +0100 Subject: [PATCH 25/65] fix tests and add benchmarks for chill --- .../nomination-pools/benchmarking/src/lib.rs | 23 +++++++++++++++- frame/nomination-pools/src/lib.rs | 1 + frame/nomination-pools/src/mock.rs | 9 +++++-- frame/nomination-pools/src/tests.rs | 26 ++++++++++++------- frame/staking/src/pallet/impls.rs | 5 ++++ frame/support/src/storage/mod.rs | 2 +- frame/support/src/storage/transactional.rs | 6 ++--- primitives/staking/src/lib.rs | 4 +++ 8 files changed, 60 insertions(+), 16 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 275b914cda297..7fb57ca8926ff 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -24,7 +24,7 @@ mod mock; use frame_benchmarking::{account, frame_support::traits::Currency, vec, whitelist_account, Vec}; use frame_election_provider_support::SortedListProvider; -use frame_support::{ensure, traits::Get}; +use frame_support::{ensure, assert_ok, traits::Get}; use frame_system::RawOrigin as Origin; use pallet_nomination_pools::{ BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, MaxPoolMembers, @@ -653,6 +653,27 @@ frame_benchmarking::benchmarks! { ) } + chill { + // Create a pool + let min_create_bond = MinCreateBond::::get() + .max(T::StakingInterface::minimum_bond()) + .max(CurrencyOf::::minimum_balance()); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + + // Nominate with the pool. + let validators: Vec<_> = (0..T::MaxNominations::get()) + .map(|i| account("stash", USER_SEED, i)) + .collect(); + + assert_ok!(Pools::::nominate(Origin::Signed(depositor.clone()).into(), 1, validators)); + assert!(T::StakingInterface::nominations(Pools::::create_bonded_account(1)).is_some()); + + whitelist_account!(depositor); + }:_(Origin::Signed(depositor.clone()), 1) + verify { + assert!(T::StakingInterface::nominations(Pools::::create_bonded_account(1)).is_none()); + } + impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext(), diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d8b646e4d5a17..2568801b13bc9 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1549,6 +1549,7 @@ pub mod pallet { /// there are too many unlocking chunks, the result of this call will likely be the /// `NoMoreChunks` error from the staking system. #[pallet::weight(T::WeightInfo::unbond())] + // #[frame_support::transactional] pub fn unbond( origin: OriginFor, member_account: T::AccountId, diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index d347d1c5c6023..2b4a7bc5a4267 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -23,7 +23,7 @@ parameter_types! { pub storage UnbondingBalanceMap: BTreeMap = Default::default(); #[derive(Clone, PartialEq)] pub static MaxUnbonding: u32 = 8; - pub storage Nominations: Vec = vec![]; + pub storage Nominations: Option> = None; } pub struct StakingMock; @@ -107,9 +107,14 @@ impl sp_staking::StakingInterface for StakingMock { } fn nominate(_: Self::AccountId, nominations: Vec) -> DispatchResult { - Nominations::set(&nominations); + Nominations::set(&Some(nominations)); + dbg!(Nominations::get()); Ok(()) } + + fn nominations(_: Self::AccountId) -> Option> { + Nominations::get() + } } impl frame_system::Config for Runtime { diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 34be57165dfec..97104423c5910 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -18,7 +18,7 @@ use super::*; use crate::{mock::*, Event}; use frame_support::{ - assert_noop, assert_ok, assert_storage_noop, bounded_btree_map, + assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_btree_map, storage::{with_transaction, TransactionOutcome}, }; use pallet_balances::Event as BEvent; @@ -66,7 +66,7 @@ fn test_setup_works() { ); assert_eq!( RewardPools::::get(last_pool).unwrap(), - RewardPool:: { balance: 0, points: 0.into(), total_earnings: 0 } + RewardPool:: { balance: 0, points: 0u32.into(), total_earnings: 0 } ); assert_eq!( PoolMembers::::get(10).unwrap(), @@ -81,7 +81,7 @@ fn test_setup_works() { assert_eq!(StakingMock::total_stake(&bonded_account).unwrap(), 10); // but not nominating yet. - assert!(Nominations::get().is_empty()); + assert!(Nominations::get().is_none()); // reward account should have an initial ED in it. assert_eq!(Balances::free_balance(&reward_account), Balances::minimum_balance()); @@ -2059,8 +2059,12 @@ mod unbond { ); // when: unbonding more than our active: error - assert_noop!( - Pools::unbond(Origin::signed(10), 10, 5), + assert_err!( + frame_support::storage::in_storage_layer(|| Pools::unbond( + Origin::signed(10), + 10, + 5 + )), Error::::NotEnoughPointsToUnbond ); // instead: @@ -2109,8 +2113,12 @@ mod unbond { // when CurrentEra::set(2); - assert_noop!( - Pools::unbond(Origin::signed(10), 10, 4), + assert_err!( + frame_support::storage::in_storage_layer(|| Pools::unbond( + Origin::signed(10), + 10, + 4 + )), Error::::MaxUnbondingLimit ); @@ -3185,11 +3193,11 @@ mod nominate { // Root can nominate assert_ok!(Pools::nominate(Origin::signed(900), 1, vec![21])); - assert_eq!(Nominations::get(), vec![21]); + assert_eq!(Nominations::get().unwrap(), vec![21]); // Nominator can nominate assert_ok!(Pools::nominate(Origin::signed(901), 1, vec![31])); - assert_eq!(Nominations::get(), vec![31]); + assert_eq!(Nominations::get().unwrap(), vec![31]); // Can't nominate for a pool that doesn't exist assert_noop!( diff --git a/frame/staking/src/pallet/impls.rs b/frame/staking/src/pallet/impls.rs index 30ae8bae7663d..7656eec80a5ff 100644 --- a/frame/staking/src/pallet/impls.rs +++ b/frame/staking/src/pallet/impls.rs @@ -1445,4 +1445,9 @@ impl StakingInterface for Pallet { let targets = targets.into_iter().map(T::Lookup::unlookup).collect::>(); Self::nominate(RawOrigin::Signed(controller).into(), targets) } + + #[cfg(feature = "runtime-benchmarks")] + fn nominations(who: Self::AccountId) -> Option> { + Nominators::::get(who).map(|n| n.targets.into_inner()) + } } diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index 6911da630cb34..d9e50a1e1345e 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -1267,7 +1267,7 @@ pub trait StoragePrefixedMap { pub trait StorageAppend: private::Sealed {} /// Marker trait that will be implemented for types that support to decode their length in an -/// effificent way. It is expected that the length is at the beginning of the encoded object +/// efficient way. It is expected that the length is at the beginning of the encoded object /// and that the length is a `Compact`. /// /// This trait is sealed. diff --git a/frame/support/src/storage/transactional.rs b/frame/support/src/storage/transactional.rs index d1bdb30af947b..909d5909ed8bd 100644 --- a/frame/support/src/storage/transactional.rs +++ b/frame/support/src/storage/transactional.rs @@ -164,9 +164,9 @@ where /// Execute the supplied function, adding a new storage layer. /// -/// This is the same as `with_transaction`, but assuming that any function returning -/// an `Err` should rollback, and any function returning `Ok` should commit. This -/// provides a cleaner API to the developer who wants this behavior. +/// This is the same as `with_transaction`, but assuming that any function returning an `Err` should +/// rollback, and any function returning `Ok` should commit. This provides a cleaner API to the +/// developer who wants this behavior. pub fn with_storage_layer(f: F) -> Result where E: From, diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index 50abfb0121621..1f191fbbb8c2d 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -134,4 +134,8 @@ pub trait StakingInterface { stash: Self::AccountId, num_slashing_spans: u32, ) -> Result; + + /// Get the nominations of a stash, if they are a nominator, `None` otherwise. + #[cfg(feature = "runtime-benchmarks")] + fn nominations(who: Self::AccountId) -> Option>; } From 12773bb09c76b3efac2ad2f2d2b9813ef6096d3a Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 9 Jun 2022 17:55:59 +0100 Subject: [PATCH 26/65] remove stuff --- frame/nomination-pools/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 2568801b13bc9..d8b646e4d5a17 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1549,7 +1549,6 @@ pub mod pallet { /// there are too many unlocking chunks, the result of this call will likely be the /// `NoMoreChunks` error from the staking system. #[pallet::weight(T::WeightInfo::unbond())] - // #[frame_support::transactional] pub fn unbond( origin: OriginFor, member_account: T::AccountId, From ca475dfd7c4ecb611d5670532786c75924e786be Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 10 Jun 2022 08:05:05 +0100 Subject: [PATCH 27/65] fix benchmarks --- .../nomination-pools/benchmarking/src/lib.rs | 63 +++++++------------ frame/nomination-pools/src/mock.rs | 1 - primitives/staking/src/lib.rs | 2 +- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/lib.rs b/frame/nomination-pools/benchmarking/src/lib.rs index 7fb57ca8926ff..4c2c902846a85 100644 --- a/frame/nomination-pools/benchmarking/src/lib.rs +++ b/frame/nomination-pools/benchmarking/src/lib.rs @@ -24,7 +24,7 @@ mod mock; use frame_benchmarking::{account, frame_support::traits::Currency, vec, whitelist_account, Vec}; use frame_election_provider_support::SortedListProvider; -use frame_support::{ensure, assert_ok, traits::Get}; +use frame_support::{assert_ok, ensure, traits::Get}; use frame_system::RawOrigin as Origin; use pallet_nomination_pools::{ BalanceOf, BondExtra, BondedPoolInner, BondedPools, ConfigOp, MaxPoolMembers, @@ -48,6 +48,12 @@ pub trait Config: pub struct Pallet(Pools); +fn min_create_bond() -> BalanceOf { + MinCreateBond::::get() + .max(T::StakingInterface::minimum_bond()) + .max(CurrencyOf::::minimum_balance()) +} + fn create_funded_user_with_balance( string: &'static str, n: u32, @@ -209,9 +215,7 @@ impl ListScenario { frame_benchmarking::benchmarks! { join { - let origin_weight = pallet_nomination_pools::MinCreateBond::::get() - .max(CurrencyOf::::minimum_balance()) - * 2u32.into(); + let origin_weight = min_create_bond::() * 2u32.into(); // setup the worst case list scenario. let scenario = ListScenario::::new(origin_weight, true)?; @@ -237,9 +241,7 @@ frame_benchmarking::benchmarks! { } bond_extra_transfer { - let origin_weight = pallet_nomination_pools::MinCreateBond::::get() - .max(CurrencyOf::::minimum_balance()) - * 2u32.into(); + let origin_weight = min_create_bond::() * 2u32.into(); let scenario = ListScenario::::new(origin_weight, true)?; let extra = scenario.dest_weight.clone() - origin_weight; @@ -254,9 +256,7 @@ frame_benchmarking::benchmarks! { } bond_extra_reward { - let origin_weight = pallet_nomination_pools::MinCreateBond::::get() - .max(CurrencyOf::::minimum_balance()) - * 2u32.into(); + let origin_weight = min_create_bond::() * 2u32.into(); let scenario = ListScenario::::new(origin_weight, true)?; let extra = (scenario.dest_weight.clone() - origin_weight).max(CurrencyOf::::minimum_balance()); @@ -274,7 +274,7 @@ frame_benchmarking::benchmarks! { } claim_payout { - let origin_weight = pallet_nomination_pools::MinCreateBond::::get().max(CurrencyOf::::minimum_balance()) * 2u32.into(); + let origin_weight = min_create_bond::() * 2u32.into(); let ed = CurrencyOf::::minimum_balance(); let (depositor, pool_account) = create_pool_account::(0, origin_weight); let reward_account = Pools::::create_reward_account(1); @@ -304,9 +304,7 @@ frame_benchmarking::benchmarks! { unbond { // The weight the nominator will start at. The value used here is expected to be // significantly higher than the first position in a list (e.g. the first bag threshold). - let origin_weight = BalanceOf::::try_from(952_994_955_240_703u128) - .map_err(|_| "balance expected to be a u128") - .unwrap(); + let origin_weight = min_create_bond::() * 200u32.into(); let scenario = ListScenario::::new(origin_weight, false)?; let amount = origin_weight - scenario.dest_weight.clone(); @@ -336,9 +334,7 @@ frame_benchmarking::benchmarks! { pool_withdraw_unbonded { let s in 0 .. MAX_SPANS; - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); + let min_create_bond = min_create_bond::(); let (depositor, pool_account) = create_pool_account::(0, min_create_bond); // Add a new member @@ -380,9 +376,7 @@ frame_benchmarking::benchmarks! { withdraw_unbonded_update { let s in 0 .. MAX_SPANS; - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); + let min_create_bond = min_create_bond::(); let (depositor, pool_account) = create_pool_account::(0, min_create_bond); // Add a new member @@ -427,10 +421,7 @@ frame_benchmarking::benchmarks! { withdraw_unbonded_kill { let s in 0 .. MAX_SPANS; - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); - + let min_create_bond = min_create_bond::(); let (depositor, pool_account) = create_pool_account::(0, min_create_bond); // We set the pool to the destroying state so the depositor can leave @@ -494,9 +485,7 @@ frame_benchmarking::benchmarks! { } create { - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); + let min_create_bond = min_create_bond::(); let depositor: T::AccountId = account("depositor", USER_SEED, 0); // Give the depositor some balance to bond @@ -542,9 +531,7 @@ frame_benchmarking::benchmarks! { let n in 1 .. T::MaxNominations::get(); // Create a pool - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); + let min_create_bond = min_create_bond::() * 2u32.into(); let (depositor, pool_account) = create_pool_account::(0, min_create_bond); // Create some accounts to nominate. For the sake of benchmarking they don't need to be @@ -581,9 +568,7 @@ frame_benchmarking::benchmarks! { set_state { // Create a pool - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); + let min_create_bond = min_create_bond::(); let (depositor, pool_account) = create_pool_account::(0, min_create_bond); BondedPools::::mutate(&1, |maybe_pool| { // Force the pool into an invalid state @@ -601,10 +586,7 @@ frame_benchmarking::benchmarks! { let n in 1 .. ::MaxMetadataLen::get(); // Create a pool - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond::() * 2u32.into()); // Create metadata of the max possible size let metadata: Vec = (0..n).map(|_| 42).collect(); @@ -633,7 +615,7 @@ frame_benchmarking::benchmarks! { update_roles { let first_id = pallet_nomination_pools::LastPoolId::::get() + 1; - let (root, _) = create_pool_account::(0, CurrencyOf::::minimum_balance() * 2u32.into()); + let (root, _) = create_pool_account::(0, min_create_bond::() * 2u32.into()); let random: T::AccountId = account("but is anything really random in computers..?", 0, USER_SEED); }:_( Origin::Signed(root.clone()), @@ -655,10 +637,7 @@ frame_benchmarking::benchmarks! { chill { // Create a pool - let min_create_bond = MinCreateBond::::get() - .max(T::StakingInterface::minimum_bond()) - .max(CurrencyOf::::minimum_balance()); - let (depositor, pool_account) = create_pool_account::(0, min_create_bond); + let (depositor, pool_account) = create_pool_account::(0, min_create_bond::() * 2u32.into()); // Nominate with the pool. let validators: Vec<_> = (0..T::MaxNominations::get()) diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 2b4a7bc5a4267..a3020e5add044 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -108,7 +108,6 @@ impl sp_staking::StakingInterface for StakingMock { fn nominate(_: Self::AccountId, nominations: Vec) -> DispatchResult { Nominations::set(&Some(nominations)); - dbg!(Nominations::get()); Ok(()) } diff --git a/primitives/staking/src/lib.rs b/primitives/staking/src/lib.rs index 1f191fbbb8c2d..5a3e97b4d5274 100644 --- a/primitives/staking/src/lib.rs +++ b/primitives/staking/src/lib.rs @@ -137,5 +137,5 @@ pub trait StakingInterface { /// Get the nominations of a stash, if they are a nominator, `None` otherwise. #[cfg(feature = "runtime-benchmarks")] - fn nominations(who: Self::AccountId) -> Option>; + fn nominations(who: Self::AccountId) -> Option>; } From f027faf1dcd4825819c4777c29502e9ffab51cc7 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Fri, 10 Jun 2022 07:25:13 +0000 Subject: [PATCH 28/65] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/nomination-pools/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/nomination-pools/src/weights.rs | 143 ++++++++++++++++---------- 1 file changed, 87 insertions(+), 56 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 7c7cca38d732b..8e3facfc5ec26 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -1,4 +1,3 @@ - // This file is part of Substrate. // Copyright (C) 2022 Parity Technologies (UK) Ltd. @@ -19,11 +18,12 @@ //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-05-23, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-06-10, 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: -// ./target/production/substrate +// target/production/substrate // benchmark // pallet // --chain=dev @@ -33,8 +33,9 @@ // --extrinsic=* // --execution=wasm // --wasm-execution=compiled -// --template=./.maintain/frame-weight-template.hbs +// --heap-pages=4096 // --output=./frame/nomination-pools/src/weights.rs +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -54,12 +55,12 @@ pub trait WeightInfo { fn withdraw_unbonded_update(s: u32, ) -> Weight; fn withdraw_unbonded_kill(s: u32, ) -> Weight; fn create() -> Weight; - fn nominate(n: u32) -> Weight; - fn chill() -> Weight; + fn nominate(n: u32, ) -> Weight; fn set_state() -> Weight; fn set_metadata(n: u32, ) -> Weight; fn set_configs() -> Weight; fn update_roles() -> Weight; + fn chill() -> Weight; } /// Weights for pallet_nomination_pools using the Substrate node and recommended hardware. @@ -79,7 +80,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn join() -> Weight { - (129_124_000 as Weight) + (124_508_000 as Weight) .saturating_add(T::DbWeight::get().reads(17 as Weight)) .saturating_add(T::DbWeight::get().writes(11 as Weight)) } @@ -93,7 +94,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - (118_193_000 as Weight) + (115_185_000 as Weight) .saturating_add(T::DbWeight::get().reads(13 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } @@ -104,19 +105,19 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Ledger (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Balances Locks (r:1 w:1) - // Storage: BagsList ListNodes (r:2 w:2) + // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - (132_390_000 as Weight) - .saturating_add(T::DbWeight::get().reads(13 as Weight)) - .saturating_add(T::DbWeight::get().writes(12 as Weight)) + (132_723_000 as Weight) + .saturating_add(T::DbWeight::get().reads(14 as Weight)) + .saturating_add(T::DbWeight::get().writes(13 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_payout() -> Weight { - (54_743_000 as Weight) + (52_498_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -135,7 +136,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - (124_684_000 as Weight) + (121_645_000 as Weight) .saturating_add(T::DbWeight::get().reads(18 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } @@ -143,10 +144,11 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Ledger (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) + /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - (44_259_000 as Weight) + (43_320_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((49_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -158,10 +160,11 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - (84_854_000 as Weight) - // Standard Error: 0 - .saturating_add((56_000 as Weight).saturating_mul(s as Weight)) + (83_195_000 as Weight) + // Standard Error: 5_000 + .saturating_add((57_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -184,8 +187,9 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForBondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) + /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (146_992_000 as Weight) + (143_495_000 as Weight) .saturating_add(T::DbWeight::get().reads(19 as Weight)) .saturating_add(T::DbWeight::get().writes(16 as Weight)) } @@ -212,7 +216,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - (138_099_000 as Weight) + (127_998_000 as Weight) .saturating_add(T::DbWeight::get().reads(22 as Weight)) .saturating_add(T::DbWeight::get().writes(15 as Weight)) } @@ -228,29 +232,28 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) + /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - (50_964_000 as Weight) - // Standard Error: 11_000 - .saturating_add((2_333_000 as Weight).saturating_mul(n as Weight)) + (49_929_000 as Weight) + // Standard Error: 16_000 + .saturating_add((2_319_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } - fn chill() -> Weight { - 0 - } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - (27_196_000 as Weight) + (27_399_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: NominationPools Metadata (r:1 w:1) // Storage: NominationPools CounterForMetadata (r:1 w:1) + /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - (15_056_000 as Weight) + (14_813_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) @@ -262,15 +265,28 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools MinCreateBond (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - (6_294_000 as Weight) + (6_115_000 as Weight) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - (22_444_000 as Weight) + (22_546_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) + // Storage: BagsList ListNodes (r:1 w:1) + // Storage: BagsList ListBags (r:1 w:1) + // Storage: BagsList CounterForListNodes (r:1 w:1) + fn chill() -> Weight { + (48_243_000 as Weight) + .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().writes(5 as Weight)) + } } // For backwards compatibility and tests @@ -289,7 +305,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn join() -> Weight { - (129_124_000 as Weight) + (124_508_000 as Weight) .saturating_add(RocksDbWeight::get().reads(17 as Weight)) .saturating_add(RocksDbWeight::get().writes(11 as Weight)) } @@ -303,7 +319,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - (118_193_000 as Weight) + (115_185_000 as Weight) .saturating_add(RocksDbWeight::get().reads(13 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } @@ -314,19 +330,19 @@ impl WeightInfo for () { // Storage: Staking Ledger (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Balances Locks (r:1 w:1) - // Storage: BagsList ListNodes (r:2 w:2) + // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - (132_390_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(13 as Weight)) - .saturating_add(RocksDbWeight::get().writes(12 as Weight)) + (132_723_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(14 as Weight)) + .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_payout() -> Weight { - (54_743_000 as Weight) + (52_498_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -345,7 +361,7 @@ impl WeightInfo for () { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - (124_684_000 as Weight) + (121_645_000 as Weight) .saturating_add(RocksDbWeight::get().reads(18 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } @@ -353,10 +369,11 @@ impl WeightInfo for () { // Storage: Staking Ledger (r:1 w:1) // Storage: Staking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) + /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - (44_259_000 as Weight) + (43_320_000 as Weight) // Standard Error: 0 - .saturating_add((51_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((49_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -368,10 +385,11 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) // Storage: NominationPools CounterForPoolMembers (r:1 w:1) + /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - (84_854_000 as Weight) - // Standard Error: 0 - .saturating_add((56_000 as Weight).saturating_mul(s as Weight)) + (83_195_000 as Weight) + // Standard Error: 5_000 + .saturating_add((57_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -394,8 +412,9 @@ impl WeightInfo for () { // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForBondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) + /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (146_992_000 as Weight) + (143_495_000 as Weight) .saturating_add(RocksDbWeight::get().reads(19 as Weight)) .saturating_add(RocksDbWeight::get().writes(16 as Weight)) } @@ -422,7 +441,7 @@ impl WeightInfo for () { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - (138_099_000 as Weight) + (127_998_000 as Weight) .saturating_add(RocksDbWeight::get().reads(22 as Weight)) .saturating_add(RocksDbWeight::get().writes(15 as Weight)) } @@ -438,29 +457,28 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) // Storage: Staking CounterForNominators (r:1 w:1) + /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - (50_964_000 as Weight) - // Standard Error: 11_000 - .saturating_add((2_333_000 as Weight).saturating_mul(n as Weight)) + (49_929_000 as Weight) + // Standard Error: 16_000 + .saturating_add((2_319_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } - fn chill() -> Weight { - 0 - } // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - (27_196_000 as Weight) + (27_399_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:0) // Storage: NominationPools Metadata (r:1 w:1) // Storage: NominationPools CounterForMetadata (r:1 w:1) + /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - (15_056_000 as Weight) + (14_813_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) @@ -472,13 +490,26 @@ impl WeightInfo for () { // Storage: NominationPools MinCreateBond (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - (6_294_000 as Weight) + (6_115_000 as Weight) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - (22_444_000 as Weight) + (22_546_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } + // Storage: NominationPools BondedPools (r:1 w:0) + // Storage: Staking Ledger (r:1 w:0) + // Storage: Staking Validators (r:1 w:0) + // Storage: Staking Nominators (r:1 w:1) + // Storage: Staking CounterForNominators (r:1 w:1) + // Storage: BagsList ListNodes (r:1 w:1) + // Storage: BagsList ListBags (r:1 w:1) + // Storage: BagsList CounterForListNodes (r:1 w:1) + fn chill() -> Weight { + (48_243_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + } } From d69af2c3ee0664cfcc09c9e5ede876bcd38124e8 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 11 Jun 2022 12:29:46 +0100 Subject: [PATCH 29/65] remove defensive --- frame/nomination-pools/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d8b646e4d5a17..19155a51405b0 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -2260,6 +2260,7 @@ impl Pallet { if reward_pool.total_earnings == BalanceOf::::max_value() { bonded_pool.set_state(PoolState::Destroying); }; + member.reward_pool_total_earnings = reward_pool.total_earnings; reward_pool.points = current_points.saturating_sub(member_virtual_points); reward_pool.balance = reward_pool.balance.saturating_sub(member_payout); @@ -2443,7 +2444,7 @@ impl OnStakerSlash> for Pallet { slashed_bonded: BalanceOf, slashed_unlocking: &BTreeMap>, ) { - if let Some(pool_id) = ReversePoolIdLookup::::get(pool_account).defensive() { + if let Some(pool_id) = ReversePoolIdLookup::::get(pool_account) { let mut sub_pools = match SubPoolsStorage::::get(pool_id).defensive() { Some(sub_pools) => sub_pools, None => return, From 486a0e9f09eca3e52be69a0d21dbef078cd1211b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 13 Jun 2022 21:32:22 +0100 Subject: [PATCH 30/65] first working version --- frame/nomination-pools/src/lib.rs | 191 +- frame/nomination-pools/src/mock.rs | 14 +- frame/nomination-pools/src/tests.rs | 6959 ++++++++++++++------------- 3 files changed, 3612 insertions(+), 3552 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 19155a51405b0..ddafd015b742b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -320,7 +320,10 @@ use frame_support::{ }; use scale_info::TypeInfo; use sp_core::U256; -use sp_runtime::traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Saturating, Zero}; +use sp_runtime::{ + traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Saturating, Zero}, + FixedU128, FixedPointNumber, +}; use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, ops::Div, vec::Vec}; @@ -350,9 +353,9 @@ pub use pallet::*; pub use weights::WeightInfo; /// The balance type used by the currency system. -pub type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; +pub type BalanceOf = ::CurrencyBalance; /// Type used to track the points of a reward pool. +// TODO: remove all things related to the u256 stuff. pub type RewardPoints = U256; /// Type used for unique identifier of each pool. pub type PoolId = u32; @@ -411,13 +414,17 @@ pub struct PoolMember { /// Assuming no massive burning events, we expect this value to always be below total issuance. /// This value lines up with the [`RewardPool::total_earnings`] after a member claims a /// payout. - pub reward_pool_total_earnings: BalanceOf, + pub last_recorded_reward_counter: FixedU128, /// The eras in which this member is unbonding, mapped from era index to the number of /// points scheduled to unbond in the given era. pub unbonding_eras: BoundedBTreeMap, T::MaxUnbonding>, } impl PoolMember { + fn pending_rewards(&self, current_reward_counter: FixedU128) -> BalanceOf { + (current_reward_counter - self.last_recorded_reward_counter).saturating_mul_int(self.active_points()) + } + fn total_points(&self) -> BalanceOf { self.active_points().saturating_add(self.unbonding_points()) } @@ -933,40 +940,25 @@ impl BondedPool { #[codec(mel_bound(T: Config))] #[scale_info(skip_type_params(T))] pub struct RewardPool { - /// The balance of this reward pool after the last claimed payout. - pub balance: BalanceOf, - /// The total earnings _ever_ of this reward pool after the last claimed payout. I.E. the sum - /// of all incoming balance through the pools life. - /// - /// NOTE: We assume this will always be less than total issuance and thus can use the runtimes - /// `Balance` type. However in a chain with a burn rate higher than the rate this increases, - /// this type should be bigger than `Balance`. - pub total_earnings: BalanceOf, - /// The total points of this reward pool after the last claimed payout. - pub points: RewardPoints, + pub last_recorded_reward_counter: FixedU128, + pub last_recorded_total_payouts: BalanceOf, + pub total_rewards_claimed: BalanceOf, } impl RewardPool { - /// Mutate the reward pool by updating the total earnings and current free balance. - fn update_total_earnings_and_balance(&mut self, id: PoolId) { - let current_balance = Self::current_balance(id); - // The earnings since the last time it was updated - let new_earnings = current_balance.saturating_sub(self.balance); - // The lifetime earnings of the of the reward pool - self.total_earnings = new_earnings.saturating_add(self.total_earnings); - self.balance = current_balance; - } - - /// Get a reward pool and update its total earnings and balance - fn get_and_update(id: PoolId) -> Option { - RewardPools::::get(id).map(|mut r| { - r.update_total_earnings_and_balance(id); - r - }) - } - - /// The current balance of the reward pool. Never access the reward pools free balance directly. - /// The existential deposit was not received as a reward, so the reward pool can not use it. + fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) { + let balance = Self::current_balance(id); + self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points); + self.last_recorded_total_payouts = balance + self.total_rewards_claimed; + } + + fn current_reward_counter(&self, id: PoolId, bonded_points: BalanceOf) -> FixedU128 { + let balance = Self::current_balance(id); + let payouts_since_last_record = + balance + self.total_rewards_claimed - self.last_recorded_total_payouts; + self.last_recorded_reward_counter + (FixedU128::saturating_from_rational(payouts_since_last_record, bonded_points)) + } + fn current_balance(id: PoolId) -> BalanceOf { T::Currency::free_balance(&Pallet::::create_reward_account(id)) .saturating_sub(T::Currency::minimum_balance()) @@ -1116,7 +1108,17 @@ pub mod pallet { type WeightInfo: weights::WeightInfo; /// The nominating balance. - type Currency: Currency; + type Currency: Currency; + // TODO: not sure if I need this after all. Update BalanceOf type accordingly. + type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned + + codec::FullCodec + + Copy + + MaybeSerializeDeserialize + + sp_std::fmt::Debug + + Default + + sp_runtime::FixedPointOperand + + TypeInfo + + MaxEncodedLen; /// The nomination pool's pallet id. #[pallet::constant] @@ -1426,10 +1428,13 @@ pub mod pallet { let mut bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; bonded_pool.ok_to_join(amount)?; - // We just need its total earnings at this point in time, but we don't need to write it - // because we are not adjusting its points (all other values can calculated virtual). - let reward_pool = RewardPool::::get_and_update(pool_id) + let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; + let current_reward_counter = + reward_pool.current_reward_counter(pool_id, bonded_pool.points); + + // reward pool records must be updated with the old points. + reward_pool.update_records(pool_id, bonded_pool.points); bonded_pool.try_inc_members()?; let points_issued = bonded_pool.try_bond_funds(&who, amount, BondType::Later)?; @@ -1439,13 +1444,7 @@ pub mod pallet { PoolMember:: { pool_id, points: points_issued, - // At best the reward pool has the rewards up through the previous era. If the - // member joins prior to the snapshot they will benefit from the rewards of - // the active era despite not contributing to the pool's vote weight. If they - // join after the snapshot is taken they will benefit from the rewards of the - // next 2 eras because their vote weight will not be counted until the - // snapshot in active era + 1. - reward_pool_total_earnings: reward_pool.total_earnings, + last_recorded_reward_counter: current_reward_counter, unbonding_eras: Default::default(), }, ); @@ -1456,7 +1455,9 @@ pub mod pallet { bonded: amount, joined: true, }); + bonded_pool.put(); + RewardPools::::insert(pool_id, reward_pool); Ok(()) } @@ -1473,6 +1474,7 @@ pub mod pallet { .max(T::WeightInfo::bond_extra_reward()) )] pub fn bond_extra(origin: OriginFor, extra: BondExtra>) -> DispatchResult { + // TODO: claim payouts here before updating the points. let who = ensure_signed(origin)?; let (mut member, mut bonded_pool, mut reward_pool) = Self::get_member_with_pools(&who)?; @@ -1839,16 +1841,16 @@ pub mod pallet { PoolMember:: { pool_id, points, - reward_pool_total_earnings: Zero::zero(), + last_recorded_reward_counter: Zero::zero(), unbonding_eras: Default::default(), }, ); RewardPools::::insert( pool_id, RewardPool:: { - balance: Zero::zero(), - points: U256::zero(), - total_earnings: Zero::zero(), + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: Zero::zero(), + total_rewards_claimed: Zero::zero(), }, ); ReversePoolIdLookup::::insert(bonded_pool.bonded_account(), pool_id); @@ -2199,75 +2201,6 @@ impl Pallet { .div(current_points) } - /// Calculate the rewards for `member`. - /// - /// Returns the payout amount. - fn calculate_member_payout( - member: &mut PoolMember, - bonded_pool: &mut BondedPool, - reward_pool: &mut RewardPool, - ) -> Result, DispatchError> { - let u256 = |x| T::BalanceToU256::convert(x); - let balance = |x| T::U256ToBalance::convert(x); - - let last_total_earnings = reward_pool.total_earnings; - reward_pool.update_total_earnings_and_balance(bonded_pool.id); - - // Notice there is an edge case where total_earnings have not increased and this is zero - let new_earnings = u256(reward_pool.total_earnings.saturating_sub(last_total_earnings)); - - // The new points that will be added to the pool. For every unit of balance that has been - // earned by the reward pool, we inflate the reward pool points by `bonded_pool.points`. In - // effect this allows each, single unit of balance (e.g. plank) to be divvied up pro rata - // among members based on points. - let new_points = u256(bonded_pool.points).saturating_mul(new_earnings); - - // The points of the reward pool after taking into account the new earnings. Notice that - // this only stays even or increases over time except for when we subtract member virtual - // shares. - let current_points = bonded_pool.bound_check(reward_pool.points.saturating_add(new_points)); - - // The rewards pool's earnings since the last time this member claimed a payout. - let new_earnings_since_last_claim = - reward_pool.total_earnings.saturating_sub(member.reward_pool_total_earnings); - - // The points of the reward pool that belong to the member. - let member_virtual_points = - // The members portion of the reward pool - u256(member.active_points()) - // times the amount the pool has earned since the member last claimed. - .saturating_mul(u256(new_earnings_since_last_claim)); - - let member_payout = if member_virtual_points.is_zero() || - current_points.is_zero() || - reward_pool.balance.is_zero() - { - Zero::zero() - } else { - // Equivalent to `(member_virtual_points / current_points) * reward_pool.balance` - let numerator = { - let numerator = member_virtual_points.saturating_mul(u256(reward_pool.balance)); - bonded_pool.bound_check(numerator) - }; - balance( - numerator - // We check for zero above - .div(current_points), - ) - }; - - // Record updates - if reward_pool.total_earnings == BalanceOf::::max_value() { - bonded_pool.set_state(PoolState::Destroying); - }; - - member.reward_pool_total_earnings = reward_pool.total_earnings; - reward_pool.points = current_points.saturating_sub(member_virtual_points); - reward_pool.balance = reward_pool.balance.saturating_sub(member_payout); - - Ok(member_payout) - } - /// If the member has some rewards, transfer a payout from the reward pool to the member. // Emits events and potentially modifies pool state if any arithmetic saturates, but does // not persist any of the mutable inputs to storage. @@ -2278,28 +2211,36 @@ impl Pallet { reward_pool: &mut RewardPool, ) -> Result, DispatchError> { debug_assert_eq!(member.pool_id, bonded_pool.id); + // a member who has no skin in the game anymore cannot claim any rewards. ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); + let was_destroying = bonded_pool.is_destroying(); - let member_payout = Self::calculate_member_payout(member, bonded_pool, reward_pool)?; + let current_reward_counter = + reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points); + let pending_rewards = member.pending_rewards(current_reward_counter); + + member.last_recorded_reward_counter = current_reward_counter; + reward_pool.total_rewards_claimed += pending_rewards; - if member_payout.is_zero() { - return Ok(member_payout) + if pending_rewards.is_zero() { + return Ok(pending_rewards) } // Transfer payout to the member. T::Currency::transfer( &bonded_pool.reward_account(), &member_account, - member_payout, + pending_rewards, ExistenceRequirement::AllowDeath, )?; + // TODO don't do this either, call site should do. Self::deposit_event(Event::::PaidOut { member: member_account.clone(), pool_id: member.pool_id, - payout: member_payout, + payout: pending_rewards, }); if bonded_pool.is_destroying() && !was_destroying { @@ -2309,7 +2250,7 @@ impl Pallet { }); } - Ok(member_payout) + Ok(pending_rewards) } /// Ensure the correctness of the state of this pallet. diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index a3020e5add044..045f289f3b370 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -111,6 +111,7 @@ impl sp_staking::StakingInterface for StakingMock { Ok(()) } + #[cfg(feature = "runtime-benchmarks")] fn nominations(_: Self::AccountId) -> Option> { Nominations::get() } @@ -183,6 +184,7 @@ impl pools::Config for Runtime { type Event = Event; type WeightInfo = (); type Currency = Balances; + type CurrencyBalance = Balance; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = StakingMock; @@ -280,8 +282,8 @@ pub(crate) fn unsafe_set_state(pool_id: PoolId, state: PoolState) -> Result<(), } parameter_types! { - static PoolsEvents: usize = 0; - static BalancesEvents: usize = 0; + storage PoolsEvents: u32 = 0; + storage BalancesEvents: u32 = 0; } /// All events of this pallet. @@ -292,8 +294,8 @@ pub(crate) fn pool_events_since_last_call() -> Vec> { .filter_map(|e| if let Event::Pools(inner) = e { Some(inner) } else { None }) .collect::>(); let already_seen = PoolsEvents::get(); - PoolsEvents::set(events.len()); - events.into_iter().skip(already_seen).collect() + PoolsEvents::set(&(events.len() as u32)); + events.into_iter().skip(already_seen as usize).collect() } /// All events of the `Balances` pallet. @@ -304,8 +306,8 @@ pub(crate) fn balances_events_since_last_call() -> Vec>(); let already_seen = BalancesEvents::get(); - BalancesEvents::set(events.len()); - events.into_iter().skip(already_seen).collect() + BalancesEvents::set(&(events.len() as u32)); + events.into_iter().skip(already_seen as usize).collect() } /// Same as `fully_unbond`, in permissioned setting. diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 97104423c5910..e084cece1d271 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -22,7 +22,7 @@ use frame_support::{ storage::{with_transaction, TransactionOutcome}, }; use pallet_balances::Event as BEvent; -use sp_runtime::traits::Dispatchable; +use sp_runtime::{traits::Dispatchable, FixedU128}; macro_rules! unbonding_pools_with_era { ($($k:expr => $v:expr),* $(,)?) => {{ @@ -42,6 +42,171 @@ macro_rules! member_unbonding_eras { pub const DEFAULT_ROLES: PoolRoles = PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), state_toggler: Some(902) }; +#[test] +fn rewards_distribution_is_fair_basic() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 10).unwrap(); + + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); + + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + ] + ); + + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + ] + ); + }); +} + +#[test] +fn rewards_distribution_is_fair_basic_with_fractions() { + // basically checks the case where the amount of rewards is less than the pool shares. for this, + // we have to rely on fixed point arithmetic. + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 3).unwrap(); + + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap(); + + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + ] + ); + + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 8).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 4 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 4 }, + ] + ); + + // uneven upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 7).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + ] + ); + }); +} + +#[test] +fn rewards_distribution_is_fair_3() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + Balances::make_free_balance_be(&30, ed + 10); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, + ] + ); + + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 }, + ] + ); + }); +} + +#[test] +fn rewards_distribution_is_fair_bond_extra() { + todo!("10 20 30 all join, reward comes in, equal, one bonds more, rewards come in, more share") +} + +#[test] +fn rewards_distribution_is_fair_unbond() { + todo!("10 20 30 all join, reward comes in, equal, one unbonds, rewards come in, less share") +} + #[test] fn test_setup_works() { ExtBuilder::default().build_and_execute(|| { @@ -66,7 +231,11 @@ fn test_setup_works() { ); assert_eq!( RewardPools::::get(last_pool).unwrap(), - RewardPool:: { balance: 0, points: 0u32.into(), total_earnings: 0 } + RewardPool:: { + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: 0, + total_rewards_claimed: 0 + } ); assert_eq!( PoolMembers::::get(10).unwrap(), @@ -269,3422 +438,3370 @@ mod reward_pool { } } -mod unbond_pool { - use super::*; - - #[test] - fn points_to_issue_works() { - ExtBuilder::default().build_and_execute(|| { - // 1 points : 1 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 10); - assert_eq!(unbond_pool.balance_to_point(0), 0); - - // 2 points : 1 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; - assert_eq!(unbond_pool.balance_to_point(10), 20); - - // 1 points : 2 balance ratio - let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 5); - - // 100 points : 0 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; - assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); - - // 0 points : 100 balance - let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; - assert_eq!(unbond_pool.balance_to_point(10), 10); - - // 10 points : 3 balance ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; - assert_eq!(unbond_pool.balance_to_point(10), 33); - - // 2 points : 3 balance ratio - let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; - assert_eq!(unbond_pool.balance_to_point(10), 6); - - // 4 points : 9 balance ratio - let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; - assert_eq!(unbond_pool.balance_to_point(90), 40); - }) - } - - #[test] - fn balance_to_unbond_works() { - // 1 balance : 1 points ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; - assert_eq!(unbond_pool.point_to_balance(10), 10); - assert_eq!(unbond_pool.point_to_balance(0), 0); - - // 1 balance : 2 points ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; - assert_eq!(unbond_pool.point_to_balance(10), 5); - - // 2 balance : 1 points ratio - let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; - assert_eq!(unbond_pool.point_to_balance(10), 20); - - // 100 balance : 0 points ratio - let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; - assert_eq!(unbond_pool.point_to_balance(10), 0); - - // 0 balance : 100 points ratio - let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; - assert_eq!(unbond_pool.point_to_balance(10), 0); - - // 10 balance : 3 points ratio - let unbond_pool = UnbondPool:: { points: 30, balance: 100 }; - assert_eq!(unbond_pool.point_to_balance(10), 33); - - // 2 balance : 3 points ratio - let unbond_pool = UnbondPool:: { points: 300, balance: 200 }; - assert_eq!(unbond_pool.point_to_balance(10), 6); - - // 4 balance : 9 points ratio - let unbond_pool = UnbondPool:: { points: 900, balance: 400 }; - assert_eq!(unbond_pool.point_to_balance(90), 40); - } -} - -mod sub_pools { - use super::*; - - #[test] - fn maybe_merge_pools_works() { - ExtBuilder::default().build_and_execute(|| { - assert_eq!(TotalUnbondingPools::::get(), 5); - assert_eq!(BondingDuration::get(), 3); - assert_eq!(PostUnbondingPoolsWindow::get(), 2); - - // Given - let mut sub_pool_0 = SubPools:: { - no_era: UnbondPool::::default(), - with_era: unbonding_pools_with_era! { - 0 => UnbondPool:: { points: 10, balance: 10 }, - 1 => UnbondPool:: { points: 10, balance: 10 }, - 2 => UnbondPool:: { points: 20, balance: 20 }, - 3 => UnbondPool:: { points: 30, balance: 30 }, - 4 => UnbondPool:: { points: 40, balance: 40 }, - }, - }; - - // When `current_era < TotalUnbondingPools`, - let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(0); - - // Then it exits early without modifications - assert_eq!(sub_pool_1, sub_pool_0); - - // When `current_era == TotalUnbondingPools`, - let sub_pool_1 = sub_pool_1.maybe_merge_pools(1); - - // Then it exits early without modifications - assert_eq!(sub_pool_1, sub_pool_0); - - // When `current_era - TotalUnbondingPools == 0`, - let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(2); - - // Then era 0 is merged into the `no_era` pool - sub_pool_0.no_era = sub_pool_0.with_era.remove(&0).unwrap(); - assert_eq!(sub_pool_1, sub_pool_0); - - // Given we have entries for era 1..=5 - sub_pool_1 - .with_era - .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) - .unwrap(); - sub_pool_0 - .with_era - .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) - .unwrap(); - - // When `current_era - TotalUnbondingPools == 1` - let sub_pool_2 = sub_pool_1.maybe_merge_pools(3); - let era_1_pool = sub_pool_0.with_era.remove(&1).unwrap(); - - // Then era 1 is merged into the `no_era` pool - sub_pool_0.no_era.points += era_1_pool.points; - sub_pool_0.no_era.balance += era_1_pool.balance; - assert_eq!(sub_pool_2, sub_pool_0); - - // When `current_era - TotalUnbondingPools == 5`, so all pools with era <= 4 are removed - let sub_pool_3 = sub_pool_2.maybe_merge_pools(7); - - // Then all eras <= 5 are merged into the `no_era` pool - for era in 2..=5 { - let to_merge = sub_pool_0.with_era.remove(&era).unwrap(); - sub_pool_0.no_era.points += to_merge.points; - sub_pool_0.no_era.balance += to_merge.balance; - } - assert_eq!(sub_pool_3, sub_pool_0); - }); - } -} - -mod join { - use super::*; - - #[test] - fn join_works() { - let bonded = |points, member_counter| BondedPool:: { - id: 1, - inner: BondedPoolInner { - state: PoolState::Open, - points, - member_counter, - roles: DEFAULT_ROLES, - }, - }; - ExtBuilder::default().build_and_execute(|| { - // Given - Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); - assert!(!PoolMembers::::contains_key(&11)); - - // When - assert_ok!(Pools::join(Origin::signed(11), 2, 1)); - - // Then - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 11, pool_id: 1, bonded: 2, joined: true }, - ] - ); - - assert_eq!( - PoolMembers::::get(&11).unwrap(), - PoolMember:: { pool_id: 1, points: 2, ..Default::default() } - ); - assert_eq!(BondedPool::::get(1).unwrap(), bonded(12, 2)); - - // Given - // The bonded balance is slashed in half - StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 6); - - // And - Balances::make_free_balance_be(&12, ExistentialDeposit::get() + 12); - assert!(!PoolMembers::::contains_key(&12)); - - // When - assert_ok!(Pools::join(Origin::signed(12), 12, 1)); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::Bonded { member: 12, pool_id: 1, bonded: 12, joined: true }] - ); - - assert_eq!( - PoolMembers::::get(&12).unwrap(), - PoolMember:: { pool_id: 1, points: 24, ..Default::default() } - ); - assert_eq!(BondedPool::::get(1).unwrap(), bonded(12 + 24, 3)); - }); - } - - #[test] - fn join_errors_correctly() { - ExtBuilder::default().with_check(0).build_and_execute(|| { - // 10 is already part of the default pool created. - assert_eq!(PoolMembers::::get(&10).unwrap().pool_id, 1); - - assert_noop!( - Pools::join(Origin::signed(10), 420, 123), - Error::::AccountBelongsToOtherPool - ); - - assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::PoolNotFound); - - // Force the pools bonded balance to 0, simulating a 100% slash - StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 0); - assert_noop!(Pools::join(Origin::signed(11), 420, 1), Error::::OverflowRisk); - - // Given a mocked bonded pool - BondedPool:: { - id: 123, - inner: BondedPoolInner { - member_counter: 1, - state: PoolState::Open, - points: 100, - roles: DEFAULT_ROLES, - }, - } - .put(); - - // and reward pool - RewardPools::::insert( - 123, - RewardPool:: { - balance: Zero::zero(), - total_earnings: Zero::zero(), - points: U256::from(0u32), - }, - ); - - // Force the points:balance ratio to `MinPointsToBalance` (100/10) - let min_points_to_balance: u128 = - <::MinPointsToBalance as Get>::get().into(); - - StakingMock::set_bonded_balance( - Pools::create_bonded_account(123), - min_points_to_balance, - ); - assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::OverflowRisk); - - StakingMock::set_bonded_balance( - Pools::create_bonded_account(123), - Balance::MAX / min_points_to_balance, - ); - // Balance needs to be gt Balance::MAX / `MinPointsToBalance` - assert_noop!(Pools::join(Origin::signed(11), 5, 123), Error::::OverflowRisk); - - StakingMock::set_bonded_balance(Pools::create_bonded_account(1), min_points_to_balance); - - // Cannot join a pool that isn't open - unsafe_set_state(123, PoolState::Blocked).unwrap(); - assert_noop!( - Pools::join(Origin::signed(11), min_points_to_balance, 123), - Error::::NotOpen - ); - - unsafe_set_state(123, PoolState::Destroying).unwrap(); - assert_noop!( - Pools::join(Origin::signed(11), min_points_to_balance, 123), - Error::::NotOpen - ); - - // Given - MinJoinBond::::put(100); - - // Then - assert_noop!( - Pools::join(Origin::signed(11), 99, 123), - Error::::MinimumBondNotMet - ); - }); - } - - #[test] - #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] - #[cfg_attr(not(debug_assertions), should_panic)] - fn join_panics_when_reward_pool_not_found() { - ExtBuilder::default().build_and_execute(|| { - StakingMock::set_bonded_balance(Pools::create_bonded_account(123), 100); - BondedPool:: { - id: 123, - inner: BondedPoolInner { - state: PoolState::Open, - points: 100, - member_counter: 1, - roles: DEFAULT_ROLES, - }, - } - .put(); - let _ = Pools::join(Origin::signed(11), 420, 123); - }); - } - - #[test] - fn join_max_member_limits_are_respected() { - ExtBuilder::default().build_and_execute(|| { - // Given - assert_eq!(MaxPoolMembersPerPool::::get(), Some(3)); - for i in 1..3 { - let account = i + 100; - Balances::make_free_balance_be(&account, 100 + Balances::minimum_balance()); - - assert_ok!(Pools::join(Origin::signed(account), 100, 1)); - } - - Balances::make_free_balance_be(&103, 100 + Balances::minimum_balance()); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 101, pool_id: 1, bonded: 100, joined: true }, - Event::Bonded { member: 102, pool_id: 1, bonded: 100, joined: true } - ] - ); - - assert_noop!( - Pools::join(Origin::signed(103), 100, 1), - Error::::MaxPoolMembers - ); - - // Given - assert_eq!(PoolMembers::::count(), 3); - assert_eq!(MaxPoolMembers::::get(), Some(4)); - - Balances::make_free_balance_be(&104, 100 + Balances::minimum_balance()); - assert_ok!(Pools::create(Origin::signed(104), 100, 104, 104, 104)); - - let pool_account = BondedPools::::iter() - .find(|(_, bonded_pool)| bonded_pool.roles.depositor == 104) - .map(|(pool_account, _)| pool_account) - .unwrap(); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 104, pool_id: 2 }, - Event::Bonded { member: 104, pool_id: 2, bonded: 100, joined: true } - ] - ); - - assert_noop!( - Pools::join(Origin::signed(103), 100, pool_account), - Error::::MaxPoolMembers - ); - }); - } -} - -mod claim_payout { - use super::*; - - fn del(points: Balance, reward_pool_total_earnings: Balance) -> PoolMember { - PoolMember { - pool_id: 1, - points, - reward_pool_total_earnings, - unbonding_eras: Default::default(), - } - } - - fn rew(balance: Balance, points: u32, total_earnings: Balance) -> RewardPool { - RewardPool { balance, points: points.into(), total_earnings } - } - - #[test] - fn claim_payout_works() { - ExtBuilder::default() - .add_members(vec![(40, 40), (50, 50)]) - .build_and_execute(|| { - // Given each member currently has a free balance of - Balances::make_free_balance_be(&10, 0); - Balances::make_free_balance_be(&40, 0); - Balances::make_free_balance_be(&50, 0); - let ed = Balances::minimum_balance(); - // and the reward pool has earned 100 in rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 100); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(10))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - ] - ); - - // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool - // balance - assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 100)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew(90, 100 * 100 - 100 * 10, 100) - ); - assert_eq!(Balances::free_balance(&10), 10); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(40))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] - ); - - // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance - assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 100)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew(50, 9_000 - 100 * 40, 100) - ); - assert_eq!(Balances::free_balance(&40), 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(50))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] - ); - - // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance - assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 100)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); - assert_eq!(Balances::free_balance(&50), 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - - // Given the reward pool has some new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 50); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(10))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); - - // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance - assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 150)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(45, 5_000 - 50 * 10, 150)); - assert_eq!(Balances::free_balance(&10), 10 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(40))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] - ); - - // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool - // balance - assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 150)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(25, 4_500 - 50 * 40, 150)); - assert_eq!(Balances::free_balance(&40), 40 + 20); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - - // Given del 50 hasn't claimed and the reward pools has just earned 50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(50))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] - ); - - // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 - // pool balance - assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 200)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew( - 25, - // old pool points + points from new earnings - del points. - // - // points from new earnings = new earnings(50) * bonded_pool.points(100) - // del points = member.points(50) * new_earnings_since_last_claim (100) - (2_500 + 50 * 100) - 50 * 100, - 200, - ) - ); - assert_eq!(Balances::free_balance(&50), 50 + 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(10))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); - - // We expect a payout of 5 - assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 200)); - assert_eq!(RewardPools::::get(&1).unwrap(), rew(20, 2_500 - 10 * 50, 200)); - assert_eq!(Balances::free_balance(&10), 15 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); - - // Given del 40 hasn't claimed and the reward pool has just earned 400 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(10))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] - ); - - // We expect a payout of 40 - assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 600)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew( - 380, - // old pool points + points from new earnings - del points - // - // points from new earnings = new earnings(400) * bonded_pool.points(100) - // del points = member.points(10) * new_earnings_since_last_claim(400) - (2_000 + 400 * 100) - 10 * 400, - 600 - ) - ); - assert_eq!(Balances::free_balance(&10), 20 + 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); - - // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(10))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] - ); - - // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool - // balance - assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 620)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew(398, (38_000 + 20 * 100) - 10 * 20, 620) - ); - assert_eq!(Balances::free_balance(&10), 60 + 2); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(40))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] - ); - - // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 - // pool balance - assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 620)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew(210, 39_800 - 40 * 470, 620) - ); - assert_eq!(Balances::free_balance(&40), 60 + 188); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); - - // When - assert_ok!(Pools::claim_payout(Origin::signed(50))); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] - ); - - // Expect payout of 210: (21,000 / 21,000) * 210 - assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 620)); - assert_eq!( - RewardPools::::get(&1).unwrap(), - rew(0, 21_000 - 50 * 420, 620) - ); - assert_eq!(Balances::free_balance(&50), 100 + 210); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - }); - } - - #[test] - fn do_reward_payout_correctly_sets_pool_state_to_destroying() { - ExtBuilder::default().build_and_execute(|| { - let _ = with_transaction(|| -> TransactionOutcome { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(10).unwrap(); - - // -- reward_pool.total_earnings saturates - - // Given - Balances::make_free_balance_be(&default_reward_account(), Balance::MAX); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert!(bonded_pool.is_destroying()); - - storage::TransactionOutcome::Rollback(Ok(())) - }); - - // -- current_points saturates (reward_pool.points + new_earnings * bonded_pool.points) - let _ = with_transaction(|| -> TransactionOutcome { - // Given - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(10).unwrap(); - // Force new_earnings * bonded_pool.points == 100 - Balances::make_free_balance_be(&default_reward_account(), 5 + 10); - assert_eq!(bonded_pool.points, 10); - // Force reward_pool.points == U256::MAX - new_earnings * bonded_pool.points - reward_pool.points = U256::MAX - U256::from(100u32); - RewardPools::::insert(1, reward_pool.clone()); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut member, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert!(bonded_pool.is_destroying()); - - storage::TransactionOutcome::Rollback(Ok(())) - }); - }); - } - - #[test] - fn reward_payout_errors_if_a_member_is_fully_unbonding() { - ExtBuilder::default().add_members(vec![(11, 11)]).build_and_execute(|| { - // fully unbond the member. - assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); - - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(11).unwrap(); - - assert_noop!( - Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), - Error::::FullyUnbonding - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true }, - Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 } - ] - ); - }); - } - - #[test] - fn calculate_member_payout_works_with_a_pool_of_1() { - let del = |reward_pool_total_earnings| del(10, reward_pool_total_earnings); - - ExtBuilder::default().build_and_execute(|| { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(10).unwrap(); - let ed = Balances::minimum_balance(); - - // Given no rewards have been earned - // When - let payout = - Pools::calculate_member_payout(&mut member, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 0); - assert_eq!(member, del(0)); - assert_eq!(reward_pool, rew(0, 0, 0)); - - // Given the pool has earned some rewards for the first time - Balances::make_free_balance_be(&default_reward_account(), ed + 5); - - // When - let payout = - Pools::calculate_member_payout(&mut member, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 5); // (10 * 5 del virtual points / 10 * 5 pool points) * 5 pool balance - assert_eq!(reward_pool, rew(0, 0, 5)); - assert_eq!(member, del(5)); - - // Given the pool has earned rewards again - Balances::make_free_balance_be(&default_reward_account(), ed + 10); - - // When - let payout = - Pools::calculate_member_payout(&mut member, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 10); // (10 * 10 del virtual points / 10 pool points) * 5 pool balance - assert_eq!(reward_pool, rew(0, 0, 15)); - assert_eq!(member, del(15)); - - // Given the pool has earned no new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 0); - - // When - let payout = - Pools::calculate_member_payout(&mut member, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 0); - assert_eq!(reward_pool, rew(0, 0, 15)); - assert_eq!(member, del(15)); - }); - } - - #[test] - fn calculate_member_payout_works_with_a_pool_of_3() { - ExtBuilder::default() - .add_members(vec![(40, 40), (50, 50)]) - .build_and_execute(|| { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let ed = Balances::minimum_balance(); - // PoolMember with 10 points - let mut del_10 = PoolMembers::::get(10).unwrap(); - // PoolMember with 40 points - let mut del_40 = PoolMembers::::get(40).unwrap(); - // PoolMember with 50 points - let mut del_50 = PoolMembers::::get(50).unwrap(); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } - ] - ); - - // Given we have a total of 100 points split among the members - assert_eq!(del_50.points + del_40.points + del_10.points, 100); - assert_eq!(bonded_pool.points, 100); - // and the reward pool has earned 100 in rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 100); - - // When - let payout = - Pools::calculate_member_payout(&mut del_10, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 10); // (10 del virtual points / 100 pool points) * 100 pool balance - assert_eq!(del_10, del(10, 100)); - assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 10)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_40, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 40); // (400 del virtual points / 900 pool points) * 90 pool balance - assert_eq!(del_40, del(40, 100)); - assert_eq!( - reward_pool, - rew( - 50, - // old pool points - member virtual points - 9_000 - 100 * 40, - 100 - ) - ); - // Mock the reward pool transferring the payout to del_40 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_50, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 50); // (50 del virtual points / 50 pool points) * 50 pool balance - assert_eq!(del_50, del(50, 100)); - assert_eq!(reward_pool, rew(0, 0, 100)); - // Mock the reward pool transferring the payout to del_50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); - - // Given the reward pool has some new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 50); - - // When - let payout = - Pools::calculate_member_payout(&mut del_10, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 5); // (500 del virtual points / 5,000 pool points) * 50 pool balance - assert_eq!(del_10, del(10, 150)); - assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_40, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 20); // (2,000 del virtual points / 4,500 pool points) * 45 pool balance - assert_eq!(del_40, del(40, 150)); - assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 20)); - - // Given del_50 hasn't claimed and the reward pools has just earned 50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - - // When - let payout = - Pools::calculate_member_payout(&mut del_50, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 50); // (5,000 del virtual points / 7,5000 pool points) * 75 pool balance - assert_eq!(del_50, del(50, 200)); - assert_eq!( - reward_pool, - rew( - 25, - // old pool points + points from new earnings - del points. - // - // points from new earnings = new earnings(50) * bonded_pool.points(100) - // del points = member.points(50) * new_earnings_since_last_claim (100) - (2_500 + 50 * 100) - 50 * 100, - 200, - ) - ); - // Mock the reward pool transferring the payout to del_50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_10, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 5); - assert_eq!(del_10, del(10, 200)); - assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); - - // Given del_40 hasn't claimed and the reward pool has just earned 400 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - - // When - let payout = - Pools::calculate_member_payout(&mut del_10, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 40); - assert_eq!(del_10, del(10, 600)); - assert_eq!( - reward_pool, - rew( - 380, - // old pool points + points from new earnings - del points - // - // points from new earnings = new earnings(400) * bonded_pool.points(100) - // del points = member.points(10) * new_earnings_since_last_claim(400) - (2_000 + 400 * 100) - 10 * 400, - 600 - ) - ); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); - - // Given del_40 + del_50 haven't claimed and the reward pool has earned 20 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - - // When - let payout = - Pools::calculate_member_payout(&mut del_10, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 2); // (200 del virtual points / 38,000 pool points) * 400 pool balance - assert_eq!(del_10, del(10, 620)); - assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 2)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_40, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 188); // (18,800 del virtual points / 39,800 pool points) * 399 pool balance - assert_eq!(del_40, del(40, 620)); - assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 188)); - - // When - let payout = - Pools::calculate_member_payout(&mut del_50, &mut bonded_pool, &mut reward_pool) - .unwrap(); - - // Then - assert_eq!(payout, 210); // (21,000 / 21,000) * 210 - assert_eq!(del_50, del(50, 620)); - assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); - }); - } - - #[test] - fn do_reward_payout_works() { - ExtBuilder::default() - .add_members(vec![(40, 40), (50, 50)]) - .build_and_execute(|| { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let ed = Balances::minimum_balance(); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } - ] - ); - - // Given the bonded pool has 100 points - assert_eq!(bonded_pool.points, 100); - // Each member currently has a free balance of - Balances::make_free_balance_be(&10, 0); - Balances::make_free_balance_be(&40, 0); - Balances::make_free_balance_be(&50, 0); - // and the reward pool has earned 100 in rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 100); - - let mut del_10 = PoolMembers::get(10).unwrap(); - let mut del_40 = PoolMembers::get(40).unwrap(); - let mut del_50 = PoolMembers::get(50).unwrap(); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] - ); - - // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool - // balance - assert_eq!(del_10, del(10, 100)); - assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); - assert_eq!(Balances::free_balance(&10), 10); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); - - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] - ); - - // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance - assert_eq!(del_40, del(40, 100)); - assert_eq!(reward_pool, rew(50, 9_000 - 100 * 40, 100)); - assert_eq!(Balances::free_balance(&40), 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); - - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] - ); - - // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance - assert_eq!(del_50, del(50, 100)); - assert_eq!(reward_pool, rew(0, 0, 100)); - assert_eq!(Balances::free_balance(&50), 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - - // Given the reward pool has some new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 50); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); - - // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance - assert_eq!(del_10, del(10, 150)); - assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); - assert_eq!(Balances::free_balance(&10), 10 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); - - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] - ); - - // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool - // balance - assert_eq!(del_40, del(40, 150)); - assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); - assert_eq!(Balances::free_balance(&40), 40 + 20); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - - // Given del 50 hasn't claimed and the reward pools has just earned 50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] - ); - - // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 - // pool balance - assert_eq!(del_50, del(50, 200)); - assert_eq!( - reward_pool, - rew( - 25, - // old pool points + points from new earnings - del points. - // - // points from new earnings = new earnings(50) * bonded_pool.points(100) - // del points = member.points(50) * new_earnings_since_last_claim (100) - (2_500 + 50 * 100) - 50 * 100, - 200, - ) - ); - assert_eq!(Balances::free_balance(&50), 50 + 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); - - // We expect a payout of 5 - assert_eq!(del_10, del(10, 200)); - assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); - assert_eq!(Balances::free_balance(&10), 15 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); - - // Given del 40 hasn't claimed and the reward pool has just earned 400 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] - ); - - // We expect a payout of 40 - assert_eq!(del_10, del(10, 600)); - assert_eq!( - reward_pool, - rew( - 380, - // old pool points + points from new earnings - del points - // - // points from new earnings = new earnings(400) * bonded_pool.points(100) - // del points = member.points(10) * new_earnings_since_last_claim(400) - (2_000 + 400 * 100) - 10 * 400, - 600 - ) - ); - assert_eq!(Balances::free_balance(&10), 20 + 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); - - // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] - ); - - // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool - // balance - assert_eq!(del_10, del(10, 620)); - assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); - assert_eq!(Balances::free_balance(&10), 60 + 2); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); - - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] - ); - - // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 - // pool balance - assert_eq!(del_40, del(40, 620)); - assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); - assert_eq!(Balances::free_balance(&40), 60 + 188); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); - - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); - - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] - ); - - // Expect payout of 210: (21,000 / 21,000) * 210 - assert_eq!(del_50, del(50, 620)); - assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); - assert_eq!(Balances::free_balance(&50), 100 + 210); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - }); - } -} - -mod unbond { - use super::*; - - #[test] - fn unbond_of_1_works() { - ExtBuilder::default().build_and_execute(|| { - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(fully_unbond_permissioned(10)); - - assert_eq!( - SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool:: { points: 10, balance: 10 }} - ); - - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - state: PoolState::Destroying, - points: 0, - member_counter: 1, - roles: DEFAULT_ROLES, - } - } - ); - - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - }); - } - - #[test] - fn unbond_of_3_works() { - ExtBuilder::default() - .add_members(vec![(40, 40), (550, 550)]) - .build_and_execute(|| { - let ed = Balances::minimum_balance(); - // Given a slash from 600 -> 100 - StakingMock::set_bonded_balance(default_bonded_account(), 100); - // and unclaimed rewards of 600. - Balances::make_free_balance_be(&default_reward_account(), ed + 600); - - // When - assert_ok!(fully_unbond_permissioned(40)); - - // Then - assert_eq!( - SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 6, balance: 6 }} - ); - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - state: PoolState::Open, - points: 560, - member_counter: 3, - roles: DEFAULT_ROLES, - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, - Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 } - ] - ); - - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); - assert_eq!( - PoolMembers::::get(40).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 6) - ); - assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding - - // When - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(fully_unbond_permissioned(550)); - - // Then - assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 98, balance: 98 }} - ); - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - state: PoolState::Destroying, - points: 10, - member_counter: 3, - roles: DEFAULT_ROLES - } - } - ); - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); - assert_eq!( - PoolMembers::::get(550).unwrap().unbonding_eras, - member_unbonding_eras!(0 + 3 => 92) - ); - assert_eq!(Balances::free_balance(&550), 550 + 550); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, - Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 } - ] - ); - - // When - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 40, 0)); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 550, 0)); - assert_ok!(fully_unbond_permissioned(10)); - - // Then - assert_eq!( - SubPoolsStorage::::get(1).unwrap().with_era, - unbonding_pools_with_era! { 6 => UnbondPool { points: 2, balance: 2 }} - ); - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - state: PoolState::Destroying, - points: 0, - member_counter: 1, - roles: DEFAULT_ROLES - } - } - ); - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - - assert_eq!(Balances::free_balance(&550), 550 + 550 + 92); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 40, pool_id: 1, points: 6, balance: 6 }, - Event::MemberRemoved { pool_id: 1, member: 40 }, - Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, - Event::MemberRemoved { pool_id: 1, member: 550 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } - ] - ); - }); - } - - #[test] - fn unbond_merges_older_pools() { - ExtBuilder::default().with_check(1).build_and_execute(|| { - // Given - assert_eq!(StakingMock::bonding_duration(), 3); - SubPoolsStorage::::insert( - 1, - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { balance: 10, points: 100 }, - 1 + 3 => UnbondPool { balance: 20, points: 20 }, - 2 + 3 => UnbondPool { balance: 101, points: 101} - }, - }, - ); - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // When - let current_era = 1 + TotalUnbondingPools::::get(); - CurrentEra::set(current_era); - - assert_ok!(fully_unbond_permissioned(10)); - - // Then - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: UnbondPool { balance: 10 + 20, points: 100 + 20 }, - with_era: unbonding_pools_with_era! { - 2 + 3 => UnbondPool { balance: 101, points: 101}, - current_era + 3 => UnbondPool { balance: 10, points: 10 }, - }, - }, - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } - ] - ); - }); - } - - #[test] - fn unbond_kick_works() { - // Kick: the pool is blocked and the caller is either the root or state-toggler. - ExtBuilder::default() - .add_members(vec![(100, 100), (200, 200)]) - .build_and_execute(|| { - // Given - unsafe_set_state(1, PoolState::Blocked).unwrap(); - let bonded_pool = BondedPool::::get(1).unwrap(); - assert_eq!(bonded_pool.roles.root.unwrap(), 900); - assert_eq!(bonded_pool.roles.nominator.unwrap(), 901); - assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902); - - // When the nominator tries to kick, then its a noop - assert_noop!( - Pools::fully_unbond(Origin::signed(901), 100), - Error::::NotKickerOrDestroying - ); - - // When the root kicks then its ok - assert_ok!(Pools::fully_unbond(Origin::signed(900), 100)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, - ] - ); - - // When the state toggler kicks then its ok - assert_ok!(Pools::fully_unbond(Origin::signed(902), 200)); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }] - ); - - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - roles: DEFAULT_ROLES, - state: PoolState::Blocked, - points: 10, // Only 10 points because 200 + 100 was unbonded - member_counter: 3, - } - } - ); - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 10); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 0 + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } - }, - } - ); - assert_eq!( - *UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), - 100 + 200 - ); - }); - } - - #[test] - fn unbond_permissionless_works() { - // Scenarios where non-admin accounts can unbond others - ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { - // Given the pool is blocked - unsafe_set_state(1, PoolState::Blocked).unwrap(); - - // A permissionless unbond attempt errors - assert_noop!( - Pools::fully_unbond(Origin::signed(420), 100), - Error::::NotKickerOrDestroying - ); - - // permissionless unbond must be full - assert_noop!( - Pools::unbond(Origin::signed(420), 100, 80), - Error::::PartialUnbondNotAllowedPermissionlessly, - ); - - // Given the pool is destroying - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // The depositor cannot be fully unbonded until they are the last member - assert_noop!( - Pools::fully_unbond(Origin::signed(10), 10), - Error::::NotOnlyPoolMember - ); - - // Any account can unbond a member that is not the depositor - assert_ok!(Pools::fully_unbond(Origin::signed(420), 100)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 } - ] - ); - - // still permissionless unbond must be full - assert_noop!( - Pools::unbond(Origin::signed(420), 100, 80), - Error::::PartialUnbondNotAllowedPermissionlessly, - ); - - // Given the pool is blocked - unsafe_set_state(1, PoolState::Blocked).unwrap(); - - // The depositor cannot be unbonded - assert_noop!( - Pools::fully_unbond(Origin::signed(420), 10), - Error::::DoesNotHavePermission - ); - - // Given the pools is destroying - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // The depositor cannot be unbonded yet. - assert_noop!( - Pools::fully_unbond(Origin::signed(420), 10), - Error::::DoesNotHavePermission, - ); - - // but when everyone is unbonded it can.. - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 100, 0)); - - // still permissionless unbond must be full. - assert_noop!( - Pools::unbond(Origin::signed(420), 10, 5), - Error::::PartialUnbondNotAllowedPermissionlessly, - ); - - // but full unbond works. - assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); - - assert_eq!(BondedPools::::get(1).unwrap().points, 0); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 + 3 => UnbondPool { points: 10, balance: 10 } - } - } - ); - assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - assert_eq!(*UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 10); - }); - } - - #[test] - #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] - #[cfg_attr(not(debug_assertions), should_panic)] - fn unbond_errors_correctly() { - ExtBuilder::default().build_and_execute(|| { - assert_noop!( - Pools::fully_unbond(Origin::signed(11), 11), - Error::::PoolMemberNotFound - ); - - // Add the member - let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; - PoolMembers::::insert(11, member); - - let _ = Pools::fully_unbond(Origin::signed(11), 11); - }); - } - - #[test] - #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] - #[cfg_attr(not(debug_assertions), should_panic)] - fn unbond_panics_when_reward_pool_not_found() { - ExtBuilder::default().build_and_execute(|| { - let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; - PoolMembers::::insert(11, member); - BondedPool:: { - id: 1, - inner: BondedPoolInner { - state: PoolState::Open, - points: 10, - member_counter: 1, - roles: DEFAULT_ROLES, - }, - } - .put(); - - let _ = Pools::fully_unbond(Origin::signed(11), 11); - }); - } - - #[test] - fn partial_unbond_era_tracking() { - ExtBuilder::default().build_and_execute(|| { - // given - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); - assert_eq!(PoolMembers::::get(10).unwrap().pool_id, 1); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!() - ); - assert_eq!(BondedPool::::get(1).unwrap().points, 10); - assert!(SubPoolsStorage::::get(1).is_none()); - assert_eq!(CurrentEra::get(), 0); - assert_eq!(BondingDuration::get(), 3); - - // so the depositor can leave, just keeps the test simpler. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // when: casual unbond - assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - - // then - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 9); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 1); - assert_eq!(BondedPool::::get(1).unwrap().points, 9); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } - ] - ); - - // when: casual further unbond, same era. - assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); - - // then - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 4); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 6); - assert_eq!(BondedPool::::get(1).unwrap().points, 4); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 6) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 6, balance: 6 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }] - ); - - // when: casual further unbond, next era. - CurrentEra::set(1); - assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - - // then - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); - assert_eq!(BondedPool::::get(1).unwrap().points, 3); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 6, 4 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 6, balance: 6 }, - 4 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }] - ); - - // when: unbonding more than our active: error - assert_err!( - frame_support::storage::in_storage_layer(|| Pools::unbond( - Origin::signed(10), - 10, - 5 - )), - Error::::NotEnoughPointsToUnbond - ); - // instead: - assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - - // then - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 0); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 10); - assert_eq!(BondedPool::::get(1).unwrap().points, 0); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 6, 4 => 4) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 6, balance: 6 }, - 4 => UnbondPool { points: 4, balance: 4 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }] - ); - }); - } - - #[test] - fn partial_unbond_max_chunks() { - ExtBuilder::default().ed(1).build_and_execute(|| { - // so the depositor can leave, just keeps the test simpler. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - MaxUnbonding::set(2); - - // given - assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); - CurrentEra::set(1); - assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 2, 4 => 3) - ); - - // when - CurrentEra::set(2); - assert_err!( - frame_support::storage::in_storage_layer(|| Pools::unbond( - Origin::signed(10), - 10, - 4 - )), - Error::::MaxUnbondingLimit - ); - - // when - MaxUnbonding::set(3); - assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 2, 4 => 3, 5 => 1) - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }, - Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, - Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } - ] - ); - }) - } - - // depositor can unbond inly up to `MinCreateBond`. - #[test] - fn depositor_permissioned_partial_unbond() { - ExtBuilder::default().ed(1).build_and_execute(|| { - // given - assert_eq!(MinCreateBond::::get(), 2); - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); - - // can unbond a bit.. - assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 7); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 3); - - // but not less than 2 - assert_noop!( - Pools::unbond(Origin::signed(10), 10, 6), - Error::::NotOnlyPoolMember - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } - ] - ); - }); - } - - // same as above, but the pool is slashed and therefore the depositor cannot partially unbond. - #[test] - fn depositor_permissioned_partial_unbond_slashed() { - ExtBuilder::default().ed(1).build_and_execute(|| { - // given - assert_eq!(MinCreateBond::::get(), 2); - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); - - // slash the default pool - StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 5); - - // cannot unbond even 7, because the value of shares is now less. - assert_noop!( - Pools::unbond(Origin::signed(10), 10, 7), - Error::::NotOnlyPoolMember - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - ] - ); - }); - } - - #[test] - fn every_unbonding_triggers_payout() { - ExtBuilder::default().build_and_execute(|| { - let initial_reward_account = Balances::free_balance(Pools::create_reward_account(1)); - assert_eq!(initial_reward_account, Balances::minimum_balance()); - assert_eq!(initial_reward_account, 5); - - // set the pool to destroying so that depositor can leave. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - Balances::make_free_balance_be( - &Pools::create_reward_account(1), - 2 * Balances::minimum_balance(), - ); - - assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - // exactly equal to ed, all that can be claimed. - Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } - ] - ); - - CurrentEra::set(1); - Balances::make_free_balance_be( - &Pools::create_reward_account(1), - 2 * Balances::minimum_balance(), - ); - - assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - assert_eq!( - pool_events_since_last_call(), - vec![ - // exactly equal to ed, all that can be claimed. - Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } - ] - ); - - CurrentEra::set(2); - Balances::make_free_balance_be( - &Pools::create_reward_account(1), - 2 * Balances::minimum_balance(), - ); - - assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, - Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 } - ] - ); - - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 2, 4 => 3, 5 => 5) - ); - }); - } -} - -mod pool_withdraw_unbonded { - use super::*; - - #[test] - fn pool_withdraw_unbonded_works() { - ExtBuilder::default().build_and_execute(|| { - // Given 10 unbond'ed directly against the pool account - assert_ok!(StakingMock::unbond(default_bonded_account(), 5)); - // and the pool account only has 10 balance - assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); - assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(10)); - assert_eq!(Balances::free_balance(&default_bonded_account()), 10); - - // When - assert_ok!(Pools::pool_withdraw_unbonded(Origin::signed(10), 1, 0)); - - // Then there unbonding balance is no longer locked - assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); - assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(5)); - assert_eq!(Balances::free_balance(&default_bonded_account()), 10); - }); - } -} - -mod withdraw_unbonded { - use super::*; - use frame_support::bounded_btree_map; - - #[test] - fn withdraw_unbonded_works_against_slashed_no_era_sub_pool() { - ExtBuilder::default() - .add_members(vec![(40, 40), (550, 550)]) - .build_and_execute(|| { - // reduce the noise a bit. - let _ = balances_events_since_last_call(); - - // Given - assert_eq!(StakingMock::bonding_duration(), 3); - assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); - assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); - assert_eq!(Balances::free_balance(&default_bonded_account()), 600); - - let mut current_era = 1; - CurrentEra::set(current_era); - - let mut sub_pools = SubPoolsStorage::::get(1).unwrap(); - let unbond_pool = sub_pools.with_era.get_mut(&3).unwrap(); - // Sanity check - assert_eq!(*unbond_pool, UnbondPool { points: 550 + 40, balance: 550 + 40 }); - - // Simulate a slash to the pool with_era(current_era), decreasing the balance by - // half - { - unbond_pool.balance /= 2; // 295 - SubPoolsStorage::::insert(1, sub_pools); - // Update the equivalent of the unbonding chunks for the `StakingMock` - let mut x = UnbondingBalanceMap::get(); - *x.get_mut(&default_bonded_account()).unwrap() /= 5; - UnbondingBalanceMap::set(&x); - Balances::make_free_balance_be( - &default_bonded_account(), - Balances::free_balance(&default_bonded_account()) / 2, // 300 - ); - StakingMock::set_bonded_balance( - default_bonded_account(), - StakingMock::active_stake(&default_bonded_account()).unwrap() / 2, - ); - }; - - // Advance the current_era to ensure all `with_era` pools will be merged into - // `no_era` pool - current_era += TotalUnbondingPools::::get(); - CurrentEra::set(current_era); - - // Simulate some other call to unbond that would merge `with_era` pools into - // `no_era` - let sub_pools = - SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); - SubPoolsStorage::::insert(1, sub_pools); - - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: UnbondPool { points: 550 + 40, balance: 275 + 20 }, - with_era: Default::default() - } - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 }, - Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 }, - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::BalanceSet { - who: default_bonded_account(), - free: 300, - reserved: 0 - }] - ); - - // When - assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); - - // Then - assert_eq!( - SubPoolsStorage::::get(1).unwrap().no_era, - UnbondPool { points: 40, balance: 20 } - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 550 }, - Event::MemberRemoved { pool_id: 1, member: 550 } - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 }] - ); - - // When - assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); - - // Then - assert_eq!( - SubPoolsStorage::::get(1).unwrap().no_era, - UnbondPool { points: 0, balance: 0 } - ); - assert!(!PoolMembers::::contains_key(40)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 40 }, - Event::MemberRemoved { pool_id: 1, member: 40 } - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 }] - ); - - // now, finally, the depositor can take out its share. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(fully_unbond_permissioned(10)); - - current_era += 3; - CurrentEra::set(current_era); - - // when - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 }, - Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 }, - Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 } - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![ - BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, - BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } - ] - ); - }); - } - - #[test] - fn withdraw_unbonded_works_against_slashed_with_era_sub_pools() { - ExtBuilder::default() - .add_members(vec![(40, 40), (550, 550)]) - .build_and_execute(|| { - let _ = balances_events_since_last_call(); - - // Given - // current bond is 600, we slash it all to 300. - StakingMock::set_bonded_balance(default_bonded_account(), 300); - Balances::make_free_balance_be(&default_bonded_account(), 300); - assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(300)); - - assert_ok!(fully_unbond_permissioned(40)); - assert_ok!(fully_unbond_permissioned(550)); - - assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 }} - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, - Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 }, - Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 }, - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::BalanceSet { - who: default_bonded_account(), - free: 300, - reserved: 0 - },] - ); - - CurrentEra::set(StakingMock::bonding_duration()); - - // When - assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); - - // Then - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 },] - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 20 }, - Event::MemberRemoved { pool_id: 1, member: 40 } - ] - ); - - assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} - ); - - // When - assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); - - // Then - assert_eq!( - balances_events_since_last_call(), - vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 },] - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 275 }, - Event::MemberRemoved { pool_id: 1, member: 550 } - ] - ); - assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); - - // now, finally, the depositor can take out its share. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(fully_unbond_permissioned(10)); - - // because everyone else has left, the points - assert_eq!( - SubPoolsStorage::::get(&1).unwrap().with_era, - unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} - ); - - CurrentEra::set(CurrentEra::get() + 3); - - // when - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - - // then - assert_eq!(Balances::free_balance(&10), 10 + 5); - assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - - // in this test 10 also gets a fair share of the slash, because the slash was - // applied to the bonded account. - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }, - Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 }, - Event::MemberRemoved { pool_id: 1, member: 10 }, - Event::Destroyed { pool_id: 1 } - ] - ); - assert_eq!( - balances_events_since_last_call(), - vec![ - BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, - BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } - ] - ); - }); - } - - #[test] - fn withdraw_unbonded_handles_faulty_sub_pool_accounting() { - ExtBuilder::default().build_and_execute(|| { - // Given - assert_eq!(Balances::minimum_balance(), 5); - assert_eq!(Balances::free_balance(&10), 5); - assert_eq!(Balances::free_balance(&default_bonded_account()), 10); - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); - - // Simulate a slash that is not accounted for in the sub pools. - Balances::make_free_balance_be(&default_bonded_account(), 5); - assert_eq!( - SubPoolsStorage::::get(1).unwrap().with_era, - //------------------------------balance decrease is not account for - unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 } } - ); - - CurrentEra::set(0 + 3); - - // When - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - - // Then - assert_eq!(Balances::free_balance(10), 10 + 5); - assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - }); - } - - #[test] - fn withdraw_unbonded_errors_correctly() { - ExtBuilder::default().with_check(0).build_and_execute(|| { - // Insert the sub-pool - let sub_pools = SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 }}, - }; - SubPoolsStorage::::insert(1, sub_pools.clone()); - - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(11), 11, 0), - Error::::PoolMemberNotFound - ); - - let mut member = PoolMember { pool_id: 1, points: 10, ..Default::default() }; - PoolMembers::::insert(11, member.clone()); - - // Simulate calling `unbond` - member.unbonding_eras = member_unbonding_eras!(3 + 0 => 10); - PoolMembers::::insert(11, member.clone()); - - // We are still in the bonding duration - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(11), 11, 0), - Error::::CannotWithdrawAny - ); - - // If we error the member does not get removed - assert_eq!(PoolMembers::::get(&11), Some(member)); - // and the sub pools do not get updated. - assert_eq!(SubPoolsStorage::::get(1).unwrap(), sub_pools) - }); - } - - #[test] - fn withdraw_unbonded_kick() { - ExtBuilder::default() - .add_members(vec![(100, 100), (200, 200)]) - .build_and_execute(|| { - // Given - assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); - assert_ok!(Pools::fully_unbond(Origin::signed(200), 200)); - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - points: 10, - state: PoolState::Open, - member_counter: 3, - roles: DEFAULT_ROLES - } - } - ); - CurrentEra::set(StakingMock::bonding_duration()); - - // Cannot kick when pool is open - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(902), 100, 0), - Error::::NotKickerOrDestroying - ); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, - Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 } - ] - ); - - // Given - unsafe_set_state(1, PoolState::Blocked).unwrap(); - - // Cannot kick as a nominator - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(901), 100, 0), - Error::::NotKickerOrDestroying - ); - - // Can kick as root - assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 100, 0)); - - // Can kick as state toggler - assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 200, 0)); - - assert_eq!(Balances::free_balance(100), 100 + 100); - assert_eq!(Balances::free_balance(200), 200 + 200); - assert!(!PoolMembers::::contains_key(100)); - assert!(!PoolMembers::::contains_key(200)); - assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, - Event::MemberRemoved { pool_id: 1, member: 100 }, - Event::Withdrawn { member: 200, pool_id: 1, points: 200, balance: 200 }, - Event::MemberRemoved { pool_id: 1, member: 200 } - ] - ); - }); - } - - #[test] - fn withdraw_unbonded_destroying_permissionless() { - ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { - // Given - assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); - assert_eq!( - BondedPool::::get(1).unwrap(), - BondedPool { - id: 1, - inner: BondedPoolInner { - points: 10, - state: PoolState::Open, - member_counter: 2, - roles: DEFAULT_ROLES, - } - } - ); - CurrentEra::set(StakingMock::bonding_duration()); - assert_eq!(Balances::free_balance(100), 100); - - // Cannot permissionlessly withdraw - assert_noop!( - Pools::fully_unbond(Origin::signed(420), 100), - Error::::NotKickerOrDestroying - ); - - // Given - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // Can permissionlesly withdraw a member that is not the depositor - assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); - - assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default(),); - assert_eq!(Balances::free_balance(100), 100 + 100); - assert!(!PoolMembers::::contains_key(100)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, - Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, - Event::MemberRemoved { pool_id: 1, member: 100 } - ] - ); - }); - } - - #[test] - fn partial_withdraw_unbonded_depositor() { - ExtBuilder::default().ed(1).build_and_execute(|| { - // so the depositor can leave, just keeps the test simpler. - unsafe_set_state(1, PoolState::Destroying).unwrap(); - - // given - assert_ok!(Pools::unbond(Origin::signed(10), 10, 6)); - CurrentEra::set(1); - assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 6, 4 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 6, balance: 6 }, - 4 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); - assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 }, - Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } - ] - ); - - // when - CurrentEra::set(2); - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(10), 10, 0), - Error::::CannotWithdrawAny - ); - - // when - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - - // then - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(4 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 4 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Withdrawn { member: 10, pool_id: 1, points: 6, balance: 6 }] - ); - - // when - CurrentEra::set(4); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - - // then - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!() - ); - assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Withdrawn { member: 10, pool_id: 1, points: 1, balance: 1 },] - ); - - // when repeating: - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(10), 10, 0), - Error::::CannotWithdrawAny - ); - }); - } - - #[test] - fn partial_withdraw_unbonded_non_depositor() { - ExtBuilder::default().add_members(vec![(11, 10)]).build_and_execute(|| { - // given - assert_ok!(Pools::unbond(Origin::signed(11), 11, 6)); - CurrentEra::set(1); - assert_ok!(Pools::unbond(Origin::signed(11), 11, 1)); - assert_eq!( - PoolMembers::::get(11).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 6, 4 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 3 => UnbondPool { points: 6, balance: 6 }, - 4 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!(PoolMembers::::get(11).unwrap().active_points(), 3); - assert_eq!(PoolMembers::::get(11).unwrap().unbonding_points(), 7); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 }, - Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 } - ] - ); - - // when - CurrentEra::set(2); - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(11), 11, 0), - Error::::CannotWithdrawAny - ); - - // when - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); - - // then - assert_eq!( - PoolMembers::::get(11).unwrap().unbonding_eras, - member_unbonding_eras!(4 => 1) - ); - assert_eq!( - SubPoolsStorage::::get(1).unwrap(), - SubPools { - no_era: Default::default(), - with_era: unbonding_pools_with_era! { - 4 => UnbondPool { points: 1, balance: 1 } - } - } - ); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Withdrawn { member: 11, pool_id: 1, points: 6, balance: 6 }] - ); - - // when - CurrentEra::set(4); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); - - // then - assert_eq!( - PoolMembers::::get(11).unwrap().unbonding_eras, - member_unbonding_eras!() - ); - assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); - assert_eq!( - pool_events_since_last_call(), - vec![Event::Withdrawn { member: 11, pool_id: 1, points: 1, balance: 1 }] - ); - - // when repeating: - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(11), 11, 0), - Error::::CannotWithdrawAny - ); - }); - } - - #[test] - fn full_multi_step_withdrawing_non_depositor() { - ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { - // given - assert_ok!(Pools::unbond(Origin::signed(100), 100, 75)); - assert_eq!( - PoolMembers::::get(100).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 75) - ); - - // progress one era and unbond the leftover. - CurrentEra::set(1); - assert_ok!(Pools::unbond(Origin::signed(100), 100, 25)); - assert_eq!( - PoolMembers::::get(100).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 75, 4 => 25) - ); - - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(100), 100, 0), - Error::::CannotWithdrawAny - ); - - // now the 75 should be free. - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, - Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 }, - Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 }, - Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 }, - ] - ); - assert_eq!( - PoolMembers::::get(100).unwrap().unbonding_eras, - member_unbonding_eras!(4 => 25) - ); - - // the 25 should be free now, and the member removed. - CurrentEra::set(4); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 100, pool_id: 1, points: 25, balance: 25 }, - Event::MemberRemoved { pool_id: 1, member: 100 } - ] - ); - }) - } - - #[test] - fn full_multi_step_withdrawing_depositor() { - ExtBuilder::default().ed(1).build_and_execute(|| { - // given - assert_ok!(Pools::unbond(Origin::signed(10), 10, 7)); - - // progress one era and unbond the leftover. - CurrentEra::set(1); - unsafe_set_state(1, PoolState::Destroying).unwrap(); - assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(3 => 7, 4 => 3) - ); - - assert_noop!( - Pools::withdraw_unbonded(Origin::signed(10), 10, 0), - Error::::CannotWithdrawAny - ); - - // now the 7 should be free. - CurrentEra::set(3); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Unbonded { member: 10, pool_id: 1, points: 7, balance: 7 }, - Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, - Event::Withdrawn { member: 10, pool_id: 1, points: 7, balance: 7 } - ] - ); - assert_eq!( - PoolMembers::::get(10).unwrap().unbonding_eras, - member_unbonding_eras!(4 => 3) - ); - - // the 25 should be free now, and the member removed. - CurrentEra::set(4); - assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Withdrawn { member: 10, pool_id: 1, points: 3, balance: 3 }, - Event::MemberRemoved { pool_id: 1, member: 10 }, - // the pool is also destroyed now. - Event::Destroyed { pool_id: 1 }, - ] - ); - }) - } -} - -mod create { - use super::*; - - #[test] - fn create_works() { - ExtBuilder::default().build_and_execute(|| { - // next pool id is 2. - let next_pool_stash = Pools::create_bonded_account(2); - let ed = Balances::minimum_balance(); - - assert!(!BondedPools::::contains_key(2)); - assert!(!RewardPools::::contains_key(2)); - assert!(!PoolMembers::::contains_key(11)); - assert_eq!(StakingMock::active_stake(&next_pool_stash), None); - - Balances::make_free_balance_be(&11, StakingMock::minimum_bond() + ed); - assert_ok!(Pools::create( - Origin::signed(11), - StakingMock::minimum_bond(), - 123, - 456, - 789 - )); - - assert_eq!(Balances::free_balance(&11), 0); - assert_eq!( - PoolMembers::::get(11).unwrap(), - PoolMember { - pool_id: 2, - points: StakingMock::minimum_bond(), - ..Default::default() - } - ); - assert_eq!( - BondedPool::::get(2).unwrap(), - BondedPool { - id: 2, - inner: BondedPoolInner { - points: StakingMock::minimum_bond(), - member_counter: 1, - state: PoolState::Open, - roles: PoolRoles { - depositor: 11, - root: Some(123), - nominator: Some(456), - state_toggler: Some(789) - } - } - } - ); - assert_eq!( - StakingMock::active_stake(&next_pool_stash).unwrap(), - StakingMock::minimum_bond() - ); - assert_eq!( - RewardPools::::get(2).unwrap(), - RewardPool { - balance: Zero::zero(), - points: U256::zero(), - total_earnings: Zero::zero(), - } - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Created { depositor: 11, pool_id: 2 }, - Event::Bonded { member: 11, pool_id: 2, bonded: 10, joined: true } - ] - ); - }); - } - - #[test] - fn create_errors_correctly() { - ExtBuilder::default().with_check(0).build_and_execute(|| { - assert_noop!( - Pools::create(Origin::signed(10), 420, 123, 456, 789), - Error::::AccountBelongsToOtherPool - ); - - // Given - assert_eq!(MinCreateBond::::get(), 2); - assert_eq!(StakingMock::minimum_bond(), 10); - - // Then - assert_noop!( - Pools::create(Origin::signed(11), 9, 123, 456, 789), - Error::::MinimumBondNotMet - ); - - // Given - MinCreateBond::::put(20); - - // Then - assert_noop!( - Pools::create(Origin::signed(11), 19, 123, 456, 789), - Error::::MinimumBondNotMet - ); - - // Given - BondedPool:: { - id: 2, - inner: BondedPoolInner { - state: PoolState::Open, - points: 10, - member_counter: 1, - roles: DEFAULT_ROLES, - }, - } - .put(); - assert_eq!(MaxPools::::get(), Some(2)); - assert_eq!(BondedPools::::count(), 2); - - // Then - assert_noop!( - Pools::create(Origin::signed(11), 20, 123, 456, 789), - Error::::MaxPools - ); - - // Given - assert_eq!(PoolMembers::::count(), 1); - MaxPools::::put(3); - MaxPoolMembers::::put(1); - Balances::make_free_balance_be(&11, 5 + 20); - - // Then - let create = Call::Pools(crate::Call::::create { - amount: 20, - root: 11, - nominator: 11, - state_toggler: 11, - }); - assert_noop!(create.dispatch(Origin::signed(11)), Error::::MaxPoolMembers); - }); - } -} - -mod nominate { - use super::*; - - #[test] - fn nominate_works() { - ExtBuilder::default().build_and_execute(|| { - // Depositor can't nominate - assert_noop!( - Pools::nominate(Origin::signed(10), 1, vec![21]), - Error::::NotNominator - ); - - // State toggler can't nominate - assert_noop!( - Pools::nominate(Origin::signed(902), 1, vec![21]), - Error::::NotNominator - ); - - // Root can nominate - assert_ok!(Pools::nominate(Origin::signed(900), 1, vec![21])); - assert_eq!(Nominations::get().unwrap(), vec![21]); - - // Nominator can nominate - assert_ok!(Pools::nominate(Origin::signed(901), 1, vec![31])); - assert_eq!(Nominations::get().unwrap(), vec![31]); - - // Can't nominate for a pool that doesn't exist - assert_noop!( - Pools::nominate(Origin::signed(902), 123, vec![21]), - Error::::PoolNotFound - ); - }); - } -} - -mod set_state { - use super::*; - - #[test] - fn set_state_works() { - ExtBuilder::default().build_and_execute(|| { - // Given - assert_ok!(BondedPool::::get(1).unwrap().ok_to_be_open(0)); - - // Only the root and state toggler can change the state when the pool is ok to be open. - assert_noop!( - Pools::set_state(Origin::signed(10), 1, PoolState::Blocked), - Error::::CanNotChangeState - ); - assert_noop!( - Pools::set_state(Origin::signed(901), 1, PoolState::Blocked), - Error::::CanNotChangeState - ); - - // Root can change state - assert_ok!(Pools::set_state(Origin::signed(900), 1, PoolState::Blocked)); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::StateChanged { pool_id: 1, new_state: PoolState::Blocked } - ] - ); - - assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Blocked); - - // State toggler can change state - assert_ok!(Pools::set_state(Origin::signed(902), 1, PoolState::Destroying)); - assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - - // If the pool is destroying, then no one can set state - assert_noop!( - Pools::set_state(Origin::signed(900), 1, PoolState::Blocked), - Error::::CanNotChangeState - ); - assert_noop!( - Pools::set_state(Origin::signed(902), 1, PoolState::Blocked), - Error::::CanNotChangeState - ); - - // If the pool is not ok to be open, then anyone can set it to destroying - - // Given - unsafe_set_state(1, PoolState::Open).unwrap(); - let mut bonded_pool = BondedPool::::get(1).unwrap(); - bonded_pool.points = 100; - bonded_pool.put(); - // When - assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); - // Then - assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - - // Given - Balances::make_free_balance_be(&default_bonded_account(), Balance::max_value() / 10); - unsafe_set_state(1, PoolState::Open).unwrap(); - // When - assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); - // Then - assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - - // If the pool is not ok to be open, it cannot be permissionleslly set to a state that - // isn't destroying - unsafe_set_state(1, PoolState::Open).unwrap(); - assert_noop!( - Pools::set_state(Origin::signed(11), 1, PoolState::Blocked), - Error::::CanNotChangeState - ); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, - Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, - Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying } - ] - ); - }); - } -} - -mod set_metadata { - use super::*; - - #[test] - fn set_metadata_works() { - ExtBuilder::default().build_and_execute(|| { - // Root can set metadata - assert_ok!(Pools::set_metadata(Origin::signed(900), 1, vec![1, 1])); - assert_eq!(Metadata::::get(1), vec![1, 1]); - - // State toggler can set metadata - assert_ok!(Pools::set_metadata(Origin::signed(902), 1, vec![2, 2])); - assert_eq!(Metadata::::get(1), vec![2, 2]); - - // Depositor can't set metadata - assert_noop!( - Pools::set_metadata(Origin::signed(10), 1, vec![3, 3]), - Error::::DoesNotHavePermission - ); - - // Nominator can't set metadata - assert_noop!( - Pools::set_metadata(Origin::signed(901), 1, vec![3, 3]), - Error::::DoesNotHavePermission - ); - - // Metadata cannot be longer than `MaxMetadataLen` - assert_noop!( - Pools::set_metadata(Origin::signed(900), 1, vec![1, 1, 1]), - Error::::MetadataExceedsMaxLen - ); - }); - } -} - -mod set_configs { - use super::*; - - #[test] - fn set_configs_works() { - ExtBuilder::default().build_and_execute(|| { - // Setting works - assert_ok!(Pools::set_configs( - Origin::root(), - ConfigOp::Set(1 as Balance), - ConfigOp::Set(2 as Balance), - ConfigOp::Set(3u32), - ConfigOp::Set(4u32), - ConfigOp::Set(5u32), - )); - assert_eq!(MinJoinBond::::get(), 1); - assert_eq!(MinCreateBond::::get(), 2); - assert_eq!(MaxPools::::get(), Some(3)); - assert_eq!(MaxPoolMembers::::get(), Some(4)); - assert_eq!(MaxPoolMembersPerPool::::get(), Some(5)); - - // Noop does nothing - assert_storage_noop!(assert_ok!(Pools::set_configs( - Origin::root(), - ConfigOp::Noop, - ConfigOp::Noop, - ConfigOp::Noop, - ConfigOp::Noop, - ConfigOp::Noop, - ))); - - // Removing works - assert_ok!(Pools::set_configs( - Origin::root(), - ConfigOp::Remove, - ConfigOp::Remove, - ConfigOp::Remove, - ConfigOp::Remove, - ConfigOp::Remove, - )); - assert_eq!(MinJoinBond::::get(), 0); - assert_eq!(MinCreateBond::::get(), 0); - assert_eq!(MaxPools::::get(), None); - assert_eq!(MaxPoolMembers::::get(), None); - assert_eq!(MaxPoolMembersPerPool::::get(), None); - }); - } -} - -mod bond_extra { - use super::*; - use crate::Event; - - #[test] - fn bond_extra_from_free_balance_creator() { - ExtBuilder::default().build_and_execute(|| { - // 10 is the owner and a member in pool 1, give them some more funds. - Balances::make_free_balance_be(&10, 100); - - // given - assert_eq!(PoolMembers::::get(10).unwrap().points, 10); - assert_eq!(BondedPools::::get(1).unwrap().points, 10); - assert_eq!(Balances::free_balance(10), 100); - - // when - assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); - - // then - assert_eq!(Balances::free_balance(10), 90); - assert_eq!(PoolMembers::::get(10).unwrap().points, 20); - assert_eq!(BondedPools::::get(1).unwrap().points, 20); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false } - ] - ); - - // when - assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(20))); - - // then - assert_eq!(Balances::free_balance(10), 70); - assert_eq!(PoolMembers::::get(10).unwrap().points, 40); - assert_eq!(BondedPools::::get(1).unwrap().points, 40); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::Bonded { member: 10, pool_id: 1, bonded: 20, joined: false }] - ); - }) - } - - #[test] - fn bond_extra_from_rewards_creator() { - ExtBuilder::default().build_and_execute(|| { - // put some money in the reward account, all of which will belong to 10 as the only - // member of the pool. - Balances::make_free_balance_be(&default_reward_account(), 7); - // ... if which only 2 is claimable to make sure the reward account does not die. - let claimable_reward = 7 - ExistentialDeposit::get(); - - // given - assert_eq!(PoolMembers::::get(10).unwrap().points, 10); - assert_eq!(BondedPools::::get(1).unwrap().points, 10); - assert_eq!(Balances::free_balance(10), 5); - - // when - assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); - - // then - assert_eq!(Balances::free_balance(10), 5); - assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + claimable_reward); - assert_eq!(BondedPools::::get(1).unwrap().points, 10 + claimable_reward); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, - Event::Bonded { - member: 10, - pool_id: 1, - bonded: claimable_reward, - joined: false - } - ] - ); - }) - } - - #[test] - fn bond_extra_from_rewards_joiner() { - ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { - // put some money in the reward account, all of which will belong to 10 as the only - // member of the pool. - Balances::make_free_balance_be(&default_reward_account(), 8); - // ... if which only 3 is claimable to make sure the reward account does not die. - let claimable_reward = 8 - ExistentialDeposit::get(); - // NOTE: easier to read of we use 3, so let's use the number instead of variable. - assert_eq!(claimable_reward, 3, "test is correct if rewards are divisible by 3"); - - // given - assert_eq!(PoolMembers::::get(10).unwrap().points, 10); - assert_eq!(PoolMembers::::get(20).unwrap().points, 20); - assert_eq!(BondedPools::::get(1).unwrap().points, 30); - assert_eq!(Balances::free_balance(10), 5); - assert_eq!(Balances::free_balance(20), 20); - - // when - assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); - - // then - assert_eq!(Balances::free_balance(10), 5); - // 10's share of the reward is 1/3, since they gave 10/30 of the total shares. - assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + 1); - assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 1); - - // when - assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::Rewards)); - - // then - assert_eq!(Balances::free_balance(20), 20); - // 20's share of the rewards is the other 2/3 of the rewards, since they have 20/30 of - // the shares - assert_eq!(PoolMembers::::get(20).unwrap().points, 20 + 2); - assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 3); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, - Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, - Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } - ] - ); - }) - } -} - -mod update_roles { - use super::*; - - #[test] - fn update_roles_works() { - ExtBuilder::default().build_and_execute(|| { - assert_eq!( - BondedPools::::get(1).unwrap().roles, - PoolRoles { - depositor: 10, - root: Some(900), - nominator: Some(901), - state_toggler: Some(902) - }, - ); - - // non-existent pools - assert_noop!( - Pools::update_roles( - Origin::signed(1), - 2, - ConfigOp::Set(5), - ConfigOp::Set(6), - ConfigOp::Set(7) - ), - Error::::PoolNotFound, - ); - - // depositor cannot change roles. - assert_noop!( - Pools::update_roles( - Origin::signed(1), - 1, - ConfigOp::Set(5), - ConfigOp::Set(6), - ConfigOp::Set(7) - ), - Error::::DoesNotHavePermission, - ); - - // nominator cannot change roles. - assert_noop!( - Pools::update_roles( - Origin::signed(901), - 1, - ConfigOp::Set(5), - ConfigOp::Set(6), - ConfigOp::Set(7) - ), - Error::::DoesNotHavePermission, - ); - // state-toggler - assert_noop!( - Pools::update_roles( - Origin::signed(902), - 1, - ConfigOp::Set(5), - ConfigOp::Set(6), - ConfigOp::Set(7) - ), - Error::::DoesNotHavePermission, - ); - - // but root can - assert_ok!(Pools::update_roles( - Origin::signed(900), - 1, - ConfigOp::Set(5), - ConfigOp::Set(6), - ConfigOp::Set(7) - )); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::RolesUpdated { - root: Some(5), - state_toggler: Some(7), - nominator: Some(6) - } - ] - ); - assert_eq!( - BondedPools::::get(1).unwrap().roles, - PoolRoles { - depositor: 10, - root: Some(5), - nominator: Some(6), - state_toggler: Some(7) - }, - ); - - // also root origin can - assert_ok!(Pools::update_roles( - Origin::root(), - 1, - ConfigOp::Set(1), - ConfigOp::Set(2), - ConfigOp::Set(3) - )); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::RolesUpdated { - root: Some(1), - state_toggler: Some(3), - nominator: Some(2) - }] - ); - assert_eq!( - BondedPools::::get(1).unwrap().roles, - PoolRoles { - depositor: 10, - root: Some(1), - nominator: Some(2), - state_toggler: Some(3) - }, - ); - - // Noop works - assert_ok!(Pools::update_roles( - Origin::root(), - 1, - ConfigOp::Set(11), - ConfigOp::Noop, - ConfigOp::Noop - )); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::RolesUpdated { - root: Some(11), - state_toggler: Some(3), - nominator: Some(2) - }] - ); - - assert_eq!( - BondedPools::::get(1).unwrap().roles, - PoolRoles { - depositor: 10, - root: Some(11), - nominator: Some(2), - state_toggler: Some(3) - }, - ); - - // Remove works - assert_ok!(Pools::update_roles( - Origin::root(), - 1, - ConfigOp::Set(69), - ConfigOp::Remove, - ConfigOp::Remove - )); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }] - ); - - assert_eq!( - BondedPools::::get(1).unwrap().roles, - PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None }, - ); - }) - } -} +// mod unbond_pool { +// use super::*; + +// #[test] +// fn points_to_issue_works() { +// ExtBuilder::default().build_and_execute(|| { +// // 1 points : 1 balance ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; +// assert_eq!(unbond_pool.balance_to_point(10), 10); +// assert_eq!(unbond_pool.balance_to_point(0), 0); + +// // 2 points : 1 balance ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; +// assert_eq!(unbond_pool.balance_to_point(10), 20); + +// // 1 points : 2 balance ratio +// let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; +// assert_eq!(unbond_pool.balance_to_point(10), 5); + +// // 100 points : 0 balance ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; +// assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); + +// // 0 points : 100 balance +// let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; +// assert_eq!(unbond_pool.balance_to_point(10), 10); + +// // 10 points : 3 balance ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; +// assert_eq!(unbond_pool.balance_to_point(10), 33); + +// // 2 points : 3 balance ratio +// let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; +// assert_eq!(unbond_pool.balance_to_point(10), 6); + +// // 4 points : 9 balance ratio +// let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; +// assert_eq!(unbond_pool.balance_to_point(90), 40); +// }) +// } + +// #[test] +// fn balance_to_unbond_works() { +// // 1 balance : 1 points ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; +// assert_eq!(unbond_pool.point_to_balance(10), 10); +// assert_eq!(unbond_pool.point_to_balance(0), 0); + +// // 1 balance : 2 points ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; +// assert_eq!(unbond_pool.point_to_balance(10), 5); + +// // 2 balance : 1 points ratio +// let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; +// assert_eq!(unbond_pool.point_to_balance(10), 20); + +// // 100 balance : 0 points ratio +// let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; +// assert_eq!(unbond_pool.point_to_balance(10), 0); + +// // 0 balance : 100 points ratio +// let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; +// assert_eq!(unbond_pool.point_to_balance(10), 0); + +// // 10 balance : 3 points ratio +// let unbond_pool = UnbondPool:: { points: 30, balance: 100 }; +// assert_eq!(unbond_pool.point_to_balance(10), 33); + +// // 2 balance : 3 points ratio +// let unbond_pool = UnbondPool:: { points: 300, balance: 200 }; +// assert_eq!(unbond_pool.point_to_balance(10), 6); + +// // 4 balance : 9 points ratio +// let unbond_pool = UnbondPool:: { points: 900, balance: 400 }; +// assert_eq!(unbond_pool.point_to_balance(90), 40); +// } +// } + +// mod sub_pools { +// use super::*; + +// #[test] +// fn maybe_merge_pools_works() { +// ExtBuilder::default().build_and_execute(|| { +// assert_eq!(TotalUnbondingPools::::get(), 5); +// assert_eq!(BondingDuration::get(), 3); +// assert_eq!(PostUnbondingPoolsWindow::get(), 2); + +// // Given +// let mut sub_pool_0 = SubPools:: { +// no_era: UnbondPool::::default(), +// with_era: unbonding_pools_with_era! { +// 0 => UnbondPool:: { points: 10, balance: 10 }, +// 1 => UnbondPool:: { points: 10, balance: 10 }, +// 2 => UnbondPool:: { points: 20, balance: 20 }, +// 3 => UnbondPool:: { points: 30, balance: 30 }, +// 4 => UnbondPool:: { points: 40, balance: 40 }, +// }, +// }; + +// // When `current_era < TotalUnbondingPools`, +// let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(0); + +// // Then it exits early without modifications +// assert_eq!(sub_pool_1, sub_pool_0); + +// // When `current_era == TotalUnbondingPools`, +// let sub_pool_1 = sub_pool_1.maybe_merge_pools(1); + +// // Then it exits early without modifications +// assert_eq!(sub_pool_1, sub_pool_0); + +// // When `current_era - TotalUnbondingPools == 0`, +// let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(2); + +// // Then era 0 is merged into the `no_era` pool +// sub_pool_0.no_era = sub_pool_0.with_era.remove(&0).unwrap(); +// assert_eq!(sub_pool_1, sub_pool_0); + +// // Given we have entries for era 1..=5 +// sub_pool_1 +// .with_era +// .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) +// .unwrap(); +// sub_pool_0 +// .with_era +// .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) +// .unwrap(); + +// // When `current_era - TotalUnbondingPools == 1` +// let sub_pool_2 = sub_pool_1.maybe_merge_pools(3); +// let era_1_pool = sub_pool_0.with_era.remove(&1).unwrap(); + +// // Then era 1 is merged into the `no_era` pool +// sub_pool_0.no_era.points += era_1_pool.points; +// sub_pool_0.no_era.balance += era_1_pool.balance; +// assert_eq!(sub_pool_2, sub_pool_0); + +// // When `current_era - TotalUnbondingPools == 5`, so all pools with era <= 4 are removed +// let sub_pool_3 = sub_pool_2.maybe_merge_pools(7); + +// // Then all eras <= 5 are merged into the `no_era` pool +// for era in 2..=5 { +// let to_merge = sub_pool_0.with_era.remove(&era).unwrap(); +// sub_pool_0.no_era.points += to_merge.points; +// sub_pool_0.no_era.balance += to_merge.balance; +// } +// assert_eq!(sub_pool_3, sub_pool_0); +// }); +// } +// } + +// mod join { +// use super::*; + +// #[test] +// fn join_works() { +// let bonded = |points, member_counter| BondedPool:: { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Open, +// points, +// member_counter, +// roles: DEFAULT_ROLES, +// }, +// }; +// ExtBuilder::default().build_and_execute(|| { +// // Given +// Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); +// assert!(!PoolMembers::::contains_key(&11)); + +// // When +// assert_ok!(Pools::join(Origin::signed(11), 2, 1)); + +// // Then + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 11, pool_id: 1, bonded: 2, joined: true }, +// ] +// ); + +// assert_eq!( +// PoolMembers::::get(&11).unwrap(), +// PoolMember:: { pool_id: 1, points: 2, ..Default::default() } +// ); +// assert_eq!(BondedPool::::get(1).unwrap(), bonded(12, 2)); + +// // Given +// // The bonded balance is slashed in half +// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 6); + +// // And +// Balances::make_free_balance_be(&12, ExistentialDeposit::get() + 12); +// assert!(!PoolMembers::::contains_key(&12)); + +// // When +// assert_ok!(Pools::join(Origin::signed(12), 12, 1)); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Bonded { member: 12, pool_id: 1, bonded: 12, joined: true }] +// ); + +// assert_eq!( +// PoolMembers::::get(&12).unwrap(), +// PoolMember:: { pool_id: 1, points: 24, ..Default::default() } +// ); +// assert_eq!(BondedPool::::get(1).unwrap(), bonded(12 + 24, 3)); +// }); +// } + +// #[test] +// fn join_errors_correctly() { +// ExtBuilder::default().with_check(0).build_and_execute(|| { +// // 10 is already part of the default pool created. +// assert_eq!(PoolMembers::::get(&10).unwrap().pool_id, 1); + +// assert_noop!( +// Pools::join(Origin::signed(10), 420, 123), +// Error::::AccountBelongsToOtherPool +// ); + +// assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::PoolNotFound); + +// // Force the pools bonded balance to 0, simulating a 100% slash +// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 0); +// assert_noop!(Pools::join(Origin::signed(11), 420, 1), Error::::OverflowRisk); + +// // Given a mocked bonded pool +// BondedPool:: { +// id: 123, +// inner: BondedPoolInner { +// member_counter: 1, +// state: PoolState::Open, +// points: 100, +// roles: DEFAULT_ROLES, +// }, +// } +// .put(); + +// // and reward pool +// RewardPools::::insert( +// 123, +// RewardPool:: { balance: Zero::zero(), total_earnings: Zero::zero() }, +// ); + +// // Force the points:balance ratio to `MinPointsToBalance` (100/10) +// let min_points_to_balance: u128 = +// <::MinPointsToBalance as Get>::get().into(); + +// StakingMock::set_bonded_balance( +// Pools::create_bonded_account(123), +// min_points_to_balance, +// ); +// assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::OverflowRisk); + +// StakingMock::set_bonded_balance( +// Pools::create_bonded_account(123), +// Balance::MAX / min_points_to_balance, +// ); +// // Balance needs to be gt Balance::MAX / `MinPointsToBalance` +// assert_noop!(Pools::join(Origin::signed(11), 5, 123), Error::::OverflowRisk); + +// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), min_points_to_balance); + +// // Cannot join a pool that isn't open +// unsafe_set_state(123, PoolState::Blocked).unwrap(); +// assert_noop!( +// Pools::join(Origin::signed(11), min_points_to_balance, 123), +// Error::::NotOpen +// ); + +// unsafe_set_state(123, PoolState::Destroying).unwrap(); +// assert_noop!( +// Pools::join(Origin::signed(11), min_points_to_balance, 123), +// Error::::NotOpen +// ); + +// // Given +// MinJoinBond::::put(100); + +// // Then +// assert_noop!( +// Pools::join(Origin::signed(11), 99, 123), +// Error::::MinimumBondNotMet +// ); +// }); +// } + +// #[test] +// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] +// #[cfg_attr(not(debug_assertions), should_panic)] +// fn join_panics_when_reward_pool_not_found() { +// ExtBuilder::default().build_and_execute(|| { +// StakingMock::set_bonded_balance(Pools::create_bonded_account(123), 100); +// BondedPool:: { +// id: 123, +// inner: BondedPoolInner { +// state: PoolState::Open, +// points: 100, +// member_counter: 1, +// roles: DEFAULT_ROLES, +// }, +// } +// .put(); +// let _ = Pools::join(Origin::signed(11), 420, 123); +// }); +// } + +// #[test] +// fn join_max_member_limits_are_respected() { +// ExtBuilder::default().build_and_execute(|| { +// // Given +// assert_eq!(MaxPoolMembersPerPool::::get(), Some(3)); +// for i in 1..3 { +// let account = i + 100; +// Balances::make_free_balance_be(&account, 100 + Balances::minimum_balance()); + +// assert_ok!(Pools::join(Origin::signed(account), 100, 1)); +// } + +// Balances::make_free_balance_be(&103, 100 + Balances::minimum_balance()); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 101, pool_id: 1, bonded: 100, joined: true }, +// Event::Bonded { member: 102, pool_id: 1, bonded: 100, joined: true } +// ] +// ); + +// assert_noop!( +// Pools::join(Origin::signed(103), 100, 1), +// Error::::MaxPoolMembers +// ); + +// // Given +// assert_eq!(PoolMembers::::count(), 3); +// assert_eq!(MaxPoolMembers::::get(), Some(4)); + +// Balances::make_free_balance_be(&104, 100 + Balances::minimum_balance()); +// assert_ok!(Pools::create(Origin::signed(104), 100, 104, 104, 104)); + +// let pool_account = BondedPools::::iter() +// .find(|(_, bonded_pool)| bonded_pool.roles.depositor == 104) +// .map(|(pool_account, _)| pool_account) +// .unwrap(); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 104, pool_id: 2 }, +// Event::Bonded { member: 104, pool_id: 2, bonded: 100, joined: true } +// ] +// ); + +// assert_noop!( +// Pools::join(Origin::signed(103), 100, pool_account), +// Error::::MaxPoolMembers +// ); +// }); +// } +// } + +// mod claim_payout { +// use super::*; + +// fn del(points: Balance, last_recorded_reward_counter: FixedU128) -> PoolMember { +// PoolMember { +// pool_id: 1, +// points, +// last_recorded_reward_counter, +// unbonding_eras: Default::default(), +// } +// } + +// fn rew( +// last_recorded_reward_counter: FixedU128, +// last_recorded_total_payouts: Balance, +// total_rewards_claimed: Balance, +// ) -> RewardPool { +// RewardPool { +// last_recorded_reward_counter, +// last_recorded_total_payouts, +// total_rewards_claimed, +// } +// } + +// #[test] +// fn claim_payout_works() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (50, 50)]) +// .build_and_execute(|| { +// // Given each member currently has a free balance of +// Balances::make_free_balance_be(&10, 0); +// Balances::make_free_balance_be(&40, 0); +// Balances::make_free_balance_be(&50, 0); +// let ed = Balances::minimum_balance(); +// // and the reward pool has earned 100 in rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 100); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(10))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true }, +// Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, +// ] +// ); + +// // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool +// // balance +// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 100)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew(90, 100 * 100 - 100 * 10, 100) +// ); +// assert_eq!(Balances::free_balance(&10), 10); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(40))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] +// ); + +// // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance +// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 100)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew(50, 9_000 - 100 * 40, 100) +// ); +// assert_eq!(Balances::free_balance(&40), 40); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(50))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] +// ); + +// // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance +// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 100)); +// assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); +// assert_eq!(Balances::free_balance(&50), 50); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + +// // Given the reward pool has some new rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 50); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(10))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] +// ); + +// // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance +// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 150)); +// assert_eq!(RewardPools::::get(&1).unwrap(), rew(45, 5_000 - 50 * 10, 150)); +// assert_eq!(Balances::free_balance(&10), 10 + 5); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(40))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] +// ); + +// // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool +// // balance +// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 150)); +// assert_eq!(RewardPools::::get(&1).unwrap(), rew(25, 4_500 - 50 * 40, 150)); +// assert_eq!(Balances::free_balance(&40), 40 + 20); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + +// // Given del 50 hasn't claimed and the reward pools has just earned 50 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(50))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] +// ); + +// // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 +// // pool balance +// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 200)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew( +// 25, +// // old pool points + points from new earnings - del points. +// // +// // points from new earnings = new earnings(50) * bonded_pool.points(100) +// // del points = member.points(50) * new_earnings_since_last_claim (100) +// (2_500 + 50 * 100) - 50 * 100, +// 200, +// ) +// ); +// assert_eq!(Balances::free_balance(&50), 50 + 50); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(10))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] +// ); + +// // We expect a payout of 5 +// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 200)); +// assert_eq!(RewardPools::::get(&1).unwrap(), rew(20, 2_500 - 10 * 50, 200)); +// assert_eq!(Balances::free_balance(&10), 15 + 5); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); + +// // Given del 40 hasn't claimed and the reward pool has just earned 400 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(10))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] +// ); + +// // We expect a payout of 40 +// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 600)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew( +// 380, +// // old pool points + points from new earnings - del points +// // +// // points from new earnings = new earnings(400) * bonded_pool.points(100) +// // del points = member.points(10) * new_earnings_since_last_claim(400) +// (2_000 + 400 * 100) - 10 * 400, +// 600 +// ) +// ); +// assert_eq!(Balances::free_balance(&10), 20 + 40); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); + +// // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(10))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] +// ); + +// // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool +// // balance +// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 620)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew(398, (38_000 + 20 * 100) - 10 * 20, 620) +// ); +// assert_eq!(Balances::free_balance(&10), 60 + 2); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(40))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] +// ); + +// // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 +// // pool balance +// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 620)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew(210, 39_800 - 40 * 470, 620) +// ); +// assert_eq!(Balances::free_balance(&40), 60 + 188); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); + +// // When +// assert_ok!(Pools::claim_payout(Origin::signed(50))); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] +// ); + +// // Expect payout of 210: (21,000 / 21,000) * 210 +// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 620)); +// assert_eq!( +// RewardPools::::get(&1).unwrap(), +// rew(0, 21_000 - 50 * 420, 620) +// ); +// assert_eq!(Balances::free_balance(&50), 100 + 210); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); +// }); +// } + +// #[test] +// fn reward_payout_errors_if_a_member_is_fully_unbonding() { +// ExtBuilder::default().add_members(vec![(11, 11)]).build_and_execute(|| { +// // fully unbond the member. +// assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); + +// let mut bonded_pool = BondedPool::::get(1).unwrap(); +// let mut reward_pool = RewardPools::::get(1).unwrap(); +// let mut member = PoolMembers::::get(11).unwrap(); + +// assert_noop!( +// Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), +// Error::::FullyUnbonding +// ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true }, +// Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 } +// ] +// ); +// }); +// } + +// #[test] +// fn do_reward_payout_works_with_a_pool_of_1() { +// let del = |reward_pool_total_earnings| del(10, reward_pool_total_earnings); + +// ExtBuilder::default().build_and_execute(|| { +// let mut bonded_pool = BondedPool::::get(1).unwrap(); +// let mut reward_pool = RewardPools::::get(1).unwrap(); +// let mut member = PoolMembers::::get(10).unwrap(); +// let ed = Balances::minimum_balance(); + +// // Given no rewards have been earned +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 0); +// assert_eq!(member, del(0)); +// assert_eq!(reward_pool, rew(0, 0, 0)); + +// // Given the pool has earned some rewards for the first time +// Balances::make_free_balance_be(&default_reward_account(), ed + 5); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 5); // (10 * 5 del virtual points / 10 * 5 pool points) * 5 pool balance +// assert_eq!(reward_pool, rew(0, 0, 5)); +// assert_eq!(member, del(5)); + +// // Given the pool has earned rewards again +// Balances::make_free_balance_be(&default_reward_account(), ed + 10); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 10); // (10 * 10 del virtual points / 10 pool points) * 5 pool balance +// assert_eq!(reward_pool, rew(0, 0, 15)); +// assert_eq!(member, del(15)); + +// // Given the pool has earned no new rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 0); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 0); +// assert_eq!(reward_pool, rew(0, 0, 15)); +// assert_eq!(member, del(15)); +// }); +// } + +// #[test] +// fn do_reward_payout_works_with_a_pool_of_3() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (50, 50)]) +// .build_and_execute(|| { +// let mut bonded_pool = BondedPool::::get(1).unwrap(); +// let mut reward_pool = RewardPools::::get(1).unwrap(); +// let ed = Balances::minimum_balance(); +// // PoolMember with 10 points +// let mut del_10 = PoolMembers::::get(10).unwrap(); +// // PoolMember with 40 points +// let mut del_40 = PoolMembers::::get(40).unwrap(); +// // PoolMember with 50 points +// let mut del_50 = PoolMembers::::get(50).unwrap(); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } +// ] +// ); + +// // Given we have a total of 100 points split among the members +// assert_eq!(del_50.points + del_40.points + del_10.points, 100); +// assert_eq!(bonded_pool.points, 100); +// // and the reward pool has earned 100 in rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 100); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 10); // (10 del virtual points / 100 pool points) * 100 pool balance +// assert_eq!(del_10, del(10, 100)); +// assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 10)); + +// // When +// let payout = +// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 40); // (400 del virtual points / 900 pool points) * 90 pool balance +// assert_eq!(del_40, del(40, 100)); +// assert_eq!( +// reward_pool, +// rew( +// 50, +// // old pool points - member virtual points +// 9_000 - 100 * 40, +// 100 +// ) +// ); +// // Mock the reward pool transferring the payout to del_40 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + +// // When +// let payout = +// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 50); // (50 del virtual points / 50 pool points) * 50 pool balance +// assert_eq!(del_50, del(50, 100)); +// assert_eq!(reward_pool, rew(0, 0, 100)); +// // Mock the reward pool transferring the payout to del_50 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); + +// // Given the reward pool has some new rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 50); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 5); // (500 del virtual points / 5,000 pool points) * 50 pool balance +// assert_eq!(del_10, del(10, 150)); +// assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + +// // When +// let payout = +// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 20); // (2,000 del virtual points / 4,500 pool points) * 45 pool balance +// assert_eq!(del_40, del(40, 150)); +// assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 20)); + +// // Given del_50 hasn't claimed and the reward pools has just earned 50 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + +// // When +// let payout = +// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 50); // (5,000 del virtual points / 7,5000 pool points) * 75 pool balance +// assert_eq!(del_50, del(50, 200)); +// assert_eq!( +// reward_pool, +// rew( +// 25, +// // old pool points + points from new earnings - del points. +// // +// // points from new earnings = new earnings(50) * bonded_pool.points(100) +// // del points = member.points(50) * new_earnings_since_last_claim (100) +// (2_500 + 50 * 100) - 50 * 100, +// 200, +// ) +// ); +// // Mock the reward pool transferring the payout to del_50 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 5); +// assert_eq!(del_10, del(10, 200)); +// assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + +// // Given del_40 hasn't claimed and the reward pool has just earned 400 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 40); +// assert_eq!(del_10, del(10, 600)); +// assert_eq!( +// reward_pool, +// rew( +// 380, +// // old pool points + points from new earnings - del points +// // +// // points from new earnings = new earnings(400) * bonded_pool.points(100) +// // del points = member.points(10) * new_earnings_since_last_claim(400) +// (2_000 + 400 * 100) - 10 * 400, +// 600 +// ) +// ); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + +// // Given del_40 + del_50 haven't claimed and the reward pool has earned 20 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + +// // When +// let payout = +// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 2); // (200 del virtual points / 38,000 pool points) * 400 pool balance +// assert_eq!(del_10, del(10, 620)); +// assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 2)); + +// // When +// let payout = +// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 188); // (18,800 del virtual points / 39,800 pool points) * 399 pool balance +// assert_eq!(del_40, del(40, 620)); +// assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); +// // Mock the reward pool transferring the payout to del_10 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 188)); + +// // When +// let payout = +// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) +// .unwrap(); + +// // Then +// assert_eq!(payout, 210); // (21,000 / 21,000) * 210 +// assert_eq!(del_50, del(50, 620)); +// assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); +// }); +// } + +// #[test] +// fn do_reward_payout_works() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (50, 50)]) +// .build_and_execute(|| { +// let mut bonded_pool = BondedPool::::get(1).unwrap(); +// let mut reward_pool = RewardPools::::get(1).unwrap(); +// let ed = Balances::minimum_balance(); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } +// ] +// ); + +// // Given the bonded pool has 100 points +// assert_eq!(bonded_pool.points, 100); +// // Each member currently has a free balance of +// Balances::make_free_balance_be(&10, 0); +// Balances::make_free_balance_be(&40, 0); +// Balances::make_free_balance_be(&50, 0); +// // and the reward pool has earned 100 in rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 100); + +// let mut del_10 = PoolMembers::get(10).unwrap(); +// let mut del_40 = PoolMembers::get(40).unwrap(); +// let mut del_50 = PoolMembers::get(50).unwrap(); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &10, +// &mut del_10, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] +// ); + +// // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool +// // balance +// assert_eq!(del_10, del(10, 100)); +// assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); +// assert_eq!(Balances::free_balance(&10), 10); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &40, +// &mut del_40, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] +// ); + +// // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance +// assert_eq!(del_40, del(40, 100)); +// assert_eq!(reward_pool, rew(50, 9_000 - 100 * 40, 100)); +// assert_eq!(Balances::free_balance(&40), 40); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &50, +// &mut del_50, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] +// ); + +// // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance +// assert_eq!(del_50, del(50, 100)); +// assert_eq!(reward_pool, rew(0, 0, 100)); +// assert_eq!(Balances::free_balance(&50), 50); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + +// // Given the reward pool has some new rewards +// Balances::make_free_balance_be(&default_reward_account(), ed + 50); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &10, +// &mut del_10, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] +// ); + +// // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance +// assert_eq!(del_10, del(10, 150)); +// assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); +// assert_eq!(Balances::free_balance(&10), 10 + 5); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &40, +// &mut del_40, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] +// ); + +// // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool +// // balance +// assert_eq!(del_40, del(40, 150)); +// assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); +// assert_eq!(Balances::free_balance(&40), 40 + 20); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + +// // Given del 50 hasn't claimed and the reward pools has just earned 50 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &50, +// &mut del_50, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] +// ); + +// // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 +// // pool balance +// assert_eq!(del_50, del(50, 200)); +// assert_eq!( +// reward_pool, +// rew( +// 25, +// // old pool points + points from new earnings - del points. +// // +// // points from new earnings = new earnings(50) * bonded_pool.points(100) +// // del points = member.points(50) * new_earnings_since_last_claim (100) +// (2_500 + 50 * 100) - 50 * 100, +// 200, +// ) +// ); +// assert_eq!(Balances::free_balance(&50), 50 + 50); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &10, +// &mut del_10, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] +// ); + +// // We expect a payout of 5 +// assert_eq!(del_10, del(10, 200)); +// assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); +// assert_eq!(Balances::free_balance(&10), 15 + 5); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); + +// // Given del 40 hasn't claimed and the reward pool has just earned 400 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &10, +// &mut del_10, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] +// ); + +// // We expect a payout of 40 +// assert_eq!(del_10, del(10, 600)); +// assert_eq!( +// reward_pool, +// rew( +// 380, +// // old pool points + points from new earnings - del points +// // +// // points from new earnings = new earnings(400) * bonded_pool.points(100) +// // del points = member.points(10) * new_earnings_since_last_claim(400) +// (2_000 + 400 * 100) - 10 * 400, +// 600 +// ) +// ); +// assert_eq!(Balances::free_balance(&10), 20 + 40); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); + +// // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 +// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &10, +// &mut del_10, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] +// ); + +// // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool +// // balance +// assert_eq!(del_10, del(10, 620)); +// assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); +// assert_eq!(Balances::free_balance(&10), 60 + 2); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &40, +// &mut del_40, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] +// ); + +// // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 +// // pool balance +// assert_eq!(del_40, del(40, 620)); +// assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); +// assert_eq!(Balances::free_balance(&40), 60 + 188); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); + +// // When +// assert_ok!(Pools::do_reward_payout( +// &50, +// &mut del_50, +// &mut bonded_pool, +// &mut reward_pool +// )); + +// // Then +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] +// ); + +// // Expect payout of 210: (21,000 / 21,000) * 210 +// assert_eq!(del_50, del(50, 620)); +// assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); +// assert_eq!(Balances::free_balance(&50), 100 + 210); +// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); +// }); +// } +// } + +// mod unbond { +// use super::*; + +// #[test] +// fn unbond_of_1_works() { +// ExtBuilder::default().build_and_execute(|| { +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(fully_unbond_permissioned(10)); + +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().with_era, +// unbonding_pools_with_era! { 0 + 3 => UnbondPool:: { points: 10, balance: 10 }} +// ); + +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Destroying, +// points: 0, +// member_counter: 1, +// roles: DEFAULT_ROLES, +// } +// } +// ); + +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); +// }); +// } + +// #[test] +// fn unbond_of_3_works() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (550, 550)]) +// .build_and_execute(|| { +// let ed = Balances::minimum_balance(); +// // Given a slash from 600 -> 100 +// StakingMock::set_bonded_balance(default_bonded_account(), 100); +// // and unclaimed rewards of 600. +// Balances::make_free_balance_be(&default_reward_account(), ed + 600); + +// // When +// assert_ok!(fully_unbond_permissioned(40)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().with_era, +// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 6, balance: 6 }} +// ); +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Open, +// points: 560, +// member_counter: 3, +// roles: DEFAULT_ROLES, +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, +// Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, +// Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 } +// ] +// ); + +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); +// assert_eq!( +// PoolMembers::::get(40).unwrap().unbonding_eras, +// member_unbonding_eras!(0 + 3 => 6) +// ); +// assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding + +// // When +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(fully_unbond_permissioned(550)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(&1).unwrap().with_era, +// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 98, balance: 98 }} +// ); +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Destroying, +// points: 10, +// member_counter: 3, +// roles: DEFAULT_ROLES +// } +// } +// ); +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); +// assert_eq!( +// PoolMembers::::get(550).unwrap().unbonding_eras, +// member_unbonding_eras!(0 + 3 => 92) +// ); +// assert_eq!(Balances::free_balance(&550), 550 + 550); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, +// Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 } +// ] +// ); + +// // When +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 40, 0)); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 550, 0)); +// assert_ok!(fully_unbond_permissioned(10)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().with_era, +// unbonding_pools_with_era! { 6 => UnbondPool { points: 2, balance: 2 }} +// ); +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Destroying, +// points: 0, +// member_counter: 1, +// roles: DEFAULT_ROLES +// } +// } +// ); +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); + +// assert_eq!(Balances::free_balance(&550), 550 + 550 + 92); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 40, pool_id: 1, points: 6, balance: 6 }, +// Event::MemberRemoved { pool_id: 1, member: 40 }, +// Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, +// Event::MemberRemoved { pool_id: 1, member: 550 }, +// Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } +// ] +// ); +// }); +// } + +// #[test] +// fn unbond_merges_older_pools() { +// ExtBuilder::default().with_check(1).build_and_execute(|| { +// // Given +// assert_eq!(StakingMock::bonding_duration(), 3); +// SubPoolsStorage::::insert( +// 1, +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 0 + 3 => UnbondPool { balance: 10, points: 100 }, +// 1 + 3 => UnbondPool { balance: 20, points: 20 }, +// 2 + 3 => UnbondPool { balance: 101, points: 101} +// }, +// }, +// ); +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // When +// let current_era = 1 + TotalUnbondingPools::::get(); +// CurrentEra::set(current_era); + +// assert_ok!(fully_unbond_permissioned(10)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: UnbondPool { balance: 10 + 20, points: 100 + 20 }, +// with_era: unbonding_pools_with_era! { +// 2 + 3 => UnbondPool { balance: 101, points: 101}, +// current_era + 3 => UnbondPool { balance: 10, points: 10 }, +// }, +// }, +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } +// ] +// ); +// }); +// } + +// #[test] +// fn unbond_kick_works() { +// // Kick: the pool is blocked and the caller is either the root or state-toggler. +// ExtBuilder::default() +// .add_members(vec![(100, 100), (200, 200)]) +// .build_and_execute(|| { +// // Given +// unsafe_set_state(1, PoolState::Blocked).unwrap(); +// let bonded_pool = BondedPool::::get(1).unwrap(); +// assert_eq!(bonded_pool.roles.root.unwrap(), 900); +// assert_eq!(bonded_pool.roles.nominator.unwrap(), 901); +// assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902); + +// // When the nominator tries to kick, then its a noop +// assert_noop!( +// Pools::fully_unbond(Origin::signed(901), 100), +// Error::::NotKickerOrDestroying +// ); + +// // When the root kicks then its ok +// assert_ok!(Pools::fully_unbond(Origin::signed(900), 100)); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, +// Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, +// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, +// ] +// ); + +// // When the state toggler kicks then its ok +// assert_ok!(Pools::fully_unbond(Origin::signed(902), 200)); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }] +// ); + +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// roles: DEFAULT_ROLES, +// state: PoolState::Blocked, +// points: 10, // Only 10 points because 200 + 100 was unbonded +// member_counter: 3, +// } +// } +// ); +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 10); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 0 + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } +// }, +// } +// ); +// assert_eq!( +// *UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), +// 100 + 200 +// ); +// }); +// } + +// #[test] +// fn unbond_permissionless_works() { +// // Scenarios where non-admin accounts can unbond others +// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { +// // Given the pool is blocked +// unsafe_set_state(1, PoolState::Blocked).unwrap(); + +// // A permissionless unbond attempt errors +// assert_noop!( +// Pools::fully_unbond(Origin::signed(420), 100), +// Error::::NotKickerOrDestroying +// ); + +// // permissionless unbond must be full +// assert_noop!( +// Pools::unbond(Origin::signed(420), 100, 80), +// Error::::PartialUnbondNotAllowedPermissionlessly, +// ); + +// // Given the pool is destroying +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // The depositor cannot be fully unbonded until they are the last member +// assert_noop!( +// Pools::fully_unbond(Origin::signed(10), 10), +// Error::::NotOnlyPoolMember +// ); + +// // Any account can unbond a member that is not the depositor +// assert_ok!(Pools::fully_unbond(Origin::signed(420), 100)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, +// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 } +// ] +// ); + +// // still permissionless unbond must be full +// assert_noop!( +// Pools::unbond(Origin::signed(420), 100, 80), +// Error::::PartialUnbondNotAllowedPermissionlessly, +// ); + +// // Given the pool is blocked +// unsafe_set_state(1, PoolState::Blocked).unwrap(); + +// // The depositor cannot be unbonded +// assert_noop!( +// Pools::fully_unbond(Origin::signed(420), 10), +// Error::::DoesNotHavePermission +// ); + +// // Given the pools is destroying +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // The depositor cannot be unbonded yet. +// assert_noop!( +// Pools::fully_unbond(Origin::signed(420), 10), +// Error::::DoesNotHavePermission, +// ); + +// // but when everyone is unbonded it can.. +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 100, 0)); + +// // still permissionless unbond must be full. +// assert_noop!( +// Pools::unbond(Origin::signed(420), 10, 5), +// Error::::PartialUnbondNotAllowedPermissionlessly, +// ); + +// // but full unbond works. +// assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); + +// assert_eq!(BondedPools::::get(1).unwrap().points, 0); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 + 3 => UnbondPool { points: 10, balance: 10 } +// } +// } +// ); +// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); +// assert_eq!(*UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 10); +// }); +// } + +// #[test] +// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] +// #[cfg_attr(not(debug_assertions), should_panic)] +// fn unbond_errors_correctly() { +// ExtBuilder::default().build_and_execute(|| { +// assert_noop!( +// Pools::fully_unbond(Origin::signed(11), 11), +// Error::::PoolMemberNotFound +// ); + +// // Add the member +// let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; +// PoolMembers::::insert(11, member); + +// let _ = Pools::fully_unbond(Origin::signed(11), 11); +// }); +// } + +// #[test] +// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] +// #[cfg_attr(not(debug_assertions), should_panic)] +// fn unbond_panics_when_reward_pool_not_found() { +// ExtBuilder::default().build_and_execute(|| { +// let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; +// PoolMembers::::insert(11, member); +// BondedPool:: { +// id: 1, +// inner: BondedPoolInner { +// state: PoolState::Open, +// points: 10, +// member_counter: 1, +// roles: DEFAULT_ROLES, +// }, +// } +// .put(); + +// let _ = Pools::fully_unbond(Origin::signed(11), 11); +// }); +// } + +// #[test] +// fn partial_unbond_era_tracking() { +// ExtBuilder::default().build_and_execute(|| { +// // given +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); +// assert_eq!(PoolMembers::::get(10).unwrap().pool_id, 1); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!() +// ); +// assert_eq!(BondedPool::::get(1).unwrap().points, 10); +// assert!(SubPoolsStorage::::get(1).is_none()); +// assert_eq!(CurrentEra::get(), 0); +// assert_eq!(BondingDuration::get(), 3); + +// // so the depositor can leave, just keeps the test simpler. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // when: casual unbond +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + +// // then +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 9); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 1); +// assert_eq!(BondedPool::::get(1).unwrap().points, 9); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } +// ] +// ); + +// // when: casual further unbond, same era. +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); + +// // then +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 4); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 6); +// assert_eq!(BondedPool::::get(1).unwrap().points, 4); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 6) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 6, balance: 6 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }] +// ); + +// // when: casual further unbond, next era. +// CurrentEra::set(1); +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + +// // then +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); +// assert_eq!(BondedPool::::get(1).unwrap().points, 3); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 6, 4 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 6, balance: 6 }, +// 4 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }] +// ); + +// // when: unbonding more than our active: error +// assert_err!( +// frame_support::storage::in_storage_layer(|| Pools::unbond( +// Origin::signed(10), +// 10, +// 5 +// )), +// Error::::NotEnoughPointsToUnbond +// ); +// // instead: +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + +// // then +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 0); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 10); +// assert_eq!(BondedPool::::get(1).unwrap().points, 0); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 6, 4 => 4) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 6, balance: 6 }, +// 4 => UnbondPool { points: 4, balance: 4 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }] +// ); +// }); +// } + +// #[test] +// fn partial_unbond_max_chunks() { +// ExtBuilder::default().ed(1).build_and_execute(|| { +// // so the depositor can leave, just keeps the test simpler. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// MaxUnbonding::set(2); + +// // given +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); +// CurrentEra::set(1); +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 2, 4 => 3) +// ); + +// // when +// CurrentEra::set(2); +// assert_err!( +// frame_support::storage::in_storage_layer(|| Pools::unbond( +// Origin::signed(10), +// 10, +// 4 +// )), +// Error::::MaxUnbondingLimit +// ); + +// // when +// MaxUnbonding::set(3); +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 2, 4 => 3, 5 => 1) +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } +// ] +// ); +// }) +// } + +// // depositor can unbond inly up to `MinCreateBond`. +// #[test] +// fn depositor_permissioned_partial_unbond() { +// ExtBuilder::default().ed(1).build_and_execute(|| { +// // given +// assert_eq!(MinCreateBond::::get(), 2); +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); + +// // can unbond a bit.. +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 7); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 3); + +// // but not less than 2 +// assert_noop!( +// Pools::unbond(Origin::signed(10), 10, 6), +// Error::::NotOnlyPoolMember +// ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } +// ] +// ); +// }); +// } + +// // same as above, but the pool is slashed and therefore the depositor cannot partially unbond. +// #[test] +// fn depositor_permissioned_partial_unbond_slashed() { +// ExtBuilder::default().ed(1).build_and_execute(|| { +// // given +// assert_eq!(MinCreateBond::::get(), 2); +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); + +// // slash the default pool +// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 5); + +// // cannot unbond even 7, because the value of shares is now less. +// assert_noop!( +// Pools::unbond(Origin::signed(10), 10, 7), +// Error::::NotOnlyPoolMember +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// ] +// ); +// }); +// } + +// #[test] +// fn every_unbonding_triggers_payout() { +// ExtBuilder::default().build_and_execute(|| { +// let initial_reward_account = Balances::free_balance(Pools::create_reward_account(1)); +// assert_eq!(initial_reward_account, Balances::minimum_balance()); +// assert_eq!(initial_reward_account, 5); + +// // set the pool to destroying so that depositor can leave. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// Balances::make_free_balance_be( +// &Pools::create_reward_account(1), +// 2 * Balances::minimum_balance(), +// ); + +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// // exactly equal to ed, all that can be claimed. +// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } +// ] +// ); + +// CurrentEra::set(1); +// Balances::make_free_balance_be( +// &Pools::create_reward_account(1), +// 2 * Balances::minimum_balance(), +// ); + +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// // exactly equal to ed, all that can be claimed. +// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } +// ] +// ); + +// CurrentEra::set(2); +// Balances::make_free_balance_be( +// &Pools::create_reward_account(1), +// 2 * Balances::minimum_balance(), +// ); + +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 } +// ] +// ); + +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 2, 4 => 3, 5 => 5) +// ); +// }); +// } +// } + +// mod pool_withdraw_unbonded { +// use super::*; + +// #[test] +// fn pool_withdraw_unbonded_works() { +// ExtBuilder::default().build_and_execute(|| { +// // Given 10 unbond'ed directly against the pool account +// assert_ok!(StakingMock::unbond(default_bonded_account(), 5)); +// // and the pool account only has 10 balance +// assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); +// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(10)); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); + +// // When +// assert_ok!(Pools::pool_withdraw_unbonded(Origin::signed(10), 1, 0)); + +// // Then there unbonding balance is no longer locked +// assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); +// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(5)); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); +// }); +// } +// } + +// mod withdraw_unbonded { +// use super::*; +// use frame_support::bounded_btree_map; + +// #[test] +// fn withdraw_unbonded_works_against_slashed_no_era_sub_pool() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (550, 550)]) +// .build_and_execute(|| { +// // reduce the noise a bit. +// let _ = balances_events_since_last_call(); + +// // Given +// assert_eq!(StakingMock::bonding_duration(), 3); +// assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); +// assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 600); + +// let mut current_era = 1; +// CurrentEra::set(current_era); + +// let mut sub_pools = SubPoolsStorage::::get(1).unwrap(); +// let unbond_pool = sub_pools.with_era.get_mut(&3).unwrap(); +// // Sanity check +// assert_eq!(*unbond_pool, UnbondPool { points: 550 + 40, balance: 550 + 40 }); + +// // Simulate a slash to the pool with_era(current_era), decreasing the balance by +// // half +// { +// unbond_pool.balance /= 2; // 295 +// SubPoolsStorage::::insert(1, sub_pools); +// // Update the equivalent of the unbonding chunks for the `StakingMock` +// let mut x = UnbondingBalanceMap::get(); +// *x.get_mut(&default_bonded_account()).unwrap() /= 5; +// UnbondingBalanceMap::set(&x); +// Balances::make_free_balance_be( +// &default_bonded_account(), +// Balances::free_balance(&default_bonded_account()) / 2, // 300 +// ); +// StakingMock::set_bonded_balance( +// default_bonded_account(), +// StakingMock::active_stake(&default_bonded_account()).unwrap() / 2, +// ); +// }; + +// // Advance the current_era to ensure all `with_era` pools will be merged into +// // `no_era` pool +// current_era += TotalUnbondingPools::::get(); +// CurrentEra::set(current_era); + +// // Simulate some other call to unbond that would merge `with_era` pools into +// // `no_era` +// let sub_pools = +// SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); +// SubPoolsStorage::::insert(1, sub_pools); + +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: UnbondPool { points: 550 + 40, balance: 275 + 20 }, +// with_era: Default::default() +// } +// ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, +// Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 }, +// Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 }, +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::BalanceSet { +// who: default_bonded_account(), +// free: 300, +// reserved: 0 +// }] +// ); + +// // When +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().no_era, +// UnbondPool { points: 40, balance: 20 } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 550 }, +// Event::MemberRemoved { pool_id: 1, member: 550 } +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 }] +// ); + +// // When +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); + +// // Then +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().no_era, +// UnbondPool { points: 0, balance: 0 } +// ); +// assert!(!PoolMembers::::contains_key(40)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 40 }, +// Event::MemberRemoved { pool_id: 1, member: 40 } +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 }] +// ); + +// // now, finally, the depositor can take out its share. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(fully_unbond_permissioned(10)); + +// current_era += 3; +// CurrentEra::set(current_era); + +// // when +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 }, +// Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 }, +// Event::MemberRemoved { pool_id: 1, member: 10 }, +// Event::Destroyed { pool_id: 1 } +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![ +// BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, +// BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } +// ] +// ); +// }); +// } + +// #[test] +// fn withdraw_unbonded_works_against_slashed_with_era_sub_pools() { +// ExtBuilder::default() +// .add_members(vec![(40, 40), (550, 550)]) +// .build_and_execute(|| { +// let _ = balances_events_since_last_call(); + +// // Given +// // current bond is 600, we slash it all to 300. +// StakingMock::set_bonded_balance(default_bonded_account(), 300); +// Balances::make_free_balance_be(&default_bonded_account(), 300); +// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(300)); + +// assert_ok!(fully_unbond_permissioned(40)); +// assert_ok!(fully_unbond_permissioned(550)); + +// assert_eq!( +// SubPoolsStorage::::get(&1).unwrap().with_era, +// unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 +// }} ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, +// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, +// Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 }, +// Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 }, +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::BalanceSet { +// who: default_bonded_account(), +// free: 300, +// reserved: 0 +// },] +// ); + +// CurrentEra::set(StakingMock::bonding_duration()); + +// // When +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); + +// // Then +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 },] +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 20 }, +// Event::MemberRemoved { pool_id: 1, member: 40 } +// ] +// ); + +// assert_eq!( +// SubPoolsStorage::::get(&1).unwrap().with_era, +// unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} +// ); + +// // When +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); + +// // Then +// assert_eq!( +// balances_events_since_last_call(), +// vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 },] +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 275 }, +// Event::MemberRemoved { pool_id: 1, member: 550 } +// ] +// ); +// assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); + +// // now, finally, the depositor can take out its share. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(fully_unbond_permissioned(10)); + +// // because everyone else has left, the points +// assert_eq!( +// SubPoolsStorage::::get(&1).unwrap().with_era, +// unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} +// ); + +// CurrentEra::set(CurrentEra::get() + 3); + +// // when +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + +// // then +// assert_eq!(Balances::free_balance(&10), 10 + 5); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 0); + +// // in this test 10 also gets a fair share of the slash, because the slash was +// // applied to the bonded account. +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }, +// Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 }, +// Event::MemberRemoved { pool_id: 1, member: 10 }, +// Event::Destroyed { pool_id: 1 } +// ] +// ); +// assert_eq!( +// balances_events_since_last_call(), +// vec![ +// BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, +// BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } +// ] +// ); +// }); +// } + +// #[test] +// fn withdraw_unbonded_handles_faulty_sub_pool_accounting() { +// ExtBuilder::default().build_and_execute(|| { +// // Given +// assert_eq!(Balances::minimum_balance(), 5); +// assert_eq!(Balances::free_balance(&10), 5); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); + +// // Simulate a slash that is not accounted for in the sub pools. +// Balances::make_free_balance_be(&default_bonded_account(), 5); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap().with_era, +// //------------------------------balance decrease is not account for +// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 } } +// ); + +// CurrentEra::set(0 + 3); + +// // When +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + +// // Then +// assert_eq!(Balances::free_balance(10), 10 + 5); +// assert_eq!(Balances::free_balance(&default_bonded_account()), 0); +// }); +// } + +// #[test] +// fn withdraw_unbonded_errors_correctly() { +// ExtBuilder::default().with_check(0).build_and_execute(|| { +// // Insert the sub-pool +// let sub_pools = SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 }}, +// }; +// SubPoolsStorage::::insert(1, sub_pools.clone()); + +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), +// Error::::PoolMemberNotFound +// ); + +// let mut member = PoolMember { pool_id: 1, points: 10, ..Default::default() }; +// PoolMembers::::insert(11, member.clone()); + +// // Simulate calling `unbond` +// member.unbonding_eras = member_unbonding_eras!(3 + 0 => 10); +// PoolMembers::::insert(11, member.clone()); + +// // We are still in the bonding duration +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), +// Error::::CannotWithdrawAny +// ); + +// // If we error the member does not get removed +// assert_eq!(PoolMembers::::get(&11), Some(member)); +// // and the sub pools do not get updated. +// assert_eq!(SubPoolsStorage::::get(1).unwrap(), sub_pools) +// }); +// } + +// #[test] +// fn withdraw_unbonded_kick() { +// ExtBuilder::default() +// .add_members(vec![(100, 100), (200, 200)]) +// .build_and_execute(|| { +// // Given +// assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); +// assert_ok!(Pools::fully_unbond(Origin::signed(200), 200)); +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// points: 10, +// state: PoolState::Open, +// member_counter: 3, +// roles: DEFAULT_ROLES +// } +// } +// ); +// CurrentEra::set(StakingMock::bonding_duration()); + +// // Cannot kick when pool is open +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(902), 100, 0), +// Error::::NotKickerOrDestroying +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, +// Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, +// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, +// Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 } +// ] +// ); + +// // Given +// unsafe_set_state(1, PoolState::Blocked).unwrap(); + +// // Cannot kick as a nominator +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(901), 100, 0), +// Error::::NotKickerOrDestroying +// ); + +// // Can kick as root +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 100, 0)); + +// // Can kick as state toggler +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 200, 0)); + +// assert_eq!(Balances::free_balance(100), 100 + 100); +// assert_eq!(Balances::free_balance(200), 200 + 200); +// assert!(!PoolMembers::::contains_key(100)); +// assert!(!PoolMembers::::contains_key(200)); +// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, +// Event::MemberRemoved { pool_id: 1, member: 100 }, +// Event::Withdrawn { member: 200, pool_id: 1, points: 200, balance: 200 }, +// Event::MemberRemoved { pool_id: 1, member: 200 } +// ] +// ); +// }); +// } + +// #[test] +// fn withdraw_unbonded_destroying_permissionless() { +// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { +// // Given +// assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); +// assert_eq!( +// BondedPool::::get(1).unwrap(), +// BondedPool { +// id: 1, +// inner: BondedPoolInner { +// points: 10, +// state: PoolState::Open, +// member_counter: 2, +// roles: DEFAULT_ROLES, +// } +// } +// ); +// CurrentEra::set(StakingMock::bonding_duration()); +// assert_eq!(Balances::free_balance(100), 100); + +// // Cannot permissionlessly withdraw +// assert_noop!( +// Pools::fully_unbond(Origin::signed(420), 100), +// Error::::NotKickerOrDestroying +// ); + +// // Given +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // Can permissionlesly withdraw a member that is not the depositor +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); + +// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default(),); +// assert_eq!(Balances::free_balance(100), 100 + 100); +// assert!(!PoolMembers::::contains_key(100)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, +// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, +// Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, +// Event::MemberRemoved { pool_id: 1, member: 100 } +// ] +// ); +// }); +// } + +// #[test] +// fn partial_withdraw_unbonded_depositor() { +// ExtBuilder::default().ed(1).build_and_execute(|| { +// // so the depositor can leave, just keeps the test simpler. +// unsafe_set_state(1, PoolState::Destroying).unwrap(); + +// // given +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 6)); +// CurrentEra::set(1); +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 6, 4 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 6, balance: 6 }, +// 4 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); +// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } +// ] +// ); + +// // when +// CurrentEra::set(2); +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), +// Error::::CannotWithdrawAny +// ); + +// // when +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + +// // then +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(4 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 4 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Withdrawn { member: 10, pool_id: 1, points: 6, balance: 6 }] +// ); + +// // when +// CurrentEra::set(4); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + +// // then +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!() +// ); +// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Withdrawn { member: 10, pool_id: 1, points: 1, balance: 1 },] +// ); + +// // when repeating: +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), +// Error::::CannotWithdrawAny +// ); +// }); +// } + +// #[test] +// fn partial_withdraw_unbonded_non_depositor() { +// ExtBuilder::default().add_members(vec![(11, 10)]).build_and_execute(|| { +// // given +// assert_ok!(Pools::unbond(Origin::signed(11), 11, 6)); +// CurrentEra::set(1); +// assert_ok!(Pools::unbond(Origin::signed(11), 11, 1)); +// assert_eq!( +// PoolMembers::::get(11).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 6, 4 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 3 => UnbondPool { points: 6, balance: 6 }, +// 4 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!(PoolMembers::::get(11).unwrap().active_points(), 3); +// assert_eq!(PoolMembers::::get(11).unwrap().unbonding_points(), 7); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 }, +// Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 } +// ] +// ); + +// // when +// CurrentEra::set(2); +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), +// Error::::CannotWithdrawAny +// ); + +// // when +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); + +// // then +// assert_eq!( +// PoolMembers::::get(11).unwrap().unbonding_eras, +// member_unbonding_eras!(4 => 1) +// ); +// assert_eq!( +// SubPoolsStorage::::get(1).unwrap(), +// SubPools { +// no_era: Default::default(), +// with_era: unbonding_pools_with_era! { +// 4 => UnbondPool { points: 1, balance: 1 } +// } +// } +// ); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Withdrawn { member: 11, pool_id: 1, points: 6, balance: 6 }] +// ); + +// // when +// CurrentEra::set(4); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); + +// // then +// assert_eq!( +// PoolMembers::::get(11).unwrap().unbonding_eras, +// member_unbonding_eras!() +// ); +// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Withdrawn { member: 11, pool_id: 1, points: 1, balance: 1 }] +// ); + +// // when repeating: +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), +// Error::::CannotWithdrawAny +// ); +// }); +// } + +// #[test] +// fn full_multi_step_withdrawing_non_depositor() { +// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { +// // given +// assert_ok!(Pools::unbond(Origin::signed(100), 100, 75)); +// assert_eq!( +// PoolMembers::::get(100).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 75) +// ); + +// // progress one era and unbond the leftover. +// CurrentEra::set(1); +// assert_ok!(Pools::unbond(Origin::signed(100), 100, 25)); +// assert_eq!( +// PoolMembers::::get(100).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 75, 4 => 25) +// ); + +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(100), 100, 0), +// Error::::CannotWithdrawAny +// ); + +// // now the 75 should be free. +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, +// Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 }, +// Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 }, +// Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 }, +// ] +// ); +// assert_eq!( +// PoolMembers::::get(100).unwrap().unbonding_eras, +// member_unbonding_eras!(4 => 25) +// ); + +// // the 25 should be free now, and the member removed. +// CurrentEra::set(4); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 100, pool_id: 1, points: 25, balance: 25 }, +// Event::MemberRemoved { pool_id: 1, member: 100 } +// ] +// ); +// }) +// } + +// #[test] +// fn full_multi_step_withdrawing_depositor() { +// ExtBuilder::default().ed(1).build_and_execute(|| { +// // given +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 7)); + +// // progress one era and unbond the leftover. +// CurrentEra::set(1); +// unsafe_set_state(1, PoolState::Destroying).unwrap(); +// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(3 => 7, 4 => 3) +// ); + +// assert_noop!( +// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), +// Error::::CannotWithdrawAny +// ); + +// // now the 7 should be free. +// CurrentEra::set(3); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Unbonded { member: 10, pool_id: 1, points: 7, balance: 7 }, +// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, +// Event::Withdrawn { member: 10, pool_id: 1, points: 7, balance: 7 } +// ] +// ); +// assert_eq!( +// PoolMembers::::get(10).unwrap().unbonding_eras, +// member_unbonding_eras!(4 => 3) +// ); + +// // the 25 should be free now, and the member removed. +// CurrentEra::set(4); +// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Withdrawn { member: 10, pool_id: 1, points: 3, balance: 3 }, +// Event::MemberRemoved { pool_id: 1, member: 10 }, +// // the pool is also destroyed now. +// Event::Destroyed { pool_id: 1 }, +// ] +// ); +// }) +// } +// } + +// mod create { +// use super::*; + +// #[test] +// fn create_works() { +// ExtBuilder::default().build_and_execute(|| { +// // next pool id is 2. +// let next_pool_stash = Pools::create_bonded_account(2); +// let ed = Balances::minimum_balance(); + +// assert!(!BondedPools::::contains_key(2)); +// assert!(!RewardPools::::contains_key(2)); +// assert!(!PoolMembers::::contains_key(11)); +// assert_eq!(StakingMock::active_stake(&next_pool_stash), None); + +// Balances::make_free_balance_be(&11, StakingMock::minimum_bond() + ed); +// assert_ok!(Pools::create( +// Origin::signed(11), +// StakingMock::minimum_bond(), +// 123, +// 456, +// 789 +// )); + +// assert_eq!(Balances::free_balance(&11), 0); +// assert_eq!( +// PoolMembers::::get(11).unwrap(), +// PoolMember { +// pool_id: 2, +// points: StakingMock::minimum_bond(), +// ..Default::default() +// } +// ); +// assert_eq!( +// BondedPool::::get(2).unwrap(), +// BondedPool { +// id: 2, +// inner: BondedPoolInner { +// points: StakingMock::minimum_bond(), +// member_counter: 1, +// state: PoolState::Open, +// roles: PoolRoles { +// depositor: 11, +// root: Some(123), +// nominator: Some(456), +// state_toggler: Some(789) +// } +// } +// } +// ); +// assert_eq!( +// StakingMock::active_stake(&next_pool_stash).unwrap(), +// StakingMock::minimum_bond() +// ); +// assert_eq!( +// RewardPools::::get(2).unwrap(), +// RewardPool { +// balance: Zero::zero(), +// points: U256::zero(), +// total_earnings: Zero::zero(), +// } +// ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Created { depositor: 11, pool_id: 2 }, +// Event::Bonded { member: 11, pool_id: 2, bonded: 10, joined: true } +// ] +// ); +// }); +// } + +// #[test] +// fn create_errors_correctly() { +// ExtBuilder::default().with_check(0).build_and_execute(|| { +// assert_noop!( +// Pools::create(Origin::signed(10), 420, 123, 456, 789), +// Error::::AccountBelongsToOtherPool +// ); + +// // Given +// assert_eq!(MinCreateBond::::get(), 2); +// assert_eq!(StakingMock::minimum_bond(), 10); + +// // Then +// assert_noop!( +// Pools::create(Origin::signed(11), 9, 123, 456, 789), +// Error::::MinimumBondNotMet +// ); + +// // Given +// MinCreateBond::::put(20); + +// // Then +// assert_noop!( +// Pools::create(Origin::signed(11), 19, 123, 456, 789), +// Error::::MinimumBondNotMet +// ); + +// // Given +// BondedPool:: { +// id: 2, +// inner: BondedPoolInner { +// state: PoolState::Open, +// points: 10, +// member_counter: 1, +// roles: DEFAULT_ROLES, +// }, +// } +// .put(); +// assert_eq!(MaxPools::::get(), Some(2)); +// assert_eq!(BondedPools::::count(), 2); + +// // Then +// assert_noop!( +// Pools::create(Origin::signed(11), 20, 123, 456, 789), +// Error::::MaxPools +// ); + +// // Given +// assert_eq!(PoolMembers::::count(), 1); +// MaxPools::::put(3); +// MaxPoolMembers::::put(1); +// Balances::make_free_balance_be(&11, 5 + 20); + +// // Then +// let create = Call::Pools(crate::Call::::create { +// amount: 20, +// root: 11, +// nominator: 11, +// state_toggler: 11, +// }); +// assert_noop!(create.dispatch(Origin::signed(11)), Error::::MaxPoolMembers); +// }); +// } +// } + +// mod nominate { +// use super::*; + +// #[test] +// fn nominate_works() { +// ExtBuilder::default().build_and_execute(|| { +// // Depositor can't nominate +// assert_noop!( +// Pools::nominate(Origin::signed(10), 1, vec![21]), +// Error::::NotNominator +// ); + +// // State toggler can't nominate +// assert_noop!( +// Pools::nominate(Origin::signed(902), 1, vec![21]), +// Error::::NotNominator +// ); + +// // Root can nominate +// assert_ok!(Pools::nominate(Origin::signed(900), 1, vec![21])); +// assert_eq!(Nominations::get().unwrap(), vec![21]); + +// // Nominator can nominate +// assert_ok!(Pools::nominate(Origin::signed(901), 1, vec![31])); +// assert_eq!(Nominations::get().unwrap(), vec![31]); + +// // Can't nominate for a pool that doesn't exist +// assert_noop!( +// Pools::nominate(Origin::signed(902), 123, vec![21]), +// Error::::PoolNotFound +// ); +// }); +// } +// } + +// mod set_state { +// use super::*; + +// #[test] +// fn set_state_works() { +// ExtBuilder::default().build_and_execute(|| { +// // Given +// assert_ok!(BondedPool::::get(1).unwrap().ok_to_be_open(0)); + +// // Only the root and state toggler can change the state when the pool is ok to be open. +// assert_noop!( +// Pools::set_state(Origin::signed(10), 1, PoolState::Blocked), +// Error::::CanNotChangeState +// ); +// assert_noop!( +// Pools::set_state(Origin::signed(901), 1, PoolState::Blocked), +// Error::::CanNotChangeState +// ); + +// // Root can change state +// assert_ok!(Pools::set_state(Origin::signed(900), 1, PoolState::Blocked)); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::StateChanged { pool_id: 1, new_state: PoolState::Blocked } +// ] +// ); + +// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Blocked); + +// // State toggler can change state +// assert_ok!(Pools::set_state(Origin::signed(902), 1, PoolState::Destroying)); +// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + +// // If the pool is destroying, then no one can set state +// assert_noop!( +// Pools::set_state(Origin::signed(900), 1, PoolState::Blocked), +// Error::::CanNotChangeState +// ); +// assert_noop!( +// Pools::set_state(Origin::signed(902), 1, PoolState::Blocked), +// Error::::CanNotChangeState +// ); + +// // If the pool is not ok to be open, then anyone can set it to destroying + +// // Given +// unsafe_set_state(1, PoolState::Open).unwrap(); +// let mut bonded_pool = BondedPool::::get(1).unwrap(); +// bonded_pool.points = 100; +// bonded_pool.put(); +// // When +// assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); +// // Then +// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + +// // Given +// Balances::make_free_balance_be(&default_bonded_account(), Balance::max_value() / 10); +// unsafe_set_state(1, PoolState::Open).unwrap(); +// // When +// assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); +// // Then +// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + +// // If the pool is not ok to be open, it cannot be permissionleslly set to a state that +// // isn't destroying +// unsafe_set_state(1, PoolState::Open).unwrap(); +// assert_noop!( +// Pools::set_state(Origin::signed(11), 1, PoolState::Blocked), +// Error::::CanNotChangeState +// ); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, +// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, +// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying } +// ] +// ); +// }); +// } +// } + +// mod set_metadata { +// use super::*; + +// #[test] +// fn set_metadata_works() { +// ExtBuilder::default().build_and_execute(|| { +// // Root can set metadata +// assert_ok!(Pools::set_metadata(Origin::signed(900), 1, vec![1, 1])); +// assert_eq!(Metadata::::get(1), vec![1, 1]); + +// // State toggler can set metadata +// assert_ok!(Pools::set_metadata(Origin::signed(902), 1, vec![2, 2])); +// assert_eq!(Metadata::::get(1), vec![2, 2]); + +// // Depositor can't set metadata +// assert_noop!( +// Pools::set_metadata(Origin::signed(10), 1, vec![3, 3]), +// Error::::DoesNotHavePermission +// ); + +// // Nominator can't set metadata +// assert_noop!( +// Pools::set_metadata(Origin::signed(901), 1, vec![3, 3]), +// Error::::DoesNotHavePermission +// ); + +// // Metadata cannot be longer than `MaxMetadataLen` +// assert_noop!( +// Pools::set_metadata(Origin::signed(900), 1, vec![1, 1, 1]), +// Error::::MetadataExceedsMaxLen +// ); +// }); +// } +// } + +// mod set_configs { +// use super::*; + +// #[test] +// fn set_configs_works() { +// ExtBuilder::default().build_and_execute(|| { +// // Setting works +// assert_ok!(Pools::set_configs( +// Origin::root(), +// ConfigOp::Set(1 as Balance), +// ConfigOp::Set(2 as Balance), +// ConfigOp::Set(3u32), +// ConfigOp::Set(4u32), +// ConfigOp::Set(5u32), +// )); +// assert_eq!(MinJoinBond::::get(), 1); +// assert_eq!(MinCreateBond::::get(), 2); +// assert_eq!(MaxPools::::get(), Some(3)); +// assert_eq!(MaxPoolMembers::::get(), Some(4)); +// assert_eq!(MaxPoolMembersPerPool::::get(), Some(5)); + +// // Noop does nothing +// assert_storage_noop!(assert_ok!(Pools::set_configs( +// Origin::root(), +// ConfigOp::Noop, +// ConfigOp::Noop, +// ConfigOp::Noop, +// ConfigOp::Noop, +// ConfigOp::Noop, +// ))); + +// // Removing works +// assert_ok!(Pools::set_configs( +// Origin::root(), +// ConfigOp::Remove, +// ConfigOp::Remove, +// ConfigOp::Remove, +// ConfigOp::Remove, +// ConfigOp::Remove, +// )); +// assert_eq!(MinJoinBond::::get(), 0); +// assert_eq!(MinCreateBond::::get(), 0); +// assert_eq!(MaxPools::::get(), None); +// assert_eq!(MaxPoolMembers::::get(), None); +// assert_eq!(MaxPoolMembersPerPool::::get(), None); +// }); +// } +// } + +// mod bond_extra { +// use super::*; +// use crate::Event; + +// #[test] +// fn bond_extra_from_free_balance_creator() { +// ExtBuilder::default().build_and_execute(|| { +// // 10 is the owner and a member in pool 1, give them some more funds. +// Balances::make_free_balance_be(&10, 100); + +// // given +// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); +// assert_eq!(BondedPools::::get(1).unwrap().points, 10); +// assert_eq!(Balances::free_balance(10), 100); + +// // when +// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); + +// // then +// assert_eq!(Balances::free_balance(10), 90); +// assert_eq!(PoolMembers::::get(10).unwrap().points, 20); +// assert_eq!(BondedPools::::get(1).unwrap().points, 20); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false } +// ] +// ); + +// // when +// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(20))); + +// // then +// assert_eq!(Balances::free_balance(10), 70); +// assert_eq!(PoolMembers::::get(10).unwrap().points, 40); +// assert_eq!(BondedPools::::get(1).unwrap().points, 40); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::Bonded { member: 10, pool_id: 1, bonded: 20, joined: false }] +// ); +// }) +// } + +// #[test] +// fn bond_extra_from_rewards_creator() { +// ExtBuilder::default().build_and_execute(|| { +// // put some money in the reward account, all of which will belong to 10 as the only +// // member of the pool. +// Balances::make_free_balance_be(&default_reward_account(), 7); +// // ... if which only 2 is claimable to make sure the reward account does not die. +// let claimable_reward = 7 - ExistentialDeposit::get(); + +// // given +// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); +// assert_eq!(BondedPools::::get(1).unwrap().points, 10); +// assert_eq!(Balances::free_balance(10), 5); + +// // when +// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); + +// // then +// assert_eq!(Balances::free_balance(10), 5); +// assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + claimable_reward); +// assert_eq!(BondedPools::::get(1).unwrap().points, 10 + claimable_reward); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, +// Event::Bonded { +// member: 10, +// pool_id: 1, +// bonded: claimable_reward, +// joined: false +// } +// ] +// ); +// }) +// } + +// #[test] +// fn bond_extra_from_rewards_joiner() { +// ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { +// // put some money in the reward account, all of which will belong to 10 as the only +// // member of the pool. +// Balances::make_free_balance_be(&default_reward_account(), 8); +// // ... if which only 3 is claimable to make sure the reward account does not die. +// let claimable_reward = 8 - ExistentialDeposit::get(); +// // NOTE: easier to read of we use 3, so let's use the number instead of variable. +// assert_eq!(claimable_reward, 3, "test is correct if rewards are divisible by 3"); + +// // given +// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); +// assert_eq!(PoolMembers::::get(20).unwrap().points, 20); +// assert_eq!(BondedPools::::get(1).unwrap().points, 30); +// assert_eq!(Balances::free_balance(10), 5); +// assert_eq!(Balances::free_balance(20), 20); + +// // when +// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); + +// // then +// assert_eq!(Balances::free_balance(10), 5); +// // 10's share of the reward is 1/3, since they gave 10/30 of the total shares. +// assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + 1); +// assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 1); + +// // when +// assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::Rewards)); + +// // then +// assert_eq!(Balances::free_balance(20), 20); +// // 20's share of the rewards is the other 2/3 of the rewards, since they have 20/30 of +// // the shares +// assert_eq!(PoolMembers::::get(20).unwrap().points, 20 + 2); +// assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 3); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, +// Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, +// Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, +// Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } +// ] +// ); +// }) +// } +// } + +// mod update_roles { +// use super::*; + +// #[test] +// fn update_roles_works() { +// ExtBuilder::default().build_and_execute(|| { +// assert_eq!( +// BondedPools::::get(1).unwrap().roles, +// PoolRoles { +// depositor: 10, +// root: Some(900), +// nominator: Some(901), +// state_toggler: Some(902) +// }, +// ); + +// // non-existent pools +// assert_noop!( +// Pools::update_roles( +// Origin::signed(1), +// 2, +// ConfigOp::Set(5), +// ConfigOp::Set(6), +// ConfigOp::Set(7) +// ), +// Error::::PoolNotFound, +// ); + +// // depositor cannot change roles. +// assert_noop!( +// Pools::update_roles( +// Origin::signed(1), +// 1, +// ConfigOp::Set(5), +// ConfigOp::Set(6), +// ConfigOp::Set(7) +// ), +// Error::::DoesNotHavePermission, +// ); + +// // nominator cannot change roles. +// assert_noop!( +// Pools::update_roles( +// Origin::signed(901), +// 1, +// ConfigOp::Set(5), +// ConfigOp::Set(6), +// ConfigOp::Set(7) +// ), +// Error::::DoesNotHavePermission, +// ); +// // state-toggler +// assert_noop!( +// Pools::update_roles( +// Origin::signed(902), +// 1, +// ConfigOp::Set(5), +// ConfigOp::Set(6), +// ConfigOp::Set(7) +// ), +// Error::::DoesNotHavePermission, +// ); + +// // but root can +// assert_ok!(Pools::update_roles( +// Origin::signed(900), +// 1, +// ConfigOp::Set(5), +// ConfigOp::Set(6), +// ConfigOp::Set(7) +// )); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![ +// Event::Created { depositor: 10, pool_id: 1 }, +// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, +// Event::RolesUpdated { +// root: Some(5), +// state_toggler: Some(7), +// nominator: Some(6) +// } +// ] +// ); +// assert_eq!( +// BondedPools::::get(1).unwrap().roles, +// PoolRoles { +// depositor: 10, +// root: Some(5), +// nominator: Some(6), +// state_toggler: Some(7) +// }, +// ); + +// // also root origin can +// assert_ok!(Pools::update_roles( +// Origin::root(), +// 1, +// ConfigOp::Set(1), +// ConfigOp::Set(2), +// ConfigOp::Set(3) +// )); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::RolesUpdated { +// root: Some(1), +// state_toggler: Some(3), +// nominator: Some(2) +// }] +// ); +// assert_eq!( +// BondedPools::::get(1).unwrap().roles, +// PoolRoles { +// depositor: 10, +// root: Some(1), +// nominator: Some(2), +// state_toggler: Some(3) +// }, +// ); + +// // Noop works +// assert_ok!(Pools::update_roles( +// Origin::root(), +// 1, +// ConfigOp::Set(11), +// ConfigOp::Noop, +// ConfigOp::Noop +// )); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::RolesUpdated { +// root: Some(11), +// state_toggler: Some(3), +// nominator: Some(2) +// }] +// ); + +// assert_eq!( +// BondedPools::::get(1).unwrap().roles, +// PoolRoles { +// depositor: 10, +// root: Some(11), +// nominator: Some(2), +// state_toggler: Some(3) +// }, +// ); + +// // Remove works +// assert_ok!(Pools::update_roles( +// Origin::root(), +// 1, +// ConfigOp::Set(69), +// ConfigOp::Remove, +// ConfigOp::Remove +// )); + +// assert_eq!( +// pool_events_since_last_call(), +// vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }] +// ); + +// assert_eq!( +// BondedPools::::get(1).unwrap().roles, +// PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None }, +// ); +// }) +// } +// } From 36cb48408a5ec5cad2195261f2a3d5fbf7f6264b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 14 Jun 2022 12:24:31 +0100 Subject: [PATCH 31/65] bring back all tests --- frame/nomination-pools/src/lib.rs | 53 +- frame/nomination-pools/src/tests.rs | 6867 ++++++++++++++------------- 2 files changed, 3507 insertions(+), 3413 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 349438975c6bc..a3794baf24c27 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -906,16 +906,6 @@ impl BondedPool { Ok(points_issued) } - /// If `n` saturates at it's upper bound, mark the pool as destroying. This is useful when a - /// number saturating indicates the pool can no longer correctly keep track of state. - fn bound_check(&mut self, n: U256) -> U256 { - if n == U256::max_value() { - self.set_state(PoolState::Destroying) - } - - n - } - // Set the state of `self`, and deposit an event if the state changed. State should never be set // directly in in order to ensure a state change event is always correctly deposited. fn set_state(&mut self, state: PoolState) { @@ -931,7 +921,7 @@ impl BondedPool { /// A reward pool. #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound)] -#[cfg_attr(feature = "std", derive(Clone, PartialEq))] +#[cfg_attr(feature = "std", derive(Clone, PartialEq, frame_support::DefaultNoBound))] #[codec(mel_bound(T: Config))] #[scale_info(skip_type_params(T))] pub struct RewardPool { @@ -1470,22 +1460,20 @@ pub mod pallet { .max(T::WeightInfo::bond_extra_reward()) )] pub fn bond_extra(origin: OriginFor, extra: BondExtra>) -> DispatchResult { - // TODO: claim payouts here before updating the points. let who = ensure_signed(origin)?; let (mut member, mut bonded_pool, mut reward_pool) = Self::get_member_with_pools(&who)?; + // payout related stuff: we must claim the payouts, and updated recorded payout data + // before going further. + reward_pool.update_records(bonded_pool.id, bonded_pool.points); + let claimed = + Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; + let (points_issued, bonded) = match extra { BondExtra::FreeBalance(amount) => (bonded_pool.try_bond_funds(&who, amount, BondType::Later)?, amount), - BondExtra::Rewards => { - let claimed = Self::do_reward_payout( - &who, - &mut member, - &mut bonded_pool, - &mut reward_pool, - )?; - (bonded_pool.try_bond_funds(&who, claimed, BondType::Later)?, claimed) - }, + BondExtra::Rewards => + (bonded_pool.try_bond_funds(&who, claimed, BondType::Later)?, claimed), }; bonded_pool.ok_to_be_open(bonded)?; member.points = member.points.saturating_add(points_issued); @@ -1552,21 +1540,17 @@ pub mod pallet { member_account: T::AccountId, #[pallet::compact] unbonding_points: BalanceOf, ) -> DispatchResult { - let caller = ensure_signed(origin)?; + let who = ensure_signed(origin)?; let (mut member, mut bonded_pool, mut reward_pool) = Self::get_member_with_pools(&member_account)?; - bonded_pool.ok_to_unbond_with(&caller, &member_account, &member, unbonding_points)?; + bonded_pool.ok_to_unbond_with(&who, &member_account, &member, unbonding_points)?; // Claim the the payout prior to unbonding. Once the user is unbonding their points no // longer exist in the bonded pool and thus they can no longer claim their payouts. It // is not strictly necessary to claim the rewards, but we do it here for UX. - Self::do_reward_payout( - &member_account, - &mut member, - &mut bonded_pool, - &mut reward_pool, - )?; + reward_pool.update_records(bonded_pool.id, bonded_pool.points); + let _ = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; let current_era = T::StakingInterface::current_era(); let unbond_era = T::StakingInterface::bonding_duration().saturating_add(current_era); @@ -2206,8 +2190,6 @@ impl Pallet { // a member who has no skin in the game anymore cannot claim any rewards. ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); - let was_destroying = bonded_pool.is_destroying(); - let current_reward_counter = reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points); let pending_rewards = member.pending_rewards(current_reward_counter); @@ -2220,6 +2202,8 @@ impl Pallet { } // Transfer payout to the member. + // TODO: this is pretty shitty for the case of bond_extra, this function should not transfer + // anything. T::Currency::transfer( &bonded_pool.reward_account(), &member_account, @@ -2234,13 +2218,6 @@ impl Pallet { payout: pending_rewards, }); - if bonded_pool.is_destroying() && !was_destroying { - Self::deposit_event(Event::::StateChanged { - pool_id: member.pool_id, - new_state: PoolState::Destroying, - }); - } - Ok(pending_rewards) } diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index e084cece1d271..748a073905b10 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -17,12 +17,9 @@ use super::*; use crate::{mock::*, Event}; -use frame_support::{ - assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_btree_map, - storage::{with_transaction, TransactionOutcome}, -}; +use frame_support::{assert_err, assert_noop, assert_ok, assert_storage_noop, bounded_btree_map}; use pallet_balances::Event as BEvent; -use sp_runtime::{traits::Dispatchable, FixedU128}; +use sp_runtime::traits::Dispatchable; macro_rules! unbonding_pools_with_era { ($($k:expr => $v:expr),* $(,)?) => {{ @@ -128,7 +125,7 @@ fn rewards_distribution_is_fair_basic_with_fractions() { ] ); - // uneven upcoming rewards are shared equally. + // uneven upcoming rewards are shared equally, rounded down. Balances::mutate_account(&default_reward_account(), |f| f.free += 7).unwrap(); assert_ok!(Pools::claim_payout(Origin::signed(10))); @@ -199,12 +196,173 @@ fn rewards_distribution_is_fair_3() { #[test] fn rewards_distribution_is_fair_bond_extra() { - todo!("10 20 30 all join, reward comes in, equal, one bonds more, rewards come in, more share") + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + Balances::make_free_balance_be(&30, ed + 20); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); + + // everyone claims. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 } + ] + ); + + // 30 now bumps itself to be like 20. + assert_ok!(Pools::bond_extra(Origin::signed(30), BondExtra::FreeBalance(10))); + + // more rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 40 } + ] + ); + }); } #[test] fn rewards_distribution_is_fair_unbond() { - todo!("10 20 30 all join, reward comes in, equal, one unbonds, rewards come in, less share") + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + // everyone claims. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + ] + ); + + // 30 now bumps itself to be like 20. + assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); + + // more rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 50 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 50 }, + ] + ); + }); +} + +#[test] +fn unclaimed_reward_is_safe() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + Balances::make_free_balance_be(&30, ed + 20); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + // 10 gets 10, 20 gets 20, 30 gets 10 + Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + ] + ); + + // 10 gets 20, 20 gets 40, 30 gets 20 + Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + ] + ); + + // 10 gets 20, 20 gets 40, 30 gets 20 + Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + ] + ); + + // now 30 claims all at once + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 30, pool_id: 1, payout: 10 + 20 + 20 }] + ); + }); +} + +#[test] +fn bond_extra_and_delayed_claim() { + todo!("10 20 join, reward comes, 10 claims, 20 bonds extra, reward comes both claim"); } #[test] @@ -438,3370 +596,3329 @@ mod reward_pool { } } -// mod unbond_pool { -// use super::*; - -// #[test] -// fn points_to_issue_works() { -// ExtBuilder::default().build_and_execute(|| { -// // 1 points : 1 balance ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; -// assert_eq!(unbond_pool.balance_to_point(10), 10); -// assert_eq!(unbond_pool.balance_to_point(0), 0); - -// // 2 points : 1 balance ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; -// assert_eq!(unbond_pool.balance_to_point(10), 20); - -// // 1 points : 2 balance ratio -// let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; -// assert_eq!(unbond_pool.balance_to_point(10), 5); - -// // 100 points : 0 balance ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; -// assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); - -// // 0 points : 100 balance -// let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; -// assert_eq!(unbond_pool.balance_to_point(10), 10); - -// // 10 points : 3 balance ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; -// assert_eq!(unbond_pool.balance_to_point(10), 33); - -// // 2 points : 3 balance ratio -// let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; -// assert_eq!(unbond_pool.balance_to_point(10), 6); - -// // 4 points : 9 balance ratio -// let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; -// assert_eq!(unbond_pool.balance_to_point(90), 40); -// }) -// } - -// #[test] -// fn balance_to_unbond_works() { -// // 1 balance : 1 points ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; -// assert_eq!(unbond_pool.point_to_balance(10), 10); -// assert_eq!(unbond_pool.point_to_balance(0), 0); - -// // 1 balance : 2 points ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; -// assert_eq!(unbond_pool.point_to_balance(10), 5); - -// // 2 balance : 1 points ratio -// let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; -// assert_eq!(unbond_pool.point_to_balance(10), 20); - -// // 100 balance : 0 points ratio -// let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; -// assert_eq!(unbond_pool.point_to_balance(10), 0); - -// // 0 balance : 100 points ratio -// let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; -// assert_eq!(unbond_pool.point_to_balance(10), 0); - -// // 10 balance : 3 points ratio -// let unbond_pool = UnbondPool:: { points: 30, balance: 100 }; -// assert_eq!(unbond_pool.point_to_balance(10), 33); - -// // 2 balance : 3 points ratio -// let unbond_pool = UnbondPool:: { points: 300, balance: 200 }; -// assert_eq!(unbond_pool.point_to_balance(10), 6); - -// // 4 balance : 9 points ratio -// let unbond_pool = UnbondPool:: { points: 900, balance: 400 }; -// assert_eq!(unbond_pool.point_to_balance(90), 40); -// } -// } - -// mod sub_pools { -// use super::*; - -// #[test] -// fn maybe_merge_pools_works() { -// ExtBuilder::default().build_and_execute(|| { -// assert_eq!(TotalUnbondingPools::::get(), 5); -// assert_eq!(BondingDuration::get(), 3); -// assert_eq!(PostUnbondingPoolsWindow::get(), 2); - -// // Given -// let mut sub_pool_0 = SubPools:: { -// no_era: UnbondPool::::default(), -// with_era: unbonding_pools_with_era! { -// 0 => UnbondPool:: { points: 10, balance: 10 }, -// 1 => UnbondPool:: { points: 10, balance: 10 }, -// 2 => UnbondPool:: { points: 20, balance: 20 }, -// 3 => UnbondPool:: { points: 30, balance: 30 }, -// 4 => UnbondPool:: { points: 40, balance: 40 }, -// }, -// }; - -// // When `current_era < TotalUnbondingPools`, -// let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(0); - -// // Then it exits early without modifications -// assert_eq!(sub_pool_1, sub_pool_0); - -// // When `current_era == TotalUnbondingPools`, -// let sub_pool_1 = sub_pool_1.maybe_merge_pools(1); - -// // Then it exits early without modifications -// assert_eq!(sub_pool_1, sub_pool_0); - -// // When `current_era - TotalUnbondingPools == 0`, -// let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(2); - -// // Then era 0 is merged into the `no_era` pool -// sub_pool_0.no_era = sub_pool_0.with_era.remove(&0).unwrap(); -// assert_eq!(sub_pool_1, sub_pool_0); - -// // Given we have entries for era 1..=5 -// sub_pool_1 -// .with_era -// .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) -// .unwrap(); -// sub_pool_0 -// .with_era -// .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) -// .unwrap(); - -// // When `current_era - TotalUnbondingPools == 1` -// let sub_pool_2 = sub_pool_1.maybe_merge_pools(3); -// let era_1_pool = sub_pool_0.with_era.remove(&1).unwrap(); - -// // Then era 1 is merged into the `no_era` pool -// sub_pool_0.no_era.points += era_1_pool.points; -// sub_pool_0.no_era.balance += era_1_pool.balance; -// assert_eq!(sub_pool_2, sub_pool_0); - -// // When `current_era - TotalUnbondingPools == 5`, so all pools with era <= 4 are removed -// let sub_pool_3 = sub_pool_2.maybe_merge_pools(7); - -// // Then all eras <= 5 are merged into the `no_era` pool -// for era in 2..=5 { -// let to_merge = sub_pool_0.with_era.remove(&era).unwrap(); -// sub_pool_0.no_era.points += to_merge.points; -// sub_pool_0.no_era.balance += to_merge.balance; -// } -// assert_eq!(sub_pool_3, sub_pool_0); -// }); -// } -// } - -// mod join { -// use super::*; - -// #[test] -// fn join_works() { -// let bonded = |points, member_counter| BondedPool:: { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Open, -// points, -// member_counter, -// roles: DEFAULT_ROLES, -// }, -// }; -// ExtBuilder::default().build_and_execute(|| { -// // Given -// Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); -// assert!(!PoolMembers::::contains_key(&11)); - -// // When -// assert_ok!(Pools::join(Origin::signed(11), 2, 1)); - -// // Then - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 11, pool_id: 1, bonded: 2, joined: true }, -// ] -// ); - -// assert_eq!( -// PoolMembers::::get(&11).unwrap(), -// PoolMember:: { pool_id: 1, points: 2, ..Default::default() } -// ); -// assert_eq!(BondedPool::::get(1).unwrap(), bonded(12, 2)); - -// // Given -// // The bonded balance is slashed in half -// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 6); - -// // And -// Balances::make_free_balance_be(&12, ExistentialDeposit::get() + 12); -// assert!(!PoolMembers::::contains_key(&12)); - -// // When -// assert_ok!(Pools::join(Origin::signed(12), 12, 1)); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Bonded { member: 12, pool_id: 1, bonded: 12, joined: true }] -// ); - -// assert_eq!( -// PoolMembers::::get(&12).unwrap(), -// PoolMember:: { pool_id: 1, points: 24, ..Default::default() } -// ); -// assert_eq!(BondedPool::::get(1).unwrap(), bonded(12 + 24, 3)); -// }); -// } - -// #[test] -// fn join_errors_correctly() { -// ExtBuilder::default().with_check(0).build_and_execute(|| { -// // 10 is already part of the default pool created. -// assert_eq!(PoolMembers::::get(&10).unwrap().pool_id, 1); - -// assert_noop!( -// Pools::join(Origin::signed(10), 420, 123), -// Error::::AccountBelongsToOtherPool -// ); - -// assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::PoolNotFound); - -// // Force the pools bonded balance to 0, simulating a 100% slash -// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 0); -// assert_noop!(Pools::join(Origin::signed(11), 420, 1), Error::::OverflowRisk); - -// // Given a mocked bonded pool -// BondedPool:: { -// id: 123, -// inner: BondedPoolInner { -// member_counter: 1, -// state: PoolState::Open, -// points: 100, -// roles: DEFAULT_ROLES, -// }, -// } -// .put(); - -// // and reward pool -// RewardPools::::insert( -// 123, -// RewardPool:: { balance: Zero::zero(), total_earnings: Zero::zero() }, -// ); - -// // Force the points:balance ratio to `MinPointsToBalance` (100/10) -// let min_points_to_balance: u128 = -// <::MinPointsToBalance as Get>::get().into(); - -// StakingMock::set_bonded_balance( -// Pools::create_bonded_account(123), -// min_points_to_balance, -// ); -// assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::OverflowRisk); - -// StakingMock::set_bonded_balance( -// Pools::create_bonded_account(123), -// Balance::MAX / min_points_to_balance, -// ); -// // Balance needs to be gt Balance::MAX / `MinPointsToBalance` -// assert_noop!(Pools::join(Origin::signed(11), 5, 123), Error::::OverflowRisk); - -// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), min_points_to_balance); - -// // Cannot join a pool that isn't open -// unsafe_set_state(123, PoolState::Blocked).unwrap(); -// assert_noop!( -// Pools::join(Origin::signed(11), min_points_to_balance, 123), -// Error::::NotOpen -// ); - -// unsafe_set_state(123, PoolState::Destroying).unwrap(); -// assert_noop!( -// Pools::join(Origin::signed(11), min_points_to_balance, 123), -// Error::::NotOpen -// ); - -// // Given -// MinJoinBond::::put(100); - -// // Then -// assert_noop!( -// Pools::join(Origin::signed(11), 99, 123), -// Error::::MinimumBondNotMet -// ); -// }); -// } - -// #[test] -// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] -// #[cfg_attr(not(debug_assertions), should_panic)] -// fn join_panics_when_reward_pool_not_found() { -// ExtBuilder::default().build_and_execute(|| { -// StakingMock::set_bonded_balance(Pools::create_bonded_account(123), 100); -// BondedPool:: { -// id: 123, -// inner: BondedPoolInner { -// state: PoolState::Open, -// points: 100, -// member_counter: 1, -// roles: DEFAULT_ROLES, -// }, -// } -// .put(); -// let _ = Pools::join(Origin::signed(11), 420, 123); -// }); -// } - -// #[test] -// fn join_max_member_limits_are_respected() { -// ExtBuilder::default().build_and_execute(|| { -// // Given -// assert_eq!(MaxPoolMembersPerPool::::get(), Some(3)); -// for i in 1..3 { -// let account = i + 100; -// Balances::make_free_balance_be(&account, 100 + Balances::minimum_balance()); - -// assert_ok!(Pools::join(Origin::signed(account), 100, 1)); -// } - -// Balances::make_free_balance_be(&103, 100 + Balances::minimum_balance()); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 101, pool_id: 1, bonded: 100, joined: true }, -// Event::Bonded { member: 102, pool_id: 1, bonded: 100, joined: true } -// ] -// ); - -// assert_noop!( -// Pools::join(Origin::signed(103), 100, 1), -// Error::::MaxPoolMembers -// ); - -// // Given -// assert_eq!(PoolMembers::::count(), 3); -// assert_eq!(MaxPoolMembers::::get(), Some(4)); - -// Balances::make_free_balance_be(&104, 100 + Balances::minimum_balance()); -// assert_ok!(Pools::create(Origin::signed(104), 100, 104, 104, 104)); - -// let pool_account = BondedPools::::iter() -// .find(|(_, bonded_pool)| bonded_pool.roles.depositor == 104) -// .map(|(pool_account, _)| pool_account) -// .unwrap(); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 104, pool_id: 2 }, -// Event::Bonded { member: 104, pool_id: 2, bonded: 100, joined: true } -// ] -// ); - -// assert_noop!( -// Pools::join(Origin::signed(103), 100, pool_account), -// Error::::MaxPoolMembers -// ); -// }); -// } -// } - -// mod claim_payout { -// use super::*; - -// fn del(points: Balance, last_recorded_reward_counter: FixedU128) -> PoolMember { -// PoolMember { -// pool_id: 1, -// points, -// last_recorded_reward_counter, -// unbonding_eras: Default::default(), -// } -// } - -// fn rew( -// last_recorded_reward_counter: FixedU128, -// last_recorded_total_payouts: Balance, -// total_rewards_claimed: Balance, -// ) -> RewardPool { -// RewardPool { -// last_recorded_reward_counter, -// last_recorded_total_payouts, -// total_rewards_claimed, -// } -// } - -// #[test] -// fn claim_payout_works() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (50, 50)]) -// .build_and_execute(|| { -// // Given each member currently has a free balance of -// Balances::make_free_balance_be(&10, 0); -// Balances::make_free_balance_be(&40, 0); -// Balances::make_free_balance_be(&50, 0); -// let ed = Balances::minimum_balance(); -// // and the reward pool has earned 100 in rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 100); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(10))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true }, -// Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, -// ] -// ); - -// // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool -// // balance -// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 100)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew(90, 100 * 100 - 100 * 10, 100) -// ); -// assert_eq!(Balances::free_balance(&10), 10); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(40))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] -// ); - -// // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance -// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 100)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew(50, 9_000 - 100 * 40, 100) -// ); -// assert_eq!(Balances::free_balance(&40), 40); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(50))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] -// ); - -// // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance -// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 100)); -// assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); -// assert_eq!(Balances::free_balance(&50), 50); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - -// // Given the reward pool has some new rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 50); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(10))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] -// ); - -// // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance -// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 150)); -// assert_eq!(RewardPools::::get(&1).unwrap(), rew(45, 5_000 - 50 * 10, 150)); -// assert_eq!(Balances::free_balance(&10), 10 + 5); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(40))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] -// ); - -// // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool -// // balance -// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 150)); -// assert_eq!(RewardPools::::get(&1).unwrap(), rew(25, 4_500 - 50 * 40, 150)); -// assert_eq!(Balances::free_balance(&40), 40 + 20); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - -// // Given del 50 hasn't claimed and the reward pools has just earned 50 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(50))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] -// ); - -// // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 -// // pool balance -// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 200)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew( -// 25, -// // old pool points + points from new earnings - del points. -// // -// // points from new earnings = new earnings(50) * bonded_pool.points(100) -// // del points = member.points(50) * new_earnings_since_last_claim (100) -// (2_500 + 50 * 100) - 50 * 100, -// 200, -// ) -// ); -// assert_eq!(Balances::free_balance(&50), 50 + 50); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(10))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] -// ); - -// // We expect a payout of 5 -// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 200)); -// assert_eq!(RewardPools::::get(&1).unwrap(), rew(20, 2_500 - 10 * 50, 200)); -// assert_eq!(Balances::free_balance(&10), 15 + 5); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); - -// // Given del 40 hasn't claimed and the reward pool has just earned 400 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(10))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] -// ); - -// // We expect a payout of 40 -// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 600)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew( -// 380, -// // old pool points + points from new earnings - del points -// // -// // points from new earnings = new earnings(400) * bonded_pool.points(100) -// // del points = member.points(10) * new_earnings_since_last_claim(400) -// (2_000 + 400 * 100) - 10 * 400, -// 600 -// ) -// ); -// assert_eq!(Balances::free_balance(&10), 20 + 40); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); - -// // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(10))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] -// ); - -// // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool -// // balance -// assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 620)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew(398, (38_000 + 20 * 100) - 10 * 20, 620) -// ); -// assert_eq!(Balances::free_balance(&10), 60 + 2); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(40))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] -// ); - -// // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 -// // pool balance -// assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 620)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew(210, 39_800 - 40 * 470, 620) -// ); -// assert_eq!(Balances::free_balance(&40), 60 + 188); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); - -// // When -// assert_ok!(Pools::claim_payout(Origin::signed(50))); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] -// ); - -// // Expect payout of 210: (21,000 / 21,000) * 210 -// assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 620)); -// assert_eq!( -// RewardPools::::get(&1).unwrap(), -// rew(0, 21_000 - 50 * 420, 620) -// ); -// assert_eq!(Balances::free_balance(&50), 100 + 210); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); -// }); -// } - -// #[test] -// fn reward_payout_errors_if_a_member_is_fully_unbonding() { -// ExtBuilder::default().add_members(vec![(11, 11)]).build_and_execute(|| { -// // fully unbond the member. -// assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); - -// let mut bonded_pool = BondedPool::::get(1).unwrap(); -// let mut reward_pool = RewardPools::::get(1).unwrap(); -// let mut member = PoolMembers::::get(11).unwrap(); - -// assert_noop!( -// Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), -// Error::::FullyUnbonding -// ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true }, -// Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 } -// ] -// ); -// }); -// } - -// #[test] -// fn do_reward_payout_works_with_a_pool_of_1() { -// let del = |reward_pool_total_earnings| del(10, reward_pool_total_earnings); - -// ExtBuilder::default().build_and_execute(|| { -// let mut bonded_pool = BondedPool::::get(1).unwrap(); -// let mut reward_pool = RewardPools::::get(1).unwrap(); -// let mut member = PoolMembers::::get(10).unwrap(); -// let ed = Balances::minimum_balance(); - -// // Given no rewards have been earned -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 0); -// assert_eq!(member, del(0)); -// assert_eq!(reward_pool, rew(0, 0, 0)); - -// // Given the pool has earned some rewards for the first time -// Balances::make_free_balance_be(&default_reward_account(), ed + 5); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 5); // (10 * 5 del virtual points / 10 * 5 pool points) * 5 pool balance -// assert_eq!(reward_pool, rew(0, 0, 5)); -// assert_eq!(member, del(5)); - -// // Given the pool has earned rewards again -// Balances::make_free_balance_be(&default_reward_account(), ed + 10); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 10); // (10 * 10 del virtual points / 10 pool points) * 5 pool balance -// assert_eq!(reward_pool, rew(0, 0, 15)); -// assert_eq!(member, del(15)); - -// // Given the pool has earned no new rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 0); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 0); -// assert_eq!(reward_pool, rew(0, 0, 15)); -// assert_eq!(member, del(15)); -// }); -// } - -// #[test] -// fn do_reward_payout_works_with_a_pool_of_3() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (50, 50)]) -// .build_and_execute(|| { -// let mut bonded_pool = BondedPool::::get(1).unwrap(); -// let mut reward_pool = RewardPools::::get(1).unwrap(); -// let ed = Balances::minimum_balance(); -// // PoolMember with 10 points -// let mut del_10 = PoolMembers::::get(10).unwrap(); -// // PoolMember with 40 points -// let mut del_40 = PoolMembers::::get(40).unwrap(); -// // PoolMember with 50 points -// let mut del_50 = PoolMembers::::get(50).unwrap(); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } -// ] -// ); - -// // Given we have a total of 100 points split among the members -// assert_eq!(del_50.points + del_40.points + del_10.points, 100); -// assert_eq!(bonded_pool.points, 100); -// // and the reward pool has earned 100 in rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 100); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 10); // (10 del virtual points / 100 pool points) * 100 pool balance -// assert_eq!(del_10, del(10, 100)); -// assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 10)); - -// // When -// let payout = -// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 40); // (400 del virtual points / 900 pool points) * 90 pool balance -// assert_eq!(del_40, del(40, 100)); -// assert_eq!( -// reward_pool, -// rew( -// 50, -// // old pool points - member virtual points -// 9_000 - 100 * 40, -// 100 -// ) -// ); -// // Mock the reward pool transferring the payout to del_40 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); - -// // When -// let payout = -// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 50); // (50 del virtual points / 50 pool points) * 50 pool balance -// assert_eq!(del_50, del(50, 100)); -// assert_eq!(reward_pool, rew(0, 0, 100)); -// // Mock the reward pool transferring the payout to del_50 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); - -// // Given the reward pool has some new rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 50); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 5); // (500 del virtual points / 5,000 pool points) * 50 pool balance -// assert_eq!(del_10, del(10, 150)); -// assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); - -// // When -// let payout = -// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 20); // (2,000 del virtual points / 4,500 pool points) * 45 pool balance -// assert_eq!(del_40, del(40, 150)); -// assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 20)); - -// // Given del_50 hasn't claimed and the reward pools has just earned 50 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - -// // When -// let payout = -// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 50); // (5,000 del virtual points / 7,5000 pool points) * 75 pool balance -// assert_eq!(del_50, del(50, 200)); -// assert_eq!( -// reward_pool, -// rew( -// 25, -// // old pool points + points from new earnings - del points. -// // -// // points from new earnings = new earnings(50) * bonded_pool.points(100) -// // del points = member.points(50) * new_earnings_since_last_claim (100) -// (2_500 + 50 * 100) - 50 * 100, -// 200, -// ) -// ); -// // Mock the reward pool transferring the payout to del_50 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 5); -// assert_eq!(del_10, del(10, 200)); -// assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); - -// // Given del_40 hasn't claimed and the reward pool has just earned 400 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 40); -// assert_eq!(del_10, del(10, 600)); -// assert_eq!( -// reward_pool, -// rew( -// 380, -// // old pool points + points from new earnings - del points -// // -// // points from new earnings = new earnings(400) * bonded_pool.points(100) -// // del points = member.points(10) * new_earnings_since_last_claim(400) -// (2_000 + 400 * 100) - 10 * 400, -// 600 -// ) -// ); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); - -// // Given del_40 + del_50 haven't claimed and the reward pool has earned 20 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - -// // When -// let payout = -// Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 2); // (200 del virtual points / 38,000 pool points) * 400 pool balance -// assert_eq!(del_10, del(10, 620)); -// assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 2)); - -// // When -// let payout = -// Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 188); // (18,800 del virtual points / 39,800 pool points) * 399 pool balance -// assert_eq!(del_40, del(40, 620)); -// assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); -// // Mock the reward pool transferring the payout to del_10 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 188)); - -// // When -// let payout = -// Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) -// .unwrap(); - -// // Then -// assert_eq!(payout, 210); // (21,000 / 21,000) * 210 -// assert_eq!(del_50, del(50, 620)); -// assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); -// }); -// } - -// #[test] -// fn do_reward_payout_works() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (50, 50)]) -// .build_and_execute(|| { -// let mut bonded_pool = BondedPool::::get(1).unwrap(); -// let mut reward_pool = RewardPools::::get(1).unwrap(); -// let ed = Balances::minimum_balance(); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } -// ] -// ); - -// // Given the bonded pool has 100 points -// assert_eq!(bonded_pool.points, 100); -// // Each member currently has a free balance of -// Balances::make_free_balance_be(&10, 0); -// Balances::make_free_balance_be(&40, 0); -// Balances::make_free_balance_be(&50, 0); -// // and the reward pool has earned 100 in rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 100); - -// let mut del_10 = PoolMembers::get(10).unwrap(); -// let mut del_40 = PoolMembers::get(40).unwrap(); -// let mut del_50 = PoolMembers::get(50).unwrap(); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &10, -// &mut del_10, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] -// ); - -// // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool -// // balance -// assert_eq!(del_10, del(10, 100)); -// assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); -// assert_eq!(Balances::free_balance(&10), 10); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &40, -// &mut del_40, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] -// ); - -// // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance -// assert_eq!(del_40, del(40, 100)); -// assert_eq!(reward_pool, rew(50, 9_000 - 100 * 40, 100)); -// assert_eq!(Balances::free_balance(&40), 40); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &50, -// &mut del_50, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] -// ); - -// // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance -// assert_eq!(del_50, del(50, 100)); -// assert_eq!(reward_pool, rew(0, 0, 100)); -// assert_eq!(Balances::free_balance(&50), 50); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - -// // Given the reward pool has some new rewards -// Balances::make_free_balance_be(&default_reward_account(), ed + 50); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &10, -// &mut del_10, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] -// ); - -// // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance -// assert_eq!(del_10, del(10, 150)); -// assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); -// assert_eq!(Balances::free_balance(&10), 10 + 5); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &40, -// &mut del_40, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] -// ); - -// // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool -// // balance -// assert_eq!(del_40, del(40, 150)); -// assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); -// assert_eq!(Balances::free_balance(&40), 40 + 20); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - -// // Given del 50 hasn't claimed and the reward pools has just earned 50 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &50, -// &mut del_50, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] -// ); - -// // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 -// // pool balance -// assert_eq!(del_50, del(50, 200)); -// assert_eq!( -// reward_pool, -// rew( -// 25, -// // old pool points + points from new earnings - del points. -// // -// // points from new earnings = new earnings(50) * bonded_pool.points(100) -// // del points = member.points(50) * new_earnings_since_last_claim (100) -// (2_500 + 50 * 100) - 50 * 100, -// 200, -// ) -// ); -// assert_eq!(Balances::free_balance(&50), 50 + 50); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &10, -// &mut del_10, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] -// ); - -// // We expect a payout of 5 -// assert_eq!(del_10, del(10, 200)); -// assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); -// assert_eq!(Balances::free_balance(&10), 15 + 5); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); - -// // Given del 40 hasn't claimed and the reward pool has just earned 400 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &10, -// &mut del_10, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] -// ); - -// // We expect a payout of 40 -// assert_eq!(del_10, del(10, 600)); -// assert_eq!( -// reward_pool, -// rew( -// 380, -// // old pool points + points from new earnings - del points -// // -// // points from new earnings = new earnings(400) * bonded_pool.points(100) -// // del points = member.points(10) * new_earnings_since_last_claim(400) -// (2_000 + 400 * 100) - 10 * 400, -// 600 -// ) -// ); -// assert_eq!(Balances::free_balance(&10), 20 + 40); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); - -// // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 -// assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &10, -// &mut del_10, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] -// ); - -// // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool -// // balance -// assert_eq!(del_10, del(10, 620)); -// assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); -// assert_eq!(Balances::free_balance(&10), 60 + 2); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &40, -// &mut del_40, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] -// ); - -// // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 -// // pool balance -// assert_eq!(del_40, del(40, 620)); -// assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); -// assert_eq!(Balances::free_balance(&40), 60 + 188); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); - -// // When -// assert_ok!(Pools::do_reward_payout( -// &50, -// &mut del_50, -// &mut bonded_pool, -// &mut reward_pool -// )); - -// // Then -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] -// ); - -// // Expect payout of 210: (21,000 / 21,000) * 210 -// assert_eq!(del_50, del(50, 620)); -// assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); -// assert_eq!(Balances::free_balance(&50), 100 + 210); -// assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); -// }); -// } -// } - -// mod unbond { -// use super::*; - -// #[test] -// fn unbond_of_1_works() { -// ExtBuilder::default().build_and_execute(|| { -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(fully_unbond_permissioned(10)); - -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().with_era, -// unbonding_pools_with_era! { 0 + 3 => UnbondPool:: { points: 10, balance: 10 }} -// ); - -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Destroying, -// points: 0, -// member_counter: 1, -// roles: DEFAULT_ROLES, -// } -// } -// ); - -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); -// }); -// } - -// #[test] -// fn unbond_of_3_works() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (550, 550)]) -// .build_and_execute(|| { -// let ed = Balances::minimum_balance(); -// // Given a slash from 600 -> 100 -// StakingMock::set_bonded_balance(default_bonded_account(), 100); -// // and unclaimed rewards of 600. -// Balances::make_free_balance_be(&default_reward_account(), ed + 600); - -// // When -// assert_ok!(fully_unbond_permissioned(40)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().with_era, -// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 6, balance: 6 }} -// ); -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Open, -// points: 560, -// member_counter: 3, -// roles: DEFAULT_ROLES, -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, -// Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, -// Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 } -// ] -// ); - -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); -// assert_eq!( -// PoolMembers::::get(40).unwrap().unbonding_eras, -// member_unbonding_eras!(0 + 3 => 6) -// ); -// assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding - -// // When -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(fully_unbond_permissioned(550)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(&1).unwrap().with_era, -// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 98, balance: 98 }} -// ); -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Destroying, -// points: 10, -// member_counter: 3, -// roles: DEFAULT_ROLES -// } -// } -// ); -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); -// assert_eq!( -// PoolMembers::::get(550).unwrap().unbonding_eras, -// member_unbonding_eras!(0 + 3 => 92) -// ); -// assert_eq!(Balances::free_balance(&550), 550 + 550); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, -// Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 } -// ] -// ); - -// // When -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 40, 0)); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 550, 0)); -// assert_ok!(fully_unbond_permissioned(10)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().with_era, -// unbonding_pools_with_era! { 6 => UnbondPool { points: 2, balance: 2 }} -// ); -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Destroying, -// points: 0, -// member_counter: 1, -// roles: DEFAULT_ROLES -// } -// } -// ); -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); - -// assert_eq!(Balances::free_balance(&550), 550 + 550 + 92); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 40, pool_id: 1, points: 6, balance: 6 }, -// Event::MemberRemoved { pool_id: 1, member: 40 }, -// Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, -// Event::MemberRemoved { pool_id: 1, member: 550 }, -// Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } -// ] -// ); -// }); -// } - -// #[test] -// fn unbond_merges_older_pools() { -// ExtBuilder::default().with_check(1).build_and_execute(|| { -// // Given -// assert_eq!(StakingMock::bonding_duration(), 3); -// SubPoolsStorage::::insert( -// 1, -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 0 + 3 => UnbondPool { balance: 10, points: 100 }, -// 1 + 3 => UnbondPool { balance: 20, points: 20 }, -// 2 + 3 => UnbondPool { balance: 101, points: 101} -// }, -// }, -// ); -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // When -// let current_era = 1 + TotalUnbondingPools::::get(); -// CurrentEra::set(current_era); - -// assert_ok!(fully_unbond_permissioned(10)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: UnbondPool { balance: 10 + 20, points: 100 + 20 }, -// with_era: unbonding_pools_with_era! { -// 2 + 3 => UnbondPool { balance: 101, points: 101}, -// current_era + 3 => UnbondPool { balance: 10, points: 10 }, -// }, -// }, -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } -// ] -// ); -// }); -// } - -// #[test] -// fn unbond_kick_works() { -// // Kick: the pool is blocked and the caller is either the root or state-toggler. -// ExtBuilder::default() -// .add_members(vec![(100, 100), (200, 200)]) -// .build_and_execute(|| { -// // Given -// unsafe_set_state(1, PoolState::Blocked).unwrap(); -// let bonded_pool = BondedPool::::get(1).unwrap(); -// assert_eq!(bonded_pool.roles.root.unwrap(), 900); -// assert_eq!(bonded_pool.roles.nominator.unwrap(), 901); -// assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902); - -// // When the nominator tries to kick, then its a noop -// assert_noop!( -// Pools::fully_unbond(Origin::signed(901), 100), -// Error::::NotKickerOrDestroying -// ); - -// // When the root kicks then its ok -// assert_ok!(Pools::fully_unbond(Origin::signed(900), 100)); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, -// Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, -// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, -// ] -// ); - -// // When the state toggler kicks then its ok -// assert_ok!(Pools::fully_unbond(Origin::signed(902), 200)); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }] -// ); - -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// roles: DEFAULT_ROLES, -// state: PoolState::Blocked, -// points: 10, // Only 10 points because 200 + 100 was unbonded -// member_counter: 3, -// } -// } -// ); -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 10); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 0 + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } -// }, -// } -// ); -// assert_eq!( -// *UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), -// 100 + 200 -// ); -// }); -// } - -// #[test] -// fn unbond_permissionless_works() { -// // Scenarios where non-admin accounts can unbond others -// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { -// // Given the pool is blocked -// unsafe_set_state(1, PoolState::Blocked).unwrap(); - -// // A permissionless unbond attempt errors -// assert_noop!( -// Pools::fully_unbond(Origin::signed(420), 100), -// Error::::NotKickerOrDestroying -// ); - -// // permissionless unbond must be full -// assert_noop!( -// Pools::unbond(Origin::signed(420), 100, 80), -// Error::::PartialUnbondNotAllowedPermissionlessly, -// ); - -// // Given the pool is destroying -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // The depositor cannot be fully unbonded until they are the last member -// assert_noop!( -// Pools::fully_unbond(Origin::signed(10), 10), -// Error::::NotOnlyPoolMember -// ); - -// // Any account can unbond a member that is not the depositor -// assert_ok!(Pools::fully_unbond(Origin::signed(420), 100)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, -// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 } -// ] -// ); - -// // still permissionless unbond must be full -// assert_noop!( -// Pools::unbond(Origin::signed(420), 100, 80), -// Error::::PartialUnbondNotAllowedPermissionlessly, -// ); - -// // Given the pool is blocked -// unsafe_set_state(1, PoolState::Blocked).unwrap(); - -// // The depositor cannot be unbonded -// assert_noop!( -// Pools::fully_unbond(Origin::signed(420), 10), -// Error::::DoesNotHavePermission -// ); - -// // Given the pools is destroying -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // The depositor cannot be unbonded yet. -// assert_noop!( -// Pools::fully_unbond(Origin::signed(420), 10), -// Error::::DoesNotHavePermission, -// ); - -// // but when everyone is unbonded it can.. -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 100, 0)); - -// // still permissionless unbond must be full. -// assert_noop!( -// Pools::unbond(Origin::signed(420), 10, 5), -// Error::::PartialUnbondNotAllowedPermissionlessly, -// ); - -// // but full unbond works. -// assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); - -// assert_eq!(BondedPools::::get(1).unwrap().points, 0); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 + 3 => UnbondPool { points: 10, balance: 10 } -// } -// } -// ); -// assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); -// assert_eq!(*UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 10); -// }); -// } - -// #[test] -// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] -// #[cfg_attr(not(debug_assertions), should_panic)] -// fn unbond_errors_correctly() { -// ExtBuilder::default().build_and_execute(|| { -// assert_noop!( -// Pools::fully_unbond(Origin::signed(11), 11), -// Error::::PoolMemberNotFound -// ); - -// // Add the member -// let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; -// PoolMembers::::insert(11, member); - -// let _ = Pools::fully_unbond(Origin::signed(11), 11); -// }); -// } - -// #[test] -// #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] -// #[cfg_attr(not(debug_assertions), should_panic)] -// fn unbond_panics_when_reward_pool_not_found() { -// ExtBuilder::default().build_and_execute(|| { -// let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; -// PoolMembers::::insert(11, member); -// BondedPool:: { -// id: 1, -// inner: BondedPoolInner { -// state: PoolState::Open, -// points: 10, -// member_counter: 1, -// roles: DEFAULT_ROLES, -// }, -// } -// .put(); - -// let _ = Pools::fully_unbond(Origin::signed(11), 11); -// }); -// } - -// #[test] -// fn partial_unbond_era_tracking() { -// ExtBuilder::default().build_and_execute(|| { -// // given -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); -// assert_eq!(PoolMembers::::get(10).unwrap().pool_id, 1); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!() -// ); -// assert_eq!(BondedPool::::get(1).unwrap().points, 10); -// assert!(SubPoolsStorage::::get(1).is_none()); -// assert_eq!(CurrentEra::get(), 0); -// assert_eq!(BondingDuration::get(), 3); - -// // so the depositor can leave, just keeps the test simpler. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // when: casual unbond -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - -// // then -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 9); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 1); -// assert_eq!(BondedPool::::get(1).unwrap().points, 9); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } -// ] -// ); - -// // when: casual further unbond, same era. -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); - -// // then -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 4); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 6); -// assert_eq!(BondedPool::::get(1).unwrap().points, 4); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 6) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 6, balance: 6 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }] -// ); - -// // when: casual further unbond, next era. -// CurrentEra::set(1); -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); - -// // then -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); -// assert_eq!(BondedPool::::get(1).unwrap().points, 3); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 6, 4 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 6, balance: 6 }, -// 4 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }] -// ); - -// // when: unbonding more than our active: error -// assert_err!( -// frame_support::storage::in_storage_layer(|| Pools::unbond( -// Origin::signed(10), -// 10, -// 5 -// )), -// Error::::NotEnoughPointsToUnbond -// ); -// // instead: -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); - -// // then -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 0); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 10); -// assert_eq!(BondedPool::::get(1).unwrap().points, 0); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 6, 4 => 4) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 6, balance: 6 }, -// 4 => UnbondPool { points: 4, balance: 4 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }] -// ); -// }); -// } - -// #[test] -// fn partial_unbond_max_chunks() { -// ExtBuilder::default().ed(1).build_and_execute(|| { -// // so the depositor can leave, just keeps the test simpler. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// MaxUnbonding::set(2); - -// // given -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); -// CurrentEra::set(1); -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 2, 4 => 3) -// ); - -// // when -// CurrentEra::set(2); -// assert_err!( -// frame_support::storage::in_storage_layer(|| Pools::unbond( -// Origin::signed(10), -// 10, -// 4 -// )), -// Error::::MaxUnbondingLimit -// ); - -// // when -// MaxUnbonding::set(3); -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 2, 4 => 3, 5 => 1) -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } -// ] -// ); -// }) -// } - -// // depositor can unbond inly up to `MinCreateBond`. -// #[test] -// fn depositor_permissioned_partial_unbond() { -// ExtBuilder::default().ed(1).build_and_execute(|| { -// // given -// assert_eq!(MinCreateBond::::get(), 2); -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); - -// // can unbond a bit.. -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 7); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 3); - -// // but not less than 2 -// assert_noop!( -// Pools::unbond(Origin::signed(10), 10, 6), -// Error::::NotOnlyPoolMember -// ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } -// ] -// ); -// }); -// } - -// // same as above, but the pool is slashed and therefore the depositor cannot partially unbond. -// #[test] -// fn depositor_permissioned_partial_unbond_slashed() { -// ExtBuilder::default().ed(1).build_and_execute(|| { -// // given -// assert_eq!(MinCreateBond::::get(), 2); -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); - -// // slash the default pool -// StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 5); - -// // cannot unbond even 7, because the value of shares is now less. -// assert_noop!( -// Pools::unbond(Origin::signed(10), 10, 7), -// Error::::NotOnlyPoolMember -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// ] -// ); -// }); -// } - -// #[test] -// fn every_unbonding_triggers_payout() { -// ExtBuilder::default().build_and_execute(|| { -// let initial_reward_account = Balances::free_balance(Pools::create_reward_account(1)); -// assert_eq!(initial_reward_account, Balances::minimum_balance()); -// assert_eq!(initial_reward_account, 5); - -// // set the pool to destroying so that depositor can leave. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// Balances::make_free_balance_be( -// &Pools::create_reward_account(1), -// 2 * Balances::minimum_balance(), -// ); - -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// // exactly equal to ed, all that can be claimed. -// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } -// ] -// ); - -// CurrentEra::set(1); -// Balances::make_free_balance_be( -// &Pools::create_reward_account(1), -// 2 * Balances::minimum_balance(), -// ); - -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// // exactly equal to ed, all that can be claimed. -// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } -// ] -// ); - -// CurrentEra::set(2); -// Balances::make_free_balance_be( -// &Pools::create_reward_account(1), -// 2 * Balances::minimum_balance(), -// ); - -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 } -// ] -// ); - -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 2, 4 => 3, 5 => 5) -// ); -// }); -// } -// } - -// mod pool_withdraw_unbonded { -// use super::*; - -// #[test] -// fn pool_withdraw_unbonded_works() { -// ExtBuilder::default().build_and_execute(|| { -// // Given 10 unbond'ed directly against the pool account -// assert_ok!(StakingMock::unbond(default_bonded_account(), 5)); -// // and the pool account only has 10 balance -// assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); -// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(10)); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); - -// // When -// assert_ok!(Pools::pool_withdraw_unbonded(Origin::signed(10), 1, 0)); - -// // Then there unbonding balance is no longer locked -// assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); -// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(5)); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); -// }); -// } -// } - -// mod withdraw_unbonded { -// use super::*; -// use frame_support::bounded_btree_map; - -// #[test] -// fn withdraw_unbonded_works_against_slashed_no_era_sub_pool() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (550, 550)]) -// .build_and_execute(|| { -// // reduce the noise a bit. -// let _ = balances_events_since_last_call(); - -// // Given -// assert_eq!(StakingMock::bonding_duration(), 3); -// assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); -// assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 600); - -// let mut current_era = 1; -// CurrentEra::set(current_era); - -// let mut sub_pools = SubPoolsStorage::::get(1).unwrap(); -// let unbond_pool = sub_pools.with_era.get_mut(&3).unwrap(); -// // Sanity check -// assert_eq!(*unbond_pool, UnbondPool { points: 550 + 40, balance: 550 + 40 }); - -// // Simulate a slash to the pool with_era(current_era), decreasing the balance by -// // half -// { -// unbond_pool.balance /= 2; // 295 -// SubPoolsStorage::::insert(1, sub_pools); -// // Update the equivalent of the unbonding chunks for the `StakingMock` -// let mut x = UnbondingBalanceMap::get(); -// *x.get_mut(&default_bonded_account()).unwrap() /= 5; -// UnbondingBalanceMap::set(&x); -// Balances::make_free_balance_be( -// &default_bonded_account(), -// Balances::free_balance(&default_bonded_account()) / 2, // 300 -// ); -// StakingMock::set_bonded_balance( -// default_bonded_account(), -// StakingMock::active_stake(&default_bonded_account()).unwrap() / 2, -// ); -// }; - -// // Advance the current_era to ensure all `with_era` pools will be merged into -// // `no_era` pool -// current_era += TotalUnbondingPools::::get(); -// CurrentEra::set(current_era); - -// // Simulate some other call to unbond that would merge `with_era` pools into -// // `no_era` -// let sub_pools = -// SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); -// SubPoolsStorage::::insert(1, sub_pools); - -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: UnbondPool { points: 550 + 40, balance: 275 + 20 }, -// with_era: Default::default() -// } -// ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, -// Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 }, -// Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 }, -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::BalanceSet { -// who: default_bonded_account(), -// free: 300, -// reserved: 0 -// }] -// ); - -// // When -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().no_era, -// UnbondPool { points: 40, balance: 20 } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 550 }, -// Event::MemberRemoved { pool_id: 1, member: 550 } -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 }] -// ); - -// // When -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); - -// // Then -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().no_era, -// UnbondPool { points: 0, balance: 0 } -// ); -// assert!(!PoolMembers::::contains_key(40)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 40 }, -// Event::MemberRemoved { pool_id: 1, member: 40 } -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 }] -// ); - -// // now, finally, the depositor can take out its share. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(fully_unbond_permissioned(10)); - -// current_era += 3; -// CurrentEra::set(current_era); - -// // when -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 }, -// Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 }, -// Event::MemberRemoved { pool_id: 1, member: 10 }, -// Event::Destroyed { pool_id: 1 } -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![ -// BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, -// BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } -// ] -// ); -// }); -// } - -// #[test] -// fn withdraw_unbonded_works_against_slashed_with_era_sub_pools() { -// ExtBuilder::default() -// .add_members(vec![(40, 40), (550, 550)]) -// .build_and_execute(|| { -// let _ = balances_events_since_last_call(); - -// // Given -// // current bond is 600, we slash it all to 300. -// StakingMock::set_bonded_balance(default_bonded_account(), 300); -// Balances::make_free_balance_be(&default_bonded_account(), 300); -// assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(300)); - -// assert_ok!(fully_unbond_permissioned(40)); -// assert_ok!(fully_unbond_permissioned(550)); - -// assert_eq!( -// SubPoolsStorage::::get(&1).unwrap().with_era, -// unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 -// }} ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, -// Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, -// Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 }, -// Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 }, -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::BalanceSet { -// who: default_bonded_account(), -// free: 300, -// reserved: 0 -// },] -// ); - -// CurrentEra::set(StakingMock::bonding_duration()); - -// // When -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); - -// // Then -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 },] -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 20 }, -// Event::MemberRemoved { pool_id: 1, member: 40 } -// ] -// ); - -// assert_eq!( -// SubPoolsStorage::::get(&1).unwrap().with_era, -// unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} -// ); - -// // When -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); - -// // Then -// assert_eq!( -// balances_events_since_last_call(), -// vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 },] -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 275 }, -// Event::MemberRemoved { pool_id: 1, member: 550 } -// ] -// ); -// assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); - -// // now, finally, the depositor can take out its share. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(fully_unbond_permissioned(10)); - -// // because everyone else has left, the points -// assert_eq!( -// SubPoolsStorage::::get(&1).unwrap().with_era, -// unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} -// ); - -// CurrentEra::set(CurrentEra::get() + 3); - -// // when -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - -// // then -// assert_eq!(Balances::free_balance(&10), 10 + 5); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 0); - -// // in this test 10 also gets a fair share of the slash, because the slash was -// // applied to the bonded account. -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }, -// Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 }, -// Event::MemberRemoved { pool_id: 1, member: 10 }, -// Event::Destroyed { pool_id: 1 } -// ] -// ); -// assert_eq!( -// balances_events_since_last_call(), -// vec![ -// BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, -// BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } -// ] -// ); -// }); -// } - -// #[test] -// fn withdraw_unbonded_handles_faulty_sub_pool_accounting() { -// ExtBuilder::default().build_and_execute(|| { -// // Given -// assert_eq!(Balances::minimum_balance(), 5); -// assert_eq!(Balances::free_balance(&10), 5); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 10); -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); - -// // Simulate a slash that is not accounted for in the sub pools. -// Balances::make_free_balance_be(&default_bonded_account(), 5); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap().with_era, -// //------------------------------balance decrease is not account for -// unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 } } -// ); - -// CurrentEra::set(0 + 3); - -// // When -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - -// // Then -// assert_eq!(Balances::free_balance(10), 10 + 5); -// assert_eq!(Balances::free_balance(&default_bonded_account()), 0); -// }); -// } - -// #[test] -// fn withdraw_unbonded_errors_correctly() { -// ExtBuilder::default().with_check(0).build_and_execute(|| { -// // Insert the sub-pool -// let sub_pools = SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 }}, -// }; -// SubPoolsStorage::::insert(1, sub_pools.clone()); - -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), -// Error::::PoolMemberNotFound -// ); - -// let mut member = PoolMember { pool_id: 1, points: 10, ..Default::default() }; -// PoolMembers::::insert(11, member.clone()); - -// // Simulate calling `unbond` -// member.unbonding_eras = member_unbonding_eras!(3 + 0 => 10); -// PoolMembers::::insert(11, member.clone()); - -// // We are still in the bonding duration -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), -// Error::::CannotWithdrawAny -// ); - -// // If we error the member does not get removed -// assert_eq!(PoolMembers::::get(&11), Some(member)); -// // and the sub pools do not get updated. -// assert_eq!(SubPoolsStorage::::get(1).unwrap(), sub_pools) -// }); -// } - -// #[test] -// fn withdraw_unbonded_kick() { -// ExtBuilder::default() -// .add_members(vec![(100, 100), (200, 200)]) -// .build_and_execute(|| { -// // Given -// assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); -// assert_ok!(Pools::fully_unbond(Origin::signed(200), 200)); -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// points: 10, -// state: PoolState::Open, -// member_counter: 3, -// roles: DEFAULT_ROLES -// } -// } -// ); -// CurrentEra::set(StakingMock::bonding_duration()); - -// // Cannot kick when pool is open -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(902), 100, 0), -// Error::::NotKickerOrDestroying -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, -// Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, -// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, -// Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 } -// ] -// ); - -// // Given -// unsafe_set_state(1, PoolState::Blocked).unwrap(); - -// // Cannot kick as a nominator -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(901), 100, 0), -// Error::::NotKickerOrDestroying -// ); - -// // Can kick as root -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 100, 0)); - -// // Can kick as state toggler -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 200, 0)); - -// assert_eq!(Balances::free_balance(100), 100 + 100); -// assert_eq!(Balances::free_balance(200), 200 + 200); -// assert!(!PoolMembers::::contains_key(100)); -// assert!(!PoolMembers::::contains_key(200)); -// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, -// Event::MemberRemoved { pool_id: 1, member: 100 }, -// Event::Withdrawn { member: 200, pool_id: 1, points: 200, balance: 200 }, -// Event::MemberRemoved { pool_id: 1, member: 200 } -// ] -// ); -// }); -// } - -// #[test] -// fn withdraw_unbonded_destroying_permissionless() { -// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { -// // Given -// assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); -// assert_eq!( -// BondedPool::::get(1).unwrap(), -// BondedPool { -// id: 1, -// inner: BondedPoolInner { -// points: 10, -// state: PoolState::Open, -// member_counter: 2, -// roles: DEFAULT_ROLES, -// } -// } -// ); -// CurrentEra::set(StakingMock::bonding_duration()); -// assert_eq!(Balances::free_balance(100), 100); - -// // Cannot permissionlessly withdraw -// assert_noop!( -// Pools::fully_unbond(Origin::signed(420), 100), -// Error::::NotKickerOrDestroying -// ); - -// // Given -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // Can permissionlesly withdraw a member that is not the depositor -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); - -// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default(),); -// assert_eq!(Balances::free_balance(100), 100 + 100); -// assert!(!PoolMembers::::contains_key(100)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, -// Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, -// Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, -// Event::MemberRemoved { pool_id: 1, member: 100 } -// ] -// ); -// }); -// } - -// #[test] -// fn partial_withdraw_unbonded_depositor() { -// ExtBuilder::default().ed(1).build_and_execute(|| { -// // so the depositor can leave, just keeps the test simpler. -// unsafe_set_state(1, PoolState::Destroying).unwrap(); - -// // given -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 6)); -// CurrentEra::set(1); -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 6, 4 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 6, balance: 6 }, -// 4 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); -// assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } -// ] -// ); - -// // when -// CurrentEra::set(2); -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), -// Error::::CannotWithdrawAny -// ); - -// // when -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - -// // then -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(4 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 4 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Withdrawn { member: 10, pool_id: 1, points: 6, balance: 6 }] -// ); - -// // when -// CurrentEra::set(4); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); - -// // then -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!() -// ); -// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Withdrawn { member: 10, pool_id: 1, points: 1, balance: 1 },] -// ); - -// // when repeating: -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), -// Error::::CannotWithdrawAny -// ); -// }); -// } - -// #[test] -// fn partial_withdraw_unbonded_non_depositor() { -// ExtBuilder::default().add_members(vec![(11, 10)]).build_and_execute(|| { -// // given -// assert_ok!(Pools::unbond(Origin::signed(11), 11, 6)); -// CurrentEra::set(1); -// assert_ok!(Pools::unbond(Origin::signed(11), 11, 1)); -// assert_eq!( -// PoolMembers::::get(11).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 6, 4 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 3 => UnbondPool { points: 6, balance: 6 }, -// 4 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!(PoolMembers::::get(11).unwrap().active_points(), 3); -// assert_eq!(PoolMembers::::get(11).unwrap().unbonding_points(), 7); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 }, -// Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 } -// ] -// ); - -// // when -// CurrentEra::set(2); -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), -// Error::::CannotWithdrawAny -// ); - -// // when -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); - -// // then -// assert_eq!( -// PoolMembers::::get(11).unwrap().unbonding_eras, -// member_unbonding_eras!(4 => 1) -// ); -// assert_eq!( -// SubPoolsStorage::::get(1).unwrap(), -// SubPools { -// no_era: Default::default(), -// with_era: unbonding_pools_with_era! { -// 4 => UnbondPool { points: 1, balance: 1 } -// } -// } -// ); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Withdrawn { member: 11, pool_id: 1, points: 6, balance: 6 }] -// ); - -// // when -// CurrentEra::set(4); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); - -// // then -// assert_eq!( -// PoolMembers::::get(11).unwrap().unbonding_eras, -// member_unbonding_eras!() -// ); -// assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Withdrawn { member: 11, pool_id: 1, points: 1, balance: 1 }] -// ); - -// // when repeating: -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(11), 11, 0), -// Error::::CannotWithdrawAny -// ); -// }); -// } - -// #[test] -// fn full_multi_step_withdrawing_non_depositor() { -// ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { -// // given -// assert_ok!(Pools::unbond(Origin::signed(100), 100, 75)); -// assert_eq!( -// PoolMembers::::get(100).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 75) -// ); - -// // progress one era and unbond the leftover. -// CurrentEra::set(1); -// assert_ok!(Pools::unbond(Origin::signed(100), 100, 25)); -// assert_eq!( -// PoolMembers::::get(100).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 75, 4 => 25) -// ); - -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(100), 100, 0), -// Error::::CannotWithdrawAny -// ); - -// // now the 75 should be free. -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, -// Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 }, -// Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 }, -// Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 }, -// ] -// ); -// assert_eq!( -// PoolMembers::::get(100).unwrap().unbonding_eras, -// member_unbonding_eras!(4 => 25) -// ); - -// // the 25 should be free now, and the member removed. -// CurrentEra::set(4); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 100, pool_id: 1, points: 25, balance: 25 }, -// Event::MemberRemoved { pool_id: 1, member: 100 } -// ] -// ); -// }) -// } - -// #[test] -// fn full_multi_step_withdrawing_depositor() { -// ExtBuilder::default().ed(1).build_and_execute(|| { -// // given -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 7)); - -// // progress one era and unbond the leftover. -// CurrentEra::set(1); -// unsafe_set_state(1, PoolState::Destroying).unwrap(); -// assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(3 => 7, 4 => 3) -// ); - -// assert_noop!( -// Pools::withdraw_unbonded(Origin::signed(10), 10, 0), -// Error::::CannotWithdrawAny -// ); - -// // now the 7 should be free. -// CurrentEra::set(3); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Unbonded { member: 10, pool_id: 1, points: 7, balance: 7 }, -// Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, -// Event::Withdrawn { member: 10, pool_id: 1, points: 7, balance: 7 } -// ] -// ); -// assert_eq!( -// PoolMembers::::get(10).unwrap().unbonding_eras, -// member_unbonding_eras!(4 => 3) -// ); - -// // the 25 should be free now, and the member removed. -// CurrentEra::set(4); -// assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Withdrawn { member: 10, pool_id: 1, points: 3, balance: 3 }, -// Event::MemberRemoved { pool_id: 1, member: 10 }, -// // the pool is also destroyed now. -// Event::Destroyed { pool_id: 1 }, -// ] -// ); -// }) -// } -// } - -// mod create { -// use super::*; - -// #[test] -// fn create_works() { -// ExtBuilder::default().build_and_execute(|| { -// // next pool id is 2. -// let next_pool_stash = Pools::create_bonded_account(2); -// let ed = Balances::minimum_balance(); - -// assert!(!BondedPools::::contains_key(2)); -// assert!(!RewardPools::::contains_key(2)); -// assert!(!PoolMembers::::contains_key(11)); -// assert_eq!(StakingMock::active_stake(&next_pool_stash), None); - -// Balances::make_free_balance_be(&11, StakingMock::minimum_bond() + ed); -// assert_ok!(Pools::create( -// Origin::signed(11), -// StakingMock::minimum_bond(), -// 123, -// 456, -// 789 -// )); - -// assert_eq!(Balances::free_balance(&11), 0); -// assert_eq!( -// PoolMembers::::get(11).unwrap(), -// PoolMember { -// pool_id: 2, -// points: StakingMock::minimum_bond(), -// ..Default::default() -// } -// ); -// assert_eq!( -// BondedPool::::get(2).unwrap(), -// BondedPool { -// id: 2, -// inner: BondedPoolInner { -// points: StakingMock::minimum_bond(), -// member_counter: 1, -// state: PoolState::Open, -// roles: PoolRoles { -// depositor: 11, -// root: Some(123), -// nominator: Some(456), -// state_toggler: Some(789) -// } -// } -// } -// ); -// assert_eq!( -// StakingMock::active_stake(&next_pool_stash).unwrap(), -// StakingMock::minimum_bond() -// ); -// assert_eq!( -// RewardPools::::get(2).unwrap(), -// RewardPool { -// balance: Zero::zero(), -// points: U256::zero(), -// total_earnings: Zero::zero(), -// } -// ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Created { depositor: 11, pool_id: 2 }, -// Event::Bonded { member: 11, pool_id: 2, bonded: 10, joined: true } -// ] -// ); -// }); -// } - -// #[test] -// fn create_errors_correctly() { -// ExtBuilder::default().with_check(0).build_and_execute(|| { -// assert_noop!( -// Pools::create(Origin::signed(10), 420, 123, 456, 789), -// Error::::AccountBelongsToOtherPool -// ); - -// // Given -// assert_eq!(MinCreateBond::::get(), 2); -// assert_eq!(StakingMock::minimum_bond(), 10); - -// // Then -// assert_noop!( -// Pools::create(Origin::signed(11), 9, 123, 456, 789), -// Error::::MinimumBondNotMet -// ); - -// // Given -// MinCreateBond::::put(20); - -// // Then -// assert_noop!( -// Pools::create(Origin::signed(11), 19, 123, 456, 789), -// Error::::MinimumBondNotMet -// ); - -// // Given -// BondedPool:: { -// id: 2, -// inner: BondedPoolInner { -// state: PoolState::Open, -// points: 10, -// member_counter: 1, -// roles: DEFAULT_ROLES, -// }, -// } -// .put(); -// assert_eq!(MaxPools::::get(), Some(2)); -// assert_eq!(BondedPools::::count(), 2); - -// // Then -// assert_noop!( -// Pools::create(Origin::signed(11), 20, 123, 456, 789), -// Error::::MaxPools -// ); - -// // Given -// assert_eq!(PoolMembers::::count(), 1); -// MaxPools::::put(3); -// MaxPoolMembers::::put(1); -// Balances::make_free_balance_be(&11, 5 + 20); - -// // Then -// let create = Call::Pools(crate::Call::::create { -// amount: 20, -// root: 11, -// nominator: 11, -// state_toggler: 11, -// }); -// assert_noop!(create.dispatch(Origin::signed(11)), Error::::MaxPoolMembers); -// }); -// } -// } - -// mod nominate { -// use super::*; - -// #[test] -// fn nominate_works() { -// ExtBuilder::default().build_and_execute(|| { -// // Depositor can't nominate -// assert_noop!( -// Pools::nominate(Origin::signed(10), 1, vec![21]), -// Error::::NotNominator -// ); - -// // State toggler can't nominate -// assert_noop!( -// Pools::nominate(Origin::signed(902), 1, vec![21]), -// Error::::NotNominator -// ); - -// // Root can nominate -// assert_ok!(Pools::nominate(Origin::signed(900), 1, vec![21])); -// assert_eq!(Nominations::get().unwrap(), vec![21]); - -// // Nominator can nominate -// assert_ok!(Pools::nominate(Origin::signed(901), 1, vec![31])); -// assert_eq!(Nominations::get().unwrap(), vec![31]); - -// // Can't nominate for a pool that doesn't exist -// assert_noop!( -// Pools::nominate(Origin::signed(902), 123, vec![21]), -// Error::::PoolNotFound -// ); -// }); -// } -// } - -// mod set_state { -// use super::*; - -// #[test] -// fn set_state_works() { -// ExtBuilder::default().build_and_execute(|| { -// // Given -// assert_ok!(BondedPool::::get(1).unwrap().ok_to_be_open(0)); - -// // Only the root and state toggler can change the state when the pool is ok to be open. -// assert_noop!( -// Pools::set_state(Origin::signed(10), 1, PoolState::Blocked), -// Error::::CanNotChangeState -// ); -// assert_noop!( -// Pools::set_state(Origin::signed(901), 1, PoolState::Blocked), -// Error::::CanNotChangeState -// ); - -// // Root can change state -// assert_ok!(Pools::set_state(Origin::signed(900), 1, PoolState::Blocked)); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::StateChanged { pool_id: 1, new_state: PoolState::Blocked } -// ] -// ); - -// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Blocked); - -// // State toggler can change state -// assert_ok!(Pools::set_state(Origin::signed(902), 1, PoolState::Destroying)); -// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - -// // If the pool is destroying, then no one can set state -// assert_noop!( -// Pools::set_state(Origin::signed(900), 1, PoolState::Blocked), -// Error::::CanNotChangeState -// ); -// assert_noop!( -// Pools::set_state(Origin::signed(902), 1, PoolState::Blocked), -// Error::::CanNotChangeState -// ); - -// // If the pool is not ok to be open, then anyone can set it to destroying - -// // Given -// unsafe_set_state(1, PoolState::Open).unwrap(); -// let mut bonded_pool = BondedPool::::get(1).unwrap(); -// bonded_pool.points = 100; -// bonded_pool.put(); -// // When -// assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); -// // Then -// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - -// // Given -// Balances::make_free_balance_be(&default_bonded_account(), Balance::max_value() / 10); -// unsafe_set_state(1, PoolState::Open).unwrap(); -// // When -// assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); -// // Then -// assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); - -// // If the pool is not ok to be open, it cannot be permissionleslly set to a state that -// // isn't destroying -// unsafe_set_state(1, PoolState::Open).unwrap(); -// assert_noop!( -// Pools::set_state(Origin::signed(11), 1, PoolState::Blocked), -// Error::::CanNotChangeState -// ); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, -// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, -// Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying } -// ] -// ); -// }); -// } -// } - -// mod set_metadata { -// use super::*; - -// #[test] -// fn set_metadata_works() { -// ExtBuilder::default().build_and_execute(|| { -// // Root can set metadata -// assert_ok!(Pools::set_metadata(Origin::signed(900), 1, vec![1, 1])); -// assert_eq!(Metadata::::get(1), vec![1, 1]); - -// // State toggler can set metadata -// assert_ok!(Pools::set_metadata(Origin::signed(902), 1, vec![2, 2])); -// assert_eq!(Metadata::::get(1), vec![2, 2]); - -// // Depositor can't set metadata -// assert_noop!( -// Pools::set_metadata(Origin::signed(10), 1, vec![3, 3]), -// Error::::DoesNotHavePermission -// ); - -// // Nominator can't set metadata -// assert_noop!( -// Pools::set_metadata(Origin::signed(901), 1, vec![3, 3]), -// Error::::DoesNotHavePermission -// ); - -// // Metadata cannot be longer than `MaxMetadataLen` -// assert_noop!( -// Pools::set_metadata(Origin::signed(900), 1, vec![1, 1, 1]), -// Error::::MetadataExceedsMaxLen -// ); -// }); -// } -// } - -// mod set_configs { -// use super::*; - -// #[test] -// fn set_configs_works() { -// ExtBuilder::default().build_and_execute(|| { -// // Setting works -// assert_ok!(Pools::set_configs( -// Origin::root(), -// ConfigOp::Set(1 as Balance), -// ConfigOp::Set(2 as Balance), -// ConfigOp::Set(3u32), -// ConfigOp::Set(4u32), -// ConfigOp::Set(5u32), -// )); -// assert_eq!(MinJoinBond::::get(), 1); -// assert_eq!(MinCreateBond::::get(), 2); -// assert_eq!(MaxPools::::get(), Some(3)); -// assert_eq!(MaxPoolMembers::::get(), Some(4)); -// assert_eq!(MaxPoolMembersPerPool::::get(), Some(5)); - -// // Noop does nothing -// assert_storage_noop!(assert_ok!(Pools::set_configs( -// Origin::root(), -// ConfigOp::Noop, -// ConfigOp::Noop, -// ConfigOp::Noop, -// ConfigOp::Noop, -// ConfigOp::Noop, -// ))); - -// // Removing works -// assert_ok!(Pools::set_configs( -// Origin::root(), -// ConfigOp::Remove, -// ConfigOp::Remove, -// ConfigOp::Remove, -// ConfigOp::Remove, -// ConfigOp::Remove, -// )); -// assert_eq!(MinJoinBond::::get(), 0); -// assert_eq!(MinCreateBond::::get(), 0); -// assert_eq!(MaxPools::::get(), None); -// assert_eq!(MaxPoolMembers::::get(), None); -// assert_eq!(MaxPoolMembersPerPool::::get(), None); -// }); -// } -// } - -// mod bond_extra { -// use super::*; -// use crate::Event; - -// #[test] -// fn bond_extra_from_free_balance_creator() { -// ExtBuilder::default().build_and_execute(|| { -// // 10 is the owner and a member in pool 1, give them some more funds. -// Balances::make_free_balance_be(&10, 100); - -// // given -// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); -// assert_eq!(BondedPools::::get(1).unwrap().points, 10); -// assert_eq!(Balances::free_balance(10), 100); - -// // when -// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); - -// // then -// assert_eq!(Balances::free_balance(10), 90); -// assert_eq!(PoolMembers::::get(10).unwrap().points, 20); -// assert_eq!(BondedPools::::get(1).unwrap().points, 20); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false } -// ] -// ); - -// // when -// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(20))); - -// // then -// assert_eq!(Balances::free_balance(10), 70); -// assert_eq!(PoolMembers::::get(10).unwrap().points, 40); -// assert_eq!(BondedPools::::get(1).unwrap().points, 40); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::Bonded { member: 10, pool_id: 1, bonded: 20, joined: false }] -// ); -// }) -// } - -// #[test] -// fn bond_extra_from_rewards_creator() { -// ExtBuilder::default().build_and_execute(|| { -// // put some money in the reward account, all of which will belong to 10 as the only -// // member of the pool. -// Balances::make_free_balance_be(&default_reward_account(), 7); -// // ... if which only 2 is claimable to make sure the reward account does not die. -// let claimable_reward = 7 - ExistentialDeposit::get(); - -// // given -// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); -// assert_eq!(BondedPools::::get(1).unwrap().points, 10); -// assert_eq!(Balances::free_balance(10), 5); - -// // when -// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); - -// // then -// assert_eq!(Balances::free_balance(10), 5); -// assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + claimable_reward); -// assert_eq!(BondedPools::::get(1).unwrap().points, 10 + claimable_reward); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, -// Event::Bonded { -// member: 10, -// pool_id: 1, -// bonded: claimable_reward, -// joined: false -// } -// ] -// ); -// }) -// } - -// #[test] -// fn bond_extra_from_rewards_joiner() { -// ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { -// // put some money in the reward account, all of which will belong to 10 as the only -// // member of the pool. -// Balances::make_free_balance_be(&default_reward_account(), 8); -// // ... if which only 3 is claimable to make sure the reward account does not die. -// let claimable_reward = 8 - ExistentialDeposit::get(); -// // NOTE: easier to read of we use 3, so let's use the number instead of variable. -// assert_eq!(claimable_reward, 3, "test is correct if rewards are divisible by 3"); - -// // given -// assert_eq!(PoolMembers::::get(10).unwrap().points, 10); -// assert_eq!(PoolMembers::::get(20).unwrap().points, 20); -// assert_eq!(BondedPools::::get(1).unwrap().points, 30); -// assert_eq!(Balances::free_balance(10), 5); -// assert_eq!(Balances::free_balance(20), 20); - -// // when -// assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); - -// // then -// assert_eq!(Balances::free_balance(10), 5); -// // 10's share of the reward is 1/3, since they gave 10/30 of the total shares. -// assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + 1); -// assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 1); - -// // when -// assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::Rewards)); - -// // then -// assert_eq!(Balances::free_balance(20), 20); -// // 20's share of the rewards is the other 2/3 of the rewards, since they have 20/30 of -// // the shares -// assert_eq!(PoolMembers::::get(20).unwrap().points, 20 + 2); -// assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 3); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, -// Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, -// Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, -// Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } -// ] -// ); -// }) -// } -// } - -// mod update_roles { -// use super::*; - -// #[test] -// fn update_roles_works() { -// ExtBuilder::default().build_and_execute(|| { -// assert_eq!( -// BondedPools::::get(1).unwrap().roles, -// PoolRoles { -// depositor: 10, -// root: Some(900), -// nominator: Some(901), -// state_toggler: Some(902) -// }, -// ); - -// // non-existent pools -// assert_noop!( -// Pools::update_roles( -// Origin::signed(1), -// 2, -// ConfigOp::Set(5), -// ConfigOp::Set(6), -// ConfigOp::Set(7) -// ), -// Error::::PoolNotFound, -// ); - -// // depositor cannot change roles. -// assert_noop!( -// Pools::update_roles( -// Origin::signed(1), -// 1, -// ConfigOp::Set(5), -// ConfigOp::Set(6), -// ConfigOp::Set(7) -// ), -// Error::::DoesNotHavePermission, -// ); - -// // nominator cannot change roles. -// assert_noop!( -// Pools::update_roles( -// Origin::signed(901), -// 1, -// ConfigOp::Set(5), -// ConfigOp::Set(6), -// ConfigOp::Set(7) -// ), -// Error::::DoesNotHavePermission, -// ); -// // state-toggler -// assert_noop!( -// Pools::update_roles( -// Origin::signed(902), -// 1, -// ConfigOp::Set(5), -// ConfigOp::Set(6), -// ConfigOp::Set(7) -// ), -// Error::::DoesNotHavePermission, -// ); - -// // but root can -// assert_ok!(Pools::update_roles( -// Origin::signed(900), -// 1, -// ConfigOp::Set(5), -// ConfigOp::Set(6), -// ConfigOp::Set(7) -// )); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![ -// Event::Created { depositor: 10, pool_id: 1 }, -// Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, -// Event::RolesUpdated { -// root: Some(5), -// state_toggler: Some(7), -// nominator: Some(6) -// } -// ] -// ); -// assert_eq!( -// BondedPools::::get(1).unwrap().roles, -// PoolRoles { -// depositor: 10, -// root: Some(5), -// nominator: Some(6), -// state_toggler: Some(7) -// }, -// ); - -// // also root origin can -// assert_ok!(Pools::update_roles( -// Origin::root(), -// 1, -// ConfigOp::Set(1), -// ConfigOp::Set(2), -// ConfigOp::Set(3) -// )); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::RolesUpdated { -// root: Some(1), -// state_toggler: Some(3), -// nominator: Some(2) -// }] -// ); -// assert_eq!( -// BondedPools::::get(1).unwrap().roles, -// PoolRoles { -// depositor: 10, -// root: Some(1), -// nominator: Some(2), -// state_toggler: Some(3) -// }, -// ); - -// // Noop works -// assert_ok!(Pools::update_roles( -// Origin::root(), -// 1, -// ConfigOp::Set(11), -// ConfigOp::Noop, -// ConfigOp::Noop -// )); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::RolesUpdated { -// root: Some(11), -// state_toggler: Some(3), -// nominator: Some(2) -// }] -// ); - -// assert_eq!( -// BondedPools::::get(1).unwrap().roles, -// PoolRoles { -// depositor: 10, -// root: Some(11), -// nominator: Some(2), -// state_toggler: Some(3) -// }, -// ); - -// // Remove works -// assert_ok!(Pools::update_roles( -// Origin::root(), -// 1, -// ConfigOp::Set(69), -// ConfigOp::Remove, -// ConfigOp::Remove -// )); - -// assert_eq!( -// pool_events_since_last_call(), -// vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }] -// ); - -// assert_eq!( -// BondedPools::::get(1).unwrap().roles, -// PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None }, -// ); -// }) -// } -// } +mod unbond_pool { + use super::*; + + #[test] + fn points_to_issue_works() { + ExtBuilder::default().build_and_execute(|| { + // 1 points : 1 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 10); + assert_eq!(unbond_pool.balance_to_point(0), 0); + + // 2 points : 1 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; + assert_eq!(unbond_pool.balance_to_point(10), 20); + + // 1 points : 2 balance ratio + let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 5); + + // 100 points : 0 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; + assert_eq!(unbond_pool.balance_to_point(10), 100 * 10); + + // 0 points : 100 balance + let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; + assert_eq!(unbond_pool.balance_to_point(10), 10); + + // 10 points : 3 balance ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 30 }; + assert_eq!(unbond_pool.balance_to_point(10), 33); + + // 2 points : 3 balance ratio + let unbond_pool = UnbondPool:: { points: 200, balance: 300 }; + assert_eq!(unbond_pool.balance_to_point(10), 6); + + // 4 points : 9 balance ratio + let unbond_pool = UnbondPool:: { points: 400, balance: 900 }; + assert_eq!(unbond_pool.balance_to_point(90), 40); + }) + } + + #[test] + fn balance_to_unbond_works() { + // 1 balance : 1 points ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 100 }; + assert_eq!(unbond_pool.point_to_balance(10), 10); + assert_eq!(unbond_pool.point_to_balance(0), 0); + + // 1 balance : 2 points ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 50 }; + assert_eq!(unbond_pool.point_to_balance(10), 5); + + // 2 balance : 1 points ratio + let unbond_pool = UnbondPool:: { points: 50, balance: 100 }; + assert_eq!(unbond_pool.point_to_balance(10), 20); + + // 100 balance : 0 points ratio + let unbond_pool = UnbondPool:: { points: 0, balance: 100 }; + assert_eq!(unbond_pool.point_to_balance(10), 0); + + // 0 balance : 100 points ratio + let unbond_pool = UnbondPool:: { points: 100, balance: 0 }; + assert_eq!(unbond_pool.point_to_balance(10), 0); + + // 10 balance : 3 points ratio + let unbond_pool = UnbondPool:: { points: 30, balance: 100 }; + assert_eq!(unbond_pool.point_to_balance(10), 33); + + // 2 balance : 3 points ratio + let unbond_pool = UnbondPool:: { points: 300, balance: 200 }; + assert_eq!(unbond_pool.point_to_balance(10), 6); + + // 4 balance : 9 points ratio + let unbond_pool = UnbondPool:: { points: 900, balance: 400 }; + assert_eq!(unbond_pool.point_to_balance(90), 40); + } +} + +mod sub_pools { + use super::*; + + #[test] + fn maybe_merge_pools_works() { + ExtBuilder::default().build_and_execute(|| { + assert_eq!(TotalUnbondingPools::::get(), 5); + assert_eq!(BondingDuration::get(), 3); + assert_eq!(PostUnbondingPoolsWindow::get(), 2); + + // Given + let mut sub_pool_0 = SubPools:: { + no_era: UnbondPool::::default(), + with_era: unbonding_pools_with_era! { + 0 => UnbondPool:: { points: 10, balance: 10 }, + 1 => UnbondPool:: { points: 10, balance: 10 }, + 2 => UnbondPool:: { points: 20, balance: 20 }, + 3 => UnbondPool:: { points: 30, balance: 30 }, + 4 => UnbondPool:: { points: 40, balance: 40 }, + }, + }; + + // When `current_era < TotalUnbondingPools`, + let sub_pool_1 = sub_pool_0.clone().maybe_merge_pools(0); + + // Then it exits early without modifications + assert_eq!(sub_pool_1, sub_pool_0); + + // When `current_era == TotalUnbondingPools`, + let sub_pool_1 = sub_pool_1.maybe_merge_pools(1); + + // Then it exits early without modifications + assert_eq!(sub_pool_1, sub_pool_0); + + // When `current_era - TotalUnbondingPools == 0`, + let mut sub_pool_1 = sub_pool_1.maybe_merge_pools(2); + + // Then era 0 is merged into the `no_era` pool + sub_pool_0.no_era = sub_pool_0.with_era.remove(&0).unwrap(); + assert_eq!(sub_pool_1, sub_pool_0); + + // Given we have entries for era 1..=5 + sub_pool_1 + .with_era + .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) + .unwrap(); + sub_pool_0 + .with_era + .try_insert(5, UnbondPool:: { points: 50, balance: 50 }) + .unwrap(); + + // When `current_era - TotalUnbondingPools == 1` + let sub_pool_2 = sub_pool_1.maybe_merge_pools(3); + let era_1_pool = sub_pool_0.with_era.remove(&1).unwrap(); + + // Then era 1 is merged into the `no_era` pool + sub_pool_0.no_era.points += era_1_pool.points; + sub_pool_0.no_era.balance += era_1_pool.balance; + assert_eq!(sub_pool_2, sub_pool_0); + + // When `current_era - TotalUnbondingPools == 5`, so all pools with era <= 4 are removed + let sub_pool_3 = sub_pool_2.maybe_merge_pools(7); + + // Then all eras <= 5 are merged into the `no_era` pool + for era in 2..=5 { + let to_merge = sub_pool_0.with_era.remove(&era).unwrap(); + sub_pool_0.no_era.points += to_merge.points; + sub_pool_0.no_era.balance += to_merge.balance; + } + assert_eq!(sub_pool_3, sub_pool_0); + }); + } +} + +mod join { + use super::*; + + #[test] + fn join_works() { + let bonded = |points, member_counter| BondedPool:: { + id: 1, + inner: BondedPoolInner { + state: PoolState::Open, + points, + member_counter, + roles: DEFAULT_ROLES, + }, + }; + ExtBuilder::default().build_and_execute(|| { + // Given + Balances::make_free_balance_be(&11, ExistentialDeposit::get() + 2); + assert!(!PoolMembers::::contains_key(&11)); + + // When + assert_ok!(Pools::join(Origin::signed(11), 2, 1)); + + // Then + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 11, pool_id: 1, bonded: 2, joined: true }, + ] + ); + + assert_eq!( + PoolMembers::::get(&11).unwrap(), + PoolMember:: { pool_id: 1, points: 2, ..Default::default() } + ); + assert_eq!(BondedPool::::get(1).unwrap(), bonded(12, 2)); + + // Given + // The bonded balance is slashed in half + StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 6); + + // And + Balances::make_free_balance_be(&12, ExistentialDeposit::get() + 12); + assert!(!PoolMembers::::contains_key(&12)); + + // When + assert_ok!(Pools::join(Origin::signed(12), 12, 1)); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::Bonded { member: 12, pool_id: 1, bonded: 12, joined: true }] + ); + + assert_eq!( + PoolMembers::::get(&12).unwrap(), + PoolMember:: { pool_id: 1, points: 24, ..Default::default() } + ); + assert_eq!(BondedPool::::get(1).unwrap(), bonded(12 + 24, 3)); + }); + } + + #[test] + fn join_errors_correctly() { + ExtBuilder::default().with_check(0).build_and_execute(|| { + // 10 is already part of the default pool created. + assert_eq!(PoolMembers::::get(&10).unwrap().pool_id, 1); + + assert_noop!( + Pools::join(Origin::signed(10), 420, 123), + Error::::AccountBelongsToOtherPool + ); + + assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::PoolNotFound); + + // Force the pools bonded balance to 0, simulating a 100% slash + StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 0); + assert_noop!(Pools::join(Origin::signed(11), 420, 1), Error::::OverflowRisk); + + // Given a mocked bonded pool + BondedPool:: { + id: 123, + inner: BondedPoolInner { + member_counter: 1, + state: PoolState::Open, + points: 100, + roles: DEFAULT_ROLES, + }, + } + .put(); + + // and reward pool + RewardPools::::insert(123, RewardPool:: { ..Default::default() }); + + // Force the points:balance ratio to `MinPointsToBalance` (100/10) + let min_points_to_balance: u128 = + <::MinPointsToBalance as Get>::get().into(); + + StakingMock::set_bonded_balance( + Pools::create_bonded_account(123), + min_points_to_balance, + ); + assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::OverflowRisk); + + StakingMock::set_bonded_balance( + Pools::create_bonded_account(123), + Balance::MAX / min_points_to_balance, + ); + // Balance needs to be gt Balance::MAX / `MinPointsToBalance` + assert_noop!(Pools::join(Origin::signed(11), 5, 123), Error::::OverflowRisk); + + StakingMock::set_bonded_balance(Pools::create_bonded_account(1), min_points_to_balance); + + // Cannot join a pool that isn't open + unsafe_set_state(123, PoolState::Blocked).unwrap(); + assert_noop!( + Pools::join(Origin::signed(11), min_points_to_balance, 123), + Error::::NotOpen + ); + + unsafe_set_state(123, PoolState::Destroying).unwrap(); + assert_noop!( + Pools::join(Origin::signed(11), min_points_to_balance, 123), + Error::::NotOpen + ); + + // Given + MinJoinBond::::put(100); + + // Then + assert_noop!( + Pools::join(Origin::signed(11), 99, 123), + Error::::MinimumBondNotMet + ); + }); + } + + #[test] + #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] + #[cfg_attr(not(debug_assertions), should_panic)] + fn join_panics_when_reward_pool_not_found() { + ExtBuilder::default().build_and_execute(|| { + StakingMock::set_bonded_balance(Pools::create_bonded_account(123), 100); + BondedPool:: { + id: 123, + inner: BondedPoolInner { + state: PoolState::Open, + points: 100, + member_counter: 1, + roles: DEFAULT_ROLES, + }, + } + .put(); + let _ = Pools::join(Origin::signed(11), 420, 123); + }); + } + + #[test] + fn join_max_member_limits_are_respected() { + ExtBuilder::default().build_and_execute(|| { + // Given + assert_eq!(MaxPoolMembersPerPool::::get(), Some(3)); + for i in 1..3 { + let account = i + 100; + Balances::make_free_balance_be(&account, 100 + Balances::minimum_balance()); + + assert_ok!(Pools::join(Origin::signed(account), 100, 1)); + } + + Balances::make_free_balance_be(&103, 100 + Balances::minimum_balance()); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 101, pool_id: 1, bonded: 100, joined: true }, + Event::Bonded { member: 102, pool_id: 1, bonded: 100, joined: true } + ] + ); + + assert_noop!( + Pools::join(Origin::signed(103), 100, 1), + Error::::MaxPoolMembers + ); + + // Given + assert_eq!(PoolMembers::::count(), 3); + assert_eq!(MaxPoolMembers::::get(), Some(4)); + + Balances::make_free_balance_be(&104, 100 + Balances::minimum_balance()); + assert_ok!(Pools::create(Origin::signed(104), 100, 104, 104, 104)); + + let pool_account = BondedPools::::iter() + .find(|(_, bonded_pool)| bonded_pool.roles.depositor == 104) + .map(|(pool_account, _)| pool_account) + .unwrap(); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 104, pool_id: 2 }, + Event::Bonded { member: 104, pool_id: 2, bonded: 100, joined: true } + ] + ); + + assert_noop!( + Pools::join(Origin::signed(103), 100, pool_account), + Error::::MaxPoolMembers + ); + }); + } +} + +mod claim_payout { + use super::*; + + fn del(points: Balance, last_recorded_reward_counter: u128) -> PoolMember { + PoolMember { + pool_id: 1, + points, + last_recorded_reward_counter: last_recorded_reward_counter.into(), + unbonding_eras: Default::default(), + } + } + + fn del_float(points: Balance, last_recorded_reward_counter: f64) -> PoolMember { + PoolMember { + pool_id: 1, + points, + last_recorded_reward_counter: RewardCounter::from_float(last_recorded_reward_counter), + unbonding_eras: Default::default(), + } + } + + fn rew( + last_recorded_reward_counter: u128, + last_recorded_total_payouts: Balance, + total_rewards_claimed: Balance, + ) -> RewardPool { + RewardPool { + last_recorded_reward_counter: last_recorded_reward_counter.into(), + last_recorded_total_payouts, + total_rewards_claimed, + } + } + + fn rew_float( + last_recorded_reward_counter: f64, + last_recorded_total_payouts: Balance, + total_rewards_claimed: Balance, + ) -> RewardPool { + RewardPool { + last_recorded_reward_counter: RewardCounter::from_float(last_recorded_reward_counter), + last_recorded_total_payouts, + total_rewards_claimed, + } + } + + #[test] + fn claim_payout_works() { + ExtBuilder::default() + .add_members(vec![(40, 40), (50, 50)]) + .build_and_execute(|| { + // Given each member currently has a free balance of + Balances::make_free_balance_be(&10, 0); + Balances::make_free_balance_be(&40, 0); + Balances::make_free_balance_be(&50, 0); + let ed = Balances::minimum_balance(); + + // and the reward pool has earned 100 in rewards + assert_eq!(Balances::free_balance(default_reward_account()), ed); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + ] + ); + // last recorded reward counter at the time of this member's payout is 1 + assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 1)); + // pool's 'last_recorded_reward_counter' and 'last_recorded_total_payouts' don't + // really change unless if someone bonds/unbonds. + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 10)); + assert_eq!(Balances::free_balance(&10), 10); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(40))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] + ); + assert_eq!(PoolMembers::::get(40).unwrap(), del(40, 1)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 50)); + assert_eq!(Balances::free_balance(&40), 40); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(50))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + assert_eq!(PoolMembers::::get(50).unwrap(), del(50, 1)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 100)); + assert_eq!(Balances::free_balance(&50), 50); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + + // Given the reward pool has some new rewards + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); + assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 1.5)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 105)); + assert_eq!(Balances::free_balance(&10), 10 + 5); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(40))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] + ); + assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 1.5)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 125)); + assert_eq!(Balances::free_balance(&40), 40 + 20); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + + // Given del 50 hasn't claimed and the reward pools has just earned 50 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(50))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 2.0)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 175)); + assert_eq!(Balances::free_balance(&50), 50 + 50); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); + assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 2)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 180)); + assert_eq!(Balances::free_balance(&10), 15 + 5); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); + + // CHECK + // Given del 40 hasn't claimed and the reward pool has just earned 400 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] + ); + + // We expect a payout of 40 + assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 6)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 220)); + assert_eq!(Balances::free_balance(&10), 20 + 40); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); + + // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] + ); + assert_eq!(PoolMembers::::get(10).unwrap(), del_float(10, 6.2)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 222)); + assert_eq!(Balances::free_balance(&10), 60 + 2); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(40))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] + ); + assert_eq!(PoolMembers::::get(40).unwrap(), del_float(40, 6.2)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 410)); + assert_eq!(Balances::free_balance(&40), 60 + 188); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); + + // When + assert_ok!(Pools::claim_payout(Origin::signed(50))); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] + ); + assert_eq!(PoolMembers::::get(50).unwrap(), del_float(50, 6.2)); + assert_eq!(RewardPools::::get(&1).unwrap(), rew(0, 0, 620)); + assert_eq!(Balances::free_balance(&50), 100 + 210); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + }); + } + + #[test] + fn reward_payout_errors_if_a_member_is_fully_unbonding() { + ExtBuilder::default().add_members(vec![(11, 11)]).build_and_execute(|| { + // fully unbond the member. + assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); + + let mut bonded_pool = BondedPool::::get(1).unwrap(); + let mut reward_pool = RewardPools::::get(1).unwrap(); + let mut member = PoolMembers::::get(11).unwrap(); + + assert_noop!( + Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), + Error::::FullyUnbonding + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 11, pool_id: 1, bonded: 11, joined: true }, + Event::Unbonded { member: 11, pool_id: 1, points: 11, balance: 11 } + ] + ); + }); + } + + #[test] + fn do_reward_payout_works_with_a_pool_of_1() { + let del = |reward_pool_total_earnings| del(10, reward_pool_total_earnings); + + ExtBuilder::default().build_and_execute(|| { + let mut bonded_pool = BondedPool::::get(1).unwrap(); + let mut reward_pool = RewardPools::::get(1).unwrap(); + let mut member = PoolMembers::::get(10).unwrap(); + let ed = Balances::minimum_balance(); + + // Given no rewards have been earned + // When + let payout = + Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 0); + assert_eq!(member, del(0)); + assert_eq!(reward_pool, rew(0, 0, 0)); + + // Given the pool has earned some rewards for the first time + Balances::make_free_balance_be(&default_reward_account(), ed + 5); + + // When + let payout = + Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 5); // (10 * 5 del virtual points / 10 * 5 pool points) * 5 pool balance + assert_eq!(reward_pool, rew(0, 0, 5)); + assert_eq!(member, del(5)); + + // Given the pool has earned rewards again + Balances::make_free_balance_be(&default_reward_account(), ed + 10); + + // When + let payout = + Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 10); // (10 * 10 del virtual points / 10 pool points) * 5 pool balance + assert_eq!(reward_pool, rew(0, 0, 15)); + assert_eq!(member, del(15)); + + // Given the pool has earned no new rewards + Balances::make_free_balance_be(&default_reward_account(), ed + 0); + + // When + let payout = + Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 0); + assert_eq!(reward_pool, rew(0, 0, 15)); + assert_eq!(member, del(15)); + }); + } + + #[test] + fn do_reward_payout_works_with_a_pool_of_3() { + ExtBuilder::default() + .add_members(vec![(40, 40), (50, 50)]) + .build_and_execute(|| { + let mut bonded_pool = BondedPool::::get(1).unwrap(); + let mut reward_pool = RewardPools::::get(1).unwrap(); + let ed = Balances::minimum_balance(); + // PoolMember with 10 points + let mut del_10 = PoolMembers::::get(10).unwrap(); + // PoolMember with 40 points + let mut del_40 = PoolMembers::::get(40).unwrap(); + // PoolMember with 50 points + let mut del_50 = PoolMembers::::get(50).unwrap(); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } + ] + ); + + // Given we have a total of 100 points split among the members + assert_eq!(del_50.points + del_40.points + del_10.points, 100); + assert_eq!(bonded_pool.points, 100); + // and the reward pool has earned 100 in rewards + Balances::make_free_balance_be(&default_reward_account(), ed + 100); + + // When + let payout = + Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 10); // (10 del virtual points / 100 pool points) * 100 pool balance + assert_eq!(del_10, del(10, 100)); + assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 10)); + + // When + let payout = + Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 40); // (400 del virtual points / 900 pool points) * 90 pool balance + assert_eq!(del_40, del(40, 100)); + assert_eq!( + reward_pool, + rew( + 50, + // old pool points - member virtual points + 9_000 - 100 * 40, + 100 + ) + ); + // Mock the reward pool transferring the payout to del_40 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + + // When + let payout = + Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 50); // (50 del virtual points / 50 pool points) * 50 pool balance + assert_eq!(del_50, del(50, 100)); + assert_eq!(reward_pool, rew(0, 0, 100)); + // Mock the reward pool transferring the payout to del_50 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); + + // Given the reward pool has some new rewards + Balances::make_free_balance_be(&default_reward_account(), ed + 50); + + // When + let payout = + Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 5); // (500 del virtual points / 5,000 pool points) * 50 pool balance + assert_eq!(del_10, del(10, 150)); + assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + + // When + let payout = + Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 20); // (2,000 del virtual points / 4,500 pool points) * 45 pool balance + assert_eq!(del_40, del(40, 150)); + assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 20)); + + // Given del_50 hasn't claimed and the reward pools has just earned 50 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + + // When + let payout = + Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 50); // (5,000 del virtual points / 7,5000 pool points) * 75 pool balance + assert_eq!(del_50, del(50, 200)); + assert_eq!( + reward_pool, + rew( + 25, + // old pool points + points from new earnings - del points. + // + // points from new earnings = new earnings(50) * bonded_pool.points(100) + // del points = member.points(50) * new_earnings_since_last_claim (100) + (2_500 + 50 * 100) - 50 * 100, + 200, + ) + ); + // Mock the reward pool transferring the payout to del_50 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); + + // When + let payout = + Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 5); + assert_eq!(del_10, del(10, 200)); + assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + + // Given del_40 hasn't claimed and the reward pool has just earned 400 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + + // When + let payout = + Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 40); + assert_eq!(del_10, del(10, 600)); + assert_eq!( + reward_pool, + rew( + 380, + // old pool points + points from new earnings - del points + // + // points from new earnings = new earnings(400) * bonded_pool.points(100) + // del points = member.points(10) * new_earnings_since_last_claim(400) + (2_000 + 400 * 100) - 10 * 400, + 600 + ) + ); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + + // Given del_40 + del_50 haven't claimed and the reward pool has earned 20 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + + // When + let payout = + Pools::do_reward_payout(&10, &mut del_10, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 2); // (200 del virtual points / 38,000 pool points) * 400 pool balance + assert_eq!(del_10, del(10, 620)); + assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 2)); + + // When + let payout = + Pools::do_reward_payout(&40, &mut del_40, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 188); // (18,800 del virtual points / 39,800 pool points) * 399 pool balance + assert_eq!(del_40, del(40, 620)); + assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); + // Mock the reward pool transferring the payout to del_10 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 188)); + + // When + let payout = + Pools::do_reward_payout(&50, &mut del_50, &mut bonded_pool, &mut reward_pool) + .unwrap(); + + // Then + assert_eq!(payout, 210); // (21,000 / 21,000) * 210 + assert_eq!(del_50, del(50, 620)); + assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); + }); + } + + #[test] + fn do_reward_payout_works() { + ExtBuilder::default() + .add_members(vec![(40, 40), (50, 50)]) + .build_and_execute(|| { + let mut bonded_pool = BondedPool::::get(1).unwrap(); + let mut reward_pool = RewardPools::::get(1).unwrap(); + let ed = Balances::minimum_balance(); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } + ] + ); + + // Given the bonded pool has 100 points + assert_eq!(bonded_pool.points, 100); + // Each member currently has a free balance of + Balances::make_free_balance_be(&10, 0); + Balances::make_free_balance_be(&40, 0); + Balances::make_free_balance_be(&50, 0); + // and the reward pool has earned 100 in rewards + Balances::make_free_balance_be(&default_reward_account(), ed + 100); + + let mut del_10 = PoolMembers::get(10).unwrap(); + let mut del_40 = PoolMembers::get(40).unwrap(); + let mut del_50 = PoolMembers::get(50).unwrap(); + + // When + assert_ok!(Pools::do_reward_payout( + &10, + &mut del_10, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + ); + + // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool + // balance + assert_eq!(del_10, del(10, 100)); + assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); + assert_eq!(Balances::free_balance(&10), 10); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); + + // When + assert_ok!(Pools::do_reward_payout( + &40, + &mut del_40, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] + ); + + // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance + assert_eq!(del_40, del(40, 100)); + assert_eq!(reward_pool, rew(50, 9_000 - 100 * 40, 100)); + assert_eq!(Balances::free_balance(&40), 40); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); + + // When + assert_ok!(Pools::do_reward_payout( + &50, + &mut del_50, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + + // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance + assert_eq!(del_50, del(50, 100)); + assert_eq!(reward_pool, rew(0, 0, 100)); + assert_eq!(Balances::free_balance(&50), 50); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + + // Given the reward pool has some new rewards + Balances::make_free_balance_be(&default_reward_account(), ed + 50); + + // When + assert_ok!(Pools::do_reward_payout( + &10, + &mut del_10, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); + + // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance + assert_eq!(del_10, del(10, 150)); + assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); + assert_eq!(Balances::free_balance(&10), 10 + 5); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); + + // When + assert_ok!(Pools::do_reward_payout( + &40, + &mut del_40, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] + ); + + // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool + // balance + assert_eq!(del_40, del(40, 150)); + assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); + assert_eq!(Balances::free_balance(&40), 40 + 20); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + + // Given del 50 hasn't claimed and the reward pools has just earned 50 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + + // When + assert_ok!(Pools::do_reward_payout( + &50, + &mut del_50, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + + // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 + // pool balance + assert_eq!(del_50, del(50, 200)); + assert_eq!( + reward_pool, + rew( + 25, + // old pool points + points from new earnings - del points. + // + // points from new earnings = new earnings(50) * bonded_pool.points(100) + // del points = member.points(50) * new_earnings_since_last_claim (100) + (2_500 + 50 * 100) - 50 * 100, + 200, + ) + ); + assert_eq!(Balances::free_balance(&50), 50 + 50); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + + // When + assert_ok!(Pools::do_reward_payout( + &10, + &mut del_10, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); + + // We expect a payout of 5 + assert_eq!(del_10, del(10, 200)); + assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); + assert_eq!(Balances::free_balance(&10), 15 + 5); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); + + // Given del 40 hasn't claimed and the reward pool has just earned 400 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + + // When + assert_ok!(Pools::do_reward_payout( + &10, + &mut del_10, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] + ); + + // We expect a payout of 40 + assert_eq!(del_10, del(10, 600)); + assert_eq!( + reward_pool, + rew( + 380, + // old pool points + points from new earnings - del points + // + // points from new earnings = new earnings(400) * bonded_pool.points(100) + // del points = member.points(10) * new_earnings_since_last_claim(400) + (2_000 + 400 * 100) - 10 * 400, + 600 + ) + ); + assert_eq!(Balances::free_balance(&10), 20 + 40); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); + + // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + + // When + assert_ok!(Pools::do_reward_payout( + &10, + &mut del_10, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] + ); + + // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool + // balance + assert_eq!(del_10, del(10, 620)); + assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); + assert_eq!(Balances::free_balance(&10), 60 + 2); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); + + // When + assert_ok!(Pools::do_reward_payout( + &40, + &mut del_40, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] + ); + + // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 + // pool balance + assert_eq!(del_40, del(40, 620)); + assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); + assert_eq!(Balances::free_balance(&40), 60 + 188); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); + + // When + assert_ok!(Pools::do_reward_payout( + &50, + &mut del_50, + &mut bonded_pool, + &mut reward_pool + )); + + // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] + ); + + // Expect payout of 210: (21,000 / 21,000) * 210 + assert_eq!(del_50, del(50, 620)); + assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); + assert_eq!(Balances::free_balance(&50), 100 + 210); + assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + }); + } +} + +mod unbond { + use super::*; + + #[test] + fn unbond_of_1_works() { + ExtBuilder::default().build_and_execute(|| { + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(10)); + + assert_eq!( + SubPoolsStorage::::get(1).unwrap().with_era, + unbonding_pools_with_era! { 0 + 3 => UnbondPool:: { points: 10, balance: 10 }} + ); + + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + state: PoolState::Destroying, + points: 0, + member_counter: 1, + roles: DEFAULT_ROLES, + } + } + ); + + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); + }); + } + + #[test] + fn unbond_of_3_works() { + ExtBuilder::default() + .add_members(vec![(40, 40), (550, 550)]) + .build_and_execute(|| { + let ed = Balances::minimum_balance(); + // Given a slash from 600 -> 100 + StakingMock::set_bonded_balance(default_bonded_account(), 100); + // and unclaimed rewards of 600. + Balances::make_free_balance_be(&default_reward_account(), ed + 600); + + // When + assert_ok!(fully_unbond_permissioned(40)); + + // Then + assert_eq!( + SubPoolsStorage::::get(1).unwrap().with_era, + unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 6, balance: 6 }} + ); + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + state: PoolState::Open, + points: 560, + member_counter: 3, + roles: DEFAULT_ROLES, + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::PaidOut { member: 40, pool_id: 1, payout: 40 }, + Event::Unbonded { member: 40, pool_id: 1, points: 6, balance: 6 } + ] + ); + + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 94); + assert_eq!( + PoolMembers::::get(40).unwrap().unbonding_eras, + member_unbonding_eras!(0 + 3 => 6) + ); + assert_eq!(Balances::free_balance(&40), 40 + 40); // We claim rewards when unbonding + + // When + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(550)); + + // Then + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 98, balance: 98 }} + ); + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + state: PoolState::Destroying, + points: 10, + member_counter: 3, + roles: DEFAULT_ROLES + } + } + ); + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 2); + assert_eq!( + PoolMembers::::get(550).unwrap().unbonding_eras, + member_unbonding_eras!(0 + 3 => 92) + ); + assert_eq!(Balances::free_balance(&550), 550 + 550); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 550, pool_id: 1, payout: 550 }, + Event::Unbonded { member: 550, pool_id: 1, points: 92, balance: 92 } + ] + ); + + // When + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 40, 0)); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 550, 0)); + assert_ok!(fully_unbond_permissioned(10)); + + // Then + assert_eq!( + SubPoolsStorage::::get(1).unwrap().with_era, + unbonding_pools_with_era! { 6 => UnbondPool { points: 2, balance: 2 }} + ); + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + state: PoolState::Destroying, + points: 0, + member_counter: 1, + roles: DEFAULT_ROLES + } + } + ); + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); + + assert_eq!(Balances::free_balance(&550), 550 + 550 + 92); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 40, pool_id: 1, points: 6, balance: 6 }, + Event::MemberRemoved { pool_id: 1, member: 40 }, + Event::Withdrawn { member: 550, pool_id: 1, points: 92, balance: 92 }, + Event::MemberRemoved { pool_id: 1, member: 550 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } + ] + ); + }); + } + + #[test] + fn unbond_merges_older_pools() { + ExtBuilder::default().with_check(1).build_and_execute(|| { + // Given + assert_eq!(StakingMock::bonding_duration(), 3); + SubPoolsStorage::::insert( + 1, + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 0 + 3 => UnbondPool { balance: 10, points: 100 }, + 1 + 3 => UnbondPool { balance: 20, points: 20 }, + 2 + 3 => UnbondPool { balance: 101, points: 101} + }, + }, + ); + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // When + let current_era = 1 + TotalUnbondingPools::::get(); + CurrentEra::set(current_era); + + assert_ok!(fully_unbond_permissioned(10)); + + // Then + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: UnbondPool { balance: 10 + 20, points: 100 + 20 }, + with_era: unbonding_pools_with_era! { + 2 + 3 => UnbondPool { balance: 101, points: 101}, + current_era + 3 => UnbondPool { balance: 10, points: 10 }, + }, + }, + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 10, balance: 10 } + ] + ); + }); + } + + #[test] + fn unbond_kick_works() { + // Kick: the pool is blocked and the caller is either the root or state-toggler. + ExtBuilder::default() + .add_members(vec![(100, 100), (200, 200)]) + .build_and_execute(|| { + // Given + unsafe_set_state(1, PoolState::Blocked).unwrap(); + let bonded_pool = BondedPool::::get(1).unwrap(); + assert_eq!(bonded_pool.roles.root.unwrap(), 900); + assert_eq!(bonded_pool.roles.nominator.unwrap(), 901); + assert_eq!(bonded_pool.roles.state_toggler.unwrap(), 902); + + // When the nominator tries to kick, then its a noop + assert_noop!( + Pools::fully_unbond(Origin::signed(901), 100), + Error::::NotKickerOrDestroying + ); + + // When the root kicks then its ok + assert_ok!(Pools::fully_unbond(Origin::signed(900), 100)); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, + Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, + ] + ); + + // When the state toggler kicks then its ok + assert_ok!(Pools::fully_unbond(Origin::signed(902), 200)); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 }] + ); + + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + roles: DEFAULT_ROLES, + state: PoolState::Blocked, + points: 10, // Only 10 points because 200 + 100 was unbonded + member_counter: 3, + } + } + ); + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 10); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 0 + 3 => UnbondPool { points: 100 + 200, balance: 100 + 200 } + }, + } + ); + assert_eq!( + *UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), + 100 + 200 + ); + }); + } + + #[test] + fn unbond_permissionless_works() { + // Scenarios where non-admin accounts can unbond others + ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { + // Given the pool is blocked + unsafe_set_state(1, PoolState::Blocked).unwrap(); + + // A permissionless unbond attempt errors + assert_noop!( + Pools::fully_unbond(Origin::signed(420), 100), + Error::::NotKickerOrDestroying + ); + + // permissionless unbond must be full + assert_noop!( + Pools::unbond(Origin::signed(420), 100, 80), + Error::::PartialUnbondNotAllowedPermissionlessly, + ); + + // Given the pool is destroying + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // The depositor cannot be fully unbonded until they are the last member + assert_noop!( + Pools::fully_unbond(Origin::signed(10), 10), + Error::::NotOnlyPoolMember + ); + + // Any account can unbond a member that is not the depositor + assert_ok!(Pools::fully_unbond(Origin::signed(420), 100)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 } + ] + ); + + // still permissionless unbond must be full + assert_noop!( + Pools::unbond(Origin::signed(420), 100, 80), + Error::::PartialUnbondNotAllowedPermissionlessly, + ); + + // Given the pool is blocked + unsafe_set_state(1, PoolState::Blocked).unwrap(); + + // The depositor cannot be unbonded + assert_noop!( + Pools::fully_unbond(Origin::signed(420), 10), + Error::::DoesNotHavePermission + ); + + // Given the pools is destroying + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // The depositor cannot be unbonded yet. + assert_noop!( + Pools::fully_unbond(Origin::signed(420), 10), + Error::::DoesNotHavePermission, + ); + + // but when everyone is unbonded it can.. + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 100, 0)); + + // still permissionless unbond must be full. + assert_noop!( + Pools::unbond(Origin::signed(420), 10, 5), + Error::::PartialUnbondNotAllowedPermissionlessly, + ); + + // but full unbond works. + assert_ok!(Pools::fully_unbond(Origin::signed(420), 10)); + + assert_eq!(BondedPools::::get(1).unwrap().points, 0); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 + 3 => UnbondPool { points: 10, balance: 10 } + } + } + ); + assert_eq!(StakingMock::active_stake(&default_bonded_account()).unwrap(), 0); + assert_eq!(*UnbondingBalanceMap::get().get(&default_bonded_account()).unwrap(), 10); + }); + } + + #[test] + #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] + #[cfg_attr(not(debug_assertions), should_panic)] + fn unbond_errors_correctly() { + ExtBuilder::default().build_and_execute(|| { + assert_noop!( + Pools::fully_unbond(Origin::signed(11), 11), + Error::::PoolMemberNotFound + ); + + // Add the member + let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; + PoolMembers::::insert(11, member); + + let _ = Pools::fully_unbond(Origin::signed(11), 11); + }); + } + + #[test] + #[cfg_attr(debug_assertions, should_panic(expected = "Defensive failure has been triggered!"))] + #[cfg_attr(not(debug_assertions), should_panic)] + fn unbond_panics_when_reward_pool_not_found() { + ExtBuilder::default().build_and_execute(|| { + let member = PoolMember { pool_id: 2, points: 10, ..Default::default() }; + PoolMembers::::insert(11, member); + BondedPool:: { + id: 1, + inner: BondedPoolInner { + state: PoolState::Open, + points: 10, + member_counter: 1, + roles: DEFAULT_ROLES, + }, + } + .put(); + + let _ = Pools::fully_unbond(Origin::signed(11), 11); + }); + } + + #[test] + fn partial_unbond_era_tracking() { + ExtBuilder::default().build_and_execute(|| { + // given + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); + assert_eq!(PoolMembers::::get(10).unwrap().pool_id, 1); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!() + ); + assert_eq!(BondedPool::::get(1).unwrap().points, 10); + assert!(SubPoolsStorage::::get(1).is_none()); + assert_eq!(CurrentEra::get(), 0); + assert_eq!(BondingDuration::get(), 3); + + // so the depositor can leave, just keeps the test simpler. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // when: casual unbond + assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + + // then + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 9); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 1); + assert_eq!(BondedPool::::get(1).unwrap().points, 9); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } + ] + ); + + // when: casual further unbond, same era. + assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); + + // then + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 4); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 6); + assert_eq!(BondedPool::::get(1).unwrap().points, 4); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 6) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 6, balance: 6 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }] + ); + + // when: casual further unbond, next era. + CurrentEra::set(1); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + + // then + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); + assert_eq!(BondedPool::::get(1).unwrap().points, 3); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 6, 4 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 6, balance: 6 }, + 4 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 }] + ); + + // when: unbonding more than our active: error + assert_err!( + frame_support::storage::in_storage_layer(|| Pools::unbond( + Origin::signed(10), + 10, + 5 + )), + Error::::NotEnoughPointsToUnbond + ); + // instead: + assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + + // then + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 0); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 10); + assert_eq!(BondedPool::::get(1).unwrap().points, 0); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 6, 4 => 4) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 6, balance: 6 }, + 4 => UnbondPool { points: 4, balance: 4 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }] + ); + }); + } + + #[test] + fn partial_unbond_max_chunks() { + ExtBuilder::default().ed(1).build_and_execute(|| { + // so the depositor can leave, just keeps the test simpler. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + MaxUnbonding::set(2); + + // given + assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); + CurrentEra::set(1); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 2, 4 => 3) + ); + + // when + CurrentEra::set(2); + assert_err!( + frame_support::storage::in_storage_layer(|| Pools::unbond( + Origin::signed(10), + 10, + 4 + )), + Error::::MaxUnbondingLimit + ); + + // when + MaxUnbonding::set(3); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 2, 4 => 3, 5 => 1) + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } + ] + ); + }) + } + + // depositor can unbond inly up to `MinCreateBond`. + #[test] + fn depositor_permissioned_partial_unbond() { + ExtBuilder::default().ed(1).build_and_execute(|| { + // given + assert_eq!(MinCreateBond::::get(), 2); + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); + + // can unbond a bit.. + assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 7); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 3); + + // but not less than 2 + assert_noop!( + Pools::unbond(Origin::signed(10), 10, 6), + Error::::NotOnlyPoolMember + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } + ] + ); + }); + } + + // same as above, but the pool is slashed and therefore the depositor cannot partially unbond. + #[test] + fn depositor_permissioned_partial_unbond_slashed() { + ExtBuilder::default().ed(1).build_and_execute(|| { + // given + assert_eq!(MinCreateBond::::get(), 2); + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 10); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 0); + + // slash the default pool + StakingMock::set_bonded_balance(Pools::create_bonded_account(1), 5); + + // cannot unbond even 7, because the value of shares is now less. + assert_noop!( + Pools::unbond(Origin::signed(10), 10, 7), + Error::::NotOnlyPoolMember + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + ] + ); + }); + } + + #[test] + fn every_unbonding_triggers_payout() { + ExtBuilder::default().build_and_execute(|| { + let initial_reward_account = Balances::free_balance(Pools::create_reward_account(1)); + assert_eq!(initial_reward_account, Balances::minimum_balance()); + assert_eq!(initial_reward_account, 5); + + // set the pool to destroying so that depositor can leave. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + Balances::make_free_balance_be( + &Pools::create_reward_account(1), + 2 * Balances::minimum_balance(), + ); + + assert_ok!(Pools::unbond(Origin::signed(10), 10, 2)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + // exactly equal to ed, all that can be claimed. + Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, + Event::Unbonded { member: 10, pool_id: 1, points: 2, balance: 2 } + ] + ); + + CurrentEra::set(1); + Balances::make_free_balance_be( + &Pools::create_reward_account(1), + 2 * Balances::minimum_balance(), + ); + + assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + assert_eq!( + pool_events_since_last_call(), + vec![ + // exactly equal to ed, all that can be claimed. + Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 } + ] + ); + + CurrentEra::set(2); + Balances::make_free_balance_be( + &Pools::create_reward_account(1), + 2 * Balances::minimum_balance(), + ); + + assert_ok!(Pools::unbond(Origin::signed(10), 10, 5)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 5 }, + Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 } + ] + ); + + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 2, 4 => 3, 5 => 5) + ); + }); + } +} + +mod pool_withdraw_unbonded { + use super::*; + + #[test] + fn pool_withdraw_unbonded_works() { + ExtBuilder::default().build_and_execute(|| { + // Given 10 unbond'ed directly against the pool account + assert_ok!(StakingMock::unbond(default_bonded_account(), 5)); + // and the pool account only has 10 balance + assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); + assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(10)); + assert_eq!(Balances::free_balance(&default_bonded_account()), 10); + + // When + assert_ok!(Pools::pool_withdraw_unbonded(Origin::signed(10), 1, 0)); + + // Then there unbonding balance is no longer locked + assert_eq!(StakingMock::active_stake(&default_bonded_account()), Some(5)); + assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(5)); + assert_eq!(Balances::free_balance(&default_bonded_account()), 10); + }); + } +} + +mod withdraw_unbonded { + use super::*; + use frame_support::bounded_btree_map; + + #[test] + fn withdraw_unbonded_works_against_slashed_no_era_sub_pool() { + ExtBuilder::default() + .add_members(vec![(40, 40), (550, 550)]) + .build_and_execute(|| { + // reduce the noise a bit. + let _ = balances_events_since_last_call(); + + // Given + assert_eq!(StakingMock::bonding_duration(), 3); + assert_ok!(Pools::fully_unbond(Origin::signed(550), 550)); + assert_ok!(Pools::fully_unbond(Origin::signed(40), 40)); + assert_eq!(Balances::free_balance(&default_bonded_account()), 600); + + let mut current_era = 1; + CurrentEra::set(current_era); + + let mut sub_pools = SubPoolsStorage::::get(1).unwrap(); + let unbond_pool = sub_pools.with_era.get_mut(&3).unwrap(); + // Sanity check + assert_eq!(*unbond_pool, UnbondPool { points: 550 + 40, balance: 550 + 40 }); + + // Simulate a slash to the pool with_era(current_era), decreasing the balance by + // half + { + unbond_pool.balance /= 2; // 295 + SubPoolsStorage::::insert(1, sub_pools); + // Update the equivalent of the unbonding chunks for the `StakingMock` + let mut x = UnbondingBalanceMap::get(); + *x.get_mut(&default_bonded_account()).unwrap() /= 5; + UnbondingBalanceMap::set(&x); + Balances::make_free_balance_be( + &default_bonded_account(), + Balances::free_balance(&default_bonded_account()) / 2, // 300 + ); + StakingMock::set_bonded_balance( + default_bonded_account(), + StakingMock::active_stake(&default_bonded_account()).unwrap() / 2, + ); + }; + + // Advance the current_era to ensure all `with_era` pools will be merged into + // `no_era` pool + current_era += TotalUnbondingPools::::get(); + CurrentEra::set(current_era); + + // Simulate some other call to unbond that would merge `with_era` pools into + // `no_era` + let sub_pools = + SubPoolsStorage::::get(1).unwrap().maybe_merge_pools(current_era); + SubPoolsStorage::::insert(1, sub_pools); + + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: UnbondPool { points: 550 + 40, balance: 275 + 20 }, + with_era: Default::default() + } + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::Unbonded { member: 550, pool_id: 1, points: 550, balance: 550 }, + Event::Unbonded { member: 40, pool_id: 1, points: 40, balance: 40 }, + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::BalanceSet { + who: default_bonded_account(), + free: 300, + reserved: 0 + }] + ); + + // When + assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); + + // Then + assert_eq!( + SubPoolsStorage::::get(1).unwrap().no_era, + UnbondPool { points: 40, balance: 20 } + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 550 }, + Event::MemberRemoved { pool_id: 1, member: 550 } + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 }] + ); + + // When + assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); + + // Then + assert_eq!( + SubPoolsStorage::::get(1).unwrap().no_era, + UnbondPool { points: 0, balance: 0 } + ); + assert!(!PoolMembers::::contains_key(40)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 40 }, + Event::MemberRemoved { pool_id: 1, member: 40 } + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 }] + ); + + // now, finally, the depositor can take out its share. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(10)); + + current_era += 3; + CurrentEra::set(current_era); + + // when + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Unbonded { member: 10, pool_id: 1, balance: 5, points: 5 }, + Event::Withdrawn { member: 10, pool_id: 1, balance: 5, points: 5 }, + Event::MemberRemoved { pool_id: 1, member: 10 }, + Event::Destroyed { pool_id: 1 } + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![ + BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, + BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } + ] + ); + }); + } + + #[test] + fn withdraw_unbonded_works_against_slashed_with_era_sub_pools() { + ExtBuilder::default() + .add_members(vec![(40, 40), (550, 550)]) + .build_and_execute(|| { + let _ = balances_events_since_last_call(); + + // Given + // current bond is 600, we slash it all to 300. + StakingMock::set_bonded_balance(default_bonded_account(), 300); + Balances::make_free_balance_be(&default_bonded_account(), 300); + assert_eq!(StakingMock::total_stake(&default_bonded_account()), Some(300)); + + assert_ok!(fully_unbond_permissioned(40)); + assert_ok!(fully_unbond_permissioned(550)); + + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2 + 40 / 2, balance: 550 / 2 + 40 / 2 + }} + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, + Event::Bonded { member: 550, pool_id: 1, bonded: 550, joined: true }, + Event::Unbonded { member: 40, pool_id: 1, balance: 20, points: 20 }, + Event::Unbonded { member: 550, pool_id: 1, balance: 275, points: 275 }, + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::BalanceSet { + who: default_bonded_account(), + free: 300, + reserved: 0 + },] + ); + + CurrentEra::set(StakingMock::bonding_duration()); + + // When + assert_ok!(Pools::withdraw_unbonded(Origin::signed(40), 40, 0)); + + // Then + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 40, amount: 20 },] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 40, pool_id: 1, balance: 20, points: 20 }, + Event::MemberRemoved { pool_id: 1, member: 40 } + ] + ); + + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 3 => UnbondPool { points: 550 / 2, balance: 550 / 2 }} + ); + + // When + assert_ok!(Pools::withdraw_unbonded(Origin::signed(550), 550, 0)); + + // Then + assert_eq!( + balances_events_since_last_call(), + vec![BEvent::Transfer { from: default_bonded_account(), to: 550, amount: 275 },] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 550, pool_id: 1, balance: 275, points: 275 }, + Event::MemberRemoved { pool_id: 1, member: 550 } + ] + ); + assert!(SubPoolsStorage::::get(&1).unwrap().with_era.is_empty()); + + // now, finally, the depositor can take out its share. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(fully_unbond_permissioned(10)); + + // because everyone else has left, the points + assert_eq!( + SubPoolsStorage::::get(&1).unwrap().with_era, + unbonding_pools_with_era! { 6 => UnbondPool { points: 5, balance: 5 }} + ); + + CurrentEra::set(CurrentEra::get() + 3); + + // when + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + // then + assert_eq!(Balances::free_balance(&10), 10 + 5); + assert_eq!(Balances::free_balance(&default_bonded_account()), 0); + + // in this test 10 also gets a fair share of the slash, because the slash was + // applied to the bonded account. + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Unbonded { member: 10, pool_id: 1, points: 5, balance: 5 }, + Event::Withdrawn { member: 10, pool_id: 1, points: 5, balance: 5 }, + Event::MemberRemoved { pool_id: 1, member: 10 }, + Event::Destroyed { pool_id: 1 } + ] + ); + assert_eq!( + balances_events_since_last_call(), + vec![ + BEvent::Transfer { from: default_bonded_account(), to: 10, amount: 5 }, + BEvent::Transfer { from: default_reward_account(), to: 10, amount: 5 } + ] + ); + }); + } + + #[test] + fn withdraw_unbonded_handles_faulty_sub_pool_accounting() { + ExtBuilder::default().build_and_execute(|| { + // Given + assert_eq!(Balances::minimum_balance(), 5); + assert_eq!(Balances::free_balance(&10), 5); + assert_eq!(Balances::free_balance(&default_bonded_account()), 10); + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(Pools::fully_unbond(Origin::signed(10), 10)); + + // Simulate a slash that is not accounted for in the sub pools. + Balances::make_free_balance_be(&default_bonded_account(), 5); + assert_eq!( + SubPoolsStorage::::get(1).unwrap().with_era, + //------------------------------balance decrease is not account for + unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 } } + ); + + CurrentEra::set(0 + 3); + + // When + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + // Then + assert_eq!(Balances::free_balance(10), 10 + 5); + assert_eq!(Balances::free_balance(&default_bonded_account()), 0); + }); + } + + #[test] + fn withdraw_unbonded_errors_correctly() { + ExtBuilder::default().with_check(0).build_and_execute(|| { + // Insert the sub-pool + let sub_pools = SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { 0 + 3 => UnbondPool { points: 10, balance: 10 }}, + }; + SubPoolsStorage::::insert(1, sub_pools.clone()); + + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(11), 11, 0), + Error::::PoolMemberNotFound + ); + + let mut member = PoolMember { pool_id: 1, points: 10, ..Default::default() }; + PoolMembers::::insert(11, member.clone()); + + // Simulate calling `unbond` + member.unbonding_eras = member_unbonding_eras!(3 + 0 => 10); + PoolMembers::::insert(11, member.clone()); + + // We are still in the bonding duration + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(11), 11, 0), + Error::::CannotWithdrawAny + ); + + // If we error the member does not get removed + assert_eq!(PoolMembers::::get(&11), Some(member)); + // and the sub pools do not get updated. + assert_eq!(SubPoolsStorage::::get(1).unwrap(), sub_pools) + }); + } + + #[test] + fn withdraw_unbonded_kick() { + ExtBuilder::default() + .add_members(vec![(100, 100), (200, 200)]) + .build_and_execute(|| { + // Given + assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); + assert_ok!(Pools::fully_unbond(Origin::signed(200), 200)); + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + points: 10, + state: PoolState::Open, + member_counter: 3, + roles: DEFAULT_ROLES + } + } + ); + CurrentEra::set(StakingMock::bonding_duration()); + + // Cannot kick when pool is open + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(902), 100, 0), + Error::::NotKickerOrDestroying + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, + Event::Bonded { member: 200, pool_id: 1, bonded: 200, joined: true }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::Unbonded { member: 200, pool_id: 1, points: 200, balance: 200 } + ] + ); + + // Given + unsafe_set_state(1, PoolState::Blocked).unwrap(); + + // Cannot kick as a nominator + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(901), 100, 0), + Error::::NotKickerOrDestroying + ); + + // Can kick as root + assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 100, 0)); + + // Can kick as state toggler + assert_ok!(Pools::withdraw_unbonded(Origin::signed(900), 200, 0)); + + assert_eq!(Balances::free_balance(100), 100 + 100); + assert_eq!(Balances::free_balance(200), 200 + 200); + assert!(!PoolMembers::::contains_key(100)); + assert!(!PoolMembers::::contains_key(200)); + assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::MemberRemoved { pool_id: 1, member: 100 }, + Event::Withdrawn { member: 200, pool_id: 1, points: 200, balance: 200 }, + Event::MemberRemoved { pool_id: 1, member: 200 } + ] + ); + }); + } + + #[test] + fn withdraw_unbonded_destroying_permissionless() { + ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { + // Given + assert_ok!(Pools::fully_unbond(Origin::signed(100), 100)); + assert_eq!( + BondedPool::::get(1).unwrap(), + BondedPool { + id: 1, + inner: BondedPoolInner { + points: 10, + state: PoolState::Open, + member_counter: 2, + roles: DEFAULT_ROLES, + } + } + ); + CurrentEra::set(StakingMock::bonding_duration()); + assert_eq!(Balances::free_balance(100), 100); + + // Cannot permissionlessly withdraw + assert_noop!( + Pools::fully_unbond(Origin::signed(420), 100), + Error::::NotKickerOrDestroying + ); + + // Given + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // Can permissionlesly withdraw a member that is not the depositor + assert_ok!(Pools::withdraw_unbonded(Origin::signed(420), 100, 0)); + + assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default(),); + assert_eq!(Balances::free_balance(100), 100 + 100); + assert!(!PoolMembers::::contains_key(100)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, + Event::Unbonded { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 100, balance: 100 }, + Event::MemberRemoved { pool_id: 1, member: 100 } + ] + ); + }); + } + + #[test] + fn partial_withdraw_unbonded_depositor() { + ExtBuilder::default().ed(1).build_and_execute(|| { + // so the depositor can leave, just keeps the test simpler. + unsafe_set_state(1, PoolState::Destroying).unwrap(); + + // given + assert_ok!(Pools::unbond(Origin::signed(10), 10, 6)); + CurrentEra::set(1); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 1)); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 6, 4 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 6, balance: 6 }, + 4 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!(PoolMembers::::get(10).unwrap().active_points(), 3); + assert_eq!(PoolMembers::::get(10).unwrap().unbonding_points(), 7); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 6, balance: 6 }, + Event::Unbonded { member: 10, pool_id: 1, points: 1, balance: 1 } + ] + ); + + // when + CurrentEra::set(2); + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(10), 10, 0), + Error::::CannotWithdrawAny + ); + + // when + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + // then + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(4 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 4 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Withdrawn { member: 10, pool_id: 1, points: 6, balance: 6 }] + ); + + // when + CurrentEra::set(4); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + // then + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!() + ); + assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Withdrawn { member: 10, pool_id: 1, points: 1, balance: 1 },] + ); + + // when repeating: + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(10), 10, 0), + Error::::CannotWithdrawAny + ); + }); + } + + #[test] + fn partial_withdraw_unbonded_non_depositor() { + ExtBuilder::default().add_members(vec![(11, 10)]).build_and_execute(|| { + // given + assert_ok!(Pools::unbond(Origin::signed(11), 11, 6)); + CurrentEra::set(1); + assert_ok!(Pools::unbond(Origin::signed(11), 11, 1)); + assert_eq!( + PoolMembers::::get(11).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 6, 4 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 3 => UnbondPool { points: 6, balance: 6 }, + 4 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!(PoolMembers::::get(11).unwrap().active_points(), 3); + assert_eq!(PoolMembers::::get(11).unwrap().unbonding_points(), 7); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 11, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 11, pool_id: 1, points: 6, balance: 6 }, + Event::Unbonded { member: 11, pool_id: 1, points: 1, balance: 1 } + ] + ); + + // when + CurrentEra::set(2); + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(11), 11, 0), + Error::::CannotWithdrawAny + ); + + // when + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); + + // then + assert_eq!( + PoolMembers::::get(11).unwrap().unbonding_eras, + member_unbonding_eras!(4 => 1) + ); + assert_eq!( + SubPoolsStorage::::get(1).unwrap(), + SubPools { + no_era: Default::default(), + with_era: unbonding_pools_with_era! { + 4 => UnbondPool { points: 1, balance: 1 } + } + } + ); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Withdrawn { member: 11, pool_id: 1, points: 6, balance: 6 }] + ); + + // when + CurrentEra::set(4); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(11), 11, 0)); + + // then + assert_eq!( + PoolMembers::::get(11).unwrap().unbonding_eras, + member_unbonding_eras!() + ); + assert_eq!(SubPoolsStorage::::get(1).unwrap(), Default::default()); + assert_eq!( + pool_events_since_last_call(), + vec![Event::Withdrawn { member: 11, pool_id: 1, points: 1, balance: 1 }] + ); + + // when repeating: + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(11), 11, 0), + Error::::CannotWithdrawAny + ); + }); + } + + #[test] + fn full_multi_step_withdrawing_non_depositor() { + ExtBuilder::default().add_members(vec![(100, 100)]).build_and_execute(|| { + // given + assert_ok!(Pools::unbond(Origin::signed(100), 100, 75)); + assert_eq!( + PoolMembers::::get(100).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 75) + ); + + // progress one era and unbond the leftover. + CurrentEra::set(1); + assert_ok!(Pools::unbond(Origin::signed(100), 100, 25)); + assert_eq!( + PoolMembers::::get(100).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 75, 4 => 25) + ); + + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(100), 100, 0), + Error::::CannotWithdrawAny + ); + + // now the 75 should be free. + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 100, pool_id: 1, bonded: 100, joined: true }, + Event::Unbonded { member: 100, pool_id: 1, points: 75, balance: 75 }, + Event::Unbonded { member: 100, pool_id: 1, points: 25, balance: 25 }, + Event::Withdrawn { member: 100, pool_id: 1, points: 75, balance: 75 }, + ] + ); + assert_eq!( + PoolMembers::::get(100).unwrap().unbonding_eras, + member_unbonding_eras!(4 => 25) + ); + + // the 25 should be free now, and the member removed. + CurrentEra::set(4); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(100), 100, 0)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 100, pool_id: 1, points: 25, balance: 25 }, + Event::MemberRemoved { pool_id: 1, member: 100 } + ] + ); + }) + } + + #[test] + fn full_multi_step_withdrawing_depositor() { + ExtBuilder::default().ed(1).build_and_execute(|| { + // given + assert_ok!(Pools::unbond(Origin::signed(10), 10, 7)); + + // progress one era and unbond the leftover. + CurrentEra::set(1); + unsafe_set_state(1, PoolState::Destroying).unwrap(); + assert_ok!(Pools::unbond(Origin::signed(10), 10, 3)); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(3 => 7, 4 => 3) + ); + + assert_noop!( + Pools::withdraw_unbonded(Origin::signed(10), 10, 0), + Error::::CannotWithdrawAny + ); + + // now the 7 should be free. + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Unbonded { member: 10, pool_id: 1, points: 7, balance: 7 }, + Event::Unbonded { member: 10, pool_id: 1, points: 3, balance: 3 }, + Event::Withdrawn { member: 10, pool_id: 1, points: 7, balance: 7 } + ] + ); + assert_eq!( + PoolMembers::::get(10).unwrap().unbonding_eras, + member_unbonding_eras!(4 => 3) + ); + + // the 25 should be free now, and the member removed. + CurrentEra::set(4); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Withdrawn { member: 10, pool_id: 1, points: 3, balance: 3 }, + Event::MemberRemoved { pool_id: 1, member: 10 }, + // the pool is also destroyed now. + Event::Destroyed { pool_id: 1 }, + ] + ); + }) + } +} + +mod create { + use super::*; + + #[test] + fn create_works() { + ExtBuilder::default().build_and_execute(|| { + // next pool id is 2. + let next_pool_stash = Pools::create_bonded_account(2); + let ed = Balances::minimum_balance(); + + assert!(!BondedPools::::contains_key(2)); + assert!(!RewardPools::::contains_key(2)); + assert!(!PoolMembers::::contains_key(11)); + assert_eq!(StakingMock::active_stake(&next_pool_stash), None); + + Balances::make_free_balance_be(&11, StakingMock::minimum_bond() + ed); + assert_ok!(Pools::create( + Origin::signed(11), + StakingMock::minimum_bond(), + 123, + 456, + 789 + )); + + assert_eq!(Balances::free_balance(&11), 0); + assert_eq!( + PoolMembers::::get(11).unwrap(), + PoolMember { + pool_id: 2, + points: StakingMock::minimum_bond(), + ..Default::default() + } + ); + assert_eq!( + BondedPool::::get(2).unwrap(), + BondedPool { + id: 2, + inner: BondedPoolInner { + points: StakingMock::minimum_bond(), + member_counter: 1, + state: PoolState::Open, + roles: PoolRoles { + depositor: 11, + root: Some(123), + nominator: Some(456), + state_toggler: Some(789) + } + } + } + ); + assert_eq!( + StakingMock::active_stake(&next_pool_stash).unwrap(), + StakingMock::minimum_bond() + ); + assert_eq!( + RewardPools::::get(2).unwrap(), + RewardPool { ..Default::default() } + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Created { depositor: 11, pool_id: 2 }, + Event::Bonded { member: 11, pool_id: 2, bonded: 10, joined: true } + ] + ); + }); + } + + #[test] + fn create_errors_correctly() { + ExtBuilder::default().with_check(0).build_and_execute(|| { + assert_noop!( + Pools::create(Origin::signed(10), 420, 123, 456, 789), + Error::::AccountBelongsToOtherPool + ); + + // Given + assert_eq!(MinCreateBond::::get(), 2); + assert_eq!(StakingMock::minimum_bond(), 10); + + // Then + assert_noop!( + Pools::create(Origin::signed(11), 9, 123, 456, 789), + Error::::MinimumBondNotMet + ); + + // Given + MinCreateBond::::put(20); + + // Then + assert_noop!( + Pools::create(Origin::signed(11), 19, 123, 456, 789), + Error::::MinimumBondNotMet + ); + + // Given + BondedPool:: { + id: 2, + inner: BondedPoolInner { + state: PoolState::Open, + points: 10, + member_counter: 1, + roles: DEFAULT_ROLES, + }, + } + .put(); + assert_eq!(MaxPools::::get(), Some(2)); + assert_eq!(BondedPools::::count(), 2); + + // Then + assert_noop!( + Pools::create(Origin::signed(11), 20, 123, 456, 789), + Error::::MaxPools + ); + + // Given + assert_eq!(PoolMembers::::count(), 1); + MaxPools::::put(3); + MaxPoolMembers::::put(1); + Balances::make_free_balance_be(&11, 5 + 20); + + // Then + let create = Call::Pools(crate::Call::::create { + amount: 20, + root: 11, + nominator: 11, + state_toggler: 11, + }); + assert_noop!(create.dispatch(Origin::signed(11)), Error::::MaxPoolMembers); + }); + } +} + +mod nominate { + use super::*; + + #[test] + fn nominate_works() { + ExtBuilder::default().build_and_execute(|| { + // Depositor can't nominate + assert_noop!( + Pools::nominate(Origin::signed(10), 1, vec![21]), + Error::::NotNominator + ); + + // State toggler can't nominate + assert_noop!( + Pools::nominate(Origin::signed(902), 1, vec![21]), + Error::::NotNominator + ); + + // Root can nominate + assert_ok!(Pools::nominate(Origin::signed(900), 1, vec![21])); + assert_eq!(Nominations::get().unwrap(), vec![21]); + + // Nominator can nominate + assert_ok!(Pools::nominate(Origin::signed(901), 1, vec![31])); + assert_eq!(Nominations::get().unwrap(), vec![31]); + + // Can't nominate for a pool that doesn't exist + assert_noop!( + Pools::nominate(Origin::signed(902), 123, vec![21]), + Error::::PoolNotFound + ); + }); + } +} + +mod set_state { + use super::*; + + #[test] + fn set_state_works() { + ExtBuilder::default().build_and_execute(|| { + // Given + assert_ok!(BondedPool::::get(1).unwrap().ok_to_be_open(0)); + + // Only the root and state toggler can change the state when the pool is ok to be open. + assert_noop!( + Pools::set_state(Origin::signed(10), 1, PoolState::Blocked), + Error::::CanNotChangeState + ); + assert_noop!( + Pools::set_state(Origin::signed(901), 1, PoolState::Blocked), + Error::::CanNotChangeState + ); + + // Root can change state + assert_ok!(Pools::set_state(Origin::signed(900), 1, PoolState::Blocked)); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::StateChanged { pool_id: 1, new_state: PoolState::Blocked } + ] + ); + + assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Blocked); + + // State toggler can change state + assert_ok!(Pools::set_state(Origin::signed(902), 1, PoolState::Destroying)); + assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + + // If the pool is destroying, then no one can set state + assert_noop!( + Pools::set_state(Origin::signed(900), 1, PoolState::Blocked), + Error::::CanNotChangeState + ); + assert_noop!( + Pools::set_state(Origin::signed(902), 1, PoolState::Blocked), + Error::::CanNotChangeState + ); + + // If the pool is not ok to be open, then anyone can set it to destroying + + // Given + unsafe_set_state(1, PoolState::Open).unwrap(); + let mut bonded_pool = BondedPool::::get(1).unwrap(); + bonded_pool.points = 100; + bonded_pool.put(); + // When + assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); + // Then + assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + + // Given + Balances::make_free_balance_be(&default_bonded_account(), Balance::max_value() / 10); + unsafe_set_state(1, PoolState::Open).unwrap(); + // When + assert_ok!(Pools::set_state(Origin::signed(11), 1, PoolState::Destroying)); + // Then + assert_eq!(BondedPool::::get(1).unwrap().state, PoolState::Destroying); + + // If the pool is not ok to be open, it cannot be permissionleslly set to a state that + // isn't destroying + unsafe_set_state(1, PoolState::Open).unwrap(); + assert_noop!( + Pools::set_state(Origin::signed(11), 1, PoolState::Blocked), + Error::::CanNotChangeState + ); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, + Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, + Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying } + ] + ); + }); + } +} + +mod set_metadata { + use super::*; + + #[test] + fn set_metadata_works() { + ExtBuilder::default().build_and_execute(|| { + // Root can set metadata + assert_ok!(Pools::set_metadata(Origin::signed(900), 1, vec![1, 1])); + assert_eq!(Metadata::::get(1), vec![1, 1]); + + // State toggler can set metadata + assert_ok!(Pools::set_metadata(Origin::signed(902), 1, vec![2, 2])); + assert_eq!(Metadata::::get(1), vec![2, 2]); + + // Depositor can't set metadata + assert_noop!( + Pools::set_metadata(Origin::signed(10), 1, vec![3, 3]), + Error::::DoesNotHavePermission + ); + + // Nominator can't set metadata + assert_noop!( + Pools::set_metadata(Origin::signed(901), 1, vec![3, 3]), + Error::::DoesNotHavePermission + ); + + // Metadata cannot be longer than `MaxMetadataLen` + assert_noop!( + Pools::set_metadata(Origin::signed(900), 1, vec![1, 1, 1]), + Error::::MetadataExceedsMaxLen + ); + }); + } +} + +mod set_configs { + use super::*; + + #[test] + fn set_configs_works() { + ExtBuilder::default().build_and_execute(|| { + // Setting works + assert_ok!(Pools::set_configs( + Origin::root(), + ConfigOp::Set(1 as Balance), + ConfigOp::Set(2 as Balance), + ConfigOp::Set(3u32), + ConfigOp::Set(4u32), + ConfigOp::Set(5u32), + )); + assert_eq!(MinJoinBond::::get(), 1); + assert_eq!(MinCreateBond::::get(), 2); + assert_eq!(MaxPools::::get(), Some(3)); + assert_eq!(MaxPoolMembers::::get(), Some(4)); + assert_eq!(MaxPoolMembersPerPool::::get(), Some(5)); + + // Noop does nothing + assert_storage_noop!(assert_ok!(Pools::set_configs( + Origin::root(), + ConfigOp::Noop, + ConfigOp::Noop, + ConfigOp::Noop, + ConfigOp::Noop, + ConfigOp::Noop, + ))); + + // Removing works + assert_ok!(Pools::set_configs( + Origin::root(), + ConfigOp::Remove, + ConfigOp::Remove, + ConfigOp::Remove, + ConfigOp::Remove, + ConfigOp::Remove, + )); + assert_eq!(MinJoinBond::::get(), 0); + assert_eq!(MinCreateBond::::get(), 0); + assert_eq!(MaxPools::::get(), None); + assert_eq!(MaxPoolMembers::::get(), None); + assert_eq!(MaxPoolMembersPerPool::::get(), None); + }); + } +} + +mod bond_extra { + use super::*; + use crate::Event; + + #[test] + fn bond_extra_from_free_balance_creator() { + ExtBuilder::default().build_and_execute(|| { + // 10 is the owner and a member in pool 1, give them some more funds. + Balances::make_free_balance_be(&10, 100); + + // given + assert_eq!(PoolMembers::::get(10).unwrap().points, 10); + assert_eq!(BondedPools::::get(1).unwrap().points, 10); + assert_eq!(Balances::free_balance(10), 100); + + // when + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); + + // then + assert_eq!(Balances::free_balance(10), 90); + assert_eq!(PoolMembers::::get(10).unwrap().points, 20); + assert_eq!(BondedPools::::get(1).unwrap().points, 20); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false } + ] + ); + + // when + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(20))); + + // then + assert_eq!(Balances::free_balance(10), 70); + assert_eq!(PoolMembers::::get(10).unwrap().points, 40); + assert_eq!(BondedPools::::get(1).unwrap().points, 40); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::Bonded { member: 10, pool_id: 1, bonded: 20, joined: false }] + ); + }) + } + + #[test] + fn bond_extra_from_rewards_creator() { + ExtBuilder::default().build_and_execute(|| { + // put some money in the reward account, all of which will belong to 10 as the only + // member of the pool. + Balances::make_free_balance_be(&default_reward_account(), 7); + // ... if which only 2 is claimable to make sure the reward account does not die. + let claimable_reward = 7 - ExistentialDeposit::get(); + + // given + assert_eq!(PoolMembers::::get(10).unwrap().points, 10); + assert_eq!(BondedPools::::get(1).unwrap().points, 10); + assert_eq!(Balances::free_balance(10), 5); + + // when + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); + + // then + assert_eq!(Balances::free_balance(10), 5); + assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + claimable_reward); + assert_eq!(BondedPools::::get(1).unwrap().points, 10 + claimable_reward); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: claimable_reward }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: claimable_reward, + joined: false + } + ] + ); + }) + } + + #[test] + fn bond_extra_from_rewards_joiner() { + ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { + // put some money in the reward account, all of which will belong to 10 as the only + // member of the pool. + Balances::make_free_balance_be(&default_reward_account(), 8); + // ... if which only 3 is claimable to make sure the reward account does not die. + let claimable_reward = 8 - ExistentialDeposit::get(); + // NOTE: easier to read of we use 3, so let's use the number instead of variable. + assert_eq!(claimable_reward, 3, "test is correct if rewards are divisible by 3"); + + // given + assert_eq!(PoolMembers::::get(10).unwrap().points, 10); + assert_eq!(PoolMembers::::get(20).unwrap().points, 20); + assert_eq!(BondedPools::::get(1).unwrap().points, 30); + assert_eq!(Balances::free_balance(10), 5); + assert_eq!(Balances::free_balance(20), 20); + + // when + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::Rewards)); + + // then + assert_eq!(Balances::free_balance(10), 5); + // 10's share of the reward is 1/3, since they gave 10/30 of the total shares. + assert_eq!(PoolMembers::::get(10).unwrap().points, 10 + 1); + assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 1); + + // when + assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::Rewards)); + + // then + assert_eq!(Balances::free_balance(20), 20); + // 20's share of the rewards is the other 2/3 of the rewards, since they have 20/30 of + // the shares + assert_eq!(PoolMembers::::get(20).unwrap().points, 20 + 2); + assert_eq!(BondedPools::::get(1).unwrap().points, 30 + 3); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 1, joined: false }, + Event::PaidOut { member: 20, pool_id: 1, payout: 2 }, + Event::Bonded { member: 20, pool_id: 1, bonded: 2, joined: false } + ] + ); + }) + } +} + +mod update_roles { + use super::*; + + #[test] + fn update_roles_works() { + ExtBuilder::default().build_and_execute(|| { + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { + depositor: 10, + root: Some(900), + nominator: Some(901), + state_toggler: Some(902) + }, + ); + + // non-existent pools + assert_noop!( + Pools::update_roles( + Origin::signed(1), + 2, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), + Error::::PoolNotFound, + ); + + // depositor cannot change roles. + assert_noop!( + Pools::update_roles( + Origin::signed(1), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), + Error::::DoesNotHavePermission, + ); + + // nominator cannot change roles. + assert_noop!( + Pools::update_roles( + Origin::signed(901), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), + Error::::DoesNotHavePermission, + ); + // state-toggler + assert_noop!( + Pools::update_roles( + Origin::signed(902), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + ), + Error::::DoesNotHavePermission, + ); + + // but root can + assert_ok!(Pools::update_roles( + Origin::signed(900), + 1, + ConfigOp::Set(5), + ConfigOp::Set(6), + ConfigOp::Set(7) + )); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::RolesUpdated { + root: Some(5), + state_toggler: Some(7), + nominator: Some(6) + } + ] + ); + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { + depositor: 10, + root: Some(5), + nominator: Some(6), + state_toggler: Some(7) + }, + ); + + // also root origin can + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(1), + ConfigOp::Set(2), + ConfigOp::Set(3) + )); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::RolesUpdated { + root: Some(1), + state_toggler: Some(3), + nominator: Some(2) + }] + ); + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { + depositor: 10, + root: Some(1), + nominator: Some(2), + state_toggler: Some(3) + }, + ); + + // Noop works + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(11), + ConfigOp::Noop, + ConfigOp::Noop + )); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::RolesUpdated { + root: Some(11), + state_toggler: Some(3), + nominator: Some(2) + }] + ); + + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { + depositor: 10, + root: Some(11), + nominator: Some(2), + state_toggler: Some(3) + }, + ); + + // Remove works + assert_ok!(Pools::update_roles( + Origin::root(), + 1, + ConfigOp::Set(69), + ConfigOp::Remove, + ConfigOp::Remove + )); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::RolesUpdated { root: Some(69), state_toggler: None, nominator: None }] + ); + + assert_eq!( + BondedPools::::get(1).unwrap().roles, + PoolRoles { depositor: 10, root: Some(69), nominator: None, state_toggler: None }, + ); + }) + } +} From 723574b0e94c991fe8f5fe602e0a8470b595ded9 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 14 Jun 2022 16:19:27 +0100 Subject: [PATCH 32/65] ALL new tests work now --- frame/nomination-pools/src/lib.rs | 17 +- frame/nomination-pools/src/tests.rs | 1477 ++++++++++++++------------- 2 files changed, 801 insertions(+), 693 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index a3794baf24c27..8979bb097359a 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -921,7 +921,7 @@ impl BondedPool { /// A reward pool. #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound)] -#[cfg_attr(feature = "std", derive(Clone, PartialEq, frame_support::DefaultNoBound))] +#[cfg_attr(feature = "std", derive(Clone, PartialEq, DefaultNoBound))] #[codec(mel_bound(T: Config))] #[scale_info(skip_type_params(T))] pub struct RewardPool { @@ -1416,10 +1416,8 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; - let current_reward_counter = - reward_pool.current_reward_counter(pool_id, bonded_pool.points); - // reward pool records must be updated with the old points. + // IMPORTANT: reward pool records must be updated with the old points. reward_pool.update_records(pool_id, bonded_pool.points); bonded_pool.try_inc_members()?; @@ -1430,7 +1428,9 @@ pub mod pallet { PoolMember:: { pool_id, points: points_issued, - last_recorded_reward_counter: current_reward_counter, + // we just updated `last_known_reward_counter` to the current one in + // `update_recorded`. + last_recorded_reward_counter: reward_pool.last_recorded_reward_counter, unbonding_eras: Default::default(), }, ); @@ -1464,8 +1464,10 @@ pub mod pallet { let (mut member, mut bonded_pool, mut reward_pool) = Self::get_member_with_pools(&who)?; // payout related stuff: we must claim the payouts, and updated recorded payout data - // before going further. + // before updating the bonded pool points, similar to that of `join` transaction. reward_pool.update_records(bonded_pool.id, bonded_pool.points); + // TODO: optimize this to not touch the free balance of `who ` at all in benchmarks. + // Currently, bonding rewards is like a batch. let claimed = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; @@ -1475,6 +1477,7 @@ pub mod pallet { BondExtra::Rewards => (bonded_pool.try_bond_funds(&who, claimed, BondType::Later)?, claimed), }; + bonded_pool.ok_to_be_open(bonded)?; member.points = member.points.saturating_add(points_issued); @@ -1834,10 +1837,12 @@ pub mod pallet { }, ); ReversePoolIdLookup::::insert(bonded_pool.bonded_account(), pool_id); + Self::deposit_event(Event::::Created { depositor: who.clone(), pool_id: pool_id.clone(), }); + Self::deposit_event(Event::::Bonded { member: who, pool_id, diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 748a073905b10..044499408f600 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -39,332 +39,6 @@ macro_rules! member_unbonding_eras { pub const DEFAULT_ROLES: PoolRoles = PoolRoles { depositor: 10, root: Some(900), nominator: Some(901), state_toggler: Some(902) }; -#[test] -fn rewards_distribution_is_fair_basic() { - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 10).unwrap(); - - Balances::make_free_balance_be(&20, ed + 10); - assert_ok!(Pools::join(Origin::signed(20), 10, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); - - // 10 should claim 10, 20 should claim nothing. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, - ] - ); - - // any upcoming rewards are shared equally. - Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, - ] - ); - }); -} - -#[test] -fn rewards_distribution_is_fair_basic_with_fractions() { - // basically checks the case where the amount of rewards is less than the pool shares. for this, - // we have to rely on fixed point arithmetic. - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 3).unwrap(); - - Balances::make_free_balance_be(&20, ed + 10); - assert_ok!(Pools::join(Origin::signed(20), 10, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap(); - - // 10 should claim 10, 20 should claim nothing. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, - ] - ); - - // any upcoming rewards are shared equally. - Balances::mutate_account(&default_reward_account(), |f| f.free += 8).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 4 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 4 }, - ] - ); - - // uneven upcoming rewards are shared equally, rounded down. - Balances::mutate_account(&default_reward_account(), |f| f.free += 7).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, - ] - ); - }); -} - -#[test] -fn rewards_distribution_is_fair_3() { - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); - - Balances::make_free_balance_be(&20, ed + 10); - assert_ok!(Pools::join(Origin::signed(20), 10, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); - - Balances::make_free_balance_be(&30, ed + 10); - assert_ok!(Pools::join(Origin::signed(30), 10, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); - - // 10 should claim 10, 20 should claim nothing. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - assert_ok!(Pools::claim_payout(Origin::signed(30))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, - ] - ); - - // any upcoming rewards are shared equally. - Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - assert_ok!(Pools::claim_payout(Origin::signed(30))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10 }, - ] - ); - }); -} - -#[test] -fn rewards_distribution_is_fair_bond_extra() { - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::make_free_balance_be(&20, ed + 20); - assert_ok!(Pools::join(Origin::signed(20), 20, 1)); - Balances::make_free_balance_be(&30, ed + 20); - assert_ok!(Pools::join(Origin::signed(30), 10, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); - - // everyone claims. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - assert_ok!(Pools::claim_payout(Origin::signed(30))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 10 } - ] - ); - - // 30 now bumps itself to be like 20. - assert_ok!(Pools::bond_extra(Origin::signed(30), BondExtra::FreeBalance(10))); - - // more rewards come in. - Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - assert_ok!(Pools::claim_payout(Origin::signed(30))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, - Event::PaidOut { member: 30, pool_id: 1, payout: 40 } - ] - ); - }); -} - -#[test] -fn rewards_distribution_is_fair_unbond() { - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::make_free_balance_be(&20, ed + 20); - assert_ok!(Pools::join(Origin::signed(20), 20, 1)); - - Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); - - // everyone claims. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 } - ] - ); - - // 30 now bumps itself to be like 20. - assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); - - // more rewards come in. - Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); - - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 }, - Event::PaidOut { member: 10, pool_id: 1, payout: 50 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 50 }, - ] - ); - }); -} - -#[test] -fn unclaimed_reward_is_safe() { - ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - - Balances::make_free_balance_be(&20, ed + 20); - assert_ok!(Pools::join(Origin::signed(20), 20, 1)); - Balances::make_free_balance_be(&30, ed + 20); - assert_ok!(Pools::join(Origin::signed(30), 10, 1)); - - // 10 gets 10, 20 gets 20, 30 gets 10 - Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); - - // some claim. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, - Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 20 } - ] - ); - - // 10 gets 20, 20 gets 40, 30 gets 20 - Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); - - // some claim. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 } - ] - ); - - // 10 gets 20, 20 gets 40, 30 gets 20 - Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); - - // some claim. - assert_ok!(Pools::claim_payout(Origin::signed(10))); - assert_ok!(Pools::claim_payout(Origin::signed(20))); - - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, - Event::PaidOut { member: 20, pool_id: 1, payout: 40 } - ] - ); - - // now 30 claims all at once - assert_ok!(Pools::claim_payout(Origin::signed(30))); - - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 30, pool_id: 1, payout: 10 + 20 + 20 }] - ); - }); -} - -#[test] -fn bond_extra_and_delayed_claim() { - todo!("10 20 join, reward comes, 10 claims, 20 bonds extra, reward comes both claim"); -} - #[test] fn test_setup_works() { ExtBuilder::default().build_and_execute(|| { @@ -999,18 +673,6 @@ mod claim_payout { } } - fn rew_float( - last_recorded_reward_counter: f64, - last_recorded_total_payouts: Balance, - total_rewards_claimed: Balance, - ) -> RewardPool { - RewardPool { - last_recorded_reward_counter: RewardCounter::from_float(last_recorded_reward_counter), - last_recorded_total_payouts, - total_rewards_claimed, - } - } - #[test] fn claim_payout_works() { ExtBuilder::default() @@ -1204,9 +866,8 @@ mod claim_payout { // fully unbond the member. assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(11).unwrap(); + let (mut member, mut bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&11).unwrap(); assert_noop!( Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), @@ -1227,27 +888,24 @@ mod claim_payout { #[test] fn do_reward_payout_works_with_a_pool_of_1() { - let del = |reward_pool_total_earnings| del(10, reward_pool_total_earnings); + let del = |last_recorded_reward_counter| del_float(10, last_recorded_reward_counter); ExtBuilder::default().build_and_execute(|| { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let mut member = PoolMembers::::get(10).unwrap(); + let (mut member, mut bonded_pool, mut reward_pool) = + Pools::get_member_with_pools(&10).unwrap(); let ed = Balances::minimum_balance(); - // Given no rewards have been earned - // When let payout = Pools::do_reward_payout(&10, &mut member, &mut bonded_pool, &mut reward_pool) .unwrap(); // Then assert_eq!(payout, 0); - assert_eq!(member, del(0)); + assert_eq!(member, del(0.0)); assert_eq!(reward_pool, rew(0, 0, 0)); // Given the pool has earned some rewards for the first time - Balances::make_free_balance_be(&default_reward_account(), ed + 5); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 5)); // When let payout = @@ -1255,12 +913,20 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 5); // (10 * 5 del virtual points / 10 * 5 pool points) * 5 pool balance + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 5 } + ] + ); + assert_eq!(payout, 5); assert_eq!(reward_pool, rew(0, 0, 5)); - assert_eq!(member, del(5)); + assert_eq!(member, del(0.5)); // Given the pool has earned rewards again - Balances::make_free_balance_be(&default_reward_account(), ed + 10); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 10)); // When let payout = @@ -1268,9 +934,13 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 10); // (10 * 10 del virtual points / 10 pool points) * 5 pool balance + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + ); + assert_eq!(payout, 10); assert_eq!(reward_pool, rew(0, 0, 15)); - assert_eq!(member, del(15)); + assert_eq!(member, del(1.5)); // Given the pool has earned no new rewards Balances::make_free_balance_be(&default_reward_account(), ed + 0); @@ -1281,9 +951,10 @@ mod claim_payout { .unwrap(); // Then + assert_eq!(pool_events_since_last_call(), vec![]); assert_eq!(payout, 0); assert_eq!(reward_pool, rew(0, 0, 15)); - assert_eq!(member, del(15)); + assert_eq!(member, del(1.5)); }); } @@ -1294,12 +965,9 @@ mod claim_payout { .build_and_execute(|| { let mut bonded_pool = BondedPool::::get(1).unwrap(); let mut reward_pool = RewardPools::::get(1).unwrap(); - let ed = Balances::minimum_balance(); - // PoolMember with 10 points + let mut del_10 = PoolMembers::::get(10).unwrap(); - // PoolMember with 40 points let mut del_40 = PoolMembers::::get(40).unwrap(); - // PoolMember with 50 points let mut del_50 = PoolMembers::::get(50).unwrap(); assert_eq!( @@ -1315,8 +983,9 @@ mod claim_payout { // Given we have a total of 100 points split among the members assert_eq!(del_50.points + del_40.points + del_10.points, 100); assert_eq!(bonded_pool.points, 100); + // and the reward pool has earned 100 in rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 100); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); // When let payout = @@ -1324,11 +993,13 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 10); // (10 del virtual points / 100 pool points) * 100 pool balance - assert_eq!(del_10, del(10, 100)); - assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 10)); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] + ); + assert_eq!(payout, 10); + assert_eq!(del_10, del(10, 1)); + assert_eq!(reward_pool, rew(0, 0, 10)); // When let payout = @@ -1336,19 +1007,13 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 40); // (400 del virtual points / 900 pool points) * 90 pool balance - assert_eq!(del_40, del(40, 100)); assert_eq!( - reward_pool, - rew( - 50, - // old pool points - member virtual points - 9_000 - 100 * 40, - 100 - ) + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] ); - // Mock the reward pool transferring the payout to del_40 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + assert_eq!(payout, 40); + assert_eq!(del_40, del(40, 1)); + assert_eq!(reward_pool, rew(0, 0, 50)); // When let payout = @@ -1356,14 +1021,16 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 50); // (50 del virtual points / 50 pool points) * 50 pool balance - assert_eq!(del_50, del(50, 100)); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + assert_eq!(payout, 50); + assert_eq!(del_50, del(50, 1)); assert_eq!(reward_pool, rew(0, 0, 100)); - // Mock the reward pool transferring the payout to del_50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); // Given the reward pool has some new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 50); + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); // When let payout = @@ -1371,11 +1038,13 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 5); // (500 del virtual points / 5,000 pool points) * 50 pool balance - assert_eq!(del_10, del(10, 150)); - assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); + assert_eq!(payout, 5); + assert_eq!(del_10, del_float(10, 1.5)); + assert_eq!(reward_pool, rew(0, 0, 105)); // When let payout = @@ -1383,14 +1052,16 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 20); // (2,000 del virtual points / 4,500 pool points) * 45 pool balance - assert_eq!(del_40, del(40, 150)); - assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 20)); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] + ); + assert_eq!(payout, 20); + assert_eq!(del_40, del_float(40, 1.5)); + assert_eq!(reward_pool, rew(0, 0, 125)); // Given del_50 hasn't claimed and the reward pools has just earned 50 assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); // When let payout = @@ -1398,22 +1069,13 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 50); // (5,000 del virtual points / 7,5000 pool points) * 75 pool balance - assert_eq!(del_50, del(50, 200)); - assert_eq!( - reward_pool, - rew( - 25, - // old pool points + points from new earnings - del points. - // - // points from new earnings = new earnings(50) * bonded_pool.points(100) - // del points = member.points(50) * new_earnings_since_last_claim (100) - (2_500 + 50 * 100) - 50 * 100, - 200, - ) - ); - // Mock the reward pool transferring the payout to del_50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 50)); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + ); + assert_eq!(payout, 50); + assert_eq!(del_50, del_float(50, 2.0)); + assert_eq!(reward_pool, rew(0, 0, 175)); // When let payout = @@ -1421,15 +1083,16 @@ mod claim_payout { .unwrap(); // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] + ); assert_eq!(payout, 5); - assert_eq!(del_10, del(10, 200)); - assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 5)); + assert_eq!(del_10, del_float(10, 2.0)); + assert_eq!(reward_pool, rew(0, 0, 180)); // Given del_40 hasn't claimed and the reward pool has just earned 400 assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); // When let payout = @@ -1437,26 +1100,16 @@ mod claim_payout { .unwrap(); // Then + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] + ); assert_eq!(payout, 40); - assert_eq!(del_10, del(10, 600)); - assert_eq!( - reward_pool, - rew( - 380, - // old pool points + points from new earnings - del points - // - // points from new earnings = new earnings(400) * bonded_pool.points(100) - // del points = member.points(10) * new_earnings_since_last_claim(400) - (2_000 + 400 * 100) - 10 * 400, - 600 - ) - ); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 40)); + assert_eq!(del_10, del_float(10, 6.0)); + assert_eq!(reward_pool, rew(0, 0, 220)); // Given del_40 + del_50 haven't claimed and the reward pool has earned 20 assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); // When let payout = @@ -1464,11 +1117,9 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 2); // (200 del virtual points / 38,000 pool points) * 400 pool balance - assert_eq!(del_10, del(10, 620)); - assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 2)); + assert_eq!(payout, 2); + assert_eq!(del_10, del_float(10, 6.2)); + assert_eq!(reward_pool, rew(0, 0, 222)); // When let payout = @@ -1476,11 +1127,9 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 188); // (18,800 del virtual points / 39,800 pool points) * 399 pool balance - assert_eq!(del_40, del(40, 620)); - assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); - // Mock the reward pool transferring the payout to del_10 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= 188)); + assert_eq!(payout, 188); // 20 (from the 50) + 160 (from the 400) + 8 (from the 20) + assert_eq!(del_40, del_float(40, 6.2)); + assert_eq!(reward_pool, rew(0, 0, 410)); // When let payout = @@ -1488,306 +1137,760 @@ mod claim_payout { .unwrap(); // Then - assert_eq!(payout, 210); // (21,000 / 21,000) * 210 - assert_eq!(del_50, del(50, 620)); - assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); + assert_eq!(payout, 210); // 200 (from the 400) + 10 (from the 20) + assert_eq!(del_50, del_float(50, 6.2)); + assert_eq!(reward_pool, rew(0, 0, 620)); }); } #[test] - fn do_reward_payout_works() { - ExtBuilder::default() - .add_members(vec![(40, 40), (50, 50)]) - .build_and_execute(|| { - let mut bonded_pool = BondedPool::::get(1).unwrap(); - let mut reward_pool = RewardPools::::get(1).unwrap(); - let ed = Balances::minimum_balance(); + fn rewards_distribution_is_fair_basic() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); - assert_eq!( - pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true } - ] - ); + Balances::mutate_account(&default_reward_account(), |f| f.free += 10).unwrap(); - // Given the bonded pool has 100 points - assert_eq!(bonded_pool.points, 100); - // Each member currently has a free balance of - Balances::make_free_balance_be(&10, 0); - Balances::make_free_balance_be(&40, 0); - Balances::make_free_balance_be(&50, 0); - // and the reward pool has earned 100 in rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 100); + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); - let mut del_10 = PoolMembers::get(10).unwrap(); - let mut del_40 = PoolMembers::get(40).unwrap(); - let mut del_50 = PoolMembers::get(50).unwrap(); + Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 }] - ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + ] + ); - // Expect a payout of 10: (10 del virtual points / 100 pool points) * 100 pool - // balance - assert_eq!(del_10, del(10, 100)); - assert_eq!(reward_pool, rew(90, 100 * 100 - 100 * 10, 100)); - assert_eq!(Balances::free_balance(&10), 10); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 90); + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 40 }] - ); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + ] + ); + }); + } - // Expect payout 40: (400 del virtual points / 900 pool points) * 90 pool balance - assert_eq!(del_40, del(40, 100)); - assert_eq!(reward_pool, rew(50, 9_000 - 100 * 40, 100)); - assert_eq!(Balances::free_balance(&40), 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 50); + #[test] + fn rewards_distribution_is_fair_basic_with_fractions() { + // basically checks the case where the amount of rewards is less than the pool shares. for + // this, we have to rely on fixed point arithmetic. + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); + Balances::mutate_account(&default_reward_account(), |f| f.free += 3).unwrap(); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] - ); + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); - // Expect payout 50: (50 del virtual points / 50 pool points) * 50 pool balance - assert_eq!(del_50, del(50, 100)); - assert_eq!(reward_pool, rew(0, 0, 100)); - assert_eq!(Balances::free_balance(&50), 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); + Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap(); - // Given the reward pool has some new rewards - Balances::make_free_balance_be(&default_reward_account(), ed + 50); + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 3 + 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + ] + ); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 8).unwrap(); - // Expect payout 5: (500 del virtual points / 5,000 pool points) * 50 pool balance - assert_eq!(del_10, del(10, 150)); - assert_eq!(reward_pool, rew(45, 5_000 - 50 * 10, 150)); - assert_eq!(Balances::free_balance(&10), 10 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 45); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 4 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 4 }, + ] + ); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 20 }] - ); + // uneven upcoming rewards are shared equally, rounded down. + Balances::mutate_account(&default_reward_account(), |f| f.free += 7).unwrap(); - // Expect payout 20: (2,000 del virtual points / 4,500 pool points) * 45 pool - // balance - assert_eq!(del_40, del(40, 150)); - assert_eq!(reward_pool, rew(25, 4_500 - 50 * 40, 150)); - assert_eq!(Balances::free_balance(&40), 40 + 20); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // Given del 50 hasn't claimed and the reward pools has just earned 50 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 50)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 75); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 3 }, + ] + ); + }); + } - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); + #[test] + fn rewards_distribution_is_fair_3() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); - // Then + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + Balances::make_free_balance_be(&20, ed + 10); + assert_ok!(Pools::join(Origin::signed(20), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + Balances::make_free_balance_be(&30, ed + 10); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + // 10 should claim 10, 20 should claim nothing. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 30 + 100 / 2 + 60 / 3 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 100 / 2 + 60 / 3 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 60 / 3 }, + ] + ); + + // any upcoming rewards are shared equally. + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 }, + ] + ); + }); + } + + #[test] + fn rewards_distribution_is_fair_bond_extra() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + Balances::make_free_balance_be(&30, ed + 20); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); + + // everyone claims. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 10 } + ] + ); + + // 30 now bumps itself to be like 20. + assert_ok!(Pools::bond_extra(Origin::signed(30), BondExtra::FreeBalance(10))); + + // more rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: false }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 40 } + ] + ); + }); + } + + #[test] + fn rewards_distribution_is_fair_unbond() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + // everyone claims. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + ] + ); + + // 30 now bumps itself to be like 20. + assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); + + // more rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 100).unwrap(); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 50 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 50 }, + ] + ); + }); + } + + #[test] + fn unclaimed_reward_is_safe() { + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 20); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + Balances::make_free_balance_be(&30, ed + 20); + assert_ok!(Pools::join(Origin::signed(30), 10, 1)); + + // 10 gets 10, 20 gets 20, 30 gets 10 + Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 20 } + ] + ); + + // 10 gets 20, 20 gets 40, 30 gets 20 + Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + ] + ); + + // 10 gets 20, 20 gets 40, 30 gets 20 + Balances::mutate_account(&default_reward_account(), |f| f.free += 80).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 20 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 40 } + ] + ); + + // now 30 claims all at once + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 30, pool_id: 1, payout: 10 + 20 + 20 }] + ); + }); + } + + #[test] + fn bond_extra_and_delayed_claim() { + // todo!("10 20 join, reward comes, 10 claims, 20 bonds extra, reward comes both claim"); + ExtBuilder::default().build_and_execute(|| { + let ed = Balances::minimum_balance(); + + Balances::make_free_balance_be(&20, ed + 200); + assert_ok!(Pools::join(Origin::signed(20), 20, 1)); + + // 10 gets 10, 20 gets 20, 30 gets 10 + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + // some claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 10 } + ] + ); + + // 20 has not claimed yet, more reward comes + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + // and 20 bonds more -- they should not have more share of this reward. + assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::FreeBalance(10))); + + // everyone claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + // 20 + 40, which means the extra amount they bonded did not impact us. + Event::PaidOut { member: 20, pool_id: 1, payout: 60 }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false }, + Event::PaidOut { member: 10, pool_id: 1, payout: 20 } + ] + ); + + // but in the next round of rewards, the extra10 they bonded has an impact. + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + // everyone claim. + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 45 } + ] + ); + }); + } + + #[test] + fn create_sets_recorded_data() { + ExtBuilder::default().build_and_execute(|| { + MaxPools::::set(None); + // pool 10 has already been created. + let (member_10, _, reward_pool_10) = Pools::get_member_with_pools(&10).unwrap(); + + assert_eq!(reward_pool_10.last_recorded_total_payouts, 0); + assert_eq!(reward_pool_10.total_rewards_claimed, 0); + assert_eq!(reward_pool_10.last_recorded_reward_counter, 0.into()); + + assert_eq!(member_10.last_recorded_reward_counter, 0.into()); + + // transfer some reward to pool 1. + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + // create pool 2 + Balances::make_free_balance_be(&20, 100); + assert_ok!(Pools::create(Origin::signed(20), 10, 20, 20, 20)); + + // has no impact -- initial + let (member_20, _, reward_pool_20) = Pools::get_member_with_pools(&20).unwrap(); + + assert_eq!(reward_pool_20.last_recorded_total_payouts, 0); + assert_eq!(reward_pool_20.total_rewards_claimed, 0); + assert_eq!(reward_pool_20.last_recorded_reward_counter, 0.into()); + + assert_eq!(member_20.last_recorded_reward_counter, 0.into()); + + // pre-fund the reward account of pool id 3 with some funds. + Balances::make_free_balance_be(&Pools::create_reward_account(3), 10); + + // create pool 3 + Balances::make_free_balance_be(&30, 100); + assert_ok!(Pools::create(Origin::signed(30), 10, 30, 30, 30)); + + // reward counter is still the same. + let (member_30, _, reward_pool_30) = Pools::get_member_with_pools(&30).unwrap(); + assert_eq!( + Balances::free_balance(&Pools::create_reward_account(3)), + 10 + Balances::minimum_balance() + ); + + assert_eq!(reward_pool_30.last_recorded_total_payouts, 0); + assert_eq!(reward_pool_30.total_rewards_claimed, 0); + assert_eq!(reward_pool_30.last_recorded_reward_counter, 0.into()); + + assert_eq!(member_30.last_recorded_reward_counter, 0.into()); + + // and 30 can claim the reward now. + assert_ok!(Pools::claim_payout(Origin::signed(30))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Created { depositor: 20, pool_id: 2 }, + Event::Bonded { member: 20, pool_id: 2, bonded: 10, joined: true }, + Event::Created { depositor: 30, pool_id: 3 }, + Event::Bonded { member: 30, pool_id: 3, bonded: 10, joined: true }, + Event::PaidOut { member: 30, pool_id: 3, payout: 10 } + ] + ); + }) + } + + #[test] + fn join_updates_recorded_data() { + ExtBuilder::default().build_and_execute(|| { + MaxPoolMembers::::set(None); + MaxPoolMembersPerPool::::set(None); + let join = |x, y| { + Balances::make_free_balance_be(&x, y + Balances::minimum_balance()); + assert_ok!(Pools::join(Origin::signed(x), y, 1)); + }; + + { + let (member_10, _, reward_pool_10) = Pools::get_member_with_pools(&10).unwrap(); + + assert_eq!(reward_pool_10.last_recorded_total_payouts, 0); + assert_eq!(reward_pool_10.total_rewards_claimed, 0); + assert_eq!(reward_pool_10.last_recorded_reward_counter, 0.into()); + + assert_eq!(member_10.last_recorded_reward_counter, 0.into()); + } + + // someone joins without any rewards being issued. + { + join(20, 10); + let (member, _, reward_pool) = Pools::get_member_with_pools(&20).unwrap(); + // reward counter is 0 both before.. + assert_eq!(member.last_recorded_reward_counter, 0.into()); + assert_eq!(reward_pool.last_recorded_total_payouts, 0); + assert_eq!(reward_pool.last_recorded_reward_counter, 0.into()); + } + + // transfer some reward to pool 1. + Balances::mutate_account(&default_reward_account(), |f| f.free += 60).unwrap(); + + { + join(30, 10); + let (member, _, reward_pool) = Pools::get_member_with_pools(&30).unwrap(); + assert_eq!(reward_pool.last_recorded_total_payouts, 60); + // explanation: we have a total of 20 points so far (excluding the 10 that just got + // bonded), and 60 unclaimed rewards. each share is then roughly worth of 3 units of + // rewards, thus reward counter is 3. member's reward counter is the same + assert_eq!(member.last_recorded_reward_counter, 3.into()); + assert_eq!(reward_pool.last_recorded_reward_counter, 3.into()); + } + + // someone else joins + { + join(40, 10); + let (member, _, reward_pool) = Pools::get_member_with_pools(&40).unwrap(); + // reward counter does not change since no rewards have came in. + assert_eq!(member.last_recorded_reward_counter, 3.into()); + assert_eq!(reward_pool.last_recorded_reward_counter, 3.into()); + assert_eq!(reward_pool.last_recorded_total_payouts, 60); + } + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 40, pool_id: 1, bonded: 10, joined: true } + ] + ); + }) + } + + #[test] + fn bond_extra_updates_recorded_data() { + ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { + MaxPoolMembers::::set(None); + MaxPoolMembersPerPool::::set(None); + + // initial state of pool 1. + { + let (member_10, _, reward_pool_10) = Pools::get_member_with_pools(&10).unwrap(); + + assert_eq!(reward_pool_10.last_recorded_total_payouts, 0); + assert_eq!(reward_pool_10.total_rewards_claimed, 0); + assert_eq!(reward_pool_10.last_recorded_reward_counter, 0.into()); + + assert_eq!(member_10.last_recorded_reward_counter, 0.into()); + } + + Balances::make_free_balance_be(&10, 100); + Balances::make_free_balance_be(&20, 100); + + // 10 bonds extra without any rewards. + { + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); + let (member, _, reward_pool) = Pools::get_member_with_pools(&10).unwrap(); + assert_eq!(member.last_recorded_reward_counter, 0.into()); + assert_eq!(reward_pool.last_recorded_total_payouts, 0); + assert_eq!(reward_pool.last_recorded_reward_counter, 0.into()); + } + + // 10 bonds extra again with some rewards. This reward should be split equally between + // 10 and 20, as they both have equal points now. + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); + + { + assert_ok!(Pools::bond_extra(Origin::signed(10), BondExtra::FreeBalance(10))); + let (member, _, reward_pool) = Pools::get_member_with_pools(&10).unwrap(); + // explanation: before bond_extra takes place, there is 40 points and 30 balance in + // the system, RewardCounter is therefore 7.5 + assert_eq!(member.last_recorded_reward_counter, RewardCounter::from_float(0.75)); assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 50 }] + reward_pool.last_recorded_reward_counter, + RewardCounter::from_float(0.75) ); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + } - // We expect a payout of 50: (5,000 del virtual points / 7,5000 pool points) * 75 - // pool balance - assert_eq!(del_50, del(50, 200)); + // 20 bonds extra again, without further rewards. + { + assert_ok!(Pools::bond_extra(Origin::signed(20), BondExtra::FreeBalance(10))); + let (member, _, reward_pool) = Pools::get_member_with_pools(&20).unwrap(); + assert_eq!(member.last_recorded_reward_counter, RewardCounter::from_float(0.75)); assert_eq!( - reward_pool, - rew( - 25, - // old pool points + points from new earnings - del points. - // - // points from new earnings = new earnings(50) * bonded_pool.points(100) - // del points = member.points(50) * new_earnings_since_last_claim (100) - (2_500 + 50 * 100) - 50 * 100, - 200, - ) + reward_pool.last_recorded_reward_counter, + RewardCounter::from_float(0.75) ); - assert_eq!(Balances::free_balance(&50), 50 + 50); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 25); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + } - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, + Event::PaidOut { member: 10, pool_id: 1, payout: 15 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: false }, + Event::PaidOut { member: 20, pool_id: 1, payout: 15 }, + Event::Bonded { member: 20, pool_id: 1, bonded: 10, joined: false } + ] + ); + }) + } - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 5 }] - ); + #[test] + fn unbond_updates_recorded_data() { + ExtBuilder::default() + .add_members(vec![(20, 20), (30, 20)]) + .build_and_execute(|| { + MaxPoolMembers::::set(None); + MaxPoolMembersPerPool::::set(None); - // We expect a payout of 5 - assert_eq!(del_10, del(10, 200)); - assert_eq!(reward_pool, rew(20, 2_500 - 10 * 50, 200)); - assert_eq!(Balances::free_balance(&10), 15 + 5); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); + // initial state of pool 1. + { + let (member, _, reward_pool) = Pools::get_member_with_pools(&10).unwrap(); - // Given del 40 hasn't claimed and the reward pool has just earned 400 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); + assert_eq!(reward_pool.last_recorded_total_payouts, 0); + assert_eq!(reward_pool.total_rewards_claimed, 0); + assert_eq!(reward_pool.last_recorded_reward_counter, 0.into()); - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); + assert_eq!(member.last_recorded_reward_counter, 0.into()); + } - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 40 }] - ); + // 20 unbonds without any rewards. + { + assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); + let (member, _, reward_pool) = Pools::get_member_with_pools(&20).unwrap(); + assert_eq!(member.last_recorded_reward_counter, 0.into()); + assert_eq!(reward_pool.last_recorded_total_payouts, 0); + assert_eq!(reward_pool.last_recorded_reward_counter, 0.into()); + } - // We expect a payout of 40 - assert_eq!(del_10, del(10, 600)); - assert_eq!( - reward_pool, - rew( - 380, - // old pool points + points from new earnings - del points - // - // points from new earnings = new earnings(400) * bonded_pool.points(100) - // del points = member.points(10) * new_earnings_since_last_claim(400) - (2_000 + 400 * 100) - 10 * 400, - 600 - ) - ); - assert_eq!(Balances::free_balance(&10), 20 + 40); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 380); + // some rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 30).unwrap(); - // Given del 40 + del 50 haven't claimed and the reward pool has earned 20 - assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 20)); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 400); + // and 30 also unbonds half. + { + assert_ok!(Pools::unbond(Origin::signed(30), 30, 10)); + let (member, _, reward_pool) = Pools::get_member_with_pools(&30).unwrap(); + // 30 reward in the system, and 40 points before this unbond to collect it, + // RewardCounter is 3/4. + assert_eq!( + member.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + assert_eq!( + reward_pool.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + } - // When - assert_ok!(Pools::do_reward_payout( - &10, - &mut del_10, - &mut bonded_pool, - &mut reward_pool - )); + // 30 unbonds again, not change this time. + { + assert_ok!(Pools::unbond(Origin::signed(30), 30, 5)); + let (member, _, reward_pool) = Pools::get_member_with_pools(&30).unwrap(); + assert_eq!( + member.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + assert_eq!( + reward_pool.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + } + + // 20 unbonds again, not change this time, just collecting their reward. + { + assert_ok!(Pools::unbond(Origin::signed(20), 20, 5)); + let (member, _, reward_pool) = Pools::get_member_with_pools(&20).unwrap(); + assert_eq!( + member.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + assert_eq!(reward_pool.last_recorded_total_payouts, 30); + assert_eq!( + reward_pool.last_recorded_reward_counter, + RewardCounter::from_float(0.75) + ); + } + + // trigger 10's reward as well to see all of the payouts. + assert_ok!(Pools::claim_payout(Origin::signed(10))); - // Then assert_eq!( pool_events_since_last_call(), - vec![Event::PaidOut { member: 10, pool_id: 1, payout: 2 }] + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::Bonded { member: 30, pool_id: 1, bonded: 20, joined: true }, + Event::Unbonded { member: 20, pool_id: 1, balance: 10, points: 10 }, + Event::PaidOut { member: 30, pool_id: 1, payout: 15 }, + Event::Unbonded { member: 30, pool_id: 1, balance: 10, points: 10 }, + Event::Unbonded { member: 30, pool_id: 1, balance: 5, points: 5 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 7 }, + Event::Unbonded { member: 20, pool_id: 1, balance: 5, points: 5 }, + Event::PaidOut { member: 10, pool_id: 1, payout: 7 } + ] ); + }) + } - // Expect a payout of 2: (200 del virtual points / 38,000 pool points) * 400 pool - // balance - assert_eq!(del_10, del(10, 620)); - assert_eq!(reward_pool, rew(398, (38_000 + 20 * 100) - 10 * 20, 620)); - assert_eq!(Balances::free_balance(&10), 60 + 2); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 398); + #[test] + fn rewards_are_rounded_down_depositor_collects_them() { + ExtBuilder::default().add_members(vec![(20, 20)]).build_and_execute(|| { + // initial balance of 10. + assert_eq!(Balances::free_balance(&10), 5); + assert_eq!( + Balances::free_balance(&default_reward_account()), + Balances::minimum_balance() + ); - // When - assert_ok!(Pools::do_reward_payout( - &40, - &mut del_40, - &mut bonded_pool, - &mut reward_pool - )); + // some rewards come in. + Balances::mutate_account(&default_reward_account(), |f| f.free += 40).unwrap(); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 40, pool_id: 1, payout: 188 }] - ); + // everyone claims + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); - // Expect a payout of 188: (18,800 del virtual points / 39,800 pool points) * 399 - // pool balance - assert_eq!(del_40, del(40, 620)); - assert_eq!(reward_pool, rew(210, 39_800 - 40 * 470, 620)); - assert_eq!(Balances::free_balance(&40), 60 + 188); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 210); + // some dust (1) remains in the reward account. + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, + Event::Bonded { member: 20, pool_id: 1, bonded: 20, joined: true }, + Event::PaidOut { member: 10, pool_id: 1, payout: 13 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 26 } + ] + ); - // When - assert_ok!(Pools::do_reward_payout( - &50, - &mut del_50, - &mut bonded_pool, - &mut reward_pool - )); + // start dismantling the pool. + assert_ok!(Pools::set_state(Origin::signed(902), 1, PoolState::Destroying)); + assert_ok!(fully_unbond_permissioned(20)); - // Then - assert_eq!( - pool_events_since_last_call(), - vec![Event::PaidOut { member: 50, pool_id: 1, payout: 210 }] - ); + CurrentEra::set(3); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(20), 20, 0)); + assert_ok!(fully_unbond_permissioned(10)); - // Expect payout of 210: (21,000 / 21,000) * 210 - assert_eq!(del_50, del(50, 620)); - assert_eq!(reward_pool, rew(0, 21_000 - 50 * 420, 620)); - assert_eq!(Balances::free_balance(&50), 100 + 210); - assert_eq!(Balances::free_balance(&default_reward_account()), ed + 0); - }); + CurrentEra::set(6); + assert_ok!(Pools::withdraw_unbonded(Origin::signed(10), 10, 0)); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::StateChanged { pool_id: 1, new_state: PoolState::Destroying }, + Event::Unbonded { member: 20, pool_id: 1, balance: 20, points: 20 }, + Event::Withdrawn { member: 20, pool_id: 1, balance: 20, points: 20 }, + Event::MemberRemoved { pool_id: 1, member: 20 }, + Event::Unbonded { member: 10, pool_id: 1, balance: 10, points: 10 }, + Event::Withdrawn { member: 10, pool_id: 1, balance: 10, points: 10 }, + Event::MemberRemoved { pool_id: 1, member: 10 }, + Event::Destroyed { pool_id: 1 } + ] + ); + + // original ed + ed put into reward account + reward + bond + dust. + assert_eq!(Balances::free_balance(&10), 5 + 5 + 13 + 10 + 1); + }) } } From 82287b0705ebeee563507cb9fb81f2e9d3611d1d Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 14 Jun 2022 21:13:20 +0100 Subject: [PATCH 33/65] cleanup --- frame/nomination-pools/src/lib.rs | 51 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 8979bb097359a..7f9a155ddbf5e 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -348,7 +348,8 @@ pub use pallet::*; pub use weights::WeightInfo; /// The balance type used by the currency system. -pub type BalanceOf = ::CurrencyBalance; +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; /// Type used for unique identifier of each pool. pub type PoolId = u32; /// The fixed point type used for all reward counters. @@ -920,23 +921,46 @@ impl BondedPool { } /// A reward pool. +/// +/// A reward pool is not so much a pool anymore, since it does not contain any shares or point +/// anymore, rather simply to fit nicely next to bonded pool and unbonding pools. In reality, a +/// reward pool is just a container for a few pool-dependent data related to the rewards. #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound)] #[cfg_attr(feature = "std", derive(Clone, PartialEq, DefaultNoBound))] #[codec(mel_bound(T: Config))] #[scale_info(skip_type_params(T))] pub struct RewardPool { - pub last_recorded_reward_counter: RewardCounter, - pub last_recorded_total_payouts: BalanceOf, - pub total_rewards_claimed: BalanceOf, + /// The last recorded value of the reward counter. + /// + /// This is updated ONLY when the points in the bonded pool change, which means `join`, + /// `bond_extra` and `unbond`, all of which is done through `update_recorded`. + last_recorded_reward_counter: RewardCounter, + /// The last recorded total payouts of the reward pool. + /// + /// Payouts is essentially income of the pool. + last_recorded_total_payouts: BalanceOf, + /// Total amount that this pool has paid out so far to the members. + total_rewards_claimed: BalanceOf, } impl RewardPool { + fn last_recorded_reward_counter(&self) -> RewardCounter { + self.last_recorded_reward_counter + } + + /// Register some rewards that are claimed from the pool by the members. + fn register_claimed_reward(&mut self, reward: BalanceOf) { + self.total_rewards_claimed += reward + } + + /// Update the recorded values of the pool. fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) { let balance = Self::current_balance(id); self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points); self.last_recorded_total_payouts = balance + self.total_rewards_claimed; } + /// Get the current reward counter, based on the given `bonded_points`. fn current_reward_counter(&self, id: PoolId, bonded_points: BalanceOf) -> RewardCounter { let balance = Self::current_balance(id); let payouts_since_last_record = @@ -945,6 +969,9 @@ impl RewardPool { (RewardCounter::saturating_from_rational(payouts_since_last_record, bonded_points)) } + /// Current free balance of the reward pool. + /// + /// This is sum of all the rewards that are claimable. fn current_balance(id: PoolId) -> BalanceOf { T::Currency::free_balance(&Pallet::::create_reward_account(id)) .saturating_sub(T::Currency::minimum_balance()) @@ -1095,7 +1122,8 @@ pub mod pallet { /// The nominating balance. type Currency: Currency; - // TODO: not sure if I need this after all. Update BalanceOf type accordingly. + + /// The balance type. Needed to bound it to `FixedPointOperand`. type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned + codec::FullCodec + Copy @@ -1430,7 +1458,7 @@ pub mod pallet { points: points_issued, // we just updated `last_known_reward_counter` to the current one in // `update_recorded`. - last_recorded_reward_counter: reward_pool.last_recorded_reward_counter, + last_recorded_reward_counter: reward_pool.last_recorded_reward_counter(), unbonding_eras: Default::default(), }, ); @@ -1467,7 +1495,9 @@ pub mod pallet { // before updating the bonded pool points, similar to that of `join` transaction. reward_pool.update_records(bonded_pool.id, bonded_pool.points); // TODO: optimize this to not touch the free balance of `who ` at all in benchmarks. - // Currently, bonding rewards is like a batch. + // Currently, bonding rewards is like a batch. In the same PR, also make this function + // take a boolean argument that make it either 100% pure (no storage update), or make it + // also emit event and do the transfer. let claimed = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; @@ -2088,7 +2118,7 @@ impl Pallet { ExistenceRequirement::AllowDeath, ); - // TODO: this is purely defensive. + // NOTE: this is purely defensive. T::Currency::make_free_balance_be(&reward_account, Zero::zero()); T::Currency::make_free_balance_be(&bonded_pool.bonded_account(), Zero::zero()); @@ -2200,15 +2230,13 @@ impl Pallet { let pending_rewards = member.pending_rewards(current_reward_counter); member.last_recorded_reward_counter = current_reward_counter; - reward_pool.total_rewards_claimed += pending_rewards; + reward_pool.register_claimed_reward(pending_rewards); if pending_rewards.is_zero() { return Ok(pending_rewards) } // Transfer payout to the member. - // TODO: this is pretty shitty for the case of bond_extra, this function should not transfer - // anything. T::Currency::transfer( &bonded_pool.reward_account(), &member_account, @@ -2216,7 +2244,6 @@ impl Pallet { ExistenceRequirement::AllowDeath, )?; - // TODO don't do this either, call site should do. Self::deposit_event(Event::::PaidOut { member: member_account.clone(), pool_id: member.pool_id, From e403fb1e447df110932b3e3a0a5e7ee7032d0cad Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 15 Jun 2022 08:58:51 +0100 Subject: [PATCH 34/65] make sure benchmarks and all work --- bin/node/runtime/src/lib.rs | 1 + frame/nomination-pools/benchmarking/src/mock.rs | 1 + frame/nomination-pools/src/lib.rs | 2 +- frame/nomination-pools/test-staking/src/lib.rs | 5 +++-- frame/nomination-pools/test-staking/src/mock.rs | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 6f3df7416681e..c94f65279ddce 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -750,6 +750,7 @@ impl pallet_nomination_pools::Config for Runtime { type WeightInfo = (); type Event = Event; type Currency = Balances; + type CurrencyBalance = Balance; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = pallet_staking::Pallet; diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index eb884869f6d32..64d29df7146e2 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -151,6 +151,7 @@ impl pallet_nomination_pools::Config for Runtime { type Event = Event; type WeightInfo = (); type Currency = Balances; + type CurrencyBalance = Balance; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = Staking; diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 7f9a155ddbf5e..2b5c5b6440122 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1497,7 +1497,7 @@ pub mod pallet { // TODO: optimize this to not touch the free balance of `who ` at all in benchmarks. // Currently, bonding rewards is like a batch. In the same PR, also make this function // take a boolean argument that make it either 100% pure (no storage update), or make it - // also emit event and do the transfer. + // also emit event and do the transfer. #11671 let claimed = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 2e40e8c6d917d..736982ee4c61f 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -25,6 +25,7 @@ use pallet_nomination_pools::{ Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers, PoolState, }; use pallet_staking::{CurrentEra, Event as StakingEvent, Payee, RewardDestination}; +use sp_runtime::traits::Zero; #[test] fn pool_lifecycle_e2e() { @@ -295,7 +296,7 @@ fn pool_slash_e2e() { PoolMember { pool_id: 1, points: 0, - reward_pool_total_earnings: 0, + last_recorded_reward_counter: Zero::zero(), // the 10 points unlocked just now correspond to 5 points in the unbond pool. unbonding_eras: bounded_btree_map!(5 => 10, 6 => 5) } @@ -350,7 +351,7 @@ fn pool_slash_e2e() { PoolMember { pool_id: 1, points: 0, - reward_pool_total_earnings: 0, + last_recorded_reward_counter: Zero::zero(), unbonding_eras: bounded_btree_map!(4 => 10, 5 => 10, 9 => 10) } ); diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 7b720c009b29b..2e7aace49d027 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -157,6 +157,7 @@ impl pallet_nomination_pools::Config for Runtime { type Event = Event; type WeightInfo = (); type Currency = Balances; + type CurrencyBalance = Balance; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = Staking; From 221369bb80a85da39a8f1e9aa7c6d86622ca47fd Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Wed, 15 Jun 2022 08:17:09 +0000 Subject: [PATCH 35/65] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_nomination_pools --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/nomination-pools/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/nomination-pools/src/weights.rs | 98 +++++++++++++-------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/frame/nomination-pools/src/weights.rs b/frame/nomination-pools/src/weights.rs index 8e3facfc5ec26..a9003ffd3fb4c 100644 --- a/frame/nomination-pools/src/weights.rs +++ b/frame/nomination-pools/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_nomination_pools //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-06-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-06-15, 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 @@ -70,7 +70,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:1) - // Storage: NominationPools RewardPools (r:1 w:0) + // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:2 w:1) // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) // Storage: NominationPools MaxPoolMembers (r:1 w:0) @@ -80,22 +80,22 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn join() -> Weight { - (124_508_000 as Weight) + (123_947_000 as Weight) .saturating_add(T::DbWeight::get().reads(17 as Weight)) - .saturating_add(T::DbWeight::get().writes(11 as Weight)) + .saturating_add(T::DbWeight::get().writes(12 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) - // Storage: System Account (r:2 w:2) + // Storage: System Account (r:3 w:2) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - (115_185_000 as Weight) - .saturating_add(T::DbWeight::get().reads(13 as Weight)) + (118_236_000 as Weight) + .saturating_add(T::DbWeight::get().reads(14 as Weight)) .saturating_add(T::DbWeight::get().writes(12 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) @@ -108,7 +108,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - (132_723_000 as Weight) + (132_475_000 as Weight) .saturating_add(T::DbWeight::get().reads(14 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } @@ -117,7 +117,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_payout() -> Weight { - (52_498_000 as Weight) + (50_299_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } @@ -136,7 +136,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - (121_645_000 as Weight) + (121_254_000 as Weight) .saturating_add(T::DbWeight::get().reads(18 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight)) } @@ -146,9 +146,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - (43_320_000 as Weight) + (41_928_000 as Weight) // Standard Error: 0 - .saturating_add((49_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -162,9 +162,9 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - (83_195_000 as Weight) - // Standard Error: 5_000 - .saturating_add((57_000 as Weight).saturating_mul(s as Weight)) + (81_611_000 as Weight) + // Standard Error: 1_000 + .saturating_add((56_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } @@ -189,7 +189,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (143_495_000 as Weight) + (139_849_000 as Weight) .saturating_add(T::DbWeight::get().reads(19 as Weight)) .saturating_add(T::DbWeight::get().writes(16 as Weight)) } @@ -216,7 +216,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - (127_998_000 as Weight) + (126_246_000 as Weight) .saturating_add(T::DbWeight::get().reads(22 as Weight)) .saturating_add(T::DbWeight::get().writes(15 as Weight)) } @@ -234,9 +234,9 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - (49_929_000 as Weight) - // Standard Error: 16_000 - .saturating_add((2_319_000 as Weight).saturating_mul(n as Weight)) + (48_829_000 as Weight) + // Standard Error: 10_000 + .saturating_add((2_204_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(12 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(5 as Weight)) @@ -244,7 +244,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - (27_399_000 as Weight) + (26_761_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -253,7 +253,7 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - (14_813_000 as Weight) + (14_519_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight)) @@ -265,12 +265,12 @@ impl WeightInfo for SubstrateWeight { // Storage: NominationPools MinCreateBond (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - (6_115_000 as Weight) + (6_173_000 as Weight) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - (22_546_000 as Weight) + (22_261_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -283,7 +283,7 @@ impl WeightInfo for SubstrateWeight { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (48_243_000 as Weight) + (47_959_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } @@ -295,7 +295,7 @@ impl WeightInfo for () { // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:1) - // Storage: NominationPools RewardPools (r:1 w:0) + // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:2 w:1) // Storage: NominationPools MaxPoolMembersPerPool (r:1 w:0) // Storage: NominationPools MaxPoolMembers (r:1 w:0) @@ -305,22 +305,22 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn join() -> Weight { - (124_508_000 as Weight) + (123_947_000 as Weight) .saturating_add(RocksDbWeight::get().reads(17 as Weight)) - .saturating_add(RocksDbWeight::get().writes(11 as Weight)) + .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) // Storage: NominationPools BondedPools (r:1 w:1) // Storage: NominationPools RewardPools (r:1 w:1) - // Storage: System Account (r:2 w:2) + // Storage: System Account (r:3 w:2) // Storage: Staking Ledger (r:1 w:1) // Storage: Staking Bonded (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_transfer() -> Weight { - (115_185_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(13 as Weight)) + (118_236_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(14 as Weight)) .saturating_add(RocksDbWeight::get().writes(12 as Weight)) } // Storage: NominationPools PoolMembers (r:1 w:1) @@ -333,7 +333,7 @@ impl WeightInfo for () { // Storage: BagsList ListNodes (r:3 w:3) // Storage: BagsList ListBags (r:2 w:2) fn bond_extra_reward() -> Weight { - (132_723_000 as Weight) + (132_475_000 as Weight) .saturating_add(RocksDbWeight::get().reads(14 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } @@ -342,7 +342,7 @@ impl WeightInfo for () { // Storage: NominationPools RewardPools (r:1 w:1) // Storage: System Account (r:1 w:1) fn claim_payout() -> Weight { - (52_498_000 as Weight) + (50_299_000 as Weight) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } @@ -361,7 +361,7 @@ impl WeightInfo for () { // Storage: NominationPools SubPoolsStorage (r:1 w:1) // Storage: NominationPools CounterForSubPoolsStorage (r:1 w:1) fn unbond() -> Weight { - (121_645_000 as Weight) + (121_254_000 as Weight) .saturating_add(RocksDbWeight::get().reads(18 as Weight)) .saturating_add(RocksDbWeight::get().writes(13 as Weight)) } @@ -371,9 +371,9 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn pool_withdraw_unbonded(s: u32, ) -> Weight { - (43_320_000 as Weight) + (41_928_000 as Weight) // Standard Error: 0 - .saturating_add((49_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((52_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -387,9 +387,9 @@ impl WeightInfo for () { // Storage: NominationPools CounterForPoolMembers (r:1 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_update(s: u32, ) -> Weight { - (83_195_000 as Weight) - // Standard Error: 5_000 - .saturating_add((57_000 as Weight).saturating_mul(s as Weight)) + (81_611_000 as Weight) + // Standard Error: 1_000 + .saturating_add((56_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } @@ -414,7 +414,7 @@ impl WeightInfo for () { // Storage: Staking Payee (r:0 w:1) /// The range of component `s` is `[0, 100]`. fn withdraw_unbonded_kill(_s: u32, ) -> Weight { - (143_495_000 as Weight) + (139_849_000 as Weight) .saturating_add(RocksDbWeight::get().reads(19 as Weight)) .saturating_add(RocksDbWeight::get().writes(16 as Weight)) } @@ -441,7 +441,7 @@ impl WeightInfo for () { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Payee (r:0 w:1) fn create() -> Weight { - (127_998_000 as Weight) + (126_246_000 as Weight) .saturating_add(RocksDbWeight::get().reads(22 as Weight)) .saturating_add(RocksDbWeight::get().writes(15 as Weight)) } @@ -459,9 +459,9 @@ impl WeightInfo for () { // Storage: Staking CounterForNominators (r:1 w:1) /// The range of component `n` is `[1, 16]`. fn nominate(n: u32, ) -> Weight { - (49_929_000 as Weight) - // Standard Error: 16_000 - .saturating_add((2_319_000 as Weight).saturating_mul(n as Weight)) + (48_829_000 as Weight) + // Standard Error: 10_000 + .saturating_add((2_204_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(12 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) @@ -469,7 +469,7 @@ impl WeightInfo for () { // Storage: NominationPools BondedPools (r:1 w:1) // Storage: Staking Ledger (r:1 w:0) fn set_state() -> Weight { - (27_399_000 as Weight) + (26_761_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -478,7 +478,7 @@ impl WeightInfo for () { // Storage: NominationPools CounterForMetadata (r:1 w:1) /// The range of component `n` is `[1, 256]`. fn set_metadata(n: u32, ) -> Weight { - (14_813_000 as Weight) + (14_519_000 as Weight) // Standard Error: 0 .saturating_add((1_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) @@ -490,12 +490,12 @@ impl WeightInfo for () { // Storage: NominationPools MinCreateBond (r:0 w:1) // Storage: NominationPools MaxPools (r:0 w:1) fn set_configs() -> Weight { - (6_115_000 as Weight) + (6_173_000 as Weight) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } // Storage: NominationPools BondedPools (r:1 w:1) fn update_roles() -> Weight { - (22_546_000 as Weight) + (22_261_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -508,7 +508,7 @@ impl WeightInfo for () { // Storage: BagsList ListBags (r:1 w:1) // Storage: BagsList CounterForListNodes (r:1 w:1) fn chill() -> Weight { - (48_243_000 as Weight) + (47_959_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } From 696a55e9a96953cb21a11efb00b45e5b5664f965 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 15 Jun 2022 09:20:19 +0100 Subject: [PATCH 36/65] round of self-review, make arithmetic safe --- frame/nomination-pools/src/lib.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 2b5c5b6440122..2a7abcaa15623 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -417,7 +417,7 @@ pub struct PoolMember { impl PoolMember { fn pending_rewards(&self, current_reward_counter: RewardCounter) -> BalanceOf { - (current_reward_counter - self.last_recorded_reward_counter) + (current_reward_counter.saturating_sub(self.last_recorded_reward_counter)) .saturating_mul_int(self.active_points()) } @@ -922,9 +922,9 @@ impl BondedPool { /// A reward pool. /// -/// A reward pool is not so much a pool anymore, since it does not contain any shares or point -/// anymore, rather simply to fit nicely next to bonded pool and unbonding pools. In reality, a -/// reward pool is just a container for a few pool-dependent data related to the rewards. +/// A reward pool is not so much a pool anymore, since it does not contain any shares or points. +/// Rather, simply to fit nicely next to bonded pool and unbonding pools in terms of terminology. In +/// reality, a reward pool is just a container for a few pool-dependent data related to the rewards. #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound)] #[cfg_attr(feature = "std", derive(Clone, PartialEq, DefaultNoBound))] #[codec(mel_bound(T: Config))] @@ -938,6 +938,8 @@ pub struct RewardPool { /// The last recorded total payouts of the reward pool. /// /// Payouts is essentially income of the pool. + /// + /// Update criteria is same as that of `last_recorded_reward_counter`. last_recorded_total_payouts: BalanceOf, /// Total amount that this pool has paid out so far to the members. total_rewards_claimed: BalanceOf, @@ -950,23 +952,25 @@ impl RewardPool { /// Register some rewards that are claimed from the pool by the members. fn register_claimed_reward(&mut self, reward: BalanceOf) { - self.total_rewards_claimed += reward + self.total_rewards_claimed = self.total_rewards_claimed.saturating_add(reward); } /// Update the recorded values of the pool. fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) { let balance = Self::current_balance(id); self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points); - self.last_recorded_total_payouts = balance + self.total_rewards_claimed; + self.last_recorded_total_payouts = balance.saturating_add(self.total_rewards_claimed); } /// Get the current reward counter, based on the given `bonded_points`. fn current_reward_counter(&self, id: PoolId, bonded_points: BalanceOf) -> RewardCounter { let balance = Self::current_balance(id); - let payouts_since_last_record = - balance + self.total_rewards_claimed - self.last_recorded_total_payouts; - self.last_recorded_reward_counter + - (RewardCounter::saturating_from_rational(payouts_since_last_record, bonded_points)) + let payouts_since_last_record = balance + .saturating_add(self.total_rewards_claimed) + .saturating_sub(self.last_recorded_total_payouts); + self.last_recorded_reward_counter.saturating_add( + (RewardCounter::saturating_from_rational(payouts_since_last_record, bonded_points)), + ) } /// Current free balance of the reward pool. @@ -1444,7 +1448,6 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; - // IMPORTANT: reward pool records must be updated with the old points. reward_pool.update_records(pool_id, bonded_pool.points); From bcb413cf9fab9495c858f506719b151cba689bd1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 15 Jun 2022 09:33:48 +0100 Subject: [PATCH 37/65] fix warn --- frame/nomination-pools/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 2a7abcaa15623..c4125f769b102 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -968,9 +968,11 @@ impl RewardPool { let payouts_since_last_record = balance .saturating_add(self.total_rewards_claimed) .saturating_sub(self.last_recorded_total_payouts); - self.last_recorded_reward_counter.saturating_add( - (RewardCounter::saturating_from_rational(payouts_since_last_record, bonded_points)), - ) + self.last_recorded_reward_counter + .saturating_add(RewardCounter::saturating_from_rational( + payouts_since_last_record, + bonded_points, + )) } /// Current free balance of the reward pool. From bce40f7fbc64ea8f74f0f53dc8192514ca431a7c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 16 Jun 2022 10:27:46 +0100 Subject: [PATCH 38/65] add migration code --- frame/nomination-pools/src/lib.rs | 23 +-- frame/nomination-pools/src/migration.rs | 262 +++++++++++++++++++++++- frame/nomination-pools/src/tests.rs | 14 +- 3 files changed, 277 insertions(+), 22 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index c4125f769b102..df488cec55621 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -405,10 +405,7 @@ pub struct PoolMember { /// The quantity of points this member has in the bonded pool or in a sub pool if /// `Self::unbonding_era` is some. pub points: BalanceOf, - /// The reward pools total earnings _ever_ the last time this member claimed a payout. - /// Assuming no massive burning events, we expect this value to always be below total issuance. - /// This value lines up with the [`RewardPool::total_earnings`] after a member claims a - /// payout. + /// The reward counter at the time of this member's last payout claim. pub last_recorded_reward_counter: RewardCounter, /// The eras in which this member is unbonding, mapped from era index to the number of /// points scheduled to unbond in the given era. @@ -416,20 +413,17 @@ pub struct PoolMember { } impl PoolMember { + /// The pending rewards of this member. fn pending_rewards(&self, current_reward_counter: RewardCounter) -> BalanceOf { (current_reward_counter.saturating_sub(self.last_recorded_reward_counter)) .saturating_mul_int(self.active_points()) } - fn total_points(&self) -> BalanceOf { - self.active_points().saturating_add(self.unbonding_points()) - } - /// Active balance of the member. /// /// This is derived from the ratio of points in the pool to which the member belongs to. /// Might return different values based on the pool state for the same member and points. - pub(crate) fn active_balance(&self) -> BalanceOf { + fn active_balance(&self) -> BalanceOf { if let Some(pool) = BondedPool::::get(self.pool_id).defensive() { pool.points_to_balance(self.points) } else { @@ -437,13 +431,18 @@ impl PoolMember { } } + /// Total points of this member, both active and unbonding. + fn total_points(&self) -> BalanceOf { + self.active_points().saturating_add(self.unbonding_points()) + } + /// Active points of the member. - pub(crate) fn active_points(&self) -> BalanceOf { + fn active_points(&self) -> BalanceOf { self.points } /// Inactive points of the member, waiting to be withdrawn. - pub(crate) fn unbonding_points(&self) -> BalanceOf { + fn unbonding_points(&self) -> BalanceOf { self.unbonding_eras .as_ref() .iter() @@ -1111,7 +1110,7 @@ pub mod pallet { use frame_system::{ensure_signed, pallet_prelude::*}; /// The current storage version. - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); #[pallet::pallet] #[pallet::generate_store(pub(crate) trait Store)] diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index e23a35fe85602..901cf5f379b00 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -16,11 +16,12 @@ // limitations under the License. use super::*; +use crate::log; +use frame_support::traits::OnRuntimeUpgrade; +use sp_std::collections::btree_map::BTreeMap; pub mod v1 { use super::*; - use crate::log; - use frame_support::traits::OnRuntimeUpgrade; #[derive(Decode)] pub struct OldPoolRoles { @@ -103,3 +104,260 @@ pub mod v1 { } } } + +pub mod v2 { + use super::*; + use sp_runtime::Perbill; + + #[test] + fn migration_assumption_is_correct() { + // this migrations cleans all the reward accounts to contain exactly ed, and all members + // having no claimable rewards. In this state, all fields of the `RewardPool` and + // `member.last_recorded_reward_counter` are all zero. + use crate::mock::*; + ExtBuilder::default().build_and_execute(|| { + let join = |x| { + Balances::make_free_balance_be(&x, Balances::minimum_balance() + 10); + frame_support::assert_ok!(Pools::join(Origin::signed(x), 10, 1)); + }; + + assert_eq!(BondedPool::::get(1).unwrap().points, 10); + assert_eq!( + RewardPools::::get(1).unwrap(), + RewardPool { ..Default::default() } + ); + assert_eq!( + PoolMembers::::get(10).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + + join(20); + assert_eq!(BondedPool::::get(1).unwrap().points, 20); + assert_eq!( + RewardPools::::get(1).unwrap(), + RewardPool { ..Default::default() } + ); + assert_eq!( + PoolMembers::::get(10).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + assert_eq!( + PoolMembers::::get(20).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + + join(30); + assert_eq!(BondedPool::::get(1).unwrap().points, 30); + assert_eq!( + RewardPools::::get(1).unwrap(), + RewardPool { ..Default::default() } + ); + assert_eq!( + PoolMembers::::get(10).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + assert_eq!( + PoolMembers::::get(20).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + assert_eq!( + PoolMembers::::get(30).unwrap().last_recorded_reward_counter, + Zero::zero() + ); + }); + } + + #[derive(Decode)] + pub struct OldRewardPool { + pub balance: B, + pub total_earnings: B, + pub points: U256, + } + + #[derive(Decode)] + pub struct OldPoolMember { + pub pool_id: PoolId, + pub points: BalanceOf, + pub reward_pool_total_earnings: BalanceOf, + pub unbonding_eras: BoundedBTreeMap, T::MaxUnbonding>, + } + + /// Migrate the pool reward scheme to the new version, as per https://github.com/paritytech/substrate/pull/11669. + pub struct MigrateToV2(sp_std::marker::PhantomData); + impl MigrateToV2 { + fn run(current: StorageVersion) -> Weight { + let mut reward_pools_translated = 0u64; + let mut members_translated = 0u64; + // just for logging. + let mut total_value_locked = BalanceOf::::zero(); + + // store each member of the pool, with their active points. In the process, migrate + // their data as well. + let mut temp_members = BTreeMap::)>>::new(); + PoolMembers::::translate::, _>(|key, old_member| { + let id = old_member.pool_id; + temp_members.entry(id).or_default().push((key, old_member.points)); + + members_translated += 1; + Some(PoolMember:: { + last_recorded_reward_counter: Zero::zero(), + pool_id: old_member.pool_id, + points: old_member.points, + unbonding_eras: old_member.unbonding_eras, + }) + }); + + // translate all reward pools. In the process, do the last payout as well. + RewardPools::::translate::>, _>( + |id, _old_reward_pool| { + // each pool should have at least one member. + let members = match temp_members.get(&id) { + Some(x) => x, + None => { + log!(error, "pool {} has no member! deleting it..", id); + return None + }, + }; + let bonded_pool = match BondedPools::::get(id) { + Some(x) => x, + None => { + log!(error, "pool {} has no bonded pool! deleting it..", id); + return None + }, + }; + + let accumulated_reward = RewardPool::::current_balance(id); + let reward_account = Pallet::::create_reward_account(id); + let mut sum_paid_out = BalanceOf::::zero(); + + members + .into_iter() + .filter_map(|(who, points)| { + let bonded_pool = match BondedPool::::get(id) { + Some(x) => x, + None => { + log!(error, "pool {} for member {:?} does not exist!", id, who); + return None + }, + }; + + total_value_locked += bonded_pool.points_to_balance(points.clone()); + let portion = Perbill::from_rational(*points, bonded_pool.points); + let last_claim = portion * accumulated_reward; + + log!( + debug, + "{:?} has {:?} ({:?}) of pool {} with total reward of {:?}", + who, + portion, + last_claim, + id, + accumulated_reward + ); + if last_claim.is_zero() { + None + } else { + Some((who, last_claim)) + } + }) + .for_each(|(who, last_claim)| { + let outcome = T::Currency::transfer( + &reward_account, + &who, + last_claim, + ExistenceRequirement::KeepAlive, + ); + + if let Err(reason) = outcome { + log!(warn, "last reward claim failed due to {:?}", reason,); + } else { + sum_paid_out = sum_paid_out.saturating_add(last_claim); + } + + Pallet::::deposit_event(Event::::PaidOut { + member: who.clone(), + pool_id: id, + payout: last_claim, + }); + }); + + // this can only be because of rounding down, or because the person we + // wanted to pay their reward to could not accept it (dust). + let leftover = accumulated_reward.saturating_sub(sum_paid_out); + if !leftover.is_zero() { + // pay it all to depositor. + let o = T::Currency::transfer( + &reward_account, + &bonded_pool.roles.depositor, + leftover, + ExistenceRequirement::KeepAlive, + ); + log!(warn, "paying {:?} leftover to the depositor: {:?}", leftover, o); + } + + // finally, migrate the reward pool. + reward_pools_translated += 1; + + Some(RewardPool { + last_recorded_reward_counter: Zero::zero(), + last_recorded_total_payouts: Zero::zero(), + total_rewards_claimed: Zero::zero(), + }) + }, + ); + + log!( + info, + "Upgraded {} members, {} reward pools, TVL {:?}, storage to version {:?}", + members_translated, + reward_pools_translated, + total_value_locked, + current + ); + current.put::>(); + T::DbWeight::get().reads_writes(members_translated + 1, reward_pools_translated + 1) + } + } + + impl OnRuntimeUpgrade for MigrateToV2 { + fn on_runtime_upgrade() -> Weight { + let current = Pallet::::current_storage_version(); + let onchain = Pallet::::on_chain_storage_version(); + + log!( + info, + "Running migration with current storage version {:?} / onchain {:?}", + current, + onchain + ); + + if current == 2 && onchain == 1 { + Self::run(current) + } else { + log!(info, "MigrateToV2 did not executed. This probably should be removed"); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + // new version must be set. + assert_eq!(Pallet::::on_chain_storage_version(), 2); + + // all reward pools must have exactly ED in them. This means no reward can be claimed, + // and that setting reward counters all over the board to zero will work henceforth. + RewardPools::::iter().for_each(|(id, _reward_pool)| { + assert_eq!( + RewardPool::::current_balance(id), + Zero::zero(), + "reward pool({}) balance is {:?}", + id, + RewardPool::::current_balance(id) + ); + }); + + log!(info, "post upgrade hook for MigrateToV2 executed."); + Ok(()) + } + } +} diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 044499408f600..d493d8eb043bb 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1146,19 +1146,19 @@ mod claim_payout { #[test] fn rewards_distribution_is_fair_basic() { ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - + // reward pool by 10. Balances::mutate_account(&default_reward_account(), |f| f.free += 10).unwrap(); - Balances::make_free_balance_be(&20, ed + 10); + // 20 joins afterwards. + Balances::make_free_balance_be(&20, Balances::minimum_balance() + 10); assert_ok!(Pools::join(Origin::signed(20), 10, 1)); + // reward by another 20 Balances::mutate_account(&default_reward_account(), |f| f.free += 20).unwrap(); - // 10 should claim 10, 20 should claim nothing. + // 10 should claim 10 + 10, 20 should claim 20 / 2. assert_ok!(Pools::claim_payout(Origin::signed(10))); assert_ok!(Pools::claim_payout(Origin::signed(20))); - assert_eq!( pool_events_since_last_call(), vec![ @@ -1191,11 +1191,9 @@ mod claim_payout { // basically checks the case where the amount of rewards is less than the pool shares. for // this, we have to rely on fixed point arithmetic. ExtBuilder::default().build_and_execute(|| { - let ed = Balances::minimum_balance(); - Balances::mutate_account(&default_reward_account(), |f| f.free += 3).unwrap(); - Balances::make_free_balance_be(&20, ed + 10); + Balances::make_free_balance_be(&20, Balances::minimum_balance() + 10); assert_ok!(Pools::join(Origin::signed(20), 10, 1)); Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap(); From fc3ad18139e852b76f9792aeac426d8eb44fe6c0 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 17 Jun 2022 14:15:39 +0100 Subject: [PATCH 39/65] Fix doc --- frame/nomination-pools/src/migration.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 901cf5f379b00..dd2f3d53e7363 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -182,7 +182,8 @@ pub mod v2 { pub unbonding_eras: BoundedBTreeMap, T::MaxUnbonding>, } - /// Migrate the pool reward scheme to the new version, as per https://github.com/paritytech/substrate/pull/11669. + /// Migrate the pool reward scheme to the new version, as per + /// . pub struct MigrateToV2(sp_std::marker::PhantomData); impl MigrateToV2 { fn run(current: StorageVersion) -> Weight { From 9f875a9e32ddf6e02e751e34a6a95d8705cfc4f1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Jun 2022 10:59:40 +0200 Subject: [PATCH 40/65] add precision notes --- frame/nomination-pools/src/lib.rs | 59 ++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index df488cec55621..656fa7eb722d5 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -415,6 +415,41 @@ pub struct PoolMember { impl PoolMember { /// The pending rewards of this member. fn pending_rewards(&self, current_reward_counter: RewardCounter) -> BalanceOf { + // Precision note: Reward counters are fixedU128 with base of 10^18. Multiplying it with + // points, which have the same granularity as with balance should almost always be fine for + // Polkadot and Kusama since: The total issuance of both are + // + // dot: 12,047,781,394,999,601,455 + // ksm: 12,424,748,376,019,599,766 + // + // both of which are around 60% of u64::max. So, the absolute worse case for a non-slashed + // pool that can happen is that the points are equal to the whole total issuance, and the + // reward counter is `RewardCounter::max_value()`. In this case, we get: + // + // dot_total_issuance * u128::max / 10^18 + // + // which is roughly 12 more than u128::max. This means this will overflow if: a pool's + // points is roughly 1/12th of the total issuance, which in a non-slashed dot means if a + // pool owns 1/12th of the total issuance. In reality though, the accumulated reward will + // likely be much smaller than u128::max. + // + // more on that: the reward counter is the sum of all the rewards that are always given out + // to a pool, multiplied by 10^18. Again, assuming that the rewards of a pool are equal to + // the WHOLE total issuance (which is only realistically possible in multiple decades from + // now, and a single pool earning almost all the inflation), we can compute: + // + // dot_total_issuance * 10**18 / 2**128 + // + // which is roughly 3%, meaning that roughly 3% of the capacity of the u128 is filled, and + // that a more realistic value for the previous calculation was: + // + // dot_total_issuance * (dot_total_issuance * 10^18) / 10^18 + // + // which simplifies to dot_total_issuance^2. In other words, as long as square of the total + // issuance fits in u128, this whole calculation won't saturate. Nonetheless, we make all of + // the calculations be checked arithmetic, to make sure if a pool ever reaches this state + // way earlier than the few decades we anticipate due to severe slashing, no operations can + // happen in that pool. (current_reward_counter.saturating_sub(self.last_recorded_reward_counter)) .saturating_mul_int(self.active_points()) } @@ -967,16 +1002,38 @@ impl RewardPool { let payouts_since_last_record = balance .saturating_add(self.total_rewards_claimed) .saturating_sub(self.last_recorded_total_payouts); + + // accuracy notes: `payouts_since_last_record` is a subset of the total_issuance at the very + // worse. Bonded_points are similarly, in a non-slashed pool, have the same granularity as + // balance, and are thus below within the range of total_issuance. In the worse case + // scenario, for `saturating_from_rational`, we have: + // + // dot_total_issuance * 10^18 / `minJoinBond` + // + // assuming `MinJoinBond == ED` + // + // dot_total_issuance * 10^18 / 10^10 = dot_total_issuance * 10^8 + // + // which, with the current numbers, is a miniscule fraction of the u128 capacity. + // + // Thus, adding two values of type reward counter should be safe for ages in a chain like + // Polkadot. The important note here is that `reward_pool.last_recorded_reward_counter` only + // ever accumulates, but its semantics imply that it is less than total_issuance, when + // represented as `FixedU128`, which means it is less than `total_issuance * 10^18`. self.last_recorded_reward_counter .saturating_add(RewardCounter::saturating_from_rational( payouts_since_last_record, bonded_points, )) + + // TODO: make reward counter generic type + // TODO: make any arithmetic on rewardCounter fallible. + // TODO: test for arithmetic failing + micro reward payment in a mega-pool. } /// Current free balance of the reward pool. /// - /// This is sum of all the rewards that are claimable. + /// This is sum of all the rewards that are claimable by pool members. fn current_balance(id: PoolId) -> BalanceOf { T::Currency::free_balance(&Pallet::::create_reward_account(id)) .saturating_sub(T::Currency::minimum_balance()) From 0513284cebdc8f32259c5aff11a36bd8f7decfdf Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Jun 2022 11:29:46 +0200 Subject: [PATCH 41/65] make arithmetic fallible --- .../nomination-pools/benchmarking/src/mock.rs | 3 +- frame/nomination-pools/src/lib.rs | 74 ++++++++++++------- frame/nomination-pools/src/mock.rs | 3 + .../nomination-pools/test-staking/src/mock.rs | 3 +- 4 files changed, 53 insertions(+), 30 deletions(-) diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 64d29df7146e2..956926bb8cf2e 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -17,7 +17,7 @@ use frame_election_provider_support::VoteWeight; use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; -use sp_runtime::traits::{Convert, IdentityLookup}; +use sp_runtime::{traits::{Convert, IdentityLookup}, FixedU128}; type AccountId = u128; type AccountIndex = u32; @@ -152,6 +152,7 @@ impl pallet_nomination_pools::Config for Runtime { type WeightInfo = (); type Currency = Balances; type CurrencyBalance = Balance; + type RewardCounter = FixedU128; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = Staking; diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 656fa7eb722d5..160fdb5cf44c1 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -316,8 +316,8 @@ use frame_support::{ use scale_info::TypeInfo; use sp_core::U256; use sp_runtime::{ - traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Saturating, Zero}, - FixedPointNumber, FixedU128, + traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Saturating, Zero, CheckedAdd}, + FixedPointNumber, FixedPointOperand, }; use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; use sp_std::{collections::btree_map::BTreeMap, fmt::Debug, ops::Div, vec::Vec}; @@ -352,8 +352,6 @@ pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; /// Type used for unique identifier of each pool. pub type PoolId = u32; -/// The fixed point type used for all reward counters. -pub type RewardCounter = FixedU128; type UnbondingPoolsWithEra = BoundedBTreeMap, TotalUnbondingPools>; @@ -406,7 +404,7 @@ pub struct PoolMember { /// `Self::unbonding_era` is some. pub points: BalanceOf, /// The reward counter at the time of this member's last payout claim. - pub last_recorded_reward_counter: RewardCounter, + pub last_recorded_reward_counter: T::RewardCounter, /// The eras in which this member is unbonding, mapped from era index to the number of /// points scheduled to unbond in the given era. pub unbonding_eras: BoundedBTreeMap, T::MaxUnbonding>, @@ -414,7 +412,7 @@ pub struct PoolMember { impl PoolMember { /// The pending rewards of this member. - fn pending_rewards(&self, current_reward_counter: RewardCounter) -> BalanceOf { + fn pending_rewards(&self, current_reward_counter: T::RewardCounter) -> Result, Error::> { // Precision note: Reward counters are fixedU128 with base of 10^18. Multiplying it with // points, which have the same granularity as with balance should almost always be fine for // Polkadot and Kusama since: The total issuance of both are @@ -450,8 +448,8 @@ impl PoolMember { // the calculations be checked arithmetic, to make sure if a pool ever reaches this state // way earlier than the few decades we anticipate due to severe slashing, no operations can // happen in that pool. - (current_reward_counter.saturating_sub(self.last_recorded_reward_counter)) - .saturating_mul_int(self.active_points()) + (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) + .checked_mul_int(self.active_points()).ok_or(Error::::OverflowRisk) } /// Active balance of the member. @@ -968,7 +966,7 @@ pub struct RewardPool { /// /// This is updated ONLY when the points in the bonded pool change, which means `join`, /// `bond_extra` and `unbond`, all of which is done through `update_recorded`. - last_recorded_reward_counter: RewardCounter, + last_recorded_reward_counter: T::RewardCounter, /// The last recorded total payouts of the reward pool. /// /// Payouts is essentially income of the pool. @@ -980,7 +978,7 @@ pub struct RewardPool { } impl RewardPool { - fn last_recorded_reward_counter(&self) -> RewardCounter { + fn last_recorded_reward_counter(&self) -> T::RewardCounter { self.last_recorded_reward_counter } @@ -990,14 +988,20 @@ impl RewardPool { } /// Update the recorded values of the pool. - fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) { + fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) -> Result<(), Error> { let balance = Self::current_balance(id); - self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points); - self.last_recorded_total_payouts = balance.saturating_add(self.total_rewards_claimed); + self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points)?; + self.last_recorded_total_payouts = + balance.checked_add(&self.total_rewards_claimed).ok_or(Error::::OverflowRisk)?; + Ok(()) } /// Get the current reward counter, based on the given `bonded_points`. - fn current_reward_counter(&self, id: PoolId, bonded_points: BalanceOf) -> RewardCounter { + fn current_reward_counter( + &self, + id: PoolId, + bonded_points: BalanceOf, + ) -> Result> { let balance = Self::current_balance(id); let payouts_since_last_record = balance .saturating_add(self.total_rewards_claimed) @@ -1020,14 +1024,10 @@ impl RewardPool { // Polkadot. The important note here is that `reward_pool.last_recorded_reward_counter` only // ever accumulates, but its semantics imply that it is less than total_issuance, when // represented as `FixedU128`, which means it is less than `total_issuance * 10^18`. - self.last_recorded_reward_counter - .saturating_add(RewardCounter::saturating_from_rational( - payouts_since_last_record, - bonded_points, - )) + T::RewardCounter::checked_from_rational(payouts_since_last_record, bonded_points) + .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) + .ok_or(Error::::OverflowRisk) - // TODO: make reward counter generic type - // TODO: make any arithmetic on rewardCounter fallible. // TODO: test for arithmetic failing + micro reward payment in a mega-pool. } @@ -1165,6 +1165,7 @@ pub mod pallet { use super::*; use frame_support::traits::StorageVersion; use frame_system::{ensure_signed, pallet_prelude::*}; +use sp_runtime::traits::CheckedAdd; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); @@ -1185,17 +1186,34 @@ pub mod pallet { /// The nominating balance. type Currency: Currency; - /// The balance type. Needed to bound it to `FixedPointOperand`. + /// Sadly needed to bound it to `FixedPointOperand`. + // The only alternative is to sprinkle a `where BalanceOf: FixedPointOperand` in roughly + // a million places, so we prefer doing this. type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned + codec::FullCodec + Copy + MaybeSerializeDeserialize + sp_std::fmt::Debug + Default - + sp_runtime::FixedPointOperand + + FixedPointOperand + + CheckedAdd + TypeInfo + MaxEncodedLen; + /// The type that is used for reward counter. + /// + /// The arithmetic of the reward counter might saturate based on the size of the + /// `Currency::Balance`. If this happens, operations fails. Nonetheless, this type should be + /// chosen such that this failure almost never happens, as if it happens, the pool basically + /// needs to be dismantled (or all pools migrated to a larger `RewardCounter` type, which is + /// a PITA to do). + /// + /// See the inline code docs of `Member::pending_rewards` and `RewardPool::update_recorded` + /// for example analysis. A [`sp_runtime::FixedU128`] should be fine for chains with balance + /// types similar to that of Polkadot and Kusama, in the absence of severe slashing, for + /// many many years to come. + type RewardCounter: FixedPointNumber + MaxEncodedLen + TypeInfo + Default + codec::FullCodec; + /// The nomination pool's pallet id. #[pallet::constant] type PalletId: Get; @@ -1507,7 +1525,7 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - reward_pool.update_records(pool_id, bonded_pool.points); + let _ = reward_pool.update_records(pool_id, bonded_pool.points)?; bonded_pool.try_inc_members()?; let points_issued = bonded_pool.try_bond_funds(&who, amount, BondType::Later)?; @@ -1554,7 +1572,7 @@ pub mod pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - reward_pool.update_records(bonded_pool.id, bonded_pool.points); + let _ = reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; // TODO: optimize this to not touch the free balance of `who ` at all in benchmarks. // Currently, bonding rewards is like a batch. In the same PR, also make this function // take a boolean argument that make it either 100% pure (no storage update), or make it @@ -1643,7 +1661,7 @@ pub mod pallet { // Claim the the payout prior to unbonding. Once the user is unbonding their points no // longer exist in the bonded pool and thus they can no longer claim their payouts. It // is not strictly necessary to claim the rewards, but we do it here for UX. - reward_pool.update_records(bonded_pool.id, bonded_pool.points); + let _ = reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; let _ = Self::do_reward_payout(&who, &mut member, &mut bonded_pool, &mut reward_pool)?; let current_era = T::StakingInterface::current_era(); @@ -2287,8 +2305,8 @@ impl Pallet { ensure!(!member.active_points().is_zero(), Error::::FullyUnbonding); let current_reward_counter = - reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points); - let pending_rewards = member.pending_rewards(current_reward_counter); + reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?; + let pending_rewards = member.pending_rewards(current_reward_counter)?; member.last_recorded_reward_counter = current_reward_counter; reward_pool.register_claimed_reward(pending_rewards); diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 045f289f3b370..25395d406229b 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -2,9 +2,11 @@ use super::*; use crate::{self as pools}; use frame_support::{assert_ok, parameter_types, PalletId}; use frame_system::RawOrigin; +use sp_runtime::{FixedU128}; pub type AccountId = u128; pub type Balance = u128; +pub type RewardCounter = FixedU128; // Ext builder creates a pool with id 1. pub fn default_bonded_account() -> AccountId { @@ -185,6 +187,7 @@ impl pools::Config for Runtime { type WeightInfo = (); type Currency = Balances; type CurrencyBalance = Balance; + type RewardCounter = RewardCounter; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = StakingMock; diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 2e7aace49d027..54e034862e120 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -17,7 +17,7 @@ use frame_election_provider_support::VoteWeight; use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; -use sp_runtime::traits::{Convert, IdentityLookup}; +use sp_runtime::{traits::{Convert, IdentityLookup}, FixedU128}; type AccountId = u128; type AccountIndex = u32; @@ -158,6 +158,7 @@ impl pallet_nomination_pools::Config for Runtime { type WeightInfo = (); type Currency = Balances; type CurrencyBalance = Balance; + type RewardCounter = FixedU128; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = Staking; From 1c43f09bec33c82b8e04747f98b976d108466600 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 21 Jun 2022 11:32:22 +0200 Subject: [PATCH 42/65] fix node runtime --- bin/node/runtime/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index ca9cbc0abc967..f5e01be45b246 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -69,7 +69,7 @@ use sp_runtime::{ SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill, + ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill, FixedU128, }; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] @@ -753,6 +753,7 @@ impl pallet_nomination_pools::Config for Runtime { type Event = Event; type Currency = Balances; type CurrencyBalance = Balance; + type RewardCounter = FixedU128; type BalanceToU256 = BalanceToU256; type U256ToBalance = U256ToBalance; type StakingInterface = pallet_staking::Pallet; From ef56db6e5422dec23c187e7c5703cdbcdf0e03da Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 22 Jun 2022 10:08:58 +0200 Subject: [PATCH 43/65] a lot of precision tests and notes and stuff --- frame/nomination-pools/src/lib.rs | 63 ++++-- frame/nomination-pools/src/mock.rs | 13 +- frame/nomination-pools/src/tests.rs | 309 ++++++++++++++++++++++++++++ 3 files changed, 365 insertions(+), 20 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 160fdb5cf44c1..958f2883f39b3 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -316,7 +316,7 @@ use frame_support::{ use scale_info::TypeInfo; use sp_core::U256; use sp_runtime::{ - traits::{AccountIdConversion, Bounded, CheckedSub, Convert, Saturating, Zero, CheckedAdd}, + traits::{AccountIdConversion, Bounded, CheckedAdd, CheckedSub, Convert, Saturating, Zero}, FixedPointNumber, FixedPointOperand, }; use sp_staking::{EraIndex, OnStakerSlash, StakingInterface}; @@ -412,8 +412,11 @@ pub struct PoolMember { impl PoolMember { /// The pending rewards of this member. - fn pending_rewards(&self, current_reward_counter: T::RewardCounter) -> Result, Error::> { - // Precision note: Reward counters are fixedU128 with base of 10^18. Multiplying it with + fn pending_rewards( + &self, + current_reward_counter: T::RewardCounter, + ) -> Result, Error> { + // accuracy note: Reward counters are fixedU128 with base of 10^18. Multiplying it with // points, which have the same granularity as with balance should almost always be fine for // Polkadot and Kusama since: The total issuance of both are // @@ -449,7 +452,8 @@ impl PoolMember { // way earlier than the few decades we anticipate due to severe slashing, no operations can // happen in that pool. (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) - .checked_mul_int(self.active_points()).ok_or(Error::::OverflowRisk) + .checked_mul_int(self.active_points()) + .ok_or(Error::::OverflowRisk) } /// Active balance of the member. @@ -708,7 +712,7 @@ impl BondedPool { MaxPoolMembers::::get().map_or(true, |max| PoolMembers::::count() < max), Error::::MaxPoolMembers ); - self.member_counter = self.member_counter.defensive_saturating_add(1); + self.member_counter = self.member_counter.checked_add(1).ok_or(Error::::OverflowRisk)?; Ok(()) } @@ -991,12 +995,14 @@ impl RewardPool { fn update_records(&mut self, id: PoolId, bonded_points: BalanceOf) -> Result<(), Error> { let balance = Self::current_balance(id); self.last_recorded_reward_counter = self.current_reward_counter(id, bonded_points)?; - self.last_recorded_total_payouts = - balance.checked_add(&self.total_rewards_claimed).ok_or(Error::::OverflowRisk)?; + self.last_recorded_total_payouts = balance + .checked_add(&self.total_rewards_claimed) + .ok_or(Error::::OverflowRisk)?; Ok(()) } - /// Get the current reward counter, based on the given `bonded_points`. + /// Get the current reward counter, based on the given `bonded_points` being the state of the + /// bonded pool at this time. fn current_reward_counter( &self, id: PoolId, @@ -1007,8 +1013,9 @@ impl RewardPool { .saturating_add(self.total_rewards_claimed) .saturating_sub(self.last_recorded_total_payouts); - // accuracy notes: `payouts_since_last_record` is a subset of the total_issuance at the very - // worse. Bonded_points are similarly, in a non-slashed pool, have the same granularity as + // * accuracy notes regarding the multiplication in `checked_from_rational`: + // `payouts_since_last_record` is a subset of the total_issuance at the very + // worse. `bonded_points` are similarly, in a non-slashed pool, have the same granularity as // balance, and are thus below within the range of total_issuance. In the worse case // scenario, for `saturating_from_rational`, we have: // @@ -1024,11 +1031,24 @@ impl RewardPool { // Polkadot. The important note here is that `reward_pool.last_recorded_reward_counter` only // ever accumulates, but its semantics imply that it is less than total_issuance, when // represented as `FixedU128`, which means it is less than `total_issuance * 10^18`. + // + // * accuracy notes regarding `checked_from_rational` collapsing to zero, meaning that no + // reward can be claimed: + // + // largest `bonded_points`, such that the reward counter is non-zero, with `FixedU128` + // will be when the payout is being computed. This essentially means `payout/bonded_points` + // needs to be more than 1/1^18. Thus, assuming that `bonded_points` will always be less + // than `10 * dot_total_issuance`, if the reward_counter is the smallest possible value, + // the value of the reward being calculated is: + // + // x / 10^20 = 1/ 10^18 + // + // x = 100 + // + // which is basically 10^-8 DOTs. See `smallest_claimable_reward` for an example of this. T::RewardCounter::checked_from_rational(payouts_since_last_record, bonded_points) .and_then(|ref r| self.last_recorded_reward_counter.checked_add(r)) .ok_or(Error::::OverflowRisk) - - // TODO: test for arithmetic failing + micro reward payment in a mega-pool. } /// Current free balance of the reward pool. @@ -1165,7 +1185,7 @@ pub mod pallet { use super::*; use frame_support::traits::StorageVersion; use frame_system::{ensure_signed, pallet_prelude::*}; -use sp_runtime::traits::CheckedAdd; + use sp_runtime::traits::CheckedAdd; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); @@ -1984,8 +2004,14 @@ use sp_runtime::traits::CheckedAdd; /// Set a new state for the pool. /// - /// The dispatch origin of this call must be signed by the state toggler, or the root role - /// of the pool. + /// If a pool is already in the `Destroying` state, then under no condition can its state + /// change again. + /// + /// The dispatch origin of this call must be either: + /// + /// 1. signed by the state toggler, or the root role of the pool, + /// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and + /// then the state of the pool can be permissionlessly changed to `Destroying`. #[pallet::weight(T::WeightInfo::set_state())] pub fn set_state( origin: OriginFor, @@ -2308,13 +2334,14 @@ impl Pallet { reward_pool.current_reward_counter(bonded_pool.id, bonded_pool.points)?; let pending_rewards = member.pending_rewards(current_reward_counter)?; - member.last_recorded_reward_counter = current_reward_counter; - reward_pool.register_claimed_reward(pending_rewards); - if pending_rewards.is_zero() { return Ok(pending_rewards) } + // IFF the reward is non-zero alter the member and reward pool info. + member.last_recorded_reward_counter = current_reward_counter; + reward_pool.register_claimed_reward(pending_rewards); + // Transfer payout to the member. T::Currency::transfer( &bonded_pool.reward_account(), diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 25395d406229b..71ea8bdd63eca 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -2,11 +2,14 @@ use super::*; use crate::{self as pools}; use frame_support::{assert_ok, parameter_types, PalletId}; use frame_system::RawOrigin; -use sp_runtime::{FixedU128}; +use sp_runtime::FixedU128; pub type AccountId = u128; pub type Balance = u128; pub type RewardCounter = FixedU128; +// This sneaky little hack allows us to write code exactly as we would do in the pallet in the tests +// as well, e.g. `StorageItem::::get()`. +pub type T = Runtime; // Ext builder creates a pool with id 1. pub fn default_bonded_account() -> AccountId { @@ -25,6 +28,7 @@ parameter_types! { pub storage UnbondingBalanceMap: BTreeMap = Default::default(); #[derive(Clone, PartialEq)] pub static MaxUnbonding: u32 = 8; + pub static StakingMinBond: Balance = 10; pub storage Nominations: Option> = None; } @@ -42,7 +46,7 @@ impl sp_staking::StakingInterface for StakingMock { type AccountId = AccountId; fn minimum_bond() -> Self::Balance { - 10 + StakingMinBond::get() } fn current_era() -> EraIndex { @@ -229,6 +233,11 @@ impl ExtBuilder { self } + pub(crate) fn min_bond(self, min: Balance) -> Self { + StakingMinBond::set(min); + self + } + pub(crate) fn with_check(self, level: u8) -> Self { CheckLevel::set(level); self diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index d493d8eb043bb..ad52f71ebeb56 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1143,6 +1143,7 @@ mod claim_payout { }); } + // TODO: SR-LABS must audit these tests, until the end of the module. Only remove once approved. #[test] fn rewards_distribution_is_fair_basic() { ExtBuilder::default().build_and_execute(|| { @@ -4023,3 +4024,311 @@ mod update_roles { }) } } + +mod reward_counter_precision { + use sp_runtime::FixedU128; + + // TODO: SR-LABS must audit these tests. Only remove once approved. + use super::*; + + const DOT: Balance = 10u128.pow(10u32); + const POLKADOT_TOTAL_ISSUANCE_GENESIS: Balance = DOT * 10u128.pow(9u32); + + const fn inflation(years: u128) -> u128 { + let mut i = 0; + let mut start = POLKADOT_TOTAL_ISSUANCE_GENESIS; + while i < years { + start = start + start / 10; + i += 1 + } + start + } + + fn default_pool_reward_counter() -> FixedU128 { + RewardPools::::get(1) + .unwrap() + .current_reward_counter(1, BondedPools::::get(1).unwrap().points) + .unwrap() + } + + fn pending_rewards(of: AccountId) -> Option> { + let member = PoolMembers::::get(of).unwrap(); + assert_eq!(member.pool_id, 1); + let rc = default_pool_reward_counter(); + member.pending_rewards(rc).ok() + } + + #[test] + fn smallest_claimable_reward() { + // create a pool that has all of the polkadot issuance in 50 years. + let pool_bond = inflation(50); + ExtBuilder::default().ed(DOT).min_bond(pool_bond).build_and_execute(|| { + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 1173908528796953165005, + joined: true, + } + ] + ); + + // the smallest reward that this pool can handle is + let expected_smallest_reward = inflation(50) / 10u128.pow(18); + + // tad bit less. cannot be paid out. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += + expected_smallest_reward - 1)); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_eq!(pool_events_since_last_call(), vec![]); + // revert it. + + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free -= + expected_smallest_reward - 1)); + + // tad bit more. can be claimed. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += + expected_smallest_reward + 1)); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 1173 }] + ); + }) + } + + #[test] + fn reward_counter_calc_wont_fail_in_normal_polkadot_future() { + // create a pool that has roughly half of the polkadot issuance in 10 years. + let pool_bond = inflation(10) / 2; + ExtBuilder::default().ed(DOT).min_bond(pool_bond).build_and_execute(|| { + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 12_968_712_300_500_000_000, + joined: true, + } + ] + ); + + // in 10 years, the total claimed rewards are large values as well. assuming that a pool + // is earning all of the inflation per year (which is really unrealistic, but worse + // case), that will be: + let pool_total_earnings_10_years = inflation(10) - POLKADOT_TOTAL_ISSUANCE_GENESIS; + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += + pool_total_earnings_10_years)); + + // some whale now joins with the other half ot the total issuance. This will bloat all + // the calculation regarding current reward counter. + Balances::make_free_balance_be(&20, pool_bond * 2); + assert_ok!(Pools::join(Origin::signed(20), pool_bond, 1)); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::Bonded { + member: 20, + pool_id: 1, + bonded: 12_968_712_300_500_000_000, + joined: true + }] + ); + + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 15937424600999999996 }] + ); + + // now let a small member join with 10 DOTs. + Balances::make_free_balance_be(&30, 20 * DOT); + assert_ok!(Pools::join(Origin::signed(30), 10 * DOT, 1)); + + // and give a reasonably small reward to the pool. + assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += DOT)); + + assert_ok!(Pools::claim_payout(Origin::signed(30))); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Bonded { member: 30, pool_id: 1, bonded: 100000000000, joined: true }, + // quite small, but working fine. + Event::PaidOut { member: 30, pool_id: 1, payout: 38 } + ] + ); + }) + } + + #[test] + fn reward_counter_update_can_fail_if_pool_is_highly_slashed() { + // create a pool that has roughly half of the polkadot issuance in 10 years. + let pool_bond = inflation(10) / 2; + ExtBuilder::default().ed(DOT).min_bond(pool_bond).build_and_execute(|| { + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 12_968_712_300_500_000_000, + joined: true, + } + ] + ); + + // slash this pool by 99% of that. + StakingMock::set_bonded_balance(default_bonded_account(), DOT + pool_bond / 100); + + // some whale now joins with the other half ot the total issuance. This will trigger an + // overflow. This test is actually a bit too lenient because all the reward counters are + // set to zero. In other tests that we want to assert a scenario won't fail, we should + // also set the reward counters to some large value. + Balances::make_free_balance_be(&20, pool_bond * 2); + assert_err!(Pools::join(Origin::signed(20), pool_bond, 1), Error::::OverflowRisk); + }) + } + + #[test] + fn if_small_member_waits_long_enough_they_will_earn_rewards() { + // create a pool that has a quarter of the current polkadot issuance + ExtBuilder::default() + .ed(DOT) + .min_bond(POLKADOT_TOTAL_ISSUANCE_GENESIS / 4) + .build_and_execute(|| { + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 2500000000000000000, + joined: true, + } + ] + ); + + // and have a tiny fish join the pool as well.. + Balances::make_free_balance_be(&20, 20 * DOT); + assert_ok!(Pools::join(Origin::signed(20), 10 * DOT, 1)); + + // earn some small rewards + assert_ok!( + Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000) + ); + + // no point in claiming for 20 (nonetheless, it should be harmless) + assert!(pending_rewards(20).unwrap().is_zero()); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Bonded { + member: 20, + pool_id: 1, + bonded: 100000000000, + joined: true + }, + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } + ] + ); + + // earn some small more, still nothing can be claimed for 20, but 10 claims their + // share. + assert_ok!( + Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000) + ); + assert!(pending_rewards(20).unwrap().is_zero()); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_eq!( + pool_events_since_last_call(), + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }] + ); + + // earn some more rewards, this time 20 can also claim. + assert_ok!( + Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000) + ); + assert_eq!(pending_rewards(20).unwrap(), 1); + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::PaidOut { member: 10, pool_id: 1, payout: 10000000 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 1 } + ] + ); + }); + } + + #[test] + fn zero_reward_claim_does_not_update_reward_counter() { + // create a pool that has a quarter of the current polkadot issuance + ExtBuilder::default() + .ed(DOT) + .min_bond(POLKADOT_TOTAL_ISSUANCE_GENESIS / 4) + .build_and_execute(|| { + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 2500000000000000000, + joined: true, + } + ] + ); + + // and have a tiny fish join the pool as well.. + Balances::make_free_balance_be(&20, 20 * DOT); + assert_ok!(Pools::join(Origin::signed(20), 10 * DOT, 1)); + + // earn some small rewards + assert_ok!( + Balances::mutate_account(&default_reward_account(), |a| a.free += DOT / 1000) + ); + + // if 20 claims now, their reward counter should stay the same, so that they have a + // chance of claiming this if they let it accumulate. Also see + // `if_small_member_waits_long_enough_they_will_earn_rewards` + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Bonded { + member: 20, + pool_id: 1, + bonded: 100000000000, + joined: true + }, + Event::PaidOut { member: 10, pool_id: 1, payout: 9999997 } + ] + ); + + let current_reward_counter = default_pool_reward_counter(); + // has been updated, because they actually claimed something. + assert_eq!( + PoolMembers::::get(10).unwrap().last_recorded_reward_counter, + current_reward_counter + ); + // has not be updated, even though the claim transaction went through okay. + assert_eq!( + PoolMembers::::get(20).unwrap().last_recorded_reward_counter, + Default::default() + ); + }); + } +} From 3da2364fa013c37874a66bf73e2c45049df1123b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 22 Jun 2022 10:25:27 +0200 Subject: [PATCH 44/65] document MaxPOintsToBalance better --- bin/node/runtime/src/lib.rs | 4 +-- .../nomination-pools/benchmarking/src/mock.rs | 4 +-- frame/nomination-pools/src/lib.rs | 23 ++++++++----- frame/nomination-pools/src/mock.rs | 2 +- frame/nomination-pools/src/tests.rs | 34 +++++++++---------- .../nomination-pools/test-staking/src/mock.rs | 2 +- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index f5e01be45b246..c909bc9cb9b56 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -731,7 +731,7 @@ impl pallet_bags_list::Config for Runtime { parameter_types! { pub const PostUnbondPoolsWindow: u32 = 4; pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const MinPointsToBalance: u32 = 10; + pub const MaxPointsToBalance: u32 = 10; } use sp_runtime::traits::Convert; @@ -761,7 +761,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxMetadataLen = ConstU32<256>; type MaxUnbonding = ConstU32<8>; type PalletId = NominationPoolsPalletId; - type MinPointsToBalance = MinPointsToBalance; + type MaxPointsToBalance = MaxPointsToBalance; } parameter_types! { diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 956926bb8cf2e..9bc8916a3eb7a 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -144,7 +144,7 @@ impl Convert for U256ToBalance { parameter_types! { pub static PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const MinPointsToBalance: u32 = 10; + pub const MaxPointsToBalance: u32 = 10; } impl pallet_nomination_pools::Config for Runtime { @@ -160,7 +160,7 @@ impl pallet_nomination_pools::Config for Runtime { type MaxMetadataLen = ConstU32<256>; type MaxUnbonding = ConstU32<8>; type PalletId = PoolsPalletId; - type MinPointsToBalance = MinPointsToBalance; + type MaxPointsToBalance = MaxPointsToBalance; } impl crate::Config for Runtime {} diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 958f2883f39b3..8c5322f7d7979 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -789,19 +789,19 @@ impl BondedPool { // We checked for zero above .div(bonded_balance); - let min_points_to_balance = T::MinPointsToBalance::get(); + let max_points_to_balance = T::MaxPointsToBalance::get(); // Pool points can inflate relative to balance, but only if the pool is slashed. // If we cap the ratio of points:balance so one cannot join a pool that has been slashed - // by `min_points_to_balance`%, if not zero. + // by `max_points_to_balance`%, if not zero. ensure!( - points_to_balance_ratio_floor < min_points_to_balance.into(), + points_to_balance_ratio_floor < max_points_to_balance.into(), Error::::OverflowRisk ); - // while restricting the balance to `min_points_to_balance` of max total issuance, + // while restricting the balance to `max_points_to_balance` of max total issuance, let next_bonded_balance = bonded_balance.saturating_add(new_funds); ensure!( - next_bonded_balance < BalanceOf::::max_value().div(min_points_to_balance.into()), + next_bonded_balance < BalanceOf::::max_value().div(max_points_to_balance.into()), Error::::OverflowRisk ); @@ -1238,13 +1238,20 @@ pub mod pallet { #[pallet::constant] type PalletId: Get; - /// The minimum pool points-to-balance ratio that must be maintained for it to be `open`. + /// The maximum pool points-to-balance ratio that an `open` pool can have. + /// /// This is important in the event slashing takes place and the pool's points-to-balance /// ratio becomes disproportional. + /// + /// Moreover, this relates to the `RewardCounter` type as well, as the arithmetic operations + /// are a function of number of points, and by setting this value to e.g. 10, you ensure + /// that the total number of points in the system are at most 10 times the total_issuance of + /// the chain, in the absolute worse case. + /// /// For a value of 10, the threshold would be a pool points-to-balance ratio of 10:1. /// Such a scenario would also be the equivalent of the pool being 90% slashed. #[pallet::constant] - type MinPointsToBalance: Get; + type MaxPointsToBalance: Get; /// Infallible method for converting `Currency::Balance` to `U256`. type BalanceToU256: Convert, U256>; @@ -2174,7 +2181,7 @@ pub mod pallet { impl Hooks> for Pallet { fn integrity_test() { assert!( - T::MinPointsToBalance::get() > 0, + T::MaxPointsToBalance::get() > 0, "Minimum points to balance ratio must be greater than 0" ); assert!( diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 71ea8bdd63eca..34fcaffc194b1 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -199,7 +199,7 @@ impl pools::Config for Runtime { type PalletId = PoolsPalletId; type MaxMetadataLen = MaxMetadataLen; type MaxUnbonding = MaxUnbonding; - type MinPointsToBalance = frame_support::traits::ConstU32<10>; + type MaxPointsToBalance = frame_support::traits::ConstU32<10>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index ad52f71ebeb56..f7e81d6f0db6b 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -207,34 +207,34 @@ mod bonded_pool { }, }; - let min_points_to_balance: u128 = - <::MinPointsToBalance as Get>::get().into(); + let max_points_to_balance: u128 = + <::MaxPointsToBalance as Get>::get().into(); // Simulate a 100% slashed pool StakingMock::set_bonded_balance(pool.bonded_account(), 0); assert_noop!(pool.ok_to_join(0), Error::::OverflowRisk); - // Simulate a slashed pool at `MinPointsToBalance` + 1 slashed pool + // Simulate a slashed pool at `MaxPointsToBalance` + 1 slashed pool StakingMock::set_bonded_balance( pool.bonded_account(), - min_points_to_balance.saturating_add(1).into(), + max_points_to_balance.saturating_add(1).into(), ); assert_ok!(pool.ok_to_join(0)); - // Simulate a slashed pool at `MinPointsToBalance` - StakingMock::set_bonded_balance(pool.bonded_account(), min_points_to_balance); + // Simulate a slashed pool at `MaxPointsToBalance` + StakingMock::set_bonded_balance(pool.bonded_account(), max_points_to_balance); assert_noop!(pool.ok_to_join(0), Error::::OverflowRisk); StakingMock::set_bonded_balance( pool.bonded_account(), - Balance::MAX / min_points_to_balance, + Balance::MAX / max_points_to_balance, ); // New bonded balance would be over threshold of Balance type assert_noop!(pool.ok_to_join(0), Error::::OverflowRisk); // and a sanity check StakingMock::set_bonded_balance( pool.bonded_account(), - Balance::MAX / min_points_to_balance - 1, + Balance::MAX / max_points_to_balance - 1, ); assert_ok!(pool.ok_to_join(0)); }); @@ -518,35 +518,35 @@ mod join { // and reward pool RewardPools::::insert(123, RewardPool:: { ..Default::default() }); - // Force the points:balance ratio to `MinPointsToBalance` (100/10) - let min_points_to_balance: u128 = - <::MinPointsToBalance as Get>::get().into(); + // Force the points:balance ratio to `MaxPointsToBalance` (100/10) + let max_points_to_balance: u128 = + <::MaxPointsToBalance as Get>::get().into(); StakingMock::set_bonded_balance( Pools::create_bonded_account(123), - min_points_to_balance, + max_points_to_balance, ); assert_noop!(Pools::join(Origin::signed(11), 420, 123), Error::::OverflowRisk); StakingMock::set_bonded_balance( Pools::create_bonded_account(123), - Balance::MAX / min_points_to_balance, + Balance::MAX / max_points_to_balance, ); - // Balance needs to be gt Balance::MAX / `MinPointsToBalance` + // Balance needs to be gt Balance::MAX / `MaxPointsToBalance` assert_noop!(Pools::join(Origin::signed(11), 5, 123), Error::::OverflowRisk); - StakingMock::set_bonded_balance(Pools::create_bonded_account(1), min_points_to_balance); + StakingMock::set_bonded_balance(Pools::create_bonded_account(1), max_points_to_balance); // Cannot join a pool that isn't open unsafe_set_state(123, PoolState::Blocked).unwrap(); assert_noop!( - Pools::join(Origin::signed(11), min_points_to_balance, 123), + Pools::join(Origin::signed(11), max_points_to_balance, 123), Error::::NotOpen ); unsafe_set_state(123, PoolState::Destroying).unwrap(); assert_noop!( - Pools::join(Origin::signed(11), min_points_to_balance, 123), + Pools::join(Origin::signed(11), max_points_to_balance, 123), Error::::NotOpen ); diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 54e034862e120..ae240f2f853e0 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -165,7 +165,7 @@ impl pallet_nomination_pools::Config for Runtime { type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow; type MaxMetadataLen = ConstU32<256>; type MaxUnbonding = ConstU32<8>; - type MinPointsToBalance = ConstU32<10>; + type MaxPointsToBalance = ConstU32<10>; type PalletId = PoolsPalletId; } From 3690489ccfabd54076fd8cacc90c2d6cd6fc7f04 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 23 Jun 2022 10:11:49 +0200 Subject: [PATCH 45/65] :round of self-review --- frame/nomination-pools/src/lib.rs | 207 +++++++++--------------- frame/nomination-pools/src/migration.rs | 1 + 2 files changed, 81 insertions(+), 127 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 8c5322f7d7979..5f805e934d711 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -17,8 +17,8 @@ //! # Nomination Pools for Staking Delegation //! -//! A pallet that allows members to delegate their stake to nominating pools. A nomination pool -//! acts as nominator and nominates validators on the members behalf. +//! A pallet that allows members to delegate their stake to nominating pools. A nomination pool acts +//! as nominator and nominates validators on the members behalf. //! //! # Index //! @@ -28,16 +28,27 @@ //! //! ## Key terms //! +//! * pool id: A unique identifier of each pool. Set to u12 //! * bonded pool: Tracks the distribution of actively staked funds. See [`BondedPool`] and -//! [`BondedPoolInner`]. Bonded pools are identified via the pools bonded account. +//! [`BondedPoolInner`]. //! * reward pool: Tracks rewards earned by actively staked funds. See [`RewardPool`] and -//! [`RewardPools`]. Reward pools are identified via the pools bonded account. +//! [`RewardPools`]. //! * unbonding sub pools: Collection of pools at different phases of the unbonding lifecycle. See -//! [`SubPools`] and [`SubPoolsStorage`]. Sub pools are identified via the pools bonded account. -//! * members: Accounts that are members of pools. See [`PoolMember`] and [`PoolMembers`]. Pool -//! members are identified via their account. -//! * point: A unit of measure for a members portion of a pool's funds. +//! [`SubPools`] and [`SubPoolsStorage`]. +//! * members: Accounts that are members of pools. See [`PoolMember`] and [`PoolMembers`]. +//! * roles: Administrative roles of each pool, capable of controlling nomination, and the state of +//! the pool. +//! * point: A unit of measure for a members portion of a pool's funds. Points initially have a +//! ratio of 1 (as set by `POINTS_TO_BALANCE_INIT_RATIO`) to balance, but as slashing happens, +//! this can change. //! * kick: The act of a pool administrator forcibly ejecting a member. +//! * bonded account: A key-less account id derived from the pool id that acts as the bonded +//! account. This account registers itself as a nominator in the staking system, and follows +//! exactly the same rules and conditions as a normal staker. Its bond increases or +//! decreases as members join, it can `nominate` or `chill`, and might not even earn staking +//! rewards if it is not nominating proper validators. +//! * reward account: A similar key-less account, that is set as the `Payee` account fo the bonded +//! account for all staking rewards. //! //! ## Usage //! @@ -55,11 +66,13 @@ //! //! In order to leave, a member must take two steps. //! -//! First, they must call [`Call::unbond`]. The unbond other extrinsic will start the -//! unbonding process by unbonding all of the members funds. +//! First, they must call [`Call::unbond`]. The unbond extrinsic will start the unbonding process by +//! unbonding all or a portion of the members funds. //! -//! Second, once [`sp_staking::StakingInterface::bonding_duration`] eras have passed, the member -//! can call [`Call::withdraw_unbonded`] to withdraw all their funds. +//! > A member can have up to [`MaxUnbonding`] distinct active unbonding requests. +//! +//! Second, once [`sp_staking::StakingInterface::bonding_duration`] eras have passed, the member can +//! call [`Call::withdraw_unbonded`] to withdraw any funds that are free. //! //! For design docs see the [bonded pool](#bonded-pool) and [unbonding sub //! pools](#unbonding-sub-pools) sections. @@ -67,9 +80,13 @@ //! ### Slashes //! //! Slashes are distributed evenly across the bonded pool and the unbonding pools from slash era+1 -//! through the slash apply era. Thus, any member who either a) unbonded or b) was actively -//! bonded in the aforementioned range of eras will be affected by the slash. A member is slashed -//! pro-rata based on its stake relative to the total slash amount. +//! through the slash apply era. Thus, any member who either +//! +//! 1. unbonded, or +//! 2. was actively bonded +// +//! in the aforementioned range of eras will be affected by the slash. A member is slashed pro-rata +//! based on its stake relative to the total slash amount. //! //! For design docs see the [slashing](#slashing) section. //! @@ -82,20 +99,33 @@ //! To help facilitate pool administration the pool has one of three states (see [`PoolState`]): //! //! * Open: Anyone can join the pool and no members can be permissionlessly removed. -//! * Blocked: No members can join and some admin roles can kick members. +//! * Blocked: No members can join and some admin roles can kick members. Kicking is not instant, +//! and follows the same process of `unbond` and then `withdraw_unbonded`. In other words, +//! administrators can permissionlessly unbond other members. //! * Destroying: No members can join and all members can be permissionlessly removed with //! [`Call::unbond`] and [`Call::withdraw_unbonded`]. Once a pool is in destroying state, it //! cannot be reverted to another state. //! -//! A pool has 3 administrative roles (see [`PoolRoles`]): +//! A pool has 4 administrative roles (see [`PoolRoles`]): //! //! * Depositor: creates the pool and is the initial member. They can only leave the pool once all -//! other members have left. Once they fully leave the pool is destroyed. +//! other members have left. Once they fully withdraw their funds, the pool is destroyed. //! * Nominator: can select which validators the pool nominates. //! * State-Toggler: can change the pools state and kick members if the pool is blocked. //! * Root: can change the nominator, state-toggler, or itself and can perform any of the actions //! the nominator or state-toggler can. //! +//! ### Dismantling +//! +//! As noted, a pool is destroyed once +//! +//! 1. First, all members need to fully unbond and withdraw. If the pool state is set to +//! `Destroying`, this can happen permissionlessly. +//! 2. The depositor itself fully unbonds and withdraws. Note that at this point, based on the +//! requirements of the staking system, the pool's bonded account's stake might not be able to ge +//! below a certain threshold as a nominator. At this point, the pool should `chill` itself to +//! allow the depositor to leave. +//! //! ## Design //! //! _Notes_: this section uses pseudo code to explain general design and does not necessarily @@ -108,8 +138,8 @@ //! members that where in the pool while it was backing a validator that got slashed. //! * Maximize scalability in terms of member count. //! -//! In order to maintain scalability, all operations are independent of the number of members. To -//! do this, delegation specific information is stored local to the member while the pool data +//! In order to maintain scalability, all operations are independent of the number of members. To do +//! this, delegation specific information is stored local to the member while the pool data //! structures have bounded datum. //! //! ### Bonded pool @@ -118,9 +148,9 @@ //! unbonding. The total points of a bonded pool are always equal to the sum of points of the //! delegation members. A bonded pool tracks its points and reads its bonded balance. //! -//! When a member joins a pool, `amount_transferred` is transferred from the members account -//! to the bonded pools account. Then the pool calls `staking::bond_extra(amount_transferred)` and -//! issues new points which are tracked by the member and added to the bonded pool's points. +//! When a member joins a pool, `amount_transferred` is transferred from the members account to the +//! bonded pools account. Then the pool calls `staking::bond_extra(amount_transferred)` and issues +//! new points which are tracked by the member and added to the bonded pool's points. //! //! When the pool already has some balance, we want the value of a point before the transfer to //! equal the value of a point after the transfer. So, when a member joins a bonded pool with a @@ -148,77 +178,13 @@ //! ### Reward pool //! //! When a pool is first bonded it sets up an deterministic, inaccessible account as its reward -//! destination. To track staking rewards we track how the balance of this reward account changes. -//! -//! The reward pool needs to store: -//! -//! * The pool balance at the time of the last payout: `reward_pool.balance` -//! * The total earnings ever at the time of the last payout: `reward_pool.total_earnings` -//! * The total points in the pool at the time of the last payout: `reward_pool.points` -//! -//! And the member needs to store: -//! -//! * The total payouts at the time of the last payout by that member: -//! `member.reward_pool_total_earnings` -//! -//! Before the first reward claim is initiated for a pool, all the above variables are set to zero. -//! -//! When a member initiates a claim, the following happens: -//! -//! 1) Compute the reward pool's total points and the member's virtual points in the reward pool -//! * First `current_total_earnings` is computed (`current_balance` is the free balance of the -//! reward pool at the beginning of these operations.) -//! ```text -//! current_total_earnings = -//! current_balance - reward_pool.balance + pool.total_earnings; -//! ``` -//! * Then the `current_points` is computed. Every balance unit that was added to the reward -//! pool since last time recorded means that the `pool.points` is increased by -//! `bonding_pool.total_points`. In other words, for every unit of balance that has been -//! earned by the reward pool, the reward pool points are inflated by `bonded_pool.points`. In -//! effect this allows each, single unit of balance (e.g. planck) to be divvied up pro-rata -//! among members based on points. -//! ```text -//! new_earnings = current_total_earnings - reward_pool.total_earnings; -//! current_points = reward_pool.points + bonding_pool.points * new_earnings; -//! ``` -//! * Finally, the`member_virtual_points` are computed: the product of the member's points in -//! the bonding pool and the total inflow of balance units since the last time the member -//! claimed rewards -//! ```text -//! new_earnings_since_last_claim = current_total_earnings - member.reward_pool_total_earnings; -//! member_virtual_points = member.points * new_earnings_since_last_claim; -//! ``` -//! 2) Compute the `member_payout`: -//! ```text -//! member_pool_point_ratio = member_virtual_points / current_points; -//! member_payout = current_balance * member_pool_point_ratio; -//! ``` -//! 3) Transfer `member_payout` to the member -//! 4) For the member set: -//! ```text -//! member.reward_pool_total_earnings = current_total_earnings; -//! ``` -//! 5) For the pool set: -//! ```text -//! reward_pool.points = current_points - member_virtual_points; -//! reward_pool.balance = current_balance - member_payout; -//! reward_pool.total_earnings = current_total_earnings; -//! ``` -//! -//! _Note_: One short coming of this design is that new joiners can claim rewards for the era after -//! they join even though their funds did not contribute to the pools vote weight. When a -//! member joins, it's `reward_pool_total_earnings` field is set equal to the `total_earnings` -//! of the reward pool at that point in time. At best the reward pool has the rewards up through the -//! previous era. If a member joins prior to the election snapshot it will benefit from the -//! rewards for the active era despite not contributing to the pool's vote weight. If it joins -//! after the election snapshot is taken it will benefit from the rewards of the next _2_ eras -//! because it's vote weight will not be counted until the election snapshot in active era + 1. -//! Related: -// _Note to maintainers_: In order to ensure the reward account never falls below the existential -// deposit, at creation the reward account must be endowed with the existential deposit. All logic -// for calculating rewards then does not see that existential deposit as part of the free balance. -// See `RewardPool::current_balance`. +//! destination. +//! +//! The reward pool is not really a pool anymore, as it does not track points anymore. Instead, it +//! tracks, a virtual value called `reward_counter`, among a few other values. +//! +//! See [this link](https://hackmd.io/PFGn6wI5TbCmBYoEA_f2Uw) for an in-depth explanation of the +//! reward pool mechanism. //! //! **Relevant extrinsics:** //! @@ -416,41 +382,25 @@ impl PoolMember { &self, current_reward_counter: T::RewardCounter, ) -> Result, Error> { - // accuracy note: Reward counters are fixedU128 with base of 10^18. Multiplying it with - // points, which have the same granularity as with balance should almost always be fine for - // Polkadot and Kusama since: The total issuance of both are - // - // dot: 12,047,781,394,999,601,455 - // ksm: 12,424,748,376,019,599,766 - // - // both of which are around 60% of u64::max. So, the absolute worse case for a non-slashed - // pool that can happen is that the points are equal to the whole total issuance, and the - // reward counter is `RewardCounter::max_value()`. In this case, we get: - // - // dot_total_issuance * u128::max / 10^18 + // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being + // multiplied by a point. The worse case of a point is 10x the granularity of the balance. + // Assuming roughly the current issuance of polkadot (12,047,781,394,999,601,455, which is + // 1.2 * 10^9 10^10 = 1.2 * 10^19), the worse case point value is around 10^20. // - // which is roughly 12 more than u128::max. This means this will overflow if: a pool's - // points is roughly 1/12th of the total issuance, which in a non-slashed dot means if a - // pool owns 1/12th of the total issuance. In reality though, the accumulated reward will - // likely be much smaller than u128::max. + // The final multiplication is: // - // more on that: the reward counter is the sum of all the rewards that are always given out - // to a pool, multiplied by 10^18. Again, assuming that the rewards of a pool are equal to - // the WHOLE total issuance (which is only realistically possible in multiple decades from - // now, and a single pool earning almost all the inflation), we can compute: + // rc * 10^20 / 10^18 = rc * 100 // - // dot_total_issuance * 10**18 / 2**128 + // meaning that as long as reward_counter's value is less than 1/100th of its max capacity + // (u128), `checked_mul_int` won't saturate. // - // which is roughly 3%, meaning that roughly 3% of the capacity of the u128 is filled, and - // that a more realistic value for the previous calculation was: - // - // dot_total_issuance * (dot_total_issuance * 10^18) / 10^18 - // - // which simplifies to dot_total_issuance^2. In other words, as long as square of the total - // issuance fits in u128, this whole calculation won't saturate. Nonetheless, we make all of - // the calculations be checked arithmetic, to make sure if a pool ever reaches this state - // way earlier than the few decades we anticipate due to severe slashing, no operations can - // happen in that pool. + // given the nature of reward counter being 'pending_rewards / pool_total_point', the only + // (unrealistic) way that super high values can be achieved is for a pool to suddenly + // receive massive rewards with a very very small amount of stake. In all normal pools, as + // the points increase, so does the rewards. Moreover, as long as rewards are not + // accumulated for astronomically large durations, + // `current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)` + // won't be extremely big. (current_reward_counter.defensive_saturating_sub(self.last_recorded_reward_counter)) .checked_mul_int(self.active_points()) .ok_or(Error::::OverflowRisk) @@ -982,6 +932,7 @@ pub struct RewardPool { } impl RewardPool { + /// Getter for [`RewardPool::last_recorded_reward_counter`]. fn last_recorded_reward_counter(&self) -> T::RewardCounter { self.last_recorded_reward_counter } @@ -1230,8 +1181,8 @@ pub mod pallet { /// /// See the inline code docs of `Member::pending_rewards` and `RewardPool::update_recorded` /// for example analysis. A [`sp_runtime::FixedU128`] should be fine for chains with balance - /// types similar to that of Polkadot and Kusama, in the absence of severe slashing, for - /// many many years to come. + /// types similar to that of Polkadot and Kusama, in the absence of severe slashing (or + /// prevented via a reasonable `MaxPointsToBalance`), for many many years to come. type RewardCounter: FixedPointNumber + MaxEncodedLen + TypeInfo + Default + codec::FullCodec; /// The nomination pool's pallet id. @@ -1586,6 +1537,8 @@ pub mod pallet { /// /// Additional funds can come from either the free balance of the account, of from the /// accumulated rewards, see [`BondExtra`]. + /// + /// Bonding extra funds implies an automatic payout of all pending rewards as well. // NOTE: this transaction is implemented with the sole purpose of readability and // correctness, not optimization. We read/write several storage items multiple times instead // of just once, in the spirit reusing code. diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index dd2f3d53e7363..d9ea2d6efb411 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -255,6 +255,7 @@ pub mod v2 { id, accumulated_reward ); + if last_claim.is_zero() { None } else { From 62d35c80b6efec491c6288188f7eeaaf781bf2db Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 23 Jun 2022 10:12:41 +0200 Subject: [PATCH 46/65] fmt --- bin/node/runtime/src/lib.rs | 2 +- frame/nomination-pools/benchmarking/src/mock.rs | 5 ++++- frame/nomination-pools/src/lib.rs | 6 +++--- frame/nomination-pools/test-staking/src/mock.rs | 5 ++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 47a055897eb02..1b0786015350e 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -68,7 +68,7 @@ use sp_runtime::{ SaturatedConversion, StaticLookup, }, transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, FixedPointNumber, Perbill, Percent, Permill, Perquintill, FixedU128, + ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; #[cfg(any(feature = "std", test))] diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 9bc8916a3eb7a..7e4df881c9366 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -17,7 +17,10 @@ use frame_election_provider_support::VoteWeight; use frame_support::{pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; -use sp_runtime::{traits::{Convert, IdentityLookup}, FixedU128}; +use sp_runtime::{ + traits::{Convert, IdentityLookup}, + FixedU128, +}; type AccountId = u128; type AccountIndex = u32; diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5f805e934d711..df74cf64c2468 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -44,9 +44,9 @@ //! * kick: The act of a pool administrator forcibly ejecting a member. //! * bonded account: A key-less account id derived from the pool id that acts as the bonded //! account. This account registers itself as a nominator in the staking system, and follows -//! exactly the same rules and conditions as a normal staker. Its bond increases or -//! decreases as members join, it can `nominate` or `chill`, and might not even earn staking -//! rewards if it is not nominating proper validators. +//! exactly the same rules and conditions as a normal staker. Its bond increases or decreases as +//! members join, it can `nominate` or `chill`, and might not even earn staking rewards if it is +//! not nominating proper validators. //! * reward account: A similar key-less account, that is set as the `Payee` account fo the bonded //! account for all staking rewards. //! diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index ae240f2f853e0..7acfedc3d89a8 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -17,7 +17,10 @@ use frame_election_provider_support::VoteWeight; use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; -use sp_runtime::{traits::{Convert, IdentityLookup}, FixedU128}; +use sp_runtime::{ + traits::{Convert, IdentityLookup}, + FixedU128, +}; type AccountId = u128; type AccountIndex = u32; From 1c840b258af687d7b06f4f344d5ecca59c20c375 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 23 Jun 2022 12:26:57 +0200 Subject: [PATCH 47/65] fix some comments --- frame/nomination-pools/src/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index f7e81d6f0db6b..a8a998d85ebe4 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1199,7 +1199,7 @@ mod claim_payout { Balances::mutate_account(&default_reward_account(), |f| f.free += 6).unwrap(); - // 10 should claim 10, 20 should claim nothing. + // 10 should claim 3, 20 should claim 3 + 3. assert_ok!(Pools::claim_payout(Origin::signed(10))); assert_ok!(Pools::claim_payout(Origin::signed(20))); @@ -1374,7 +1374,7 @@ mod claim_payout { ] ); - // 30 now bumps itself to be like 20. + // 30 unbonds to be equal to 10 (10 points each). assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); // more rewards come in. From a8ccd71e3a8704ca90a08150f12e052ff1ca7aa3 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 5 Jul 2022 16:55:51 +0200 Subject: [PATCH 48/65] Fix proportional slashing logic --- .../nomination-pools/test-staking/src/lib.rs | 267 +++++++++++++++++- .../nomination-pools/test-staking/src/mock.rs | 7 +- frame/staking/src/lib.rs | 62 ++-- frame/staking/src/tests.rs | 30 +- 4 files changed, 330 insertions(+), 36 deletions(-) diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index 736982ee4c61f..c4151d9bbc91d 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -22,7 +22,8 @@ mod mock; use frame_support::{assert_noop, assert_ok, bounded_btree_map, traits::Currency}; use mock::*; use pallet_nomination_pools::{ - Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers, PoolState, + BondedPools, Error as PoolsError, Event as PoolsEvent, LastPoolId, PoolMember, PoolMembers, + PoolState, }; use pallet_staking::{CurrentEra, Event as StakingEvent, Payee, RewardDestination}; use sp_runtime::traits::Zero; @@ -274,7 +275,7 @@ fn pool_slash_e2e() { 30, &mut Default::default(), &mut Default::default(), - 1, // slash era 1, affects chunks at era 5 onwards. + 2, // slash era 2, affects chunks at era 5 onwards. ); assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 30)]); @@ -372,3 +373,265 @@ fn pool_slash_e2e() { ); }); } + +#[test] +fn pool_slash_proportional() { + // a typical example where 3 pool members unbond in era 99, 100, and 101, and a slash that + // happened in era 100 should only affect the latter two. + new_test_ext().execute_with(|| { + ExistentialDeposit::set(1); + BondingDuration::set(28); + assert_eq!(Balances::minimum_balance(), 1); + assert_eq!(Staking::current_era(), None); + + // create the pool, we know this has id 1. + assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10)); + assert_eq!(LastPoolId::::get(), 1); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Created { depositor: 10, pool_id: 1 }, + PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 40, joined: true }, + ] + ); + + // have two members join + let bond = 20; + assert_ok!(Pools::join(Origin::signed(20), bond, 1)); + assert_ok!(Pools::join(Origin::signed(21), bond, 1)); + assert_ok!(Pools::join(Origin::signed(22), bond, 1)); + + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Bonded(POOL1_BONDED, bond), + StakingEvent::Bonded(POOL1_BONDED, bond), + StakingEvent::Bonded(POOL1_BONDED, bond), + ] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true }, + PoolsEvent::Bonded { member: 21, pool_id: 1, bonded: bond, joined: true }, + PoolsEvent::Bonded { member: 22, pool_id: 1, bonded: bond, joined: true }, + ] + ); + + // now let's progress a lot. + CurrentEra::::set(Some(99)); + + // and unbond + assert_ok!(Pools::unbond(Origin::signed(20), 20, bond)); + + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, bond),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 20, pool_id: 1, balance: bond, points: bond }] + ); + + CurrentEra::::set(Some(100)); + assert_ok!(Pools::unbond(Origin::signed(21), 21, bond)); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, bond),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 21, pool_id: 1, balance: bond, points: bond }] + ); + + CurrentEra::::set(Some(101)); + assert_ok!(Pools::unbond(Origin::signed(22), 22, bond)); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, bond),] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 22, pool_id: 1, balance: bond, points: bond }] + ); + + // Apply a slash that happened in era 100. This is typically applied with a delay. + // Of the total 100, 50 is slashed. + assert_eq!(BondedPools::::get(1).unwrap().points, 40); + pallet_staking::slashing::do_slash::( + &POOL1_BONDED, + 50, + &mut Default::default(), + &mut Default::default(), + 100, + ); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 50)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + // This last pool got slashed only the leftover dust. Otherwise in principle, this + // chunk/pool should have not been affected. + // TODO: We might improve this in a future PR + PoolsEvent::UnbondingPoolSlashed { pool_id: 1, era: 127, balance: 19 }, + // This pool got slashed 12.5, which rounded down to 12. + PoolsEvent::UnbondingPoolSlashed { pool_id: 1, era: 128, balance: 8 }, + // This pool got slashed 12.5, which rounded down to 12. + PoolsEvent::UnbondingPoolSlashed { pool_id: 1, era: 129, balance: 8 }, + // Bonded pool got slashed for 25, remaining 15 in it. + PoolsEvent::PoolSlashed { pool_id: 1, balance: 15 } + ] + ); + }); +} + +#[test] +fn pool_slash_non_proportional_only_bonded_pool() { + // A typical example where a pool member unbonds in era 99, and he can get away with a slash tha + // happened in era 99, as long as the pool has enough active bond to cover the slash. If + // everything else in the slashing/staking system works, this should always be the case. + // Nonetheless, `ledger.slash` has been written such that it will slash greedily from any chunk + // if it runs out of chunks that it thinks should be affected by the slash. + new_test_ext().execute_with(|| { + ExistentialDeposit::set(1); + BondingDuration::set(28); + assert_eq!(Balances::minimum_balance(), 1); + assert_eq!(Staking::current_era(), None); + + // create the pool, we know this has id 1. + assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10)); + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Created { depositor: 10, pool_id: 1 }, + PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 40, joined: true }, + ] + ); + + // have two members join + let bond = 20; + assert_ok!(Pools::join(Origin::signed(20), bond, 1)); + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Bonded(POOL1_BONDED, bond) + ] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true } + ] + ); + + // progress and unbond. + CurrentEra::::set(Some(99)); + assert_ok!(Pools::unbond(Origin::signed(20), 20, bond)); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, bond)] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 20, pool_id: 1, balance: bond, points: bond }] + ); + + // slash for 30. This will be deducted only from the bonded pool. + CurrentEra::::set(Some(100)); + assert_eq!(BondedPools::::get(1).unwrap().points, 40); + pallet_staking::slashing::do_slash::( + &POOL1_BONDED, + 30, + &mut Default::default(), + &mut Default::default(), + 100, + ); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 30)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::PoolSlashed { pool_id: 1, balance: 10 } + ] + ); + }); +} + +#[test] +fn pool_slash_non_proportional_bonded_pool_and_chunks() { + // An uncommon example where even though some funds are unlocked such that they should not be + // affected by a slash, we still slash out of them. This should not happen at all. If a + // nomination has unbonded, from the next era onwards, their exposure will drop, so if an era + // happens in that era, then their share of that slash should naturally be less, such that only + // their active ledger stake is enough to compensate it. + new_test_ext().execute_with(|| { + ExistentialDeposit::set(1); + BondingDuration::set(28); + assert_eq!(Balances::minimum_balance(), 1); + assert_eq!(Staking::current_era(), None); + + // create the pool, we know this has id 1. + assert_ok!(Pools::create(Origin::signed(10), 40, 10, 10, 10)); + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Bonded(POOL1_BONDED, 40)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Created { depositor: 10, pool_id: 1 }, + PoolsEvent::Bonded { member: 10, pool_id: 1, bonded: 40, joined: true }, + ] + ); + + // have two members join + let bond = 20; + assert_ok!(Pools::join(Origin::signed(20), bond, 1)); + assert_eq!( + staking_events_since_last_call(), + vec![ + StakingEvent::Bonded(POOL1_BONDED, bond) + ] + ); + assert_eq!( + pool_events_since_last_call(), + vec![ + PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true } + ] + ); + + // progress and unbond. + CurrentEra::::set(Some(99)); + assert_ok!(Pools::unbond(Origin::signed(20), 20, bond)); + assert_eq!( + staking_events_since_last_call(), + vec![StakingEvent::Unbonded(POOL1_BONDED, bond)] + ); + assert_eq!( + pool_events_since_last_call(), + vec![PoolsEvent::Unbonded { member: 20, pool_id: 1, balance: bond, points: bond }] + ); + + // slash 50. This will be deducted only from the bonded pool and one of the unbonding pools. + CurrentEra::::set(Some(100)); + assert_eq!(BondedPools::::get(1).unwrap().points, 40); + pallet_staking::slashing::do_slash::( + &POOL1_BONDED, + 50, + &mut Default::default(), + &mut Default::default(), + 100, + ); + + assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 50)]); + assert_eq!( + pool_events_since_last_call(), + vec![ + // out of 20, 10 was taken. + PoolsEvent::UnbondingPoolSlashed { pool_id: 1, era: 127, balance: 10 }, + // out of 40, all was taken. + PoolsEvent::PoolSlashed { pool_id: 1, balance: 0 } + ] + ); + }); +} diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 7acfedc3d89a8..91a101a2d2b8f 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -27,6 +27,8 @@ type AccountIndex = u32; type BlockNumber = u64; type Balance = u128; +pub(crate) type T = Runtime; + pub(crate) const POOL1_BONDED: AccountId = 20318131474730217858575332831085u128; pub(crate) const POOL1_REWARD: AccountId = 20397359637244482196168876781421u128; @@ -199,13 +201,14 @@ frame_support::construct_runtime!( ); pub fn new_test_ext() -> sp_io::TestExternalities { + sp_tracing::try_init_simple(); let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); let _ = pallet_nomination_pools::GenesisConfig:: { min_join_bond: 2, min_create_bond: 2, max_pools: Some(3), - max_members_per_pool: Some(3), - max_members: Some(3 * 3), + max_members_per_pool: Some(5), + max_members: Some(3 * 5), } .assimilate_storage(&mut storage) .unwrap(); diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 360d5b5efb58f..6e242128107b6 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -529,13 +529,26 @@ impl StakingLedger { (self, unlocking_balance) } - /// Slash the staker for a given amount of balance. This can grow the value of the slash in the - /// case that either the active bonded or some unlocking chunks become dust after slashing. - /// Returns the amount of funds actually slashed. + /// Slash the staker for a given amount of balance. /// - /// `slash_era` is the era in which the slash (which is being enacted now) actually happened. + /// This implements a proportional slashing system, whereby we set our preference to slash as + /// such: + /// + /// - If any unlocking chunks exist that are scheduled to be unlocked at `slash_era + + /// bonding_duration` and onwards, the slash is divided equally between the active ledger and + /// the unlocking chunks. + /// - If no such chunks exist, then only the active balance is slashed. /// - /// # Note + /// Note that the above is only a *preference*. If for any reason the active ledger, which or + /// without some portion of the unlocking chunks that are more justified to be slashed are not + /// enough, then the slashing will continue and will consume as much of the active and unlocking + /// chunks as needed. + /// + /// This will never slash more than the give amount. If any of the chunks become dusted, the + /// last chunk is slashed slightly less to compensate. Returns the amount of funds actually + /// slashed. + /// + /// `slash_era` is the era in which the slash (which is being enacted now) actually happened. /// /// This calls `Config::OnStakerSlash::on_slash` with information as to how the slash was /// applied. @@ -554,17 +567,18 @@ impl StakingLedger { let mut remaining_slash = slash_amount; let pre_slash_total = self.total; - let era_after_slash = slash_era + 1; - let chunk_unlock_era_after_slash = era_after_slash + T::BondingDuration::get(); + // for a slash_era = x, any chunk that is scheduled to be unlocked at era `x + 28` (assuming + // 28 is the bonding duration) onwards should be slashed. + let slashable_chunks_start = slash_era + T::BondingDuration::get(); // Calculate the total balance of active funds and unlocking funds in the affected range. - let (affected_balance, slash_chunks_priority): (_, Box>) = { - if let Some(start_index) = - self.unlocking.iter().position(|c| c.era >= chunk_unlock_era_after_slash) + let (is_proportional, affected_balance, slash_chunks_priority) = { + if let Some(first_slashable_index) = + self.unlocking.iter().position(|c| c.era >= slashable_chunks_start) { // The indices of the first chunk after the slash up through the most recent chunk. // (The most recent chunk is at greatest from this era) - let affected_indices = start_index..self.unlocking.len(); + let affected_indices = first_slashable_index..self.unlocking.len(); let unbonding_affected_balance = affected_indices.clone().fold(BalanceOf::::zero(), |sum, i| { if let Some(chunk) = self.unlocking.get_mut(i).defensive() { @@ -574,25 +588,41 @@ impl StakingLedger { } }); ( + true, self.active.saturating_add(unbonding_affected_balance), - Box::new(affected_indices.chain((0..start_index).rev())), + affected_indices.chain((0..first_slashable_index).rev()).collect::>(), ) } else { - (self.active, Box::new((0..self.unlocking.len()).rev())) + // We just slash from the last chunk to the most recent one, if need be. + (false, self.active, (0..self.unlocking.len()).rev().collect::>()) } }; // Helper to update `target` and the ledgers total after accounting for slashing `target`. let ratio = Perquintill::from_rational(slash_amount, affected_balance); + log!( + debug, + "slashing {:?} for era {:?} out of {:?}, affected balance = {:?}, priority: {:?}, ratio = {:?}", + slash_amount, + slash_era, + self, + affected_balance, + slash_chunks_priority, + ratio, + ); + let mut slash_out_of = |target: &mut BalanceOf, slash_remaining: &mut BalanceOf| { let mut slash_from_target = - if slash_amount < affected_balance { ratio * (*target) } else { *slash_remaining } - .min(*target); + if is_proportional { ratio * (*target) } else { *slash_remaining } + .min(*target) + .min(*slash_remaining); // slash out from *target exactly `slash_from_target`. *target = *target - slash_from_target; if *target < minimum_balance { - // Slash the rest of the target if its dust + // Slash the rest of the target if its dust. This might cause the last chunk to be + // slightly under-slashed, by at most `MaxUnlockingChunks * ED`, which is not a big + // deal. slash_from_target = sp_std::mem::replace(target, Zero::zero()).saturating_add(slash_from_target) } diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index 9a13a818f4b59..b76126f0c5d04 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -2081,8 +2081,7 @@ fn reward_validator_slashing_validator_does_not_overflow() { let _ = Balances::make_free_balance_be(&11, stake); let _ = Balances::make_free_balance_be(&2, stake); - // only slashes out of bonded stake are applied. without this line, - // it is 0. + // only slashes out of bonded stake are applied. without this line, it is 0. Staking::bond(Origin::signed(2), 20000, stake - 1, RewardDestination::default()).unwrap(); // Override exposure of 11 ErasStakers::::insert( @@ -2104,7 +2103,7 @@ fn reward_validator_slashing_validator_does_not_overflow() { &[Perbill::from_percent(100)], ); - assert_eq!(Balances::total_balance(&11), stake); + assert_eq!(Balances::total_balance(&11), stake - 1); assert_eq!(Balances::total_balance(&2), 1); }) } @@ -4960,7 +4959,6 @@ fn proportional_ledger_slash_works() { unlocking: bounded_vec![], claimed_rewards: vec![], }; - assert_eq!(BondingDuration::get(), 3); // When we slash a ledger with no unlocking chunks @@ -4997,7 +4995,7 @@ fn proportional_ledger_slash_works() { ledger.total = 4 * 100; ledger.active = 0; // When the first 2 chunks don't overlap with the affected range of unlock eras. - assert_eq!(ledger.slash(140, 0, 2), 140); + assert_eq!(ledger.slash(140, 0, 3), 140); // Then assert_eq!(ledger.unlocking, vec![c(4, 100), c(5, 100), c(6, 30), c(7, 30)]); assert_eq!(ledger.total, 4 * 100 - 140); @@ -5039,7 +5037,7 @@ fn proportional_ledger_slash_works() { ledger.active = 500; ledger.total = 40 + 10 + 100 + 250 + 500; // 900 assert_eq!(ledger.total, 900); - // When we have a higher min balance + // When we have a higher min balance assert_eq!( ledger.slash( 900 / 2, @@ -5047,16 +5045,17 @@ fn proportional_ledger_slash_works() { * get swept */ 0 ), - 475 + 450 ); - let dust = (10 / 2) + (40 / 2); assert_eq!(ledger.active, 500 / 2); - assert_eq!(ledger.unlocking, vec![c(5, 100 / 2), c(7, 250 / 2)]); - assert_eq!(ledger.total, 900 / 2 - dust); + // the last chunk was not slashed 50% like all the rest, because some other earlier chunks got + // dusted. + assert_eq!(ledger.unlocking, vec![c(5, 100 / 2), c(7, 150)]); + assert_eq!(ledger.total, 900 / 2); assert_eq!(LedgerSlashPerEra::get().0, 500 / 2); assert_eq!( LedgerSlashPerEra::get().1, - BTreeMap::from([(4, 0), (5, 100 / 2), (6, 0), (7, 250 / 2)]) + BTreeMap::from([(4, 0), (5, 100 / 2), (6, 0), (7, 150)]) ); // Given @@ -5068,7 +5067,7 @@ fn proportional_ledger_slash_works() { ledger.slash( 500 + 10 + 250 + 100 / 2, // active + era 6 + era 7 + era 5 / 2 0, - 2 /* slash era 2+4 first, so the affected parts are era 2+4, era 3+4 and + 3 /* slash era 6 first, so the affected parts are era 6, era 7 and * ledge.active. This will cause the affected to go to zero, and then we will * start slashing older chunks */ ), @@ -5091,7 +5090,7 @@ fn proportional_ledger_slash_works() { ledger.slash( 351, // active + era 6 + era 7 + era 5 / 2 + 1 50, // min balance - everything slashed below 50 will get dusted - 2 /* slash era 2+4 first, so the affected parts are era 2+4, era 3+4 and + 3 /* slash era 3+3 first, so the affected parts are era 6, era 7 and * ledge.active. This will cause the affected to go to zero, and then we will * start slashing older chunks */ ), @@ -5108,9 +5107,8 @@ fn proportional_ledger_slash_works() { // Given let slash = u64::MAX as Balance * 2; - let value = slash - - (9 * 4) // The value of the other parts of ledger that will get slashed - + 1; + // The value of the other parts of ledger that will get slashed + let value = slash - (10 * 4); ledger.active = 10; ledger.unlocking = bounded_vec![c(4, 10), c(5, 10), c(6, 10), c(7, value)]; From 60b76410fce5bcbf0a211414c01ff2ec8cec0fcf Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 6 Jul 2022 09:06:31 +0100 Subject: [PATCH 49/65] Update frame/nomination-pools/src/tests.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index a8a998d85ebe4..e960831fd7c12 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1374,7 +1374,7 @@ mod claim_payout { ] ); - // 30 unbonds to be equal to 10 (10 points each). + // 20 unbonds to be equal to 10 (10 points each). assert_ok!(Pools::unbond(Origin::signed(20), 20, 10)); // more rewards come in. From a2082cd72b07b693a096b6cda4f9489651df5061 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 6 Jul 2022 09:06:36 +0100 Subject: [PATCH 50/65] Update frame/nomination-pools/src/tests.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index e960831fd7c12..d9632a5b44871 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1465,7 +1465,6 @@ mod claim_payout { #[test] fn bond_extra_and_delayed_claim() { - // todo!("10 20 join, reward comes, 10 claims, 20 bonds extra, reward comes both claim"); ExtBuilder::default().build_and_execute(|| { let ed = Balances::minimum_balance(); From ecb78905ca477b889f5a1368e556abb774516a61 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Wed, 6 Jul 2022 09:08:35 +0100 Subject: [PATCH 51/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- frame/nomination-pools/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 57b3385d38f47..0eb71613c1ef2 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1162,7 +1162,6 @@ pub mod pallet { // a million places, so we prefer doing this. type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned + codec::FullCodec - + Copy + MaybeSerializeDeserialize + sp_std::fmt::Debug + Default From 7e56e1af9b50ce3a31c7304097c60730d3ad9778 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Jul 2022 09:27:08 +0100 Subject: [PATCH 52/65] track poinst in migration --- frame/nomination-pools/src/lib.rs | 8 +++++--- frame/nomination-pools/src/migration.rs | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 57b3385d38f47..9f0fe4457482b 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -383,16 +383,18 @@ impl PoolMember { current_reward_counter: T::RewardCounter, ) -> Result, Error> { // accuracy note: Reward counters are `FixedU128` with base of 10^18. This value is being - // multiplied by a point. The worse case of a point is 10x the granularity of the balance. + // multiplied by a point. The worse case of a point is 10x the granularity of the balance + // (10x is the common configuration of `MaxPointsToBalance`). + // // Assuming roughly the current issuance of polkadot (12,047,781,394,999,601,455, which is - // 1.2 * 10^9 10^10 = 1.2 * 10^19), the worse case point value is around 10^20. + // 1.2 * 10^9 * 10^10 = 1.2 * 10^19), the worse case point value is around 10^20. // // The final multiplication is: // // rc * 10^20 / 10^18 = rc * 100 // // meaning that as long as reward_counter's value is less than 1/100th of its max capacity - // (u128), `checked_mul_int` won't saturate. + // (u128::MAX_VALUE), `checked_mul_int` won't saturate. // // given the nature of reward counter being 'pending_rewards / pool_total_point', the only // (unrealistic) way that super high values can be achieved is for a pool to suddenly diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index d9ea2d6efb411..c2af5a9c1ba9a 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -191,6 +191,7 @@ pub mod v2 { let mut members_translated = 0u64; // just for logging. let mut total_value_locked = BalanceOf::::zero(); + let mut total_points_locked = BalanceOf::::zero(); // store each member of the pool, with their active points. In the process, migrate // their data as well. @@ -243,6 +244,7 @@ pub mod v2 { }; total_value_locked += bonded_pool.points_to_balance(points.clone()); + total_points_locked += bonded_pool.points; let portion = Perbill::from_rational(*points, bonded_pool.points); let last_claim = portion * accumulated_reward; @@ -310,10 +312,11 @@ pub mod v2 { log!( info, - "Upgraded {} members, {} reward pools, TVL {:?}, storage to version {:?}", + "Upgraded {} members, {} reward pools, TVL {:?} TPL {:?}, storage to version {:?}", members_translated, reward_pools_translated, total_value_locked, + total_points_locked, current ); current.put::>(); From 579da3788b19490655148e746a7d13b95a2acdbc Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Jul 2022 09:51:55 +0100 Subject: [PATCH 53/65] fix --- bin/node/runtime/src/lib.rs | 1 + utils/frame/try-runtime/cli/src/lib.rs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index e3996bd00030e..ce1503a2e3fa3 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1677,6 +1677,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + pallet_nomination_pools::migration::v2::MigrateToV2, >; /// MMR helper types. diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index c09a33cf3f16a..f77f92c625c9d 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -472,9 +472,10 @@ pub enum State { #[clap(short, long)] snapshot_path: Option, - /// The pallets to scrape. If empty, entire chain state will be scraped. + /// A pallet to scrape. Can be provided multiple times. If empty, entire chain state will + /// be scraped. #[clap(short, long, multiple_values = true)] - pallets: Vec, + pallet: Vec, /// Fetch the child-keys as well. /// @@ -498,7 +499,7 @@ impl State { Builder::::new().mode(Mode::Offline(OfflineConfig { state_snapshot: SnapshotConfig::new(snapshot_path), })), - State::Live { snapshot_path, pallets, uri, at, child_tree } => { + State::Live { snapshot_path, pallet, uri, at, child_tree } => { let at = match at { Some(at_str) => Some(hash_of::(at_str)?), None => None, @@ -507,7 +508,7 @@ impl State { .mode(Mode::Online(OnlineConfig { transport: uri.to_owned().into(), state_snapshot: snapshot_path.as_ref().map(SnapshotConfig::new), - pallets: pallets.clone(), + pallets: pallet.clone(), scrape_children: true, at, })) From 51c160820d5d573f86793712b5d5a606e2e7d044 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Jul 2022 09:58:30 +0100 Subject: [PATCH 54/65] fmt --- frame/nomination-pools/src/lib.rs | 2 +- .../nomination-pools/test-staking/src/lib.rs | 20 +++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 73837b308f20c..adab6ff9f6524 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -69,7 +69,7 @@ //! First, they must call [`Call::unbond`]. The unbond extrinsic will start the unbonding process by //! unbonding all or a portion of the members funds. //! -//! > A member can have up to [`MaxUnbonding`] distinct active unbonding requests. +//! > A member can have up to [`Config::MaxUnbonding`] distinct active unbonding requests. //! //! Second, once [`sp_staking::StakingInterface::bonding_duration`] eras have passed, the member can //! call [`Call::withdraw_unbonded`] to withdraw any funds that are free. diff --git a/frame/nomination-pools/test-staking/src/lib.rs b/frame/nomination-pools/test-staking/src/lib.rs index c4151d9bbc91d..14d9825c9eeeb 100644 --- a/frame/nomination-pools/test-staking/src/lib.rs +++ b/frame/nomination-pools/test-staking/src/lib.rs @@ -516,15 +516,11 @@ fn pool_slash_non_proportional_only_bonded_pool() { assert_ok!(Pools::join(Origin::signed(20), bond, 1)); assert_eq!( staking_events_since_last_call(), - vec![ - StakingEvent::Bonded(POOL1_BONDED, bond) - ] + vec![StakingEvent::Bonded(POOL1_BONDED, bond)] ); assert_eq!( pool_events_since_last_call(), - vec![ - PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true } - ] + vec![PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true }] ); // progress and unbond. @@ -553,9 +549,7 @@ fn pool_slash_non_proportional_only_bonded_pool() { assert_eq!(staking_events_since_last_call(), vec![StakingEvent::Slashed(POOL1_BONDED, 30)]); assert_eq!( pool_events_since_last_call(), - vec![ - PoolsEvent::PoolSlashed { pool_id: 1, balance: 10 } - ] + vec![PoolsEvent::PoolSlashed { pool_id: 1, balance: 10 }] ); }); } @@ -589,15 +583,11 @@ fn pool_slash_non_proportional_bonded_pool_and_chunks() { assert_ok!(Pools::join(Origin::signed(20), bond, 1)); assert_eq!( staking_events_since_last_call(), - vec![ - StakingEvent::Bonded(POOL1_BONDED, bond) - ] + vec![StakingEvent::Bonded(POOL1_BONDED, bond)] ); assert_eq!( pool_events_since_last_call(), - vec![ - PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true } - ] + vec![PoolsEvent::Bonded { member: 20, pool_id: 1, bonded: bond, joined: true }] ); // progress and unbond. From 3779081118c1f545db15dc6635da7482b22b9e10 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Jul 2022 10:45:01 +0100 Subject: [PATCH 55/65] fix migration --- frame/nomination-pools/src/migration.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index c2af5a9c1ba9a..0136703ca408c 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -200,6 +200,7 @@ pub mod v2 { let id = old_member.pool_id; temp_members.entry(id).or_default().push((key, old_member.points)); + total_points_locked += old_member.points; members_translated += 1; Some(PoolMember:: { last_recorded_reward_counter: Zero::zero(), @@ -244,7 +245,6 @@ pub mod v2 { }; total_value_locked += bonded_pool.points_to_balance(points.clone()); - total_points_locked += bonded_pool.points; let portion = Perbill::from_rational(*points, bonded_pool.points); let last_claim = portion * accumulated_reward; @@ -362,6 +362,7 @@ pub mod v2 { }); log!(info, "post upgrade hook for MigrateToV2 executed."); + log!(info, "system events: {:?}", frame_system::Pallet::::read_events_no_consensus()); Ok(()) } } From 9171a13f36cf60a1f842d01de99e3319dc824471 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Wed, 6 Jul 2022 11:12:10 +0100 Subject: [PATCH 56/65] remove event read --- frame/nomination-pools/src/migration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 0136703ca408c..4e2f252d02e3f 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -362,7 +362,6 @@ pub mod v2 { }); log!(info, "post upgrade hook for MigrateToV2 executed."); - log!(info, "system events: {:?}", frame_system::Pallet::::read_events_no_consensus()); Ok(()) } } From b9ab74705c75e90a04080bbee9f5bd0832b957e5 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Thu, 7 Jul 2022 13:01:17 +0100 Subject: [PATCH 57/65] Apply suggestions from code review --- frame/nomination-pools/src/tests.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index d9632a5b44871..fcb7de62f5cd3 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1143,7 +1143,6 @@ mod claim_payout { }); } - // TODO: SR-LABS must audit these tests, until the end of the module. Only remove once approved. #[test] fn rewards_distribution_is_fair_basic() { ExtBuilder::default().build_and_execute(|| { @@ -4027,7 +4026,6 @@ mod update_roles { mod reward_counter_precision { use sp_runtime::FixedU128; - // TODO: SR-LABS must audit these tests. Only remove once approved. use super::*; const DOT: Balance = 10u128.pow(10u32); From d4f45e7719dd3e3edbc370fef89f1c0952255f1a Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Sat, 9 Jul 2022 21:07:48 +0100 Subject: [PATCH 58/65] Update frame/staking/src/lib.rs Co-authored-by: Shawn Tabrizi --- frame/staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index 6e242128107b6..3bc619bcc6809 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -544,7 +544,7 @@ impl StakingLedger { /// enough, then the slashing will continue and will consume as much of the active and unlocking /// chunks as needed. /// - /// This will never slash more than the give amount. If any of the chunks become dusted, the + /// This will never slash more than the given amount. If any of the chunks become dusted, the /// last chunk is slashed slightly less to compensate. Returns the amount of funds actually /// slashed. /// From ca47b05985a08bb95ae9a47a0ce51d7b9c74aca0 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Sat, 9 Jul 2022 21:08:00 +0100 Subject: [PATCH 59/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Shawn Tabrizi --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index adab6ff9f6524..75a02172fcfb6 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1504,7 +1504,7 @@ pub mod pallet { let mut reward_pool = RewardPools::::get(pool_id) .defensive_ok_or::>(DefensiveError::RewardPoolNotFound.into())?; // IMPORTANT: reward pool records must be updated with the old points. - let _ = reward_pool.update_records(pool_id, bonded_pool.points)?; + reward_pool.update_records(pool_id, bonded_pool.points)?; bonded_pool.try_inc_members()?; let points_issued = bonded_pool.try_bond_funds(&who, amount, BondType::Later)?; From f3e10a929f742dd790d2054fc7733d255fba99f2 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Sat, 9 Jul 2022 21:08:26 +0100 Subject: [PATCH 60/65] Update frame/nomination-pools/src/lib.rs Co-authored-by: Shawn Tabrizi --- frame/nomination-pools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 75a02172fcfb6..bddfe3806d5c5 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1553,7 +1553,7 @@ pub mod pallet { // payout related stuff: we must claim the payouts, and updated recorded payout data // before updating the bonded pool points, similar to that of `join` transaction. - let _ = reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; + reward_pool.update_records(bonded_pool.id, bonded_pool.points)?; // TODO: optimize this to not touch the free balance of `who ` at all in benchmarks. // Currently, bonding rewards is like a batch. In the same PR, also make this function // take a boolean argument that make it either 100% pure (no storage update), or make it From c205ac37e640dcc308af1d5de03abff1084fa493 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 10 Jul 2022 10:55:25 +0100 Subject: [PATCH 61/65] update --- bin/node/runtime/src/lib.rs | 2 +- .../nomination-pools/benchmarking/src/mock.rs | 2 +- frame/nomination-pools/src/lib.rs | 2 +- frame/nomination-pools/src/migration.rs | 23 ++++++++++++++++++- frame/nomination-pools/src/mock.rs | 2 +- frame/nomination-pools/src/tests.rs | 4 ++-- .../nomination-pools/test-staking/src/mock.rs | 4 ++-- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index ce1503a2e3fa3..b2efcb196787d 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -730,7 +730,7 @@ impl pallet_bags_list::Config for Runtime { parameter_types! { pub const PostUnbondPoolsWindow: u32 = 4; pub const NominationPoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const MaxPointsToBalance: u32 = 10; + pub const MaxPointsToBalance: u8 = 10; } use sp_runtime::traits::Convert; diff --git a/frame/nomination-pools/benchmarking/src/mock.rs b/frame/nomination-pools/benchmarking/src/mock.rs index 7e4df881c9366..1c74c301e562d 100644 --- a/frame/nomination-pools/benchmarking/src/mock.rs +++ b/frame/nomination-pools/benchmarking/src/mock.rs @@ -147,7 +147,7 @@ impl Convert for U256ToBalance { parameter_types! { pub static PostUnbondingPoolsWindow: u32 = 10; pub const PoolsPalletId: PalletId = PalletId(*b"py/nopls"); - pub const MaxPointsToBalance: u32 = 10; + pub const MaxPointsToBalance: u8 = 10; } impl pallet_nomination_pools::Config for Runtime { diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 5cc74535ebdea..53e1c48a5e39e 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1203,7 +1203,7 @@ pub mod pallet { /// For a value of 10, the threshold would be a pool points-to-balance ratio of 10:1. /// Such a scenario would also be the equivalent of the pool being 90% slashed. #[pallet::constant] - type MaxPointsToBalance: Get; + type MaxPointsToBalance: Get; /// Infallible method for converting `Currency::Balance` to `U256`. type BalanceToU256: Convert, U256>; diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 4e2f252d02e3f..6740a2167a80f 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -344,14 +344,35 @@ pub mod v2 { } } + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + // all reward accounts must have more than ED. + RewardPools::::iter().for_each(|(id, _)| { + assert!( + T::Currency::free_balance(&Pallet::::create_reward_account(id)) >= + T::Currency::minimum_balance() + ) + }); + + Ok(()) + } + #[cfg(feature = "try-runtime")] fn post_upgrade() -> Result<(), &'static str> { // new version must be set. assert_eq!(Pallet::::on_chain_storage_version(), 2); + // no reward or bonded pool has been skipped. + assert_eq!( + RewardPools::::iter().count() as u32, RewardPools::::count() + ); + assert_eq!( + BondedPools::::iter().count() as u32, BondedPools::::count() + ); + // all reward pools must have exactly ED in them. This means no reward can be claimed, // and that setting reward counters all over the board to zero will work henceforth. - RewardPools::::iter().for_each(|(id, _reward_pool)| { + RewardPools::::iter().for_each(|(id, _)| { assert_eq!( RewardPool::::current_balance(id), Zero::zero(), diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 34fcaffc194b1..05e5c44824b5c 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -199,7 +199,7 @@ impl pools::Config for Runtime { type PalletId = PoolsPalletId; type MaxMetadataLen = MaxMetadataLen; type MaxUnbonding = MaxUnbonding; - type MaxPointsToBalance = frame_support::traits::ConstU32<10>; + type MaxPointsToBalance = frame_support::traits::ConstU8<10>; } type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index fcb7de62f5cd3..43bec9b85b2ca 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -208,7 +208,7 @@ mod bonded_pool { }; let max_points_to_balance: u128 = - <::MaxPointsToBalance as Get>::get().into(); + <::MaxPointsToBalance as Get>::get().into(); // Simulate a 100% slashed pool StakingMock::set_bonded_balance(pool.bonded_account(), 0); @@ -520,7 +520,7 @@ mod join { // Force the points:balance ratio to `MaxPointsToBalance` (100/10) let max_points_to_balance: u128 = - <::MaxPointsToBalance as Get>::get().into(); + <::MaxPointsToBalance as Get>::get().into(); StakingMock::set_bonded_balance( Pools::create_bonded_account(123), diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 91a101a2d2b8f..5aca68a523950 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -16,7 +16,7 @@ // limitations under the License. use frame_election_provider_support::VoteWeight; -use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::ConstU64, PalletId}; +use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::{ConstU64, ConstU8}, PalletId}; use sp_runtime::{ traits::{Convert, IdentityLookup}, FixedU128, @@ -170,7 +170,7 @@ impl pallet_nomination_pools::Config for Runtime { type PostUnbondingPoolsWindow = PostUnbondingPoolsWindow; type MaxMetadataLen = ConstU32<256>; type MaxUnbonding = ConstU32<8>; - type MaxPointsToBalance = ConstU32<10>; + type MaxPointsToBalance = ConstU8<10>; type PalletId = PoolsPalletId; } From 69d1f9c06299549a33318c9446b2bf2f0fff03ef Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 10 Jul 2022 11:37:28 +0100 Subject: [PATCH 62/65] fmt --- frame/nomination-pools/src/tests.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index 43bec9b85b2ca..b3354b7a06970 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -688,19 +688,15 @@ mod claim_payout { assert_eq!(Balances::free_balance(default_reward_account()), ed); assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 100)); + let _ = pool_events_since_last_call(); + // When assert_ok!(Pools::claim_payout(Origin::signed(10))); // Then assert_eq!( pool_events_since_last_call(), - vec![ - Event::Created { depositor: 10, pool_id: 1 }, - Event::Bonded { member: 10, pool_id: 1, bonded: 10, joined: true }, - Event::Bonded { member: 40, pool_id: 1, bonded: 40, joined: true }, - Event::Bonded { member: 50, pool_id: 1, bonded: 50, joined: true }, - Event::PaidOut { member: 10, pool_id: 1, payout: 10 }, - ] + vec![Event::PaidOut { member: 10, pool_id: 1, payout: 10 },] ); // last recorded reward counter at the time of this member's payout is 1 assert_eq!(PoolMembers::::get(10).unwrap(), del(10, 1)); @@ -795,7 +791,6 @@ mod claim_payout { assert_eq!(Balances::free_balance(&10), 15 + 5); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 20); - // CHECK // Given del 40 hasn't claimed and the reward pool has just earned 400 assert_ok!(Balances::mutate_account(&default_reward_account(), |a| a.free += 400)); assert_eq!(Balances::free_balance(&default_reward_account()), ed + 420); @@ -864,13 +859,10 @@ mod claim_payout { fn reward_payout_errors_if_a_member_is_fully_unbonding() { ExtBuilder::default().add_members(vec![(11, 11)]).build_and_execute(|| { // fully unbond the member. - assert_ok!(Pools::fully_unbond(Origin::signed(11), 11)); - - let (mut member, mut bonded_pool, mut reward_pool) = - Pools::get_member_with_pools(&11).unwrap(); + assert_ok!(fully_unbond_permissioned(11)); assert_noop!( - Pools::do_reward_payout(&11, &mut member, &mut bonded_pool, &mut reward_pool,), + Pools::claim_payout(Origin::signed(11)), Error::::FullyUnbonding ); From 3efe9f5348d993b6b2c787115aad841c01acc14b Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 10 Jul 2022 11:37:38 +0100 Subject: [PATCH 63/65] fmt --- frame/nomination-pools/src/migration.rs | 8 ++------ frame/nomination-pools/src/tests.rs | 5 +---- frame/nomination-pools/test-staking/src/mock.rs | 8 +++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/frame/nomination-pools/src/migration.rs b/frame/nomination-pools/src/migration.rs index 6740a2167a80f..f2abfe29dfbf7 100644 --- a/frame/nomination-pools/src/migration.rs +++ b/frame/nomination-pools/src/migration.rs @@ -363,12 +363,8 @@ pub mod v2 { assert_eq!(Pallet::::on_chain_storage_version(), 2); // no reward or bonded pool has been skipped. - assert_eq!( - RewardPools::::iter().count() as u32, RewardPools::::count() - ); - assert_eq!( - BondedPools::::iter().count() as u32, BondedPools::::count() - ); + assert_eq!(RewardPools::::iter().count() as u32, RewardPools::::count()); + assert_eq!(BondedPools::::iter().count() as u32, BondedPools::::count()); // all reward pools must have exactly ED in them. This means no reward can be claimed, // and that setting reward counters all over the board to zero will work henceforth. diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index b3354b7a06970..a2c2f85f2e17d 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -861,10 +861,7 @@ mod claim_payout { // fully unbond the member. assert_ok!(fully_unbond_permissioned(11)); - assert_noop!( - Pools::claim_payout(Origin::signed(11)), - Error::::FullyUnbonding - ); + assert_noop!(Pools::claim_payout(Origin::signed(11)), Error::::FullyUnbonding); assert_eq!( pool_events_since_last_call(), diff --git a/frame/nomination-pools/test-staking/src/mock.rs b/frame/nomination-pools/test-staking/src/mock.rs index 5aca68a523950..852b2c319f376 100644 --- a/frame/nomination-pools/test-staking/src/mock.rs +++ b/frame/nomination-pools/test-staking/src/mock.rs @@ -16,7 +16,13 @@ // limitations under the License. use frame_election_provider_support::VoteWeight; -use frame_support::{assert_ok, pallet_prelude::*, parameter_types, traits::{ConstU64, ConstU8}, PalletId}; +use frame_support::{ + assert_ok, + pallet_prelude::*, + parameter_types, + traits::{ConstU64, ConstU8}, + PalletId, +}; use sp_runtime::{ traits::{Convert, IdentityLookup}, FixedU128, From 84a2639d1e0b6abc9e7a7a27d930c5196e5563a2 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 10 Jul 2022 12:05:16 +0100 Subject: [PATCH 64/65] add one last test --- frame/nomination-pools/src/mock.rs | 27 +++++++++++-- frame/nomination-pools/src/tests.rs | 59 +++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 05e5c44824b5c..14c367553f423 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -216,9 +216,20 @@ frame_support::construct_runtime!( } ); -#[derive(Default)] pub struct ExtBuilder { members: Vec<(AccountId, Balance)>, + max_members: Option, + max_members_per_pool: Option, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { + members: Default::default(), + max_members: Some(4), + max_members_per_pool: Some(3), + } + } } impl ExtBuilder { @@ -243,6 +254,16 @@ impl ExtBuilder { self } + pub(crate) fn max_members(mut self, max: Option) -> Self { + self.max_members = max; + self + } + + pub(crate) fn max_members_per_pool(mut self, max: Option) -> Self { + self.max_members_per_pool = max; + self + } + pub(crate) fn build(self) -> sp_io::TestExternalities { let mut storage = frame_system::GenesisConfig::default().build_storage::().unwrap(); @@ -251,8 +272,8 @@ impl ExtBuilder { min_join_bond: 2, min_create_bond: 2, max_pools: Some(2), - max_members_per_pool: Some(3), - max_members: Some(4), + max_members_per_pool: self.max_members_per_pool, + max_members: self.max_members, } .assimilate_storage(&mut storage); diff --git a/frame/nomination-pools/src/tests.rs b/frame/nomination-pools/src/tests.rs index a2c2f85f2e17d..9989893d86462 100644 --- a/frame/nomination-pools/src/tests.rs +++ b/frame/nomination-pools/src/tests.rs @@ -1878,6 +1878,65 @@ mod claim_payout { assert_eq!(Balances::free_balance(&10), 5 + 5 + 13 + 10 + 1); }) } + + #[test] + fn claim_payout_large_numbers() { + let unit = 10u128.pow(12); // akin to KSM + ExistentialDeposit::set(unit); + StakingMinBond::set(unit * 1000); + + ExtBuilder::default() + .max_members(Some(4)) + .max_members_per_pool(Some(4)) + .add_members(vec![(20, 1500 * unit), (21, 2500 * unit), (22, 5000 * unit)]) + .build_and_execute(|| { + // some rewards come in. + assert_eq!(Balances::free_balance(&default_reward_account()), unit); + Balances::mutate_account(&default_reward_account(), |f| f.free += unit / 1000) + .unwrap(); + + // everyone claims + assert_ok!(Pools::claim_payout(Origin::signed(10))); + assert_ok!(Pools::claim_payout(Origin::signed(20))); + assert_ok!(Pools::claim_payout(Origin::signed(21))); + assert_ok!(Pools::claim_payout(Origin::signed(22))); + + assert_eq!( + pool_events_since_last_call(), + vec![ + Event::Created { depositor: 10, pool_id: 1 }, + Event::Bonded { + member: 10, + pool_id: 1, + bonded: 1000000000000000, + joined: true + }, + Event::Bonded { + member: 20, + pool_id: 1, + bonded: 1500000000000000, + joined: true + }, + Event::Bonded { + member: 21, + pool_id: 1, + bonded: 2500000000000000, + joined: true + }, + Event::Bonded { + member: 22, + pool_id: 1, + bonded: 5000000000000000, + joined: true + }, + Event::PaidOut { member: 10, pool_id: 1, payout: 100000000 }, + Event::PaidOut { member: 20, pool_id: 1, payout: 150000000 }, + Event::PaidOut { member: 21, pool_id: 1, payout: 250000000 }, + Event::PaidOut { member: 22, pool_id: 1, payout: 500000000 } + ] + ); + }) + } } mod unbond { From e7673f8b514d24309793dd308aa3da3abdbab6b1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 12 Jul 2022 17:37:49 +0100 Subject: [PATCH 65/65] fmt --- frame/nomination-pools/src/mock.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frame/nomination-pools/src/mock.rs b/frame/nomination-pools/src/mock.rs index 14c367553f423..042a0b666efb1 100644 --- a/frame/nomination-pools/src/mock.rs +++ b/frame/nomination-pools/src/mock.rs @@ -224,11 +224,7 @@ pub struct ExtBuilder { impl Default for ExtBuilder { fn default() -> Self { - Self { - members: Default::default(), - max_members: Some(4), - max_members_per_pool: Some(3), - } + Self { members: Default::default(), max_members: Some(4), max_members_per_pool: Some(3) } } }